Linting OpenAPI definitions with external JSON Schema references #27
Unanswered
jeremyfiel
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a scenario where we are using
openapi-cli
to lint our OpenAPI definitions and we are using a large amount of externally referenced JSON Schema Draft-04 definitions.Initially, I tried to lint our OAS definitions unsuccessfully because the number of errors reported for
$id
and$schema
are unbearable and the external definitions were never linted properly. This was due to OAS not fully supporting the full implementation of any JSON Schema dialect in prior versions (3.0.x)After some investigation and chatting with Ben Hutton (JSON Schema core lead), it appears OpenAPI 3.1.0 supports a new property
jsonSchemaDialect
. The behavior of this field allows definition at the top-level of your OAS definition to define which JSON draft schema should be used. The default is 2020-12 which was adopted by OAS 3.1.0. This property also allows definition of a specificdraft
in any defined schema throughout the document. Here's an example of that:source: https://github.com/readmeio/oas-examples/blob/main/3.1/json/schema-validation-top-level.json
The most interesting part of the behavior of
jsonSchemaDialect
is when a sub-schema has a different dialect defined from the top-level, that schema effectively becomes a sub-document of the original definition. That means, referencing a component from the top-level schema in the sub-schema doesn't resolve. Here's a great explanation of that behavior. http://json-schema.org/blog/posts/validating-openapi-and-json-schema#supporting-multiple-dialectsThe other interesting point of this behavior is now that the sub-schema is considered an external document, it's effectively the same as using a $ref to point to an external definition. This is where it becomes more interesting for us and takes me back to the original scenario of linting our OAS definitions with external JSON schema definitions. We have 1000's of extension files and schemas written in JSON Schema Draft-04 being referenced from our OAS definitions. All of our external definitions are well formed using the $schema property to define the draft in use. With OpenAPI 3.1.0 implementing JSON Schema 2020-12 as the default
jsonSchemaDialect
, it brings the ability to lint our external definitions where$id
and$schema
properties have been defined. No longer am I seeing errors by upgrading our OAS definitions to use 3.1.0.My questions for Redoc team are:
openapi lint
handle OAS 3.1.0 compatibility?If the tooling is properly supporting OAS 3.1.0 and also older JSON Schema dialects, we have literally resurrected years of "legacy" efforts into useful, functional schemas that can be properly linted as part of our adoption of OpenAPI into our design-first workflow.
Beta Was this translation helpful? Give feedback.
All reactions