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

[typescript] feat: Add typescript licenseName option #19888

Merged

Conversation

david-marconis
Copy link
Contributor

This change makes it possible to change the value of the license set in the package.json file for typescript client generators. Here is a detailed list of the changes made:

  • Add licenseName to additionalProperties for Typescript which sets the license in the package.json file for npm.
  • Update documentation.
  • Add getLicenceNameDefaultValue method to AbstractTypescriptClientCodegen so it can be overridden by subclasses.
  • Add default values for some subclasses of AbstractTypescriptClientCodegen to keep existing default behaviour.
  • Add test to ensure that the licenseName additionalProperty is set

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    (For Windows users, please run the script in Git BASH)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02) @davidgamero (2022/03) @mkusaka (2022/04) @joscha (2024/10)

Copy link
Contributor

@joscha joscha left a comment

Choose a reason for hiding this comment

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

Nice one!

@@ -71,6 +71,7 @@ public Map<String, String> createOptions() {
.put(CodegenConstants.LEGACY_DISCRIMINATOR_BEHAVIOR, "true")
.put(CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT, "true")
.put(CodegenConstants.ENUM_UNKNOWN_DEFAULT_CASE, ENUM_UNKNOWN_DEFAULT_CASE_VALUE)
.put(CodegenConstants.LICENSE_NAME, AbstractTypeScriptClientCodegen.LICENSE_NAME_DEFAULT_VALUE)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a thought: would it make at all sense to introduce an abstract options provider that has this for all current and also future typescript generators?

Copy link
Contributor Author

@david-marconis david-marconis Oct 16, 2024

Choose a reason for hiding this comment

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

It could make sense given that the Typescript generators seem to have a lot of options in common. I don't see any other abstract OptionsProviders though, so it is not a common practice in this repo. I could have a crack at it if I get the time, to see what it looks like.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I implemented a shared interface which all the Typescript OptionsProviders extend, let me know if you want me to keep it in or remove it. I didn't bother to add OptionsProviders for the typescript generators which were missing ones, there might be that some of the other generators shouldn't have the parameters in the shared interface, I haven't checked that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the change is ace. @macjohnny WDYT?

@@ -11,7 +11,7 @@
"openapi-client",
"openapi-generator"
],
"license": "Unlicense",
"license": "{{licenseName}}",
Copy link
Member

Choose a reason for hiding this comment

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

lets only add it when a value is set, same in the other generators

Suggested change
"license": "{{licenseName}}",
{{#licenseName}}
"license": "{{licenseName}}",
{{/licenseName}}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason why I kept it like this for some and not for others is because some will always have a default value set. IDK if it is possible for this value to be unset for generators that have the default value set in the field directly.

Copy link
Member

Choose a reason for hiding this comment

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

I guess one can explicitly set to an empty value, then it should not pass the {{#licenseName}} condition

Copy link
Contributor Author

@david-marconis david-marconis Oct 17, 2024

Choose a reason for hiding this comment

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

I wasn't able to do this with the cli. If I set the licenseName to empty value it will still be present. I tested this on this branch with typescript-fetch for which I have this in place already:

❯ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g typescript-fetch -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -t modules/openapi-generator/src/main/resources/typescript-fetch -o samples/client/petstore/typescript-fetch/builds/default --additional-properties npmName=npmName,licenseName=
❯ grep "license" samples/client/petstore/typescript-fetch/builds/default/package.json
  "license": "",
❯ java -jar ... generate ... licenseName="" > /dev/null && grep "license" ...package.json
  "license": "",
❯ java -jar ... generate ... licenseName="null" > /dev/null && grep "license" ...package.json
  "license": "null",

Maybe there is some other way to set it to null, but I was not able to do it.

I could still implement it, I guess it wouldn't hurt, but I don't think it's necessary.

Copy link
Member

Choose a reason for hiding this comment

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

ok lets leave it as it is for now, since it has been there anyway :-D

@macjohnny
Copy link
Member

@david-marconis thanks for your contribution!

@macjohnny macjohnny merged commit ce09134 into OpenAPITools:master Oct 17, 2024
15 checks passed
@david-marconis david-marconis deleted the feature/add-typescript-license branch October 17, 2024 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants