API - How to have valid nullable fields in swagger ?
See original GitHub issueHi,
Thanks for express-openapi. I really appreciate to use it 😃 But I have a problem, I need to expose fields which the type strings that could be nullable. This following code works when i run the server based on express-api :
responses: { 200: { schema: { title: 'MyObject', properties: { myfield: { type: ['string', 'null'],
But it’s not valid against Swagger (editor.swagger.io) 😦
Semantic error at definitions.MyObject.myfield “type” should be a string
Do you have a valid way to use nullable fields with express-openapi ?
Thanks by advance !
And Thanks for this top library.
Regards,
F.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
nullable fields in swagger on node.js
nullable field is supported in OpenAPI (fka Swagger) ... It's a valid Swagger type definition, and still appears as expected in Swagger UI....
Read more >How to manage nullable properties - Jane - Read the Docs
By doing this, any property of your schema will be considered nullable. ... Which support null type, you just have to add it...
Read more >Data Types
OpenAPI 3.0 does not have an explicit null type as in JSON Schema, but you can use nullable: true to specify that the...
Read more >Using Optional and Nullable Properties in API Requests
Learn how optional and nullable properties can be used flexibly in combinations in each parameter of your API requests made from a SDK....
Read more >How to specify a property can be null or a reference
“null” is not a valid type in swagger, nor is “anyOf” or multi-types. ... Please NOTE: This electronic message, including any attachments, may...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is there a way to correctly validate requests/responses having nullable fields with OpenAPI v3?
The OAI specifies that nullable fields should use the keyword “nullable”, which doesn’t seem to be implemented in any JS library for validation. There are several discussions related to this topic: https://github.com/epoberezkin/ajv/issues/486 https://github.com/OAI/OpenAPI-Specification/issues/1389 https://github.com/OAI/OpenAPI-Specification/issues/229
I started working on trying to convert OAI’s syntax to JSON-schema’s (see https://github.com/kogosoftwarellc/open-api/pull/127). Does it make sense to work in that direction?
@fdescamps I recently adding schema extension support. Should address this.