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.

Clarify spec about schemas with multiple types

See original GitHub issue

In #1401 of swagger-core, @webron mentioned that specifying multiple types for a schema is not valid.

The 2.0 Spec says for a schema object:

The following properties are taken directly from the JSON Schema definition and follow the same specifications:
[…]

  • type

JSON Schema validation says in section 5.5.2:

5.5.2. type

5.5.2.1. Valid values

The value of this keyword MUST be either a string or an array. If it is an array, elements of the array MUST be strings and MUST be unique.

String values MUST be one of the seven primitive types defined by the core specification.

5.5.2.2. Conditions for successful validation

An instance matches successfully if its primitive type is one of the types defined by keyword. Recall: “number” includes “integer”.

I would interpret this as my type: ["integer", "string"] property being valid JSON Schema, and thus also valid Swagger.

While the "null" type name is not available in swagger due to it missing in the list of available types, the same consideration applies to something like "type": ["integer", "string"]. If this is not supposed to be valid, the sentence quoted above needs to be changed.

(Also, instead of referring to the “latest” version of JSON schema, I would explicitly name the version used, so the validity of Swagger documents doesn’t suddenly change whenever there is a new version of JSON schema.)

Related issues I found here: #297, #229, #403.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

28reactions
RoyHPcommented, May 28, 2017

+1 for supporting array of types according to JSON Schema, we need this. I understand there’s a disclaimer indicating that JSON Schema is not entirely supported, but if you’re supporting the type key in the first place, it really ought to behave in the same manner.

0reactions
webroncommented, Feb 23, 2017

Not sure if there’s an existing ticket or not, would suggest searching the repo. Given the added support for oneOf, the need to support direct multi-types seems lower, but feedback is welcome.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Schema in Psychology: Definition, Types, Examples
Object schemas are just one type of schema that focuses on what an inanimate object is and how it works.
Read more >
What is a schema? - TechTarget
A database schema is (generally) broadly divided into two categories: physical database schema that defines how the data-like files are actually stored; and ......
Read more >
Schema Therapy: Theory, Schemas, Modes, Goals, and More
Schema modes help therapists group schemas together so they can address them as a single state of mind, rather than individual traits. Schema ......
Read more >
The Role of a Schema in Psychology
There are four main types of schemas. These are centered around objects, the self, roles, and events. Schemas can be changed and reconstructed ......
Read more >
Can I Add Multiple Schema Types to One Page?
What we want to do is add a couple of different types of schema. You can go over to schema.org and move through...
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