-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable-security-generation | additional-api-type-annotations (#431)
* enable-security-generation | additional-api-type-annotations * removal of custom-register-providers and client-headers-factory * documentation | fixes * Update README.md Co-authored-by: Helber Belmiro <[email protected]> * global configs | fixes * config name validation | default-security-schema | refactor * fixes * OpenApiConfigValidator * config items refactor * Update deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/OpenApiConfigValidator.java Co-authored-by: Helber Belmiro <[email protected]> * Update deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/OpenApiGeneratorCodeGenBase.java Co-authored-by: Helber Belmiro <[email protected]> * Update deployment/src/test/java/io/quarkiverse/openapi/generator/deployment/OpenApiConfigValidatorTest.java Co-authored-by: Helber Belmiro <[email protected]> * last fixes * switch default values * token propagation factory --------- Co-authored-by: Helber Belmiro <[email protected]>
- Loading branch information
1 parent
60d6605
commit 30d5501
Showing
28 changed files
with
504 additions
and
1,397 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,12 @@ If a base package name is not provided, it will be used the default `org.openapi | |
|
||
Configuring `additional-model-type-annotations` will add all annotations to the generated model files (extra details can be found in [OpenApi Generator Doc](https://openapi-generator.tech/docs/generators/java/#config-options)). | ||
|
||
The same way you can add any additional annotations to the generated api files with `additional-api-type-annotations`. Given you want to include Foo and Bar annotations, you must define additional-api-type-annotations as: | ||
|
||
```properties | ||
quarkus.openapi-generator.codegen.spec.petstore_json.additional-api-type-annotations[email protected];@org.test.Bar | ||
``` | ||
|
||
> **⚠️** Note that the file name`petstore_json`is used to configure the specific information for each spec. We follow the [Environment Variables Mapping Rules](https://github.com/eclipse/microprofile-config/blob/master/spec/src/main/asciidoc/configsources.asciidoc#environment-variables-mapping-rules) from Microprofile Configuration to sanitize the OpenAPI spec filename. Any non-alphabetic characters are replaced by an underscore `_`. | ||
Run `mvn compile` to generate your classes in `target/generated-sources/open-api-json` path: | ||
|
@@ -237,9 +243,9 @@ pattern: `quarkus.openapi-generator.[filename].auth.[security_scheme_name].[auth | |
If the OpenAPI specification file has `securitySchemes` definitions, but no [Security Requirement Object](https://spec.openapis.org/oas/v3.1.0#security-requirement-object) definitions, the generator can be configured to create these by default. In this case, for all operations without a security requirement the default one will be created. Note that the property value needs to match the name of a security scheme object definition, eg. `api_key` or `basic_auth` in the `securitySchemes` list above. | ||
|
||
| Description | Property Key | Example | | ||
| -------------------- | -------------------------------------------------------------- | ---------------------------------------------------- | | ||
| Create security for the referenced security scheme | `quarkus.openapi-generator.codegen.default.security.scheme` | `quarkus.openapi-generator.codegen.default.security.scheme=api_key` | | ||
| Description | Property Key | Example | | ||
| -------------------- |-------------------------------------------------------------|---------------------------------------------------------------------| | ||
| Create security for the referenced security scheme | `quarkus.openapi-generator.codegen.default-security-scheme` | `quarkus.openapi-generator.codegen.default-security-scheme=api_key` | | ||
|
||
See the module [security](integration-tests/security) for an example of how to use this feature. | ||
|
||
|
@@ -331,6 +337,9 @@ RESTEasy Reactive: | |
<artifactId>quarkus-oidc-client-reactive-filter</artifactId> | ||
</dependency> | ||
``` | ||
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` | ||
|
||
See the module [generation-tests](integration-tests/generation-tests) for an example of how to use this feature. | ||
|
||
|
@@ -419,17 +428,7 @@ The token propagation can be used with type "oauth2" or "bearer" security scheme | |
| `quarkus.openapi-generator.[filename].auth.[security_scheme_name].token-propagation=[true,false]` | `quarkus.openapi-generator.petstore_json.auth.petstore_auth.token-propagation=true`<br/>Enables the token propagation for all the operations that are secured with the `petstore_auth` scheme in the `petstore_json` file. | ||
| `quarkus.openapi-generator.[filename].auth.[security_scheme_name].header-name=[http_header_name]` | `quarkus.openapi-generator.petstore_json.auth.petstore_auth.header-name=MyHeaderName`<br/>Says that the authorization token to propagate will be read from the HTTP header `MyHeaderName` instead of the standard HTTP `Authorization` header. | ||
|
||
## Headers propagation | ||
Custom headers propagation can be set via MicroProfile configuration `org.eclipse.microprofile.rest.client.propagateHeaders`. | ||
In order to consider this configuration you must force `@RegisterClientHeaders` to use its default MicroProfile `ClientHeadersFactory` implementation. Therefore there is an option `client-headers-factory` where you can set any implementation of `ClientHeadersFactory`. | ||
|
||
| Description | Property Key | Example | | ||
| -------------|----------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| Bearer Token | `quarkus.openapi-generator.codegen.spec.[fileName].client-headers-factory` | `quarkus.openapi-generator.codegen.spec.open_weather_yaml.client-headers-factory=org.eclipse.microprofile.rest.client.ext.DefaultClientHeadersFactoryImpl` | | ||
|
||
If `client-headers-factory` is set to `none` `@RegisterClientHeaders` will use its default implicit implementation as in the example above. | ||
|
||
If no option is set then default generated `AuthenticationPropagationHeadersFactory` class is used. | ||
|
||
## Circuit Breaker | ||
|
||
|
@@ -676,16 +675,6 @@ file. By default, these operations are generated. You can fine tune this behavio | |
|
||
Use the property key `<base_package>.api.MyClass.generateDeprecated=false` to disable the deprecated operations in the given API. For example `org.acme.openapi.simple.api.DefaultApi.generatedDeprecated=false`. | ||
|
||
## Custom Register Providers for generated api | ||
|
||
In some cases, we need custom `RegisterProvider` for generated api, e.g. logging. You can define your own Providers in `application.properties` : | ||
|
||
| Property Key | Example | | ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------| | ||
| `quarkus.openapi-generator.codegen.spec.[filename].custom-register-providers` | `quarkus.openapi-generator.codegen.spec.simple_openapi_json.custom-register-providers=org.test.Foo,org.test.Bar`<br/>Provider classes are separated by commas | | ||
|
||
With the above configuration, the extension generates your Rest Clients with a code similar to the following: | ||
|
||
```java | ||
package org.acme.openapi.simple.api; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CommonItemConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package io.quarkiverse.openapi.generator.deployment; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
|
||
/* | ||
* Model for the configuration of this extension. | ||
* It's used for documentation purposes only. | ||
* The configuration is consumed in the codegen phase, before build time. | ||
* Not meant to be used outside this scope. | ||
* Config items can be applied on spec and globally as well | ||
*/ | ||
@ConfigGroup | ||
public class CommonItemConfig { | ||
|
||
/** | ||
* Whether to skip the generation of models for form parameters | ||
*/ | ||
@ConfigItem(name = "skip-form-model") | ||
public Optional<Boolean> skipFormModel; | ||
|
||
/** | ||
* Type Mapping is an OpenAPI Generator configuration specifying which Java types (the values) should be used for a | ||
* given OAS datatype (the keys of this map) | ||
*/ | ||
@ConfigItem(name = "type-mappings") | ||
public Map<String, String> typeMappings; | ||
|
||
/** | ||
* Import Mapping is an OpenAPI Generator configuration specifying which Java types (the values) should be | ||
* imported when a given OAS datatype (the keys of this map) is used | ||
*/ | ||
@ConfigItem(name = "import-mappings") | ||
public Map<String, String> importMappings; | ||
|
||
/** | ||
* The specified annotations will be added to the generated model files | ||
*/ | ||
@ConfigItem(name = "additional-model-type-annotations") | ||
public Optional<String> additionalModelTypeAnnotations; | ||
|
||
/** | ||
* The specified annotations will be added to the generated api files | ||
*/ | ||
@ConfigItem(name = "additional-api-type-annotations") | ||
public Optional<String> additionalApiTypeAnnotations; | ||
|
||
/** | ||
* Defines if the methods should return {@link javax.ws.rs.core.Response} or a model. Default is <code>false</code>. | ||
*/ | ||
@ConfigItem(name = "return-response") | ||
public Optional<Boolean> returnResponse; | ||
|
||
/** | ||
* Defines if security support classes should be generated | ||
*/ | ||
@ConfigItem(name = "enable-security-generation") | ||
public Optional<String> enableSecurityGeneration; | ||
|
||
/** | ||
* Defines the normalizer options. | ||
*/ | ||
@ConfigItem(name = "open-api-normalizer") | ||
public Map<String, String> normalizer; | ||
|
||
/** | ||
* Enable SmallRye Mutiny support. If you set this to `true`, all return types will be wrapped in `io.smallrye.mutiny.Uni`. | ||
*/ | ||
@ConfigItem(name = "mutiny") | ||
public Optional<Boolean> supportMutiny; | ||
} |
55 changes: 55 additions & 0 deletions
55
...oyment/src/main/java/io/quarkiverse/openapi/generator/deployment/GlobalCodegenConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.quarkiverse.openapi.generator.deployment; | ||
|
||
import java.util.Optional; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
|
||
/* | ||
* Model for the configuration of this extension. | ||
* It's used for documentation purposes only. | ||
* The configuration is consumed in the codegen phase, before build time. | ||
* Not meant to be used outside this scope. | ||
* Config items can be applied only globally | ||
*/ | ||
@ConfigGroup | ||
public class GlobalCodegenConfig extends CommonItemConfig { | ||
|
||
/** | ||
* Whether to log the internal generator codegen process in the default output or not. | ||
*/ | ||
@ConfigItem(name = "verbose", defaultValue = "false") | ||
public boolean verbose; | ||
|
||
/** | ||
* Option to change the directory where OpenAPI files must be found. | ||
*/ | ||
@ConfigItem(name = "input-base-dir") | ||
public Optional<String> inputBaseDir; | ||
|
||
/** | ||
* Whether or not to skip validating the input spec prior to generation. By default, invalid specifications will result in | ||
* an error. | ||
*/ | ||
@ConfigItem(name = "validateSpec", defaultValue = "true") | ||
public boolean validateSpec; | ||
|
||
/** | ||
* Option to specify files for which generation should be executed only | ||
*/ | ||
@ConfigItem(name = "include") | ||
public Optional<String> include; | ||
|
||
/** | ||
* Option to exclude file from generation | ||
*/ | ||
@ConfigItem(name = "exclude") | ||
public Optional<String> exclude; | ||
|
||
/** | ||
* Create security for the referenced security scheme | ||
*/ | ||
@ConfigItem(name = "default-security-scheme") | ||
public Optional<String> defaultSecuritySchema; | ||
|
||
} |
Oops, something went wrong.