func translateNumeric(schema Numeric) (*relapse.Pattern, error) { v := Number() list := []funcs.Bool{} notNum := funcs.Not(funcs.TypeDouble(Number())) if schema.MultipleOf != nil { mult := MultipleOf(v, funcs.DoubleConst(*schema.MultipleOf)) list = append(list, funcs.Or(mult, notNum)) } if schema.Maximum != nil { lt := funcs.DoubleLE(v, funcs.DoubleConst(*schema.Maximum)) if schema.ExclusiveMaximum { lt = funcs.DoubleLt(v, funcs.DoubleConst(*schema.Maximum)) } list = append(list, funcs.Or(lt, notNum)) } if schema.Minimum != nil { lt := funcs.DoubleGE(v, funcs.DoubleConst(*schema.Minimum)) if schema.ExclusiveMinimum { lt = funcs.DoubleGt(v, funcs.DoubleConst(*schema.Minimum)) } list = append(list, funcs.Or(lt, notNum)) } if len(list) == 0 { return combinator.Value(funcs.TypeDouble(v)), nil } return combinator.Value(and(list)), nil }
func translateType(typ SimpleType) (*relapse.Pattern, error) { switch typ { case TypeArray, TypeObject: //This does not distinguish between arrays and objects return combinator.Many(combinator.InAny(combinator.Any())), nil case TypeBoolean: return combinator.Value(funcs.TypeBool(funcs.BoolVar())), nil case TypeInteger: return combinator.Value(funcs.TypeDouble(Integer())), nil case TypeNull: //TODO null is not being returned by json parser, but is also not empty return combinator.Value(funcs.Not( funcs.Or( funcs.TypeDouble(Number()), funcs.Or( funcs.TypeBool(funcs.BoolVar()), funcs.TypeString(funcs.StringVar()), ), ), )), nil case TypeNumber: return combinator.Value(funcs.TypeDouble(Number())), nil case TypeString: return combinator.Value(funcs.TypeString(funcs.StringVar())), nil } panic(fmt.Sprintf("unknown simpletype: %s", typ)) }