-
Notifications
You must be signed in to change notification settings - Fork 6k
[NodeJS] Introduce NodeJS codegen for Google Cloud Functions #4406
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
Conversation
| writeOptional(outputFolder, new SupportingFile("index.mustache", "", "index.js")); | ||
| writeOptional(outputFolder, new SupportingFile("package.mustache", "", "package.json")); | ||
| writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md")); | ||
| if (System.getProperty("noservice") == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmuk thanks for the PR. Instead of using noservice system property, what about using java -Dmodels -DsupportingFiles instead? https://github.com/swagger-api/swagger-codegen#selective-generation
You may also consider using .swagger-codegen-ignore to skip certain files when regenerating the code: https://github.com/swagger-api/swagger-codegen#ignore-file-format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re: .swagger-codegen-ignore: removed
re: noservice: well, this is what currently nodejs-server is doing. I think it's better to do things like that in another PR.
| import java.util.Map; | ||
| import java.util.Map.Entry; | ||
|
|
||
| public abstract class AbstractNodeJSCodegen extends DefaultCodegen implements CodegenConfig { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmuk thanks for refactoring NodeJS generator into a common abstract class 👍
|
@jmuk thanks for the contribution.
If only index.js is different, what about adding a CLI option to use different index.js mustache template instead of introducing another generator. |
|
To be more precise, not only |
|
@jmuk One way is to pass |
This does not add a new language, but adding some client options to support Google Cloud Functions (GCF).
|
Updated. Now the single |
| writeOptional(outputFolder, new SupportingFile("index.mustache", "", "index.js")); | ||
| } | ||
| writeOptional(outputFolder, new SupportingFile("package.mustache", "", "package.json")); | ||
| writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using noservice, what about using selective generation as mentioned in https://github.com/swagger-api/swagger-codegen#selective-generation? Would that meet your need?
I prefer not to introduce another system property if the same output can already be achieved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this comes from the original NodeJSCodegen.java, I just moved the code location. I'm not adding new.
Also, the noservice is for a different purpose from the selective generation.
The nodejs-server codegen generates two files per API. For the example of petstore, it generates files like controllers/Pet.js and controllers/PetService.js (see https://github.com/swagger-api/swagger-codegen/tree/master/samples/server/petstore/nodejs/controllers).
When this noservice is specified, it omits the generation of PetService.js file or any other -Service.js files. Only Pet.js or those files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmuk thanks for the clarification. I'll review and let you know if I've further question.
| } | ||
| cliOptions.add(CliOption.newBoolean(GOOGLE_CLOUD_FUNCTIONS, | ||
| "When specified, it will generate the code which runs within Google Cloud Functions " | ||
| + "instead of standalone Node.JS server.")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SUGGESTION: A URL to tutorial on how to deploy the auto-generated code to Google Cloud Functions would be helpful for developers who are new to Google Cloud Functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea. Done. Also added a section in README.mustache template, so people can refer to the URL after the code is generated.
Adds the client options help message and the README.md file.
|
@jmuk PR merged into master. Thanks for your contribution. |
|
FYI. I merged #4411 into master to improve the NodeJS code quality a bit. |
| @@ -0,0 +1,44 @@ | |||
| 'use strict'; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmuk we'll move this file to nodejs/google-cloud-functions/index.mustache (and update the code accordingly). so that all nodejs (server) related files are under the folder.
Are you OK with the proposed change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I don't care the exact file location as long as the code works. But thank you for telling me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found that this file is the same as index-gcf.mustache so I simply removed it via #4808. I did some tests and the generator is still working properly with or without the option for Google cloud function.
* Another approach: extending NodeJS server to support GCF. This does not add a new language, but adding some client options to support Google Cloud Functions (GCF). * Add URLs for how to deploy the generated code. Adds the client options help message and the README.md file.
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates)2.3.0branch for breaking (non-backward compatible) changes.Description of the PR
This PR introduces a new language "nodejs-google-cloud-functions." This is quite similar to nodejs server but the index.js is formed to work within Google Cloud Functions.