nullable fields in swagger on node.js

非 Y 不嫁゛ 提交于 2019-12-01 03:03:34

SwaggerUI doesn't support nullable types (please, see here). But I used nullable properties as:

type: ['string','null']

After that this property disappears from UI, but validation still worked.

Nazar Gargol

nullable field is supported in OpenAPI (fka Swagger) Specification v3.0.0, but not in v2.0. Nullable types are defined as follows:

# Can be string or null
type: string
nullable: true

Instead of add null in type property, you can use default property instead.

Swagger.json property definition example:

"due_date": {
  "type": "string",
  "description": "Due date",
  "default": "null"
},

It's a valid Swagger type definition, and still appears as expected in Swagger UI.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!