Open cbb330 opened 3 months ago
Similar to https://github.com/OpenAPITools/openapi-generator/issues/19168 with RestTemplate.
@MaurizioCasciano no, it is not. That issue is for a missing auth in the init function -- it is missing code that should be there.
here we have something else, that securityRequirement doesn't result in any client-side requirement at all. auth is still optional on the client at build time.
Bug Report Checklist
actual output has no required auth header required in the public interfaces of {name}Api.java. defining a securityscheme creates getters/setters. then securityRequirement creates a parser that will propagate the value from the setter if it is present.
This is the only thing added to {name}Api.java by the securityRequirement:
to each route. This is then used later like this:
where applyToParams is an interface with this signature (note there is no exception or etc. compile time requirement for header presence):
here is HttpBearerAuth.java's implementation of the interface as an example (they are all similar in webclient)
I would expect a SecurityRequirement to be a compile time guarantee in the client because e.g. the auth header is not passed in parameters. This is exactly the case in "feign" see here:
the creation of auth in init
then the requestInterceptor will throw an exception if auth parameters are null
Description
Generated clients for any API which declare a global security requirement or route based security requirements, have no required auth at all. the requirement is simply present in the swagger UI, as well as is parsed on the client only if the auth is present, and exposes public getters/setters.
SecurityRequirement says as such the security is a requirement, so the expected outcome is the client should have compile time guarantee that the auth header be passed to the API public interfaces. e.g. just like a required header
openapi-generator version
6.6.0 7.7.0
OpenAPI declaration file content or url
Generation Details
java -jar $jar/openapi-generator-cli.jar generate \ -i $input \ --api-package com.linkedin.openhouse.$name.client.api \ --model-package com.linkedin.openhouse.$name.client.model \ --invoker-package com.linkedin.openhouse.$name.client.invoker \ --group-id com.linkedin.openhouse.$name \ --artifact-id generated-$name-client \ --artifact-version 0.0.1-SNAPSHOT \ -g java \ -p java8=true \ --library webclient \ -o $output
Steps to reproduce
use my input above, the 6.6.0 jar, java8, and webclient library
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues?q=is%3Aissue+label%3A%22Client%3A+Java%22+security+
^ none of above cover this issue.
Suggest a fix
when SecurityRequirement is present,
any of: