question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Swagger UI's display of multiple-typed attributes is confusing

See original GitHub issue

Q&A (please complete the following information)

  • OS: OS X
  • Browser: Firefox Developer Edition
  • Version: 63.0b14
  • Method of installation: dist assets
  • Swagger-UI version: 3.19.3
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

Example Swagger/OpenAPI definition:

openapi: '3.0.0'
info:
  title: Foo API
  version: '0.1.0'
components:
  schemas:
    FooType:
      type: ['null', 'string', 'number']

(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 to null.

Describe the bug you’re encountering

The output is confusing. This is how the above JSONSchema will be rendered by Swagger UI:

The type is mushed together, i.e., nullstringnumber

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
shockeycommented, Oct 23, 2018

@thanatos:

I suppose there’s nothing actionable here, then, since I was under the apparently false impression that OpenAPI was incorporating JSONSchema for validation.

OpenAPI does incorporate JSON Schema, but there are limits, which the specification covers in detail (emphasis mine):

The Schema Object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. This object is an extended subset of the JSON Schema Specification Wright Draft 00.

Additional properties defined by the JSON Schema specification that are not mentioned here are strictly unsupported.

https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#schema-object


it would be extremely helpful if Swagger UI itself validated OpenAPI

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.

0reactions
shockeycommented, Jan 15, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is multiple types shown in a bad way in Swagger UI
Show activity on this post. In OpenAPI 3.0, type cannot be a list of types, it must be a single type. A nullable...
Read more >
Adding Examples - Swagger
Note for Swagger UI users: Support for multiple examples is available since Swagger UI 3.23.0 ... Note: Do not confuse example values with...
Read more >
OpenAPI Specification - Version 2.0 - Swagger
The schema exposes two types of fields. Fixed fields, which have a declared name, and Patterned fields, which declare a regex pattern for...
Read more >
Adding Examples - Swagger
Adding Examples. An API specification can include examples for: response MIME types,; schemas (data models),; individual properties in schemas.
Read more >
Media Types - Swagger
Media type is a format of a request or response body data. ... One or multiple media types go as child keywords of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found