Open philipbjorge opened 3 years ago
@philipbjorge Not a Json schema expert, however, I believe this cannot work because allOf expects all subschemas to be be valid. IOW, nullable_ref should first be an object
before even being nullable.
I believe something like this should work.
User:
type: object
properties:
nullable_ref:
oneOf:
- $ref: "#/components/schemas/Foo"
- type: null
required:
- nullable_ref
Same issue:
type: object
required:
- result
properties:
result:
oneOf:
- $ref: "#/components/schemas/Foo"
- type: "null"
95:21 error oas3-schema `type` property should be equal to one of the allowed values: `array`, `boolean`, `integer`, `number`, `object`, `string`. Did you mean `number`?. components.schemas.Response.properties.result.oneOf[3].type
@meme --
Not that it helps the primary issue, but I can share that the - type: "null"
construct will only be valid with a OAS 3.1 doc
We have this issue too. Comoforting to know at least that it's only an issue with spectral and that the OpenAPI file is apparently correct.
I think that I traced this back to an issue with ajv
's nullable
support:
updating to openapi 3.1.0 (from 3.0.0) fixed the issue for me. Thanks to : https://github.com/stoplightio/spectral/issues/1603#issuecomment-840048026
The OpenApi 3.0.0 states: "Note that there is no null type; instead, the nullable attribute is used as a modifier of the base type." Reference
Describe the bug I'm trying to describe a nullable ref and spectral is yelling at my examples being invalid
To Reproduce
Given this OpenAPI document:
Run this command:
Received:
In the 6.0.0 alpha, I get an error:
Expected behavior I expected this example to pass validation -- I thought the
nullable: true
,allOf
approach was the appropriate way to create a nullable reference in OAS 3Screenshots If applicable, add screenshots to help explain your problem.
Environment (remove any that are not applicable):