Gi60s / openapi-enforcer

Apache License 2.0
94 stars 22 forks source link

Does not support ref or null #162

Closed erezarnon closed 3 months ago

erezarnon commented 3 months ago

Define a schema with a field that can either be a ref or null.

anyOf:
  - $ref: '#/components/schemas/X'
  - type: 'null'

Receive the following error Value must be one of: array, boolean, integer, number, object, string. Received: "null"

Gi60s commented 3 months ago

Hello, @erezarnon.

The value null is not a valid type. This is per the spec at https://spec.openapis.org/oas/v3.0.3#data-types.

In the first paragraph under section 4.4 Data Types, you'll see that it says

null is not supported as a type (see nullable for an alternative solution)

The OpenAPI Enforcer does support nullable for OpenAPI 3.0.x.

I hope that solves your problem, but if not please reach out again and I'll see if I can help out.

erezarnon commented 3 months ago

Yes. I had to use allOf instead of just the $ref for nullable to work, which is weird, but it worked

Gi60s commented 2 months ago

I thought that maybe you'd put nullable inside of the X definition, but maybe that wasn't an option for you. Either way, I'm glad you were able to resolve it.