-
Notifications
You must be signed in to change notification settings - Fork 12
Remove compat.jl in favor of explicitly breaking changes #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,9 +33,8 @@ schema = Schema(spec; parent_dir="./schemas") | |
|
|
||
| ### 2. `SingleIssue` Type Replaced by `ValidationResult` | ||
|
|
||
| The `SingleIssue` type from v1.x has been replaced by `ValidationResult`. For | ||
| backwards compatibility, `SingleIssue` is aliased to `ValidationResult`, so | ||
| existing `isa` checks will continue to work. | ||
| The `SingleIssue` type from v1.x has been removed and replaced by | ||
| `ValidationResult`. | ||
|
|
||
| **v1.x:** | ||
| ```julia | ||
|
|
@@ -56,6 +55,31 @@ if result !== nothing | |
| end | ||
| ``` | ||
|
|
||
| ### 3. `diagnose` Function | ||
|
|
||
| The previously deprecated `diagnose` function has been removed. Use | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed. This was from a long time ago. |
||
| `validate(schema, data)` instead. | ||
|
|
||
| ### 4. Inverse Argument Order | ||
|
|
||
| The `validate` and `isvalid` functions where `schema` is the second argument | ||
| have been removed. `schema` must be the first argument. | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto here. There should be only one way to do things. |
||
| ```julia | ||
| validate(data, schema) # old | ||
| validate(schema, data) # new | ||
|
|
||
| isvalid(data, schema) # old | ||
| isvalid(schema, data) # new | ||
| ``` | ||
|
|
||
| ### 5. `required` Without `properties` | ||
|
|
||
| v1.x supported non-standard schemas with `required` field and no `properties`. | ||
| In v2.0, you must specify `properties` if `required` is present. | ||
| ```julia | ||
| schema = Schema(Dict("type" => "object", "required" => ["foo"])) # Not allowed | ||
| ``` | ||
|
|
||
| ## API Compatibility | ||
|
|
||
| The following v1.x patterns are fully supported in v2.0: | ||
|
|
@@ -86,42 +110,13 @@ using JSONSchema | |
| isvalid(schema, data) # Returns true or false | ||
| ``` | ||
|
|
||
| ### `schema.data` Field Access | ||
|
|
||
| ```julia | ||
| schema = Schema(Dict("type" => "object")) | ||
| schema.data["type"] # Works - maps to schema.spec | ||
| ``` | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this was ever part of the public API |
||
|
|
||
| ### Boolean Schemas | ||
|
|
||
| ```julia | ||
| Schema(true) # Accepts everything | ||
| Schema(false) # Rejects everything | ||
| ``` | ||
|
|
||
| ### Inverse Argument Order | ||
|
|
||
| ```julia | ||
| validate(data, schema) # Works - swaps to validate(schema, data) | ||
| isvalid(data, schema) # Works - swaps to isvalid(schema, data) | ||
| ``` | ||
|
|
||
| ### `required` Without `properties` | ||
|
|
||
| ```julia | ||
| schema = Schema(Dict("type" => "object", "required" => ["foo"])) | ||
| isvalid(schema, Dict("bar" => 1)) # Returns false (v1.x behavior) | ||
| ``` | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a weird one. The current code you added to work-around was un-tested. I've removed, we can always add it back if someone complains |
||
|
|
||
| ### `diagnose` Function (Deprecated) | ||
|
|
||
| ```julia | ||
| diagnose(data, schema) # Works but emits deprecation warning | ||
| ``` | ||
|
|
||
| Use `validate(schema, data)` instead. | ||
|
|
||
| ## New Features in v2.0 | ||
|
|
||
| ### Schema Generation from Types | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,17 @@ end | |
| Schema(spec::AbstractString) = Schema(JSON.parse(spec)) | ||
| Schema(spec::AbstractVector{UInt8}) = Schema(JSON.parse(spec)) | ||
|
|
||
| # Boolean schemas are part of the draft6 specification. | ||
| function Schema(b::Bool) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a compat thing. It's part of the spec: https://github.com/json-schema-org/JSON-Schema-Test-Suite/blob/main/tests/draft6/boolean_schema.json |
||
| if b | ||
| # true schema accepts everything - empty schema | ||
| return Schema{Any}(Any, Object{String, Any}(), nothing) | ||
| else | ||
| # false schema rejects everything - use "not: {}" pattern | ||
| return Schema{Any}(Any, Object{String, Any}("not" => Object{String, Any}()), nothing) | ||
| end | ||
| end | ||
|
|
||
| # Helper functions for $ref support | ||
|
|
||
| """ | ||
|
|
@@ -797,11 +808,6 @@ end | |
| # Also support JSON.Schema (which is an alias for JSONSchema.Schema) | ||
| # and inverse argument order for v1.5.0 compatibility | ||
| function validate(schema, instance; resolver=nothing) | ||
| # Handle inverse argument order (v1.5.0 compat): validate(data, schema) | ||
| if instance isa Schema | ||
| return validate(instance, schema; resolver=resolver) | ||
| end | ||
|
|
||
| # Handle JSON.Schema (which is aliased to JSONSchema.Schema) | ||
| if typeof(schema).name.module === JSON && hasfield(typeof(schema), :type) && hasfield(typeof(schema), :spec) | ||
| return validate(Schema{typeof(schema).parameters[1]}(schema.type, schema.spec, nothing), instance; resolver=resolver) | ||
|
|
@@ -883,11 +889,6 @@ function Base.isvalid(schema::Schema{T}, instance::T; verbose::Bool=false) where | |
| return is_valid | ||
| end | ||
|
|
||
| # Also support inverse argument order for v1.5.0 compatibility | ||
| function Base.isvalid(instance, schema::Schema; verbose::Bool=false) | ||
| return Base.isvalid(schema, instance; verbose=verbose) | ||
| end | ||
|
|
||
| # Internal: Validate an instance against a schema | ||
| function _validate_instance(schema_obj, instance, ::Type{T}, path::String, errors::Vector{String}, verbose::Bool, root::Object{String, Any}) where {T} | ||
| # Handle $ref - resolve and validate against resolved schema | ||
|
|
@@ -906,30 +907,30 @@ function _validate_instance(schema_obj, instance, ::Type{T}, path::String, error | |
| if isstructtype(T) && isconcretetype(T) && haskey(schema_obj, "properties") | ||
| properties = schema_obj["properties"] | ||
| required = get(schema_obj, "required", String[]) | ||
|
|
||
| style = StructUtils.DefaultStyle() | ||
| all_field_tags = StructUtils.fieldtags(style, T) | ||
|
|
||
| for i in 1:fieldcount(T) | ||
| fname = fieldname(T, i) | ||
| ftype = fieldtype(T, i) | ||
| fvalue = getfield(instance, fname) | ||
|
|
||
| # Get field tags | ||
| field_tags = haskey(all_field_tags, fname) ? all_field_tags[fname] : nothing | ||
| tags = field_tags isa NamedTuple && haskey(field_tags, :json) ? field_tags.json : nothing | ||
|
|
||
| # Skip ignored fields | ||
| if tags isa NamedTuple && get(tags, :ignore, false) | ||
| continue | ||
| end | ||
|
|
||
| # Get JSON name (may be renamed) | ||
| json_name = string(fname) | ||
| if tags isa NamedTuple && haskey(tags, :name) | ||
| json_name = string(tags.name) | ||
| end | ||
|
|
||
| # Check if field is in schema | ||
| if haskey(properties, json_name) | ||
| field_schema = properties[json_name] | ||
|
|
@@ -1176,13 +1177,6 @@ function _validate_value(schema, value, ::Type{T}, tags, path::String, errors::V | |
|
|
||
| # Dict/Object validation (properties, patternProperties, propertyNames for Dicts) | ||
| if value isa AbstractDict | ||
| # Validate required fields even without properties (v1.5.0 compat) | ||
| # This is called from compat.jl and handles the case where "required" | ||
| # is specified without "properties" | ||
| if !haskey(schema, "properties") && haskey(schema, "required") | ||
| _validate_required_for_dict(schema, value, path, errors) | ||
| end | ||
|
|
||
| # Validate properties for Dict | ||
| if haskey(schema, "properties") | ||
| properties = schema["properties"] | ||
|
|
@@ -1349,13 +1343,13 @@ function _validate_string(schema, tags, value::String, path::String, errors::Vec | |
| if min_len !== nothing && length(value) < min_len | ||
| push!(errors, "$path: string length $(length(value)) is less than minimum $min_len") | ||
| end | ||
|
|
||
| # Check maxLength | ||
| max_len = get(schema, "maxLength", nothing) | ||
| if max_len !== nothing && length(value) > max_len | ||
| push!(errors, "$path: string length $(length(value)) exceeds maximum $max_len") | ||
| end | ||
|
|
||
| # Check pattern | ||
| pattern = get(schema, "pattern", nothing) | ||
| if pattern !== nothing | ||
|
|
@@ -1368,7 +1362,7 @@ function _validate_string(schema, tags, value::String, path::String, errors::Vec | |
| # Invalid regex pattern - skip validation | ||
| end | ||
| end | ||
|
|
||
| # Format validation (basic checks) | ||
| format = get(schema, "format", nothing) | ||
| if format !== nothing | ||
|
|
@@ -1417,7 +1411,7 @@ function _validate_number(schema, tags, value::Number, path::String, errors::Vec | |
| push!(errors, "$path: value $value is less than minimum $min_val") | ||
| end | ||
| end | ||
|
|
||
| # Check maximum | ||
| max_val = get(schema, "maximum", nothing) | ||
| exclusive_max = get(schema, "exclusiveMaximum", false) | ||
|
|
@@ -1428,7 +1422,7 @@ function _validate_number(schema, tags, value::Number, path::String, errors::Vec | |
| push!(errors, "$path: value $value exceeds maximum $max_val") | ||
| end | ||
| end | ||
|
|
||
| # Check multipleOf | ||
| multiple = get(schema, "multipleOf", nothing) | ||
| if multiple !== nothing | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit weird to keep this only so
isaworks. If anyone is constructing them or trying to query field values it will break.