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

nullable ref field #568

Closed
schmurfy opened this issue Sep 25, 2021 · 2 comments
Closed

nullable ref field #568

schmurfy opened this issue Sep 25, 2021 · 2 comments

Comments

@schmurfy
Copy link

Since nullable is now deprecated (and never worked for $ref anyway) I am trying to find how to show a field as nullable.
I found that oneOf with a null type should work but the result shown is not that great, it literally show (with a $ref):

ONE OF
1  NULL 
1 {
    name: string
   }

I was looking a way to show some kind of icon like readonly, is there a better way to do nullable fields ?

@mrin9
Copy link
Collaborator

mrin9 commented Sep 25, 2021

OpenAPI v3.0

  type: string
  nullable: true

in openapi 3.1 types can take multiple values
OpenAPI v3.1

type:
- "string"
- "null" 

check the phone field below which can take null or string

image

here is the example of this https://mrin9.github.io/RapiDoc/examples/data-types.html#post-/nested-object-in-request-body

all the examples and their spec can be found at docs/examples and docs/specs folder

@mrin9 mrin9 closed this as completed Sep 25, 2021
@schmurfy
Copy link
Author

Thanks for the reply but that did not fully answer my question for $ref fields,
I tried the following with no luck:

"user": {
  "$ref": "#/components/schemas/User",
  "type": ["object", "null"]
}

after digging a bit more I realized that the way openapi seems to handle this, and this makes it really useless for me is to add null as an allowed type in the ref:

components:
  schemas:
    User:
      properties:
        ...
      type:
        - object
        - null

I thought that the ref was a bit more clever than that but maybe I should just stop using it altogether since my code is generated anyway... My real problem is more general: OAI/OpenAPI-Specification#2026

and btw when using type array as you shown the way it is displayed is still not that great but that's a nitpick ;)

PS: love the project :)

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

No branches or pull requests

2 participants