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.

Remove "nullable" in OAS 3.1?

See original GitHub issue

Now that we have decided to discard SemVer (see PR #2243), IIRC it briefly came up on the last call that we could outright drop nullable instead of requiring that both nullable and type: "null" be supported.

Should we do this? I’d be happy to write a PR.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
handrewscommented, Aug 15, 2021

@rwalle61 it’s not much mentioned because it’s covered by JSON Schema and OAS 3.1 tries to avoid duplicating the JSON Schema spec unless it is needed to explain how JSON Schema and OAS-specific concepts interact.

What you are looking for is:

type: object
properties:
  foo:
    type: [string, "null"]

That’s the string "null", not the value null. The string "null" is the name of the type of the value null. The values in the type array can be in any order.

2reactions
rwalle61commented, Aug 15, 2021

Thanks for this and https://github.com/OAI/OpenAPI-Specification/pull/2246!

To confirm, how should an openapi doc describe an object with a property ‘foo’ that can be string or null - just like this?

type: object
properties:
  foo:
    type: string

I couldn’t find this described anywhere, and OpenAPI 3.1.0 barely mentions null.

Out of interest, is there any summary of why null has been removed since OpenAPI 3.0.3?

And fyi you may want to update this proposal about nullable to clarify that it was rejected 😃

(I maintain an OpenAPI tool and a user has asked about using nullable)

Thanks again 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to define a property that can be string or null in OpenAPI ...
The nullable keyword used in OAS 3.0.x (see below) does not exist in OAS 3.1, it was removed in favor of the 'null'...
Read more >
Migrating from OpenAPI 3.0 to 3.1.0
Swap nullable for type arrays. In line with JSON Schema, the `type` keyword can now define multiple types for a schema with an...
Read more >
OpenAPI Specification - Version 3.0.3 - Swagger
The OpenAPI Specification (OAS) defines a standard, language-agnostic interface to RESTful APIs which allows both humans and computers to discover and ...
Read more >
Using Optional and Nullable Properties in API Requests
OpenAPI supports values of data types to be null. To specify, one can use the “nullable: true” property while defining a data type...
Read more >
What's New in OpenAPI 3.1 | LornaJane - Lorna Jane Mitchell
This does impact on existing OpenAPI documents as from 3.1, the nullable keyword is removed – use the array of types and one...
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