Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[typescript] Fix incorrect enum literal case #7378

Merged
merged 3 commits into from
Sep 9, 2020
Merged

[typescript] Fix incorrect enum literal case #7378

merged 3 commits into from
Sep 9, 2020

Conversation

epidemia
Copy link
Contributor

@epidemia epidemia commented Sep 9, 2020

fixes #7369
Enum values are generated incorrectly for PascalCase enum property naming type when the source enum values are in uppercase with underscores.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • Run the shell script ./bin/generate-samples.shto update all Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

default:
throw new IllegalArgumentException("Unsupported enum property naming: '" + name);
}
}

private String prepareEnumString(String name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add some docs to explain what this function does, and include an example

I am just asking myself: why can't we use the underscore method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can use the underscore method. I deleted prepareEnumString method. Thanks.

@macjohnny macjohnny added this to the 5.0.0 milestone Sep 9, 2020
@macjohnny macjohnny changed the title Fix incorrect enum values for typescript clients [typescript] Fix incorrect enum values casing Sep 9, 2020
@macjohnny macjohnny changed the title [typescript] Fix incorrect enum values casing [typescript] Fix incorrect enum literal case Sep 9, 2020
@macjohnny
Copy link
Member

this is a breaking change, but the fallback is to use enumPropertyNaming=original

@epidemia
Copy link
Contributor Author

epidemia commented Sep 9, 2020

this is a breaking change, but the fallback is to use enumPropertyNaming=original

@macjohnny Can you give an example of broken backward compatibility?

@macjohnny
Copy link
Member

this is a breaking change, but the fallback is to use enumPropertyNaming=original

@macjohnny Can you give an example of broken backward compatibility?

Since the default value of enumPropertyNaming is PascalCase (see https://openapi-generator.tech/docs/generators/typescript-axios), for a user that does not explicitly specify enumPropertyNaming, your example

         "type": {
            "type": "string",
            "description": "Book type",
            "enum": [
              "SCIENCE",
              "SCIENCE_FICTION"
            ]
          }

currently results in

export enum BookType {
  SCIENCE = 'SCIENCE',
  SCIENCEFICTION = 'SCIENCE_FICTION'
}

With your change it results in

export enum BookType {
  Science = 'SCIENCE',
  ScienceFiction = 'SCIENCE_FICTION'
}

thus breaking his code using that enum. But he can easily use the enumPropertyNaming=original to fall back to the original behavior

@epidemia
Copy link
Contributor Author

epidemia commented Sep 9, 2020

this is a breaking change, but the fallback is to use enumPropertyNaming=original

@macjohnny Can you give an example of broken backward compatibility?

Since the default value of enumPropertyNaming is PascalCase (see https://openapi-generator.tech/docs/generators/typescript-axios), for a user that does not explicitly specify enumPropertyNaming, your example

         "type": {
            "type": "string",
            "description": "Book type",
            "enum": [
              "SCIENCE",
              "SCIENCE_FICTION"
            ]
          }

currently results in

export enum BookType {
  SCIENCE = 'SCIENCE',
  SCIENCEFICTION = 'SCIENCE_FICTION'
}

With your change it results in

export enum BookType {
  Science = 'SCIENCE',
  ScienceFiction = 'SCIENCE_FICTION'
}

thus breaking his code using that enum. But he can easily use the enumPropertyNaming=original to fall back to the original behavior

All right. Thank you.

@macjohnny macjohnny merged commit 4d8ac0e into OpenAPITools:master Sep 9, 2020
jimschubert added a commit to lwlee2608/openapi-generator that referenced this pull request Sep 12, 2020
* master: (1557 commits)
  [docs] Add notes on Windows classpath modification (OpenAPITools#7404)
  [C#][netcore] better support for additional properties in the payload (OpenAPITools#7396)
  Fix the ECDSA signature issue for PowerShellSDK (OpenAPITools#7386)
  Fix the new package that deal with Configuration (the old one is depecrated) (OpenAPITools#7391)
  update vonage logo (OpenAPITools#7387)
  [gradle][plugin] Fix tests (OpenAPITools#7384)
  [typescript] Fix incorrect enum literal case (OpenAPITools#7378)
  Rust reqwest/api_mustache Missing api Vec in parameter (OpenAPITools#7049)
  [kotlin] Fix imports of generated class (OpenAPITools#7314)
  Properly decode $ref (OpenAPITools#7191)
  fix typo, update caption
  feat(r): retry configuration for status codes (OpenAPITools#5925)
  [json][codegen] Add option: outputFileName (OpenAPITools#7348)
  RSACng class is not supported on linux replacing it by RSA (OpenAPITools#7349)
  Adds cookie auth support to ApiKeyAuth in dart2 templates (OpenAPITools#7346)
  [js][flowtype] Bump lodash from 4.17.15 to 4.17.19 (OpenAPITools#7359)
  Bugfix swift5 code generation 2966 (OpenAPITools#7301)
  Syncs validation properties for arraymodels (OpenAPITools#7357)
  Subclass Python exceptions (OpenAPITools#7321)
  Adds fix for issue7262 and a test of it (OpenAPITools#7328)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Incorrect enum values for typescript clients
2 participants