fortanix / openapi-to-effect

Generate @effect/schema definitions from an OpenAPI document
Mozilla Public License 2.0
13 stars 1 forks source link

Support OpenAPI v3.1 `type` array syntax #4

Closed midhun-pk closed 3 months ago

mkrause commented 3 months ago

Quick summary of the issue:

We support OpenAPI v3.1 now, where the schema syntax is now just fully in line with the latest JSON Schema specification. As part of this, the type field can now be an array, where the semantics is that the resulting schema validates if it is a valid schema for any of the types in array. See the relevant part of the spec here:

If the value of "type" is a string, then an instance validates successfully if its type matches the type represented by the value of the string. If the value of "type" is an array, then an instance validates successfully if its type matches any of the types indicated by the strings in the array.

One consequence of this is that for "nullable" types, we no longer use a nullable or x-nullable boolean field, instead this is represented as "type": ["null", <type>].

This generator does not support "type" as an array yet, we should add it. The desired output is similar to what would happen if we used anyOf on the schema with type replaced with one of its constituent elements.