quarkiverse / quarkus-openapi-generator

OpenAPI Generator - REST Client Generator
Apache License 2.0
119 stars 80 forks source link

custom-register-providers not working on version 2.3.0 #653

Closed blackenz closed 7 months ago

blackenz commented 7 months ago

I'm trying to use the custom-register-providers configuration but i'm having trouble to do a mvn compile. I'm using version quarkus-openapi-generator version 2.3.0 , with Quarkus 3.7 and Java 21.

pom.xml contents:

  <properties>
    <compiler-plugin.version>3.12.1</compiler-plugin.version>
    <maven.compiler.release>21</maven.compiler.release>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
    <quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
    <quarkus.platform.version>3.7.1</quarkus.platform.version>
    <skipITs>true</skipITs>
    <surefire-plugin.version>3.2.5</surefire-plugin.version>
  </properties>
    <dependency>
      <groupId>io.quarkiverse.openapi.generator</groupId>
      <artifactId>quarkus-openapi-generator</artifactId>  
      <version>2.3.0</version>
    </dependency>

Errors while building:

[ERROR] Failed to execute goal io.quarkus.platform:quarkus-maven-plugin:3.7.1:generate-code (default) on project xxxxx: Quarkus code generation phase has failed: InvocationTargetException: Found unsupported configuration: [custom-register-providers]. Supported configurations are :[verbose, input-base-dir, include, exclude, validateSpec, default-security-scheme, base-package, api-name-suffix, model-name-suffix, model-name-prefix, skip-form-model, mutiny, additional-model-type-annotations, additional-api-type-annotations, type-mappings, import-mappings, open-api-normalizer, return-response, enable-security-generation, config-key, generate-part-filename, part-filename-value, use-field-name-in-part-filename, additional-properties-as-attribute] -> [Help 1]

Is this a regression?

Best regards

mcruzdev commented 7 months ago

Hi @blackenz, how are you? Thank you for reporting!

I will try to reproduce the error here. Can you share the application.properties config?

blackenz commented 7 months ago

Thanks for the quick reply @mcruzdev. I forgot to leave my application properties. I leave it below:

quarkus.rest-client.logging.scope=request-response
quarkus.rest-client.proxy-address=127.0.0.1:8080
quarkus.tls.trust-all=true
quarkus.log.category."org.jboss.resteasy.client.logging".level=DEBUG
quarkus.openapi-generator.codegen.spec.api_json.additional-model-type-annotations=@JsonInclude(JsonInclude.Include.NON_NULL)
quarkus.openapi-generator.codegen.spec.api_json.custom-register-providers=pt.blackenz.apis.APIRequestFilter

I'm using this feature, since the OpenApi definition i'm using does not follow the specification for Security Schemes. So i am using this feature as a workaround to register a filter that injects the Authorization Header in all requests. Unfortunately, even if i define the filter anotated as a Provider, the filter gets executed, but for some reason i cannot explain, the headers are not being injected in the request, even if logging the headers, says they are. I was hoping this feature would make the filters work as expected.

Thank You

ricardozanini commented 7 months ago

@blackenz can you try using additional-api-type-annotations, instead? See: https://docs.quarkiverse.io/quarkus-openapi-generator/dev/index.html#_oauth2_authentication

If authentication support doesn’t suit your needs you can decide to disable it with enable-security-generation=false. In such case CompositeAuthenticationProvider and AuthenticationPropagationHeadersFactory wont be generated and used with your api. The option can be set globally with quarkus.openapi-generator.codegen.enable-security-generation or per api quarkus.openapi-generator.codegen.spec.my_spec_yml.enable-security-generation. Custom authentication provider can be used with additional-api-type-annotations

ricardozanini commented 7 months ago

@blackenz we've removed this option in this PR: #431

See the release notes: https://github.com/quarkiverse/quarkus-openapi-generator/releases/tag/2.2.9

mcruzdev commented 7 months ago

Thank you! @ricardozanini, I was very busy today. We need then to remove it from our documentation.

Actually the first link on README is redirecting to https://github.com/quarkiverse/quarkus-openapi-generator/blob/1.0.1/README.md documentation. Maybe that link is making confusion.

mcruzdev commented 7 months ago

The documentation was changed by #656

blackenz commented 7 months ago

@blackenz can you try using additional-api-type-annotations, instead? See: https://docs.quarkiverse.io/quarkus-openapi-generator/dev/index.html#_oauth2_authentication

If authentication support doesn’t suit your needs you can decide to disable it with enable-security-generation=false. In such case CompositeAuthenticationProvider and AuthenticationPropagationHeadersFactory wont be generated and used with your api. The option can be set globally with quarkus.openapi-generator.codegen.enable-security-generation or per api quarkus.openapi-generator.codegen.spec.my_spec_yml.enable-security-generation. Custom authentication provider can be used with additional-api-type-annotations

Thank You @ricardozanini ! Even though the oauth2 doesn't suit my purposes, the additional-api-type-annotations, did work for me. @mcruzdev as you say, the documentation is very confusing at this point, and that was the main reason why I was trying to use the custom-register-providers. I think the documentation should be taken a look at.

Thank You

ricardozanini commented 7 months ago

@mcruzdev can you open a PR to fix the documentation?

mcruzdev commented 7 months ago

Merged, sorry to not link with this issue #656