wework / speccy

Well Spectually 🤓 Enforce quality rules on your OpenAPI 3.0.x specifications.
http://speccy.io
MIT License
825 stars 78 forks source link

Support JSON schema patternProperties #186

Open austinh opened 5 years ago

austinh commented 5 years ago

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.

MikeRalphson commented 5 years ago

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.

philsturgeon commented 5 years ago

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!