swagger-ts-generator icon indicating copy to clipboard operation
swagger-ts-generator copied to clipboard

enum generation fails with same named enums

Open Matze5590 opened this issue 6 years ago • 8 comments

i have in swagger multiple enums named "kind". they have different values. unfortunately this generator only generates the first enum it finds. the others are not there.

Matze5590 avatar Sep 28 '18 09:09 Matze5590

Unfortuntly, this is not supported. You should name your enums uniquely

Op vr 28 sep. 2018 om 11:22 schreef Matze5590 [email protected]:

i have in swagger multiple enums named "kind". they have different values. unfortunately this generator only generates the first enum it finds. the others are not there.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/areijngoudt/swagger-ts-generator/issues/10, or mute the thread https://github.com/notifications/unsubscribe-auth/ACOL81PtTvq6JSkgVYUqmce_PwQc0Aw8ks5ufepTgaJpZM4W-Jso .

areijngoudt avatar Sep 28 '18 12:09 areijngoudt

@areijngoudt This makes no sense. In my Swagger docs, there's a bunch of models that have the same "status" property, with different enum values. Like so:

CaseSummary": {
  "type": "object",
  "required": [
    "status",
    "type"
  ],
  "properties": {
    "status": {
      "type": "string",
      "example": "APPROVED",
      "description": "Status of the case",
      "enum": [
        "NEW",
        "APPROVED",
        "UNRESOLVED",
        "REJECTED"
      ]
    },
    ...

As of now I only get one enum in enumTSFile called "status" and the others are missing. What do you mean by "name your enums uniquely"? The property is called "status" and that's what swagger-ts-generator will name the enum. Is it possible to get the enum in enumTSFile named CaseSummaryStatus for example?

mbohgard avatar Mar 18 '19 20:03 mbohgard

Hi Martin,

On the server the all enums are likely to have there own typename. If you switch to OpenAPI (Swagger) 2.0, enums have there own type definition in swagger.json. If you switch to this, the generator uses these type names. If you (have to) stick to swagger 1.1, the parameter names with enum values should have unique names, so instead of status use caseSummaryStatus as the property name.

Best regards, Ad

Op ma 18 mrt. 2019 om 21:03 schreef Martin Bohgard <[email protected]

:

@areijngoudt https://github.com/areijngoudt This makes no sense. In my Swagger docs, there's a bunch of models that have the same "status" property, with different enum values. Like so:

CaseSummary": { "type": "object", "required": [ "status", "type" ], "properties": { "status": { "type": "string", "example": "APPROVED", "description": "Status of the case", "enum": [ "NEW", "APPROVED", "UNRESOLVED", "REJECTED" ] }, ...

As of now I only get one enum called "status" and the others are missing. What do you mean by "name your enums uniquely"? The property is called "status" and that's what swagger-ts-generator will name the enum. Is it possible to get the enum in enumTSFile named CaseSummaryStatus for example?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/areijngoudt/swagger-ts-generator/issues/10#issuecomment-474078697, or mute the thread https://github.com/notifications/unsubscribe-auth/ACOL80yoxLSQbe6rbQ031bfEP8V9F2v-ks5vX_D7gaJpZM4W-Jso .

areijngoudt avatar Mar 19 '19 06:03 areijngoudt

Hi Ad

Thank you for such a quick response. We do use Swagger 2.0 but our swagger.json still looks like the example above. I talked with the backend devs they tried some more/different annotations but the swagger.json spec didn't change or added any kind of information that swagger-ts-generator would use, I guess(?). Can you guide us any further? Thanks!

mbohgard avatar Mar 19 '19 11:03 mbohgard

Hi Martin,

Which backend language / framework is used?

Regards, Ad

Op 19 mrt. 2019 om 12:44 heeft Martin Bohgard [email protected] het volgende geschreven:

Hi Ad

Thank you for such a quick response. We do use Swagger 2.0 but our swagger.json still looks like the example above. I talked with the backend devs they tried some more/different annotations but the swagger.json spec didn't change or added any kind of information that swagger-ts-generator would use, I guess(?). Can you guide us any further? Thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

areijngoudt avatar Mar 19 '19 14:03 areijngoudt

Java and Swaggers own implementation of adding annotations.

mbohgard avatar Mar 19 '19 14:03 mbohgard

For java we use a post process to alter the swagger.json and convert the enum values to there own enum type definitions. But this software is propriatory to the company I work for at the moment.

The way I see it you have these options:

  • implement your own post processor
  • rename the propertynames for enums types with unique names
  • fork swagger-ts-generator and change the way enums are generated

Regards, Ad

Op 19 mrt. 2019 om 15:42 heeft Martin Bohgard [email protected] het volgende geschreven:

Java and Swaggers own implementation of adding annotations.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

areijngoudt avatar Mar 19 '19 15:03 areijngoudt

I see. Thank you for taking the time. I guess it will be easier with OpenAPI 3 and "Reusable Enums".

mbohgard avatar Mar 19 '19 15:03 mbohgard