-
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
Swagger UI's display of multiple-typed attributes is confusing #4951
Comments
OpenAPI does not support The correct way to define multi-type OpenAPI schemas is components:
schemas:
FooType:
oneOf:
- type: string
- type: number
nullable: true Check out the Data Types guide. |
I can't generally paste schema into the Swagger Editor, due to it being hosted on a third party site, among other issues. I suppose there's nothing actionable here, then, since I was under the apparently false impression that OpenAPI was incorporating JSONSchema for validation. This is a more broad complaint, but it would be extremely helpful if Swagger UI itself validated OpenAPI schema it were presented with, and presented the user with actionable error messages. (Its usual response to a malformed schema is to crash, which makes debugging nigh impossible.) |
OpenAPI does incorporate JSON Schema, but there are limits, which the specification covers in detail (emphasis mine):
Thanks for the feedback 😄 We've made the decision to keep validation in Swagger Editor, since the UI is commonly used by folks that can't edit the document (think of a company using Swagger UI to host their documentation... if I'm using their API and there's a bug in their document, why should I get a validation error about it?), while the Editor is almost always used by someone that has the power to fix any errors that crop up. |
It's clear that OpenAPI has diverged from JSON Schema. What's not clear is why this compromise was made? Can you point me to an issue that points out why? From an external tooling providers perspective, this makes is difficult to use standard JSON Schema tools with OpenAPI. |
@creichert - that's a great question for the OpenAPI Technical Development Committee (which I'm not a part of). The OpenAPI issue tracker is a good place to start - here's a historical discussion concerning the JSON Schema constraints in Swagger/OpenAPI 2.0: OAI/OpenAPI-Specification#333. Also, OAI/OpenAPI-Specification#1263. You may be interested in reading through the |
Closing due to inactivity. This is simply to keep our issue tracker clean - feel free to comment if there are any further thoughts or concerns, and we'll be happy to reopen this issue. |
Q&A (please complete the following information)
Content & configuration
Example Swagger/OpenAPI definition:
(The important part is the JSON Schema
type
field being a list.Swagger-UI configuration options:
We use the defaults in the dist assets, except we set
validatorUrl
tonull
.Describe the bug you're encountering
The output is confusing. This is how the above JSONSchema will be rendered by Swagger UI:
Some whitespace between the different possible types, perhaps a
,
, or some indication that it must be one of those types, would greatly clarify what is happening.The text was updated successfully, but these errors were encountered: