-
Notifications
You must be signed in to change notification settings - Fork 9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OpenAPI 3.1.0 support: add rendering support for JSON Schema 2020-12 #8513
Comments
Existing implementationsHere is the list of researched existing implementations. atlassian json viewerSupports JSON Schema Draft 07 only. Repo: https://github.com/atlassian-labs/json-schema-viewer asyncapi-reactSupports rendring JSON Schema Draft 04/05. To me personally, this looks like the most understandable representation. Repo: spotlight json-schema-viewerSupports JSON Schema Draft 04/05. Repo: https://github.com/stoplightio/json-schema-viewer SwaggerUISupports JSON Schema Draft 04/05. UI is not the best on embedded (nested) schemas. Is intermingled with OpenAPI 3.0.x related features. |
Core vocabulary supportIdentifiers$schemaThe $schema keyword is used to declare which JSON Schema draft version is being used for the schema definition. It provides important context about the schema, but it doesn't affect the validation or interpretation of the schema itself. Therefore, it's not necessary to render it in the visual representation of the schema, as it doesn't provide any additional information to the user. However, it may be useful to display it in a text format for debugging or troubleshooting purposes. An example can be the case where $vocabularyIt could be useful to render the $vocabulary keyword in the JSON Schema 2020-12. The $vocabulary keyword allows us to specify a vocabulary to use for certain keywords and properties. For example, if we are using the draft-07 vocabulary, we can use the minimum and maximum keywords to specify numeric ranges. However, if we are using the geographical-location vocabulary, we may use latitude and longitude instead. Rendering the $vocabulary keyword could provide helpful context to understand which vocabulary is being used, and which keywords are available. $idThe $id keyword is used to associate a URI with the schema, which can be used to reference the schema from other schemas or documents. By rendering this keyword, users can see the URI associated with the schema and understand how it is used in the larger context of the application or system.
$anchorWhile it may not have a significant effect on the overall rendering of the schema, it can be useful to include the $anchor value in the rendering for reference purposes.
$dynamicAnchorThis keyword is currently not supported by ApiDOM, but we'll include this keyword into schema rendering. $refFor the MVP, it's best not to handle $ref rendering at all. As resolution and derferencing in JSON Schema 2020-12 is extremely complex, this renderer should only be concerned by rendering the schema into object representation. We can create an intercepting hook for $ref keyword, which will allow to dereference the $ref keyword before the result of dereferencing is rendered. $dynamicRefThis keyword is currently not supported by ApiDOM, but we'll include this keyword into schema rendering. $defsIt would make sense to render the $defs keyword if the schema is used in an OpenAPI 3.1.0 context. The $defs keyword is part of the JSON Schema specification and is used to define reusable schemas within a JSON Schema document. OpenAPI 3.1.0 uses JSON Schema as its schema language, and the Components Object in OpenAPI 3.1.0 is used to define reusable schemas, parameters, and responses. The Components Object can include $ref references to schemas defined in the $defs keyword, so it would be useful to render the $defs keyword in the visual representation of the JSON Schema in an OpenAPI 3.1.0 context. $commentWe will render $comment keyword, as it might rely important information attached to the schema. ApplicatorsKeywords for Applying Subschemas With LogicallOfWill be visually represented as anyOfWill be visually represented as oneOfWill be visually represented as notWill be visually represented as Keywords for Applying Subschemas ConditionallyifWill be visually represented as thenWill be visually represented as elseWill be visually represented as dependentSchemasWill be visually represented in the same way as the Keywords for Applying Subschemas to ArraysprefixItemsWill be visually represented as itemsWill be visually represented as containsWill be visually represented as Keywords for Applying Subschemas to ObjectspropertiesProperties are rendered as patternPropertiesPattern properties are rendered as additionalPropertiesCan have form of boolean or object. For propertyNamesWill be visually represented as A Vocabulary for Unevaluated LocationsunevaluatedItemsWill be visually represented as unevaluatedPropertiesWill be visually represented as |
Validation vocabulary supportValidation Keywords for Any Instance TypetypeThis keyword is already part of MVP1, where it forms the source of truth for determining the schema type. enumEvery item of the enum will be represented as string. const
Validation Keywords for Numeric Instances (number and integer)multipleOfWill be rendered using maximumWill be rendered using exclusiveMaximumWill be rendered using minimumWill be rendered using exclusiveMinimumWill be rendered using Validation Keywords for StringsmaxLengthWill be rendered using minLengthWill be rendered using patternWill be rendered using Validation Keywords for ArraysmaxItemsWill be rendered using minItemsWill be rendered using uniqueItemsDepending on this field the label of the constraint will either be maxContainsWill be rendered using minContainsWill be rendered using Validation Keywords for ObjectsmaxPropertiesWill be rendered using minPropertiesWill be rendered using requiredWill be rendered as red star ( dependentRequiredFor every property from Vocabularies for Semantic Content With "format"formatWill be rendered using A Vocabulary for the Contents of String-Encoded DatacontentEncodingWill be rendered using contentMediaTypeWill be rendered using contentSchemaWill be visually represented as A Vocabulary for Basic Meta-Data AnnotationstitleWhen description
default
deprecatedWill be rendered as red readOnlyWill be rendered as gray writeOnlyWill be rendered as gray |
Handles schema cycles as well. Refs #8513
As JSON Schema 2020-12 can be represented as a Boolean Schema, different keyword detection needs to be used. Refs #8513
As JSON Schema 2020-12 can be represented as a Boolean Schema, different keyword detection needs to be used. Refs #8513
Hi @char0n, firstly thank you for sharing your research. With these changes, does Swagger UI support rendering JSON schema data in isolation, or only as a part of OpenAPI 3.1.0 support? |
The goal of this issue is to add rendering support for JSON Schema 2020-12 within SwaggerUI. Currently there isn't any JSON Schema 2020-12 capable renderer.
There are multiple ways how JSON Schema 2020-12 can be represented depending on the use case. This issue will deal with an Object Representation. In this approach, the JSON Schema is represented as a JavaScript object that can be used in the React application. The goal of this object representation is to visualize the JSON Schema is such a way, that person look at this representation will easily understand what the JSON Schema does.
Implementation for the renderer should be done in separate SwaggerUI plugin where all JSON Schema 2020-12 related code will be concentrated. This will allow further to possibly decouple this code from SwaggerUI in future. We should not use SwaggerUI plugin system features (to allow future decupling), but rather classic React ones (like contexts).
Implementation phases
MVP1
This phase includes rendering Core vocabulary identifier keywords. This includes:
properties
keyword so that MVP1 have some valuenever
as typeSchemas section
+ lazy schema resolutionintegrate deep linking into `Schemas section(not implemented for Draft 4 Schemas)defaultModelsExpandDepth
config optionCurrent visual representation
MVP2
MVP3
MVP4
The text was updated successfully, but these errors were encountered: