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

[cli] new 'author template' command #6441

Merged

Conversation

jimschubert
Copy link
Member

@jimschubert jimschubert commented May 27, 2020

This new command allows users to extract templates for authoring (customization) without the complexity of finding and downloading a specific directory for their versioned artifact.

Example usage:

openapi-generator author template -g java --library webclient

This will write all templates with library-specific templates to the './out' directory relative to the current directory. The user can specify an alternative directory as well. See the doc changes in this PR for more details.

CLI will refer the user to https://openapi-generator.tech/docs/templating after generation.

This PR is supplemental to the template quality PR #6357

This PR provides the start of authoring commands detailed in #1811

cc @OpenAPITools/generator-core-team

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

This new command allows users to extract templates for authoring
(customization) without the complexity of finding and downloading a
specific directory for their versioned artifact.

Example usage:

```
openapi-generator author template -g java --library webclient
```

This will write all templates with library-specific templates to the
'./out' directory relative to the current directory.

CLI will refer the user to
https://openapi-generator.tech/docs/templating after generation
@auto-labeler
Copy link

auto-labeler bot commented May 27, 2020

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@jimschubert jimschubert changed the title Authoring templates command [cli] new 'author template' command May 27, 2020
@jimschubert jimschubert added this to the 5.0.0 milestone May 27, 2020
@jimschubert jimschubert added this to In progress in Simplify Contributions and Improve Usability via automation May 27, 2020
@wing328
Copy link
Member

wing328 commented May 27, 2020

Thanks for the work on this. I'm sure users will find it useful to begin the template customization.

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar author template -g java --library webcli
[main] INFO  o.o.codegen.cmd.AuthorTemplate - Extracted templates to 'out' directory. Refer to https://openapi-generator.tech/docs/templating for customization details.

I tested with an invalid library name (e.g. webcli) but got the same (correct) output.

What about validating the library name and output a proper error message if it's invalid?

@jimschubert
Copy link
Member Author

@wing328 we don't really have a way to check library names statically, especially since users can have a library on classpath by some wrapper, for instance if running via a fatjar depending on the CLI project.

It might be confusing if we write most files but throw an exception, and I agree we should let them user know. How about a check at the end which evaluates if out/libraries/name exists and log a warning if it does not? The user can check spelling and rerun, this should overwrite existing files and directories.

@jimschubert
Copy link
Member Author

I've updated with a warning message if the user passes an invalid or misspelled library option.

The first run in the following image is correct spelling and the second run has the library spelled incorrectly.

image

@jimschubert
Copy link
Member Author

I'll go ahead and merge this. We can make any necessary improvements in a follow up PR.

@jimschubert jimschubert merged commit 7d4bbcc into OpenAPITools:master May 28, 2020
Simplify Contributions and Improve Usability automation moved this from In progress to Done May 28, 2020
@jimschubert jimschubert deleted the authoring-templates-command branch May 28, 2020 04:13
jimschubert added a commit to jimschubert/openapi-generator that referenced this pull request May 30, 2020
* master:
  [PS] Refactor the http signing auth with ecdsa support (OpenAPITools#6397)
  [Rust Server] Hyper 0.13 + Async/Await support (OpenAPITools#6244)
  [Rust] set supportAsync to true as the default (OpenAPITools#6480)
  [php-symfony] Set required PHP version ^7.1.3 (OpenAPITools#6181)
  update doc
  [csharp] Rename netstandard to netstandard1.3 (OpenAPITools#6460)
  feat: support deprecated parameters for typescript-axios generator (OpenAPITools#6475)
  [REQ][typescript-axios] useSingleRequestParameter should mark parameter optional if all properties are optional (OpenAPITools#6477)
  better struct alias in rust (OpenAPITools#6470)
  Migrate Go server samples to OAS 3 only (OpenAPITools#6471)
  [Rust][reqwest] add async support (OpenAPITools#6464)
  [codegen][python-experimental] Composed schema with additionalProperties  (OpenAPITools#6290)
  [Java] Decommission Retrofit 1.x support (OpenAPITools#6447)
  remove scala oas3 samples (OpenAPITools#6446)
  [Java][jersey2] Fix RuntimeException when HTTP signature parameters are not configured (OpenAPITools#6457)
  [Java][jersey2] Improve http signature code comments (OpenAPITools#6463)
  [typescript-angular] drop support of angular below 6.0.0 (OpenAPITools#6360)
  [cli] new 'author template' command (OpenAPITools#6441)
  python-experimental updates ancestor + adds descendant discriminator tests (OpenAPITools#6417)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

2 participants