Forum Discussion

bala_praveen's avatar
3 hours ago

Handling unknown subtypes with OpenAPI discriminator property

In our API, we return different subclasses of a base class (SearchEntity) using the discriminator property (searchType) to differentiate between various types. This approach helps maintain data consistency and reduces errors during JSON deserialization.

When clients generate client code using the /v3/api-docs/disco JSON, it works well with the known discriminator mappings. However, When we introduce a new subtype on the server side, Clients using older versions of the /v3/api-docs/disco JSON encounter JSON deserialization errors, as their generated client code does not recognize the newly added subtype.

Could you provide guidance or suggestions on how to implement this fallback mechanism within the OpenAPI specification? Specifically:

  1. Is there a recommended approach to define a default or fallback logic for the discriminator property in OpenAPI?
  2. Are there alternative solutions to handle unknown subtypes more effectively without requiring frequent client code regeneration?
  3. Any best practices or tools to manage compatibility issues in such scenarios?

Note: we were using spring boot from the server side. And attached sample open api json for your reference

No RepliesBe the first to reply