speccy icon indicating copy to clipboard operation
speccy copied to clipboard

Support JSON schema patternProperties

Open austinh opened this issue 7 years ago • 2 comments

Right now, referencing a json-schema that uses "patternProperties" seems to cause a linter error. Would be great if this standard (draft 4) feature was supported without throwing errors. This is currently not supported by openapi 3, but if you use json-schema through https://github.com/wework/json-schema-to-openapi-schema, you need this property.

#/paths/~1api~1v7~1floors/get/responses/200/content/application~1json/properties/attributes
Schema object cannot have additionalProperty: patternProperties

Detailed description

Here's an example of a json schema that will cause speccy to error:

"properties": {
  "attributes": {
      "description": "Members of the attributes object (\"attributes\") represent information about the resource object in which it's defined.",
      "type": "object",
      "patternProperties": {
        "^(?!relationships$|links$)\\w[-\\w_]*$": {
          "description": "Attributes may contain any valid JSON value."
        }
      },
      "additionalProperties": false
    }
}

Context

I am currently using jsonapi's json-schema: https://jsonapi.org/schema and this schema uses patternProperties. This is very helpful when documenting a jsonapi to take use of the allOf inheritance pattern and conform to jsonapi.

Your environment

Include as many relevant details about the environment you experienced the bug in and how to reproduce it.

  • Node Version: v10.1.0

austinh avatar Oct 25 '18 02:10 austinh

Do you have a proposal for how to translate a JSON schema containing patternProperties into an OAS3 schema object? All I can think of doing is forcing additionalProperties to true.

MikeRalphson avatar Oct 25 '18 05:10 MikeRalphson

Interestingly the conversion package json-schema-to-openapi-schema already says it does that:

https://github.com/wework/json-schema-to-openapi-schema/blob/master/test/pattern_properties.test.js

Austin I’ll grab the spec and mush it through the test suite to see what happens. Thank you!

philsturgeon avatar Oct 25 '18 12:10 philsturgeon