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

[TS][Axios] To fix conflict params name 'url' #2921

Merged
merged 5 commits into from
May 27, 2019

Conversation

vellengs
Copy link
Contributor

Sometime we have api params named url that will conflict with imported module url named url.

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, ./bin/openapi3/{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\. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.
  • Filed the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

(details of the change, additional tests that have been done, reference to the issue for tracking, etc)

Sometime we have api params named url that will conflict with imported module url named url.
@wing328
Copy link
Member

wing328 commented May 17, 2019

@vellengs thanks for the PR. Can you please also run ./bin/typescript-axios-petstore-all.sh to run to update the samples as well?

@wing328
Copy link
Member

wing328 commented May 17, 2019

cc @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @nicokoenig (2018/09) @topce (2018/10)

@@ -3,7 +3,7 @@
/// <reference path="{{apiRelativeToRoot}}custom.d.ts" />
{{>licenseInfo}}

import * as url from 'url';
import * as $url from 'url';
Copy link
Member

Choose a reason for hiding this comment

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

instead of renaming the parameter, I think it is better to add url to the reserved keywords. See e.g.

private void addExtraReservedWords() {
this.reservedWords.add("BASE_PATH");

Copy link
Member

Choose a reason for hiding this comment

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

@macjohnny yup, that's one way to do it.

My little suggestion is to prefix it (like what's done in the PR) in this case as "url" may be a popular choice for naming variables/classes.

Reserved keywords are usually language specified such as return in PHP that can must be prefixed/suffixed.

Copy link
Member

Choose a reason for hiding this comment

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

but someone might also use url$ as a parameter name. I think it is a good idea to add all global symbols to the reserved keywords to avoid any naming conflicts.

Copy link
Member

Choose a reason for hiding this comment

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

I think the dollar sign and other symbols will be removed in toVarName or toParamName as part of the sanitization.

what about using the "localVar" prefix approach?

localVar may not sound right in this case so what about "globalImportUrl"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"globalImportUrl" seems fine.

Copy link
Member

Choose a reason for hiding this comment

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

@vellengs please go ahead with this approach to see if it works for you (I think it should).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wing328 can you build the shell
./bin/typescript-axios-petstore-all.sh.
I have promblem with Marven.

Copy link
Member

Choose a reason for hiding this comment

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

Can you use maven wrapper instead?

./mvnw clean install

Copy link
Contributor Author

@vellengs vellengs May 21, 2019

Choose a reason for hiding this comment

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

@naelrashdeen I changed two part of 'api.mustache' and 'apiInner.mustache'
why the build samples file still have

import * as url from 'url';

any cache of shell build?

@wing328
Copy link
Member

wing328 commented May 26, 2019

I've updated the samples. Let's see how the CI tests go.

@wing328 wing328 merged commit e4f56d5 into OpenAPITools:master May 27, 2019
@wing328 wing328 changed the title To fix conflict params name 'url' [TS][Axios] To fix conflict params name 'url' May 27, 2019
@wing328
Copy link
Member

wing328 commented Jun 3, 2019

@vellengs thanks again for your contribution, which has been included in the v4.0.1 release (https://twitter.com/oas_generator/status/1135534738658062336)

@PierreREN
Copy link

Is 'url' mentioned above https://www.npmjs.com/package/url as there seems no other url package in npm library? And if so, when building my project using "npm run build" which actually refers to "vue-cli-service build", such error occurs.
Could not find a declaration file for module 'url'. 'XXX/node_modules/url/url.js' implicitly has an 'any' type. Try npm install @types/urlif it exists or add a new declaration (.d.ts) file containingdeclare module 'url';``
How do you solve such a problem? @wing328

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.

None yet

4 participants