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 want to have automated builds of clients for my Swagger API in several languages. Swagger Codegen allows me to do that, but if I use the swagger.json that is generated by Nswag, I only get properties of the base class in the generated model. The generated model was as follows:
To check if this is true I have then written a simple script that moves the properties to allOf field if allOf field is defined and the generated clients had all the specified fields listed correctly.
I have tried using both Swagger-codegen.jar as well as the webpage that does the same (http://editor.swagger.io/).
The text was updated successfully, but these errors were encountered:
The question here is which tool has a bug. NSwag can handle both types of property locations when generating client code, but it seems that the others only generate properties when they are in allOf. The question is, whether NSwag is generating invalid specs or the other tools do not support it correctly?
If you look at the OpenAPI specification and the inheritance examples there, I would say the bug is in NSwag. I have also looked at a couple of other people implementing inheritance (top hits on google for swagger inheritance) and they were all using it as it is in OpenAPI example.
I want to have automated builds of clients for my Swagger API in several languages. Swagger Codegen allows me to do that, but if I use the swagger.json that is generated by Nswag, I only get properties of the base class in the generated model. The generated model was as follows:
Alongside using my code, I have tested the NSwag.Demo.Web swagger.json and the result was the same. I have then decided to figure out what is wrong and discovered, that in case of inheritance both base class and the properties must be listed under allOf (https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/). It lists this is valid for OpenAPI 3.0, but this has been so in OpenAPI 2.0 as well (https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md):
To check if this is true I have then written a simple script that moves the properties to allOf field if allOf field is defined and the generated clients had all the specified fields listed correctly.
I have tried using both Swagger-codegen.jar as well as the webpage that does the same (http://editor.swagger.io/).
The text was updated successfully, but these errors were encountered: