cyclosproject / ng-openapi-gen

An OpenAPI 3.0 codegen for Angular
MIT License
397 stars 132 forks source link

Missing properties for polymorphic types in case of the swagger generator is Swashbuckle.AspNetCore #142

Closed bandolir closed 3 years ago

bandolir commented 3 years ago

Old issue closed by the model definition is invalid. Swashbuckle team says that this is a valid model definition see this issue: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1942

raphibolliger commented 3 years ago

I have the same problem. @bandolir did you find a solution?

bandolir commented 3 years ago

Hi,

I made a fork from swashbuckle and I've fixed in that. Sorry I cannot share that cos' it is in our private repository and as you see the answer on the other side it is not a good solution. Just was a temporary solution for us until it get fixed. I've created these tickets for others who are in the same situation like us. If nothing will happen then we have to consider to replace either swashbuckle or ng-openapi-gen in our project.

luisfpg commented 3 years ago

I've tested this on swagger editor and it does validate:

components:
  schemas:
    Shape:
      type: object
      properties:
        name:
          type: string
    Circle:
      type: object
      allOf:
        - "$ref": "#/components/schemas/Shape"
      properties:
        radius:
          type: integer
          format: int32
      additionalProperties: false

However, the strange thing is that I couldn't find any mention of that 'mixed' form (allOf inside a type: object) in the openapi specifications, nor examples.

I don't currently have much time for new features in ng-openapi-gen. In this case, a PR is welcome.

fennekit commented 3 years ago

I think the fix is easy. In https://github.com/cyclosproject/ng-openapi-gen/blob/master/lib/model.ts (line 100) replace

 } else if (schema.type === 'object' || !!schema.properties) {

with

} 

if (schema.type === 'object' || !!schema.properties) {

Doing so generated the code I expected.

Will try to work on a PR this week...

fennekit commented 3 years ago

Pull request created. (needed in build pipeline :0)