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.

API - How to have valid nullable fields in swagger ?

See original GitHub issue

Hi,

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:closed
  • Created 6 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
lzearcommented, Jun 28, 2018

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?

1reaction
jsdevelcommented, Jun 23, 2018

@fdescamps I recently adding schema extension support. Should address this.

Read more comments on GitHub >

github_iconTop 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 >

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