Microcks Schema Validation Failure: Polymorphic oneOf + Discriminator Not Resolving Correctly #1710
-
|
We are encountering persistent schema validation failures in Microcks for an API response that contains polymorphic data structures. Despite correctly defining oneOf and a discriminator based on a type-identifying property in our OpenAPI specification, Microcks validation flags subtype-specific properties as undefined and reports that the object "must be valid to one and only one schema, but 2 are valid." API Endpoint Affected: Symptoms Observed in Microcks Validation Report: property 'additionalFieldA' is not defined in the schema and the schema does not allow additional properties (for objects of TypeB or TypeC when additionalFieldA is specific to TypeA) Relevant OpenAPI Schema: BasePolymorphicDto (the base type with oneOf and discriminator) OpenAPI Schema Verification: Confirmed oneOf and discriminator are correctly defined in the OpenAPI spec, using typeIdentifierProp as the discriminator property and simple schema names (e.g., SubtypeADto) in the mapping. additionalProperties: false is present on all relevant schemas. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
|
Hi @themalatha888 |
Beta Was this translation helpful? Give feedback.
-
|
"Thanks for the quick response! My apologies for the previous attachment. I've created a minimal OpenAPI spec file (reproducer-openapi.json) focusing on the polymorphic definitions, and ensured it's valid JSON. I've also re-attached the failing-response-payload.json for validation against this spec. Please let me know if you need anything else." |
Beta Was this translation helpful? Give feedback.
-
|
Dear Microcks Team, especially @lbroudoux Following up on our previous discussions regarding schema validation failures for polymorphic DTOs in Microcks, we have prepared a minimal, generic reproducer that highlights the specific configuration causing persistent validation errors. We are encountering the following errors: must be valid to one and only one schema, but 0 are valid additionalProperties: false on the Base Polymorphic Type: Can you confirm that additionalProperties: false on a base polymorphic type (like BasePolymorphicDto in our example) is indeed problematic and should be set to true (or removed) when using oneOf and discriminator? reproducer-openapi.json: The OpenAPI specification demonstrating the additionalProperties: false on the base type and the discriminator mapping TypeC back to BasePolymorphicDto. Thank you for your continued support. |
Beta Was this translation helpful? Give feedback.
-
|
Thank you, @themalatha888, for raising the issue and for the great technical discussion. ⭐ Star our main repo
🏢 Add your company and use case to our adopter list
Thanks a lot for your support, we really count on you! 🙌 |
Beta Was this translation helpful? Give feedback.
So here are my findings.
First, I had to modify the failing response a bit to adapt to the
dataarray required by theResponseCollectionWrappertype. Also, I removed the unknowncommonProp2property that was defined nowhere. Here is the JSON I have used:{ "data": [ { "commonProp1": "Value1A", "typeIdentifierProp": "TypeA", "commonProp3": false, "additionalFieldA": "Specific data for TypeA", "nestedCommon": { "label": "Category Alpha", "description": null } }, { "commonProp1": "Value1B", "typeIdentifierProp": "TypeB", "commonProp3": true, "additionalFieldB": 123, "additionalFieldC": "Another B field", …