Skip to content
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

Support x-nullable extension for swagger #45

Closed
Stranger6667 opened this issue Sep 12, 2019 · 0 comments · Fixed by #74
Closed

Support x-nullable extension for swagger #45

Stranger6667 opened this issue Sep 12, 2019 · 0 comments · Fixed by #74

Comments

@Stranger6667
Copy link
Member

Stranger6667 commented Sep 12, 2019

From https://help.apiary.io/api_101/swagger-extensions/#x-nullable:

As it is not possible to declare null as an additional type to schemas in Swagger 2 this brings a limitation where you cannot define types which are nullable. In OAS3 this limitation is removed with the introduction of the nullable property which when set to true allows null to be a value alongside the original value(s) or type(s). This feature is backported to our Swagger 2 parser as a vendored extension x-nullable.

For example, to declare a schema for a type that may be a string or null:

type: string
x-nullable: true

x-nullable may also be used in conjunction with enumerations. In the below example the schema represents that the permitted values are either one of the strings north, east, south, west or null:

enum:
  - north
  - east
  - south
  - west
x-nullable: true

It will be a valuable addition to support it since it is quite popular (at least in kiwi.com). It could be done with transforming relevant schema to correct JSON schema representation, for example with anyOf

{
  "anyOf": [
    { "type": "string", "maxLength": 5 },
    { "type": "null"}
  ]
}
@Stranger6667 Stranger6667 changed the title Support x-nullable convention for swagger Support x-nullable extension for swagger Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants