OpenAPITools / OpenAPITools/openapi-generator
[BUG] java-micronaut-client generator creates OAuth configuration despite it being disabled
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
OpenAPI generator configuration for java-micronaut-client generates wrong configuration for application.yml. It is clear, that in file application.yml.mustache the block that should be conditionally generated (controlled by configureAuth) is adding configuration that requires setting up additional properties.
{{#configureAuth}}
security:
oauth2:
clients:{{#oauthMethods}}
{{#lambda.replaceDotsWithUnderscore}}{{{name}}}{{/lambda.replaceDotsWithUnderscore}}:
grant-type: {{#isCode}}authorization_code{{/isCode}}{{#isImplicit}}implicit{{/isImplicit}}{{#isPassword}}password{{/isPassword}}{{#isApplication}}client_credentials{{/isApplication}}
scopes: [{{#scopes}}"{{{scope}}}"{{^-last}}, {{/-last}}{{/scopes}}]{{!authorization url}}{{#authorizationUrl}}
authorization:
url: "{{{authorizationUrl}}}"{{/authorizationUrl}}{{!token url}}{{#tokenUrl}}
token:
auth-method: client_secret_basic
url: "{{{tokenUrl}}}"{{/tokenUrl}}{{!refreshUrl is not used}}
# TODO Fill in the parameters for {{{name}}} authorization if needed
# client-id:
# client-secret:{{/oauthMethods}}{{/configureAuth}}{{!
do not configure authorization, but leave hints for user
}}{{^configureAuth}}
# TODO configure security features
security:
oauth2:
clients:
# An example of how oauth client is filled
# name:
# grant-type: authorization_code | client_credentials
# scopes: []
# token:
# auth-method: client_secret_basic
# url: "https://"
# client-id:
# client-secret:
# An example of how to apply other authorization methods
# authentication: bearer | cookie | session{{/configureAuth}}
I believe, that the second block that hints: do not configure authorization, but leave hints for user should have the security.auth2.clients: property commented out.
openapi-generator version
6.0.0
Generation Details
The gradle plugin configuration does not enable OAuth2 (configureAuth is false by default, so explicitly setting it to false in config does nothing as well):
openApiGenerate {
generatorName.set("java-micronaut-client")
inputSpec.set(oasYamlFileLocation)
outputDir.set("$buildDir/generated/openapi")
apiPackage.set("$oasClientBasePackage.api")
modelPackage.set("$oasClientBasePackage.model")
configOptions.set(
mapOf(
"serializationLibrary" to "jackson",
"openApiNullable" to "false",
"micronautVersion" to "${project.properties["micronautVersion"]}",
"reactive" to "false",
"artifactId" to oasClientArtifactId,
"artifactVersion" to "${project.properties["version"]}",
)
)
}
Suggest a fix
All lines of code should be commented out:
# TODO configure security features
# security:
# oauth2:
# clients:
# An example of how oauth client is filled
# name:
# grant-type: authorization_code | client_credentials
# scopes: []
# token:
# auth-method: client_secret_basic
# url: "https://"
# client-id:
# client-secret:
# An example of how to apply other authorization methods
# authentication: bearer | cookie | session{{/configureAuth}}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with modules/openapi-generator/src/main/resources/java-micronaut/common/configuration/application.yml.mustache and inspect the configureAuth branches, then reproduce generation with the shown java-micronaut-client Gradle configuration. Done means the disabled OAuth configuration produces only commented guidance in application.yml, without active security.oauth2.clients properties.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100