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 All] Prevent usage of reserved keyword for model fields #7112

Merged
merged 3 commits into from
Dec 14, 2017
Merged

[Typescript All] Prevent usage of reserved keyword for model fields #7112

merged 3 commits into from
Dec 14, 2017

Conversation

JFCote
Copy link
Contributor

@JFCote JFCote commented Dec 5, 2017

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: 3.0.0 branch for changes related to OpenAPI spec 3.0. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09)

Description of the PR

Reserved keywords were escaped everywhere but for this. I just add it in the AbstractTypescriptClientCodegen. I run all the typescript sample I could find. All the changes are not related to my change because the petstore doesn't contain any reserved keyword.

@TiFu
Copy link
Contributor

TiFu commented Dec 5, 2017

Just to check that I understand the issues this PR solves correctly: does this change escape Enum values, which are reserved keywords? e.g. escapes await in an enum with value await

@JFCote
Copy link
Contributor Author

JFCote commented Dec 5, 2017

I think enum were already escaped (I did not validate). I'm escaping model members which are reserved keywords.

For example, if you have a model called Dog with a boolean named default, it will escape default with _default in the final generated code.

Without this escape, the typescript is not compiling.

Does it make more sense? :)

@wing328 wing328 added this to the v2.3.0 milestone Dec 9, 2017
@@ -405,6 +405,10 @@ public String toEnumName(CodegenProperty property) {
if (Boolean.TRUE.equals(var.isEnum)) {
var.datatypeWithEnum = var.datatypeWithEnum.replace(var.enumName, cm.classname + "." + var.enumName);
}

if (isReservedWord(var.name)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Please follow the JS approach, which is used by other generators (e.g. Ruby, PHP, etc)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok! Will try to commit a fix this week! Thanks for the review!

@JFCote
Copy link
Contributor Author

JFCote commented Dec 13, 2017

@wing328 Changes are done! Let me know if something is still missing!

@wing328
Copy link
Contributor

wing328 commented Dec 13, 2017

@JFCote saw your change. Do we still need the reserved word check in postProcessModels?

@JFCote
Copy link
Contributor Author

JFCote commented Dec 13, 2017

@wing328 Do you think it's called from somewhere else automatically?

…use it is already called from somewhere else.
@JFCote
Copy link
Contributor Author

JFCote commented Dec 13, 2017

@wing328 I've just test it and you are right, it seems to be called from somewhere, so no need in the postProcessModels. I've just submit a new version.

@wing328
Copy link
Contributor

wing328 commented Dec 14, 2017

@JFCote looks good to me 👍

@wing328 wing328 merged commit e70bdf1 into swagger-api:master Dec 14, 2017
@kenisteward
Copy link
Contributor

kenisteward commented Dec 14, 2017 via email

@JFCote JFCote deleted the prevent-model-field-reserved-keywords branch December 14, 2017 13:00
@gennadiylitvinyuk
Copy link

The config Parameter modelPropertyNaming is now ignored

@JFCote
Copy link
Contributor Author

JFCote commented Dec 18, 2017

@gennadiylitvinyuk : I see. Can you create a bug related to this.
@wing328 : I will try to make a fix today or tomorrow.

I think that changing this line
name = camelize(name, true); and calling the getNameUsingModelPropertyNaming should do the trick.

Sorry about the regression @gennadiylitvinyuk
Please tag me in your new bug please.

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.

5 participants