json-schema-migrate
json-schema-migrate copied to clipboard
attention points while converting draft-04 to draft-07
Hi,
I migrated the swagger v2.0 spec from draft04 to draft07 and although the tool helped a lot (thanks for that !) I ran into a few issues I thought I'd share so maybe other people can benefit.
The swagger 2.0 spec contained a number of refs to the draft04 schema itself,e.g:
"exclusiveMinimum": {
"$ref": "http://json-schema.org/draft-04/schema#/properties/exclusiveMinimum"
},
"maxLength": {
"$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveInteger"
},
I changed these by hand to:
"exclusiveMinimum": {
"$ref": "http://json-schema.org/draft-07/schema#/properties/exclusiveMinimum"
},
"maxLength": {
"$ref": "http://json-schema.org/draft-07/schema#/definitions/nonNegativeInteger"
},
It would be nice if the tool would support this. ( "positiveInteger" being replaced by "nonNegativeInteger" was quite easy to spot ;-))
The second one took me a bit more time to figure out:
- json-schema-migrate incorrectly turned:
"parametersList": {
"type": "array",
"description": "The parameters needed to send a valid API call.",
"additionalItems": false,
"items": {
"oneOf": [
{
"$ref": "#/definitions/parameter"
},
{
"$ref": "#/definitions/jsonReference"
}
]
},
"uniqueItems": true
},
into:
"parametersList": {
"type": "array",
"description": "The parameters needed to send a valid API call.",
"additionalItems": false,
"items": [{
"oneOf": [
{
"$ref": "#/definitions/parameter"
},
{
"$ref": "#/definitions/jsonReference"
}
]
}],
"uniqueItems": true
},
which resulted in an error that the parameter list could only have 1 item. Removing the square brackets around the object in "items" again solved this one.
Thanks again, Hans
I also had to convert "media": {"binaryEncoding": "..."} to "contentEncoding", per https://json-schema.org/draft-07/json-schema-release-notes.html
And added "type": "object" alongside "additionalProperties"
I also had to convert "media": {"binaryEncoding": "..."} to "contentEncoding"
that may be added
And added "type": "object" alongside "additionalProperties"
this changes validation result, so it should not be added. In JSON Schema "type" is optional, and schema without "type" simply allows non-objects. While it's often indicates a mistake that Ajv strict mode would catch, this is not something this tool should change - missing type can be intentional and completely valid.