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

Fix nodejs-server path issue in windows platform #7808

Merged
merged 2 commits into from
Mar 12, 2018
Merged

Conversation

wing328
Copy link
Contributor

@wing328 wing328 commented Mar 9, 2018

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.

Description of the PR

To fix #6443

cc @CodeNinjai (2017/07) @frol (2017/07) @cliffano (2017/07)

@@ -164,7 +164,7 @@ public String apiFilename(String templateName, String tag) {
}

private String implFileFolder(String output) {
return outputFolder + "/" + output + "/" + apiPackage().replace('.', '/');
return (outputFolder + File.separator + output + File.separator + apiPackage()).replace('.', File.separatorChar);
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Is there a file path API for Java to avoid such an error-prone path concatenation implementation?
  2. Why should all the dots (.) be replaced with a path separator? What if I have a folder with a dot in its name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Not that I'm aware of and I agree the current solution is error-prone so I'm open to new ideas for a better implementation.

  2. I do not know the reason. The logic was added before I joined this project. My suggestion is to keep the current behavior and try to come up with workaround/solution if users file an issue about it.

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. OK

  2. If you want to keep the current behavior, you should probably drop those parentheses to limit the replacement only for the apiPackage() string instead of the whole result:

    outputFolder + File.separator + output + File.separator + apiPackage().replace('.', File.separatorChar)
    

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Done via e10c09d

@frol
Copy link
Contributor

frol commented Mar 9, 2018

LGTM

Copy link

@dlarr dlarr left a comment

Choose a reason for hiding this comment

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

Doesn't work on Windows

Change 1
NodeJSServerCodegen.java line 88: back to

supportingFiles.add(new SupportingFile("writer.mustache", ("utils").replace(".", "/"), "writer.js"));

change 2 : NodeJSServerCodegen.java, line 172
Use this :

String replacement = (java.io.File.separator.equals("\\") ?  java.io.File.separator + java.io.File.separator : java.io.File.separator) 
        			+ implFolder + 
        			(java.io.File.separator.equals("\\") ?  java.io.File.separator + java.io.File.separator : java.io.File.separator) ;

@wing328
Copy link
Contributor Author

wing328 commented Mar 12, 2018

@dlarr thanks for the review. I think my approach should still work.

Given that it does not impact Mac/Linux, I'll merge it and ask my friends to try it in their Windows box.

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.

[nodejs] generated service.js files are placed in the wrong folder
3 participants