Skip to content

Cli generator name option, replaces 'language' options in CLI and Maven Plugin#57

Merged
jmini merged 17 commits intoOpenAPITools:masterfrom
jimschubert:cli-generator-name-option
May 23, 2018
Merged

Cli generator name option, replaces 'language' options in CLI and Maven Plugin#57
jmini merged 17 commits intoOpenAPITools:masterfrom
jimschubert:cli-generator-name-option

Conversation

@jimschubert
Copy link
Member

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: Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

The language option (--lang and -l in CLI, language in maven plugin) has
drifted from the original intention of defining a top-level language
implementation with variance on library. Generators began to encode
generator type into language (e.g. erlang-client), reused language as
framework-only (e.g. scalatra), or embedded language and framework (e.g.
typescript-angular).

With the 3.0.0 release of openapi-generator, we've moved to a
standardization of these names, which means they no longer fit into the
singular concept of a "language".

We've discussed plans to provide a better user experience around the
CLI, breaking apart the generator lookup into the variations that make
up a generator:

  • language
  • type
  • framework
  • version?

To do this, we must first deprecate language and warn users that what
they're currently using (e.g. scalatra, typescript-angular) is being
replaced by generatorName and that language may mean something else in a
later version of the generator.

For discussion, see #39.

Example usage of the maven plugin is explained in the commit message for e97736f. You must first run mvn clean package install to stage the 3.0.0-SNAPSHOT from this branch into your local repository. Then, navigate to modules/openapi-generator-maven-plugin/examples and run:

mvn -f non-java.xml compile

This will create an aspnetcore generated example under target/generated-sources/.

Warning messages introduced in this PR will look like (maven plugin output):

$ mvn -f non-java.xml compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building sample-project 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- openapi-generator-maven-plugin:3.0.0-SNAPSHOT:generate (default) @ sample-project ---
[WARNING] The 'language' option is deprecated and may reference language names only in the next major release (4.0). Please use 'generatorName' instead.
[WARNING] Output directory does not exist, or is inaccessible. No file (.openapi-generator-ignore) will be evaluated.

The language option (--lang and -l in CLI, language in maven plugin) has
drifted from the original intention of defining a top-level language
implementation with variance on library. Generators began to encode
generator type into language (e.g. erlang-client), reused language as
framework-only (e.g. scalatra), or embedded language and framework (e.g.
typescript-angular).

With the 3.0.0 release of openapi-generator, we've moved to a
standardization of these names, which means they no longer fit into the
singular concept of a "language".

We've discussed plans to provide a better user experience around the
CLI, breaking apart the generator lookup into the variations that make
up a generator:

* language
* type
* framework
* version?

To do this, we must first deprecate language and warn users that what
they're currently using (e.g. scalatra, typescript-angular) is being
replaced by generatorName and that language may mean something else in a
later version of the generator.

For discussion, see OpenAPITools#39.
This example uses maven to generate via openapi codegen.

To execute:

     mvn -f non-java.xml compile

Output location will be written to console.
@jimschubert
Copy link
Member Author

question: I've left "language" as a required option for the CLI and maven plugin, but I'm wondering if we should go ahead and make both language and generatorName optional from the start? My reasoning for leaving it as required is that existing users will have this option anyway, so required/optional won't matter. However, now that I think about it, the warning message says to "use generatorName instead" and if a user does this and removes "language", they'll be told that language is required.

Thoughts on going ahead and making both optional for now, and exposing an error manually if neither is set? I think this would ease both migration for existing users and onboarding for new users.

@jmini
Copy link
Member

jmini commented May 16, 2018

This is nice, looks good to me!

I think in the CLI there is also the option to output all available langs:

openapi-generator-cli langs

Or something like that, this should be changed to generators (with backward compatibility => we keep langs in parallel during one release)


There are also error message, when an invalid lang is selected, that says "available languages" => should be changed to "available generators"


We also need to update our migration guide:
https://github.com/OpenAPITools/openapi-generator/blob/master/docs/migration-from-swagger-codegen.md


I thought you wanted also to fail (have an error) if both "language" and "generator name" are set. Maybe I missed it from your code.


If I remember well you also mention something about supporting old generator names during one release to ease the mig.

Maybe we can add this map somewhere:

Map<String,String> nameMigrationMap = new HashMap<>();
nameMigrationMap.put("akka-scala","scala-akka");
nameMigrationMap.put("scala", "scala-httpclient");
nameMigrationMap.put("jaxrs", "jaxrs-jersey");
nameMigrationMap.put("qt5cpp", "cpp-qt5");
nameMigrationMap.put("cpprest","cpp-restsdk");
nameMigrationMap.put("tizen", "cpp-tizen");
nameMigrationMap.put("sinatra","ruby-sinatra");
nameMigrationMap.put("swift", "swift2-deprecated");
nameMigrationMap.put("lumen", "php-lumen");
nameMigrationMap.put("slim","php-slim");
nameMigrationMap.put("ze-ph", "php-ze-ph");
nameMigrationMap.put("nancyfx","csharp-nancyfx");

And do a if map.containsKey() then output a warning and use the new new instead of the old. We can support this for both "language" and "generator-name" options.

@jmini
Copy link
Member

jmini commented May 16, 2018

question: I've left "language" as a required option for the CLI and maven plugin, but I'm wondering if we should go ahead and make both language and generatorName optional from the start?

I think both optional is good and error if both are set or if both are missing.

@jmini jmini added this to the 3.0.0 milestone May 16, 2018
@jimschubert
Copy link
Member Author

@jmini thanks for doing such a thorough evaluation. I hadn't even considered the langs command!

I'll make the improvements you've listed above. I think the nameMigrationMap check makes the most sense in the new setGeneratorName setter. Since I pass setLang to this method, it would be a single point in code to manage the migration mapping.

I'll change the title of the PR to indicate it's a work in progress. Should we add a WIP label as well?

@jimschubert jimschubert changed the title Cli generator name option WIP: Cli generator name option May 16, 2018
This removes CLI/maven plugin property requirements on language, to
provide a better user experience with suggesting to use the new option.
Errors on missing one of laguage/generatorName are exposed
programmatically rather than via framework (airline/mojo).

This also includes automatic mapping between "language" options which
have been renamed, to ease the transition from the 2.4.0-SNAPSHOT and
earlier users.
@jimschubert jimschubert changed the title WIP: Cli generator name option Cli generator name option, replaces 'language' options in CLI and Maven Plugin May 17, 2018
@jimschubert
Copy link
Member Author

I've pushed some changes. I've deprecated the lang CLI option, as this may likely list languages only (rather than generator) in the future.

To list generators, I've created list which outputs to a long-format, separated by headers of generator type. I've provided a --short switch to output a parseable/scriptable CSV option.

Last push also includes the mapping for the lang->generator-name renames as defined in the wiki. Once this is merged, we can update the wiki's mention of the -l switch.

configurator.setGeneratorName(language);
} else {
LOGGER.error("A generator name (generatorName) is required.");
System.exit(1);
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 it is better to throw a MojoExecutionException instead of System exist (maven will terminate with an appropriate error message and can still do some other stuff)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for catching this. I was just blindly copying what I added to the CLI code, and I can't believe I left System.exit here. 💃


configurator.setLang(language);
// TODO: After 3.0.0 release (maybe for 3.1.0): Fully deprecate lang.
if (isNotEmpty(generatorName)) {
Copy link
Member

Choose a reason for hiding this comment

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

Right after the if, I would add something:

if (isNotEmpty(language))
    LOGGER.warn("The 'language' option is deprecated and was replaced by 'generatorName'. Both can not be set together");
    throw new MojoExecutionException("Illegal configuration: 'language' and  'generatorName' can not be set both, remove 'language' from your configuration");
}

@jmini
Copy link
Member

jmini commented May 18, 2018

I have spotted 2 small changes in the MoJo.

As indicated by @kenisteward on Gitter, I think it is I good idea to update the docs in this PR:

And in the docs/migration-from-swagger-codegen.md we need a new section to say that there is a change.

@jimschubert
Copy link
Member Author

@jmini all great feedback. Thanks!

Do you think it's necessary to update the migration doc? It's not required to make the changes to the language switch in order to migrate, and it will want the user. I guess now that it's not required to change the language values, either, that it makes sense to list for consistency.

@jmini
Copy link
Member

jmini commented May 18, 2018

@jimschubert: I have named it "migration guide" but this is also a "what are the main differences between Swagger-Codegen and OpenAPI Generator".

After New maven coordinates section I would create 2 new sections:

  • Changes in the CLI
  • Changes in Maven Plugin

In each new section I would summarize what have changed with one or two sentences.

In New generators names section, I would add one sentence to say that OpenAPI Generator is tolerant with old names during one release.

@jimschubert
Copy link
Member Author

@jmini Thanks again for the second pair of eyes.

I had originally left all -l instances in scripts because the option is still valid, but on second thought I wanted these to be "current" and not produce a warning by default on initial release. Because there were about 500 locations that all had to be verified individually and changed manually, I've broken changes down into many separate commits to make them easier to scan.

I was wondering, what determines that docs should exist under /docs rather than in the wiki? It looked like you created or edited most of those files, and some of the information seems duplicated or like there are empty placeholders on the wiki:

Are we intending to move those under the folder to the wiki, or are we planning to deprecate the wiki in favor of source control docs?

@jmini
Copy link
Member

jmini commented May 18, 2018

It looked like you created or edited most of those files

@wing328 extracted those files from the README with c32ef12

I just moved them into a docs/ folder with 3d7eaf9


Yes we we have planned to move more content into the repository (and remove them from the wiki).

Multiple reasons for that:

  • Documentation belongs to software change, have a look at this PR, it is great to be able to discuss what needs to be documented.
  • GitHub Wiki does not support PR workflow, which is a great way to do suggestions, reviews and improvements
  • Wiki are not forked in GitHub forks, you need to migrate them separately (they are git repositories, but not well integrated in GitHub UI).
  • Software documentation follows the software branches. Imagine we works on 4.0 and do some bugfix release for 3.0 on a separated 3.x-maintenance branch. With a GitHub wiki you just have a master branch, you can not support both versions in parallel.
  • On the long term the plan is to generate the documentation inside a static website. For that we might need some artefacts that comes from the code itself (like for example the help in the command line that you have updated by hand). In the docs page there should be a placeholder that some content will be injected, and the static-website build tool should put the correct values in the built html manual. When we have this it make even more sense to single source everything in one repo and not in two.

I would say that we should migrate the content of the wiki into some files in the docs/ folder. This can be a step-by-step process. I you spot something outdated in the wiki that have already its counterpart in the docs just delete it and replace it with a link to the new page.

@jimschubert
Copy link
Member Author

@jmini I fully agree with moving things to /docs for the reasons you posted above. Also, docs in the repository support all of github's templating (asciidoc, csv rendering, etc).

I think we should migrate everything from the wiki, as I find it confusing that there are multiple places for all of these details and I'm not easily able to do a search across the project from the wiki. I could fork the wiki into a subdirectory, but that wouldn't share a commit with this PR.

@wing328
Copy link
Member

wing328 commented May 18, 2018

The FAQ (wiki) that I originally created intends to be community driven FAQ as anyone can update it easily without a PR. (we did see contributions from the community to add more FAQs over time)

The Q&A (mainly for the launch of openapi-generator) is not something I want people to update without approval/review as it represents our viewpoints.

I agree it may confuse users and happy to see consolidations or other approaches to make our doc more useful and easily discoverable by our users.

@jmini
Copy link
Member

jmini commented May 18, 2018

This discussion about "docs/ vs wiki" has nothing to do with this PR, I have opened #103 (it will be easier to find it later).

@jimschubert
Copy link
Member Author

@jmini I think the /docs discussion is relevant here, as it has lots of -l occurrences that would need to be changed once this is merged. I don't think the /docs vs wiki discussion has to be solved here, just whether those pages are intended to be kept up-to-date or if the /docs were only a placeholder as we migrated the wiki. What I didn't want to happen is for me to move content from /docs to the wiki or vice versa as a follow up.

Sorry if I didn't clarify the reasoning for my question previously.

@jmini
Copy link
Member

jmini commented May 18, 2018

It is OK. Better more text to clarify than misunderstanding. I have updated my comment to say that the "docs vs wiki discussion" was moved to an other issue.

It is great that you have updated the docs, and the bin/ scripts.

Tell us when you consider this ready for test.

@jimschubert
Copy link
Member Author

@jmini this is ready to test. Sorry, I thought I had included that in my comment after the last push.

Copy link
Member

@jmini jmini left a comment

Choose a reason for hiding this comment

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

This looks good to me, thank you a lot for this contribution!

@jmini
Copy link
Member

jmini commented May 22, 2018

@jimschubert can you solve the conflicts created by #124 so that we can merge this?

During the merge, for each conflict inside the bin/ folder you can take the master version and then redo a search and replace -l => -g.

* master: (36 commits)
  jaxrs-cxf-cdi: fix outer enum (OpenAPITools#131)
  Move bash argv opt to end of ags line in scripts (OpenAPITools#124)
  Reduce CI logging (OpenAPITools#119)
  Download elm dependencies without prompting user. (OpenAPITools#118)
  [aspnetcore] Make the use of Swashbuckle optional (OpenAPITools#110)
  DefaultGenerator: fix NullPointerException (OpenAPITools#109)
  [Java] use html entities in javadoc of generated code (OpenAPITools#106)
  Update PULL_REQUEST_TEMPLATE.md
  [java] Enum in array of array (OpenAPITools#66)
  Rename datatype to dataType in CodegenProperty (OpenAPITools#69)
  update elm test to compile all elm files (OpenAPITools#95)
  Fix Petstore example for Elm (OpenAPITools#96)
  Update Docker documentation (OpenAPITools#97)
  CaseFormatLambda has been added, params for Rest-assured client has been refactored (OpenAPITools#91)
  Update integration.md
  [Clojure] Add util method to set the api-context globally (OpenAPITools#93)
  [JaxRS-Java] issue with implFolder on windows, and required fields generation for containers (OpenAPITools#88)
  Set parameters allowableValues dynamically (OpenAPITools#65)
  Meta: set version for "build-helper-maven-plugin" (OpenAPITools#89)
  Fix javadoc issues in "openapi-generator" module (OpenAPITools#84)
  ...
@jimschubert
Copy link
Member Author

@jmini @wing328 I've fixed these merge conflicts. I've also added an exit code of 1 if the CLI is called without args, to indicate failure. I didn't test whether the airlift framework also does this on help, which is common behavior… but I think that's not important unless we change the default command to help.

@jmini jmini merged commit 27426f7 into OpenAPITools:master May 23, 2018
@jimschubert jimschubert deleted the cli-generator-name-option branch May 23, 2018 04:33
aserkes pushed a commit to aserkes/openapi-generator that referenced this pull request Sep 21, 2022
* Add generated samples for Helidon generators

* Add generated server doc
nilskuhn pushed a commit to nilskuhn/openapi-generator that referenced this pull request Apr 6, 2023
fix(deps): update dependency rxjs to v6.6.3
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.

3 participants