json-schema-migrate icon indicating copy to clipboard operation
json-schema-migrate copied to clipboard

attention points while converting draft-04 to draft-07

Open seriousme opened this issue 4 years ago • 3 comments
trafficstars

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

seriousme avatar May 14 '21 21:05 seriousme

I also had to convert "media": {"binaryEncoding": "..."} to "contentEncoding", per https://json-schema.org/draft-07/json-schema-release-notes.html

davedoesdev avatar Jan 13 '22 18:01 davedoesdev

And added "type": "object" alongside "additionalProperties"

davedoesdev avatar Jan 13 '22 18:01 davedoesdev

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.

epoberezkin avatar Jan 15 '22 08:01 epoberezkin