rapi-doc / RapiDoc

RapiDoc -WebComponent for OpenAPI Spec
https://rapidocweb.com
MIT License
1.71k stars 285 forks source link

Object or null VS. String | null #1048

Closed neptunecentury closed 1 month ago

neptunecentury commented 1 month ago

I noticed something interesting in the schema table, where it mentions the data type and whether or not it can accept null. It seems that for most types, it is shown as

string | null

note the pipe character. But for objects, its listed as:

object or null

Note the use of or instead of |. Is there a meaning behind the difference? Is there a way to make it all the same, (like make them all use | (pipe))? Image for reference. image

Thanks for any insights!

mrin9 commented 1 month ago

how are you providing ur dataType based on the OpenAPI version there are two ways to provide how the nulls are defined

OpenAPI 2.0

OpenAPI - 3.0

type: string
nullable: true

OpenAPI - 3.1

type: ['null', string]

or

oneOf:
  - type: 'null' 
  - type: string

In addition to that there are languages such as JavaScript where null is an object too so depending on various combinations the renderer may be talking multiple code paths and that might have resulted into how it is being rendered. but there is no semantic difference between object or null and string | null

neptunecentury commented 1 month ago

Our spec is 3.0 and our Schema has a property that looks something like this:

"MyObjectPropertyName": {
                        "description": "Some desc...",
                        "nullable": true,
                        "allOf": [
                            {
                                "$ref": "#/components/schemas/SomeOtherObjectType"
                            }
                        ]
                    }

The explorer will show the type as "object or null" Just curious why it is that way vs

"MyStringPropertyName": {
                        "type": "string",
                        "description": "Some desc about the property",
                        "nullable": true
                    }

This property will be displayed as "string | null"

Thanks again