Home > Software engineering >  Swagger generation - reference schema under same schema
Swagger generation - reference schema under same schema

Time:06-09

So I am generating a yaml file for our api. Issue is, on my code, I have an Account object, which has attributes and a list of itself as sub-accounts.

Yaml looks like this:

Account:
  type: Object
  properties: 
    name:
      type: string
    <other attributes>
      <other types>
    subAccounts:
      type: array
      $ref: '#/components/schema/Account'

The schema gets generated, but the subAccount does not. If I add a "description" - it will get generated but with blank attributes. Any way I can refer to the same object properly?

CodePudding user response:

I did a workaround - I created a new class called SubAccount, extended the Account on it then changed the List type from Account to SubAccount.

Works great.

But if anyone has proper solution - please post here. tnx.

CodePudding user response:

I ran into this problem once before, and I also did not find any solution that would "solve this issue for me". Actually result was that it is my issue to have such circular dependency in my API. If you necessary have to use same object, then I suggest you to override Swagger configuration with you own rules, you can spec there basically everything. ( https://swagger.io/docs/specification/about/ )

Nevertheless take also into consideration that having possibility of this "endless" data structure may easily cause memory issues. "Workaround" solution by Rye might be actually the best solution to specify exactly how deep this dependency tree might be.

  • Related