openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] [REGRESSION] Circular references in composed properties

Open devhl-labs opened this issue 3 years ago • 0 comments

The following yaml produces a model which is composed of itself resulting in a circular reference. This was not an issue in v6.0.0-beta 914b539eea7097ad2b4323d20c8f95144782cb68. It seems to be caused by DefaultGenerator#generateModels. There is a variable modelKeys which had two entries and now has three. Player_clan did not appear in modelKeys back in v6.0.0-beta.

openapi: 3.0.1
components:
  schemas:
    PlayerClan:
      type: object
      properties:
        tag:
          type: string
          readOnly: true
    Player:
      type: object
      properties:
        clan:
          nullable: true
          allOf:
          - $ref: '#/components/schemas/PlayerClan'
          readOnly: true

image

This issue is not for any one particular generator, but I did add debugging to a mustatche file to inspect the model. On the left is the template and the right is the generated model. The issue with allOf having PlayerClan is that this is the PlayerClan. A class can not be composed of itself. image

generate `
    -g csharp-netcore `
    -i "D:\devhl\repos\Clash-of-Clans-Swagger\swagger-3.0-debug.yml" `
    -o D:\devhl\repos\CocApi `
    --library generichost `
    --skip-validate-spec

devhl-labs avatar Oct 16 '22 22:10 devhl-labs