eclipse / microprofile-open-api

Microprofile open api
Apache License 2.0
131 stars 81 forks source link

Open API 3.1 Conditional Schemas #567

Closed manstis closed 2 months ago

manstis commented 12 months ago

Will there be support to define conditional schemas?

The OpenAPI 3.1 Specification suggests

"For more information about the properties, see JSON Schema Core and JSON Schema Validation."

https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-10.2.2

Both referenced documents cover dependencies and/or dependentSchemas.

The older Open API 3.0.x Specification implicitly states conditional schemas are unsupported.

"Additional properties defined by the JSON Schema specification that are not mentioned here are strictly unsupported".

No such comment is made for 3.1 so it could be assumed they are supported.

It is useful for consumers of Open API when used, for example, to generate User input forms programmatically.

Azquelt commented 5 months ago

At the moment, I think we have to support everything from the OpenAPI 3.1 spec, which would include both dependentSchemas and dependentRequired, but how much support we provide is may vary.

I think at a minimum we would want to allow:

However, we could also add new annotations or add to existing ones.

@manstis Did you have any examples of what you'd want to be able to do in your code to add these properties to the final OpenAPI document?

manstis commented 5 months ago

Hi @Azquelt I forget the exact details other than some notes I captured at the time:

OpenAPI for Backstage Templates

  • The generated OpenAPI definition is used to define the parameters for Backstage’s Templates. The parameter (map) entries > are used to generate the input form presented to Users to capture the parameters to execute the workflow (and > dataInputSchema generation, see below).
  • Backstage uses react-jsonschema-form that supports a concept > called dependencies to dynamically alter > the form definition. This is not supported in OpenAPI and hence this feature is missing from the SWF PoC. dependencies is only support in OpenAPI 3.1
  • SmallRye 3.1 does not support Conditional Schemas.
  • See https://github.com/eclipse/microprofile-open-api/issues/567

The issue was that a library is being used to generate forms from JSON schemas. If the JSON schemas defined dependencies (on other schemas) they failed to be recognised and the generated forms incomplete.

I've moved onto other projects now; but can try to answer any questions you have ongoing.

Azquelt commented 2 months ago

Ok, so checking through what was written above, my understanding is:

In #584 , we've made several changes which I think address this:

Based on the above, I think the features being added in 4.0 are sufficient to close this issue, but do feel free to reopen if I've missed anything.