Skip to content

Add support for normalizing bearerAuth#20860

Merged
wing328 merged 1 commit intoOpenAPITools:masterfrom
cbascom:bearer-auth
Mar 24, 2025
Merged

Add support for normalizing bearerAuth#20860
wing328 merged 1 commit intoOpenAPITools:masterfrom
cbascom:bearer-auth

Conversation

@cbascom
Copy link
Copy Markdown
Contributor

@cbascom cbascom commented Mar 12, 2025

Putting this up to help clarify my feature request in #20842. I wanted to see if something like this would be considered. If so, I will proceed and add unit tests and documentation to get the PR ready for review. If not, I'll go the direction of putting this into a user defined template instead.

The openapi 2.0 spec did not support bearer authentication but it was added in openapi 3.0. In order to support client generation that includes support for bearerAuth, this change adds a new feature to the OpenapiNormalizer so that it can be configured to look for a specific securityDefinition name and convert it to bearerAuth.

Example:

openapi-generator-cli config file includes:

openapiNormalizer:
  DETECT_BEARER_AUTH_FROM_NAME: bearerAuth

Original spec includes:

  "securityDefinitions": {
    "basicAuth": {
      "type": "basic"
    },
    "bearerAuth": {
      "type": "apiKey",
      "name": "bearer",
      "in": "header"
    }
  },

Generated spec has:

components:
  securitySchemes:
    basicAuth:
      scheme: basic
      type: http
    bearerAuth:
      scheme: bearer
      type: http

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 || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (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.

@wing328
Copy link
Copy Markdown
Member

wing328 commented Mar 13, 2025

we can give it a try. definitely something the normalizer can help in this case

will you be able to maintain this feature/normalizer rule moving forward?

and what about updating the spec to v3.x instead?

thanks for submitting a PR to start with

@cbascom
Copy link
Copy Markdown
Contributor Author

cbascom commented Mar 16, 2025

I hope future versions of the spec move to openapi 3.x, but I can't change this one unfortunately. I'm definitely willing to maintain this if anything comes up with it.

It is now updated with doc updates and a test for the new feature. I did change the name from DETECT_BEARER_AUTH_FROM_NAME to SET_BEARER_AUTH_FOR_NAME, but open to any other ideas for naming it if that doesn't work.

@wing328
Copy link
Copy Markdown
Member

wing328 commented Mar 20, 2025

Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors.

Let me know if you need help fixing it.

Ref: https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-can-i-update-commits-that-are-not-linked-to-my-github-account

The openapi 2.0 spec did not support bearer authentication but it was
added in openapi 3.0. In order to support client generation that
includes support for bearerAuth, this change adds a new feature to the
OpenapiNormalizer so that it can be configured to look for a specific
securityDefinition name and convert it to bearerAuth.
@cbascom
Copy link
Copy Markdown
Contributor Author

cbascom commented Mar 21, 2025

Thanks for the heads up. I believe I have corrected that now by resetting the author using the correct email address.

@wing328 wing328 added Enhancement: Feature OpenAPI Normalizer Normalize the spec for easier processing labels Mar 24, 2025
@wing328 wing328 added this to the 7.13.0 milestone Mar 24, 2025
@wing328 wing328 merged commit cd2fbd6 into OpenAPITools:master Mar 24, 2025
14 checks passed
@wing328
Copy link
Copy Markdown
Member

wing328 commented Mar 24, 2025

thanks for the PR.

let's give it a try

@cbascom cbascom deleted the bearer-auth branch March 30, 2025 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement: Feature OpenAPI Normalizer Normalize the spec for easier processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants