You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am investigating the use of subclasses in responses of REST operations, but don't get it to work as I expected. I came across the issue #2340, which has been closed. The fix included a test case with the expected OAS fragment. However, I regard the expected/generated fragment as insufficient.
The OpenAPI specification (both 3.0.3 and 3.1) specifies the "Discriminator Object" in section 4.7.25 (3.0.3) / 4.8.25 (3.1). This contains a field named "mapping", containing a map from the concrete type name to the concrete JSON Schema data type. While this field is marked as "optional" in the document, it is actually essential for any code generator that wants to create code to deserialize JSON into a language's object representation.
Playing around with the "OpenAPI generator" using a modified OAS file, it turns out that even the addition of the "mapping" entry is not sufficient, at least for the TypeScript generator I am working with. It also needs the JSON Schema "oneOf"/"anyOf" construct with the references to the actual subtypes to be present as well, as depicted in the OpenAPI specification 3.0.3/3.1.
So I suggest to add both the "mapping" and "oneOf"/"anyOf" definition when generating an OAS file.
The text was updated successfully, but these errors were encountered:
I am investigating the use of subclasses in responses of REST operations, but don't get it to work as I expected. I came across the issue #2340, which has been closed. The fix included a test case with the expected OAS fragment. However, I regard the expected/generated fragment as insufficient.
The OpenAPI specification (both 3.0.3 and 3.1) specifies the "Discriminator Object" in section 4.7.25 (3.0.3) / 4.8.25 (3.1). This contains a field named "mapping", containing a map from the concrete type name to the concrete JSON Schema data type. While this field is marked as "optional" in the document, it is actually essential for any code generator that wants to create code to deserialize JSON into a language's object representation.
Playing around with the "OpenAPI generator" using a modified OAS file, it turns out that even the addition of the "mapping" entry is not sufficient, at least for the TypeScript generator I am working with. It also needs the JSON Schema "oneOf"/"anyOf" construct with the references to the actual subtypes to be present as well, as depicted in the OpenAPI specification 3.0.3/3.1.
So I suggest to add both the "mapping" and "oneOf"/"anyOf" definition when generating an OAS file.
The text was updated successfully, but these errors were encountered: