Skip to content

Commit 3e1e9f3

Browse files
Fix #1035 - Add Interfaces to Configuration objects (#1089) (#1093)
Signed-off-by: Ricardo Zanini <[email protected]> Co-authored-by: Ricardo Zanini <[email protected]>
1 parent 6122f29 commit 3e1e9f3

File tree

6 files changed

+645
-47
lines changed

6 files changed

+645
-47
lines changed

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CommonItemConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,10 @@ public interface CommonItemConfig {
177177
*/
178178
@WithName("equals-hashcode")
179179
Optional<Boolean> equalsHashcode();
180+
181+
/**
182+
* Add additional properties as attribute.
183+
*/
184+
@WithName("additional-properties-as-attribute")
185+
Optional<String> additionalPropertiesAsAttribute();
180186
}

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/SpecItemConfig.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ public interface SpecItemConfig extends CommonItemConfig {
1919
@WithName("base-package")
2020
Optional<String> basePackage();
2121

22+
/**
23+
* Custom config key to use in place of the openapi spec file
24+
*/
25+
@WithName("config-key")
26+
Optional<String> configKey();
27+
2228
/**
2329
* Suffix name for generated api classes
2430
*/
@@ -55,4 +61,11 @@ public interface SpecItemConfig extends CommonItemConfig {
5561
*/
5662
@WithName("remove-operation-id-prefix-count")
5763
Optional<Integer> removeOperationIdPrefixCount();
64+
65+
/**
66+
* Set serializable model
67+
*/
68+
@WithName("serializable-model")
69+
Optional<Boolean> serializableModel();
70+
5871
}

client/runtime/src/main/codestarts/quarkus/openapi-generator-codestart/codestart.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ ref: openapi-generator
33
type: code
44
tags: extension-codestart
55
metadata:
6-
title: OpenAPI Generator Codestart
7-
description: Start to code with the OpenAPI Generator extension.
8-
related-guide-section: https://docs.quarkiverse.io/quarkus-openapi-generator/dev/index.html
6+
title: OpenAPI Generator Client Codestart
7+
description: Start to code with the OpenAPI Generator Client extension.
8+
related-guide-section: https://docs.quarkiverse.io/quarkus-openapi-generator/dev/client.html
Lines changed: 81 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
package io.quarkiverse.openapi.generator;
22

3-
import java.util.Map;
43
import java.util.Optional;
54

6-
import io.quarkiverse.openapi.generator.providers.ApiKeyAuthenticationProvider;
7-
import io.quarkiverse.openapi.generator.providers.BasicAuthenticationProvider;
8-
import io.quarkiverse.openapi.generator.providers.BearerAuthenticationProvider;
95
import io.quarkus.runtime.annotations.ConfigGroup;
10-
import io.quarkus.runtime.annotations.ConfigItem;
116

127
/**
138
* This class represents the runtime authentication related configuration for an individual securityScheme present
149
* on an OpenApi spec definition, i.e. the provided files.
1510
*/
1611
@ConfigGroup
17-
public class AuthConfig {
12+
public interface AuthConfig {
1813

19-
public static final String TOKEN_PROPAGATION = "token-propagation";
20-
public static final String HEADER_NAME = "header-name";
14+
String TOKEN_PROPAGATION = "token-propagation";
15+
String HEADER_NAME = "header-name";
2116

2217
/**
2318
* Enables the authentication token propagation for this particular securityScheme.
@@ -31,8 +26,7 @@ public class AuthConfig {
3126
* @see SpecItemConfig
3227
* @see OpenApiGeneratorConfig
3328
*/
34-
@ConfigItem(defaultValue = "false")
35-
public Optional<Boolean> tokenPropagation;
29+
Optional<Boolean> tokenPropagation();
3630

3731
/**
3832
* Configures a particular http header attribute from were to take the security token from when the token propagation
@@ -47,48 +41,91 @@ public class AuthConfig {
4741
* @see SpecItemConfig
4842
* @see OpenApiGeneratorConfig
4943
*/
50-
@ConfigItem
51-
public Optional<String> headerName;
44+
Optional<String> headerName();
5245

5346
/**
54-
* Configures a particular parameter value to be used by any of the different internal authentication filters
55-
* that processes the different securityScheme definitions.
56-
* <p>
47+
* Sets the Basic Authentication username for a given OpenAPI securityScheme.
48+
* <p/>
5749
* For example, given a file named petstore.json with a securityScheme named "petstore-basic-auth", that is of
58-
* http basic authentication type, the following configuration can establish the user and password to be used.
59-
* must be used.
60-
* <p>
50+
* http basic authentication type, the following configuration can establish the user to be used.
51+
* <p/>
6152
* quarkus.openapi-generator.petstore_json.auth.petstore_basic_auth.username=MyUserName
62-
* quarkus.openapi-generator.petstore_json.auth.petstore_basic_auth.password=MyPassword
6353
*
64-
* @see AuthsConfig
65-
* @see SpecItemConfig
66-
* @see OpenApiGeneratorConfig
67-
* @see BasicAuthenticationProvider
68-
* @see BearerAuthenticationProvider
69-
* @see ApiKeyAuthenticationProvider
54+
* @return the username portion for Basic Authentication
55+
* @see AuthConfig#password()
56+
* @see <a href="https://spec.openapis.org/oas/v3.1.0.html#basic-authentication-sample">4.8.27.2.1 Basic Authentication
57+
* Sample</a>
7058
*/
71-
@ConfigItem(name = ConfigItem.PARENT)
72-
public Map<String, String> authConfigParams;
59+
Optional<String> username();
7360

74-
public Optional<Boolean> getTokenPropagation() {
75-
return tokenPropagation;
76-
}
61+
/**
62+
* Sets the Basic Authentication password for a given OpenAPI securityScheme.
63+
* <p/>
64+
* For example, given a file named petstore.json with a securityScheme named "petstore-basic-auth", that is of
65+
* http basic authentication type, the following configuration can establish the password to be used.
66+
* <p/>
67+
* quarkus.openapi-generator.petstore_json.auth.petstore_basic_auth.password=MyPassword
68+
* <p/>
69+
* Ignored if the given securityScheme is not Basic Authentication
70+
*
71+
* @return the password portion for Basic Authentication
72+
* @see AuthConfig#username()
73+
* @see <a href="https://spec.openapis.org/oas/v3.1.0.html#basic-authentication-sample">4.8.27.2.1 Basic Authentication
74+
* Sample</a>
75+
*/
76+
Optional<String> password();
7777

78-
public Optional<String> getHeaderName() {
79-
return headerName;
80-
}
78+
/**
79+
* Sets the Bearer Token for a given OpenAPI securityScheme.
80+
* <p/>
81+
* For example, given a file named petstore.json with a securityScheme named "petstore-bearer-auth", that is of
82+
* bearer authentication type, the following configuration can establish the token to be used.
83+
* <p/>
84+
* quarkus.openapi-generator.petstore_json.auth.petstore_bearer_auth.token=1234567890
85+
* <p/>
86+
* Ignored if the given securityScheme is not Bearer Token Authentication
87+
*
88+
* @return the token
89+
* @see <a href="https://spec.openapis.org/oas/v3.1.0.html#jwt-bearer-sample">4.8.27.2.3 JWT Bearer Sample</a>
90+
*/
91+
Optional<String> bearerToken();
8192

82-
public Optional<String> getConfigParam(String paramName) {
83-
return Optional.ofNullable(authConfigParams.get(paramName));
84-
}
93+
/**
94+
* Sets the API Key for a given OpenAPI securityScheme.
95+
* <p/>
96+
* For example, given a file named petstore.json with a securityScheme named "petstore-apikey-auth", that is of
97+
* API Key authentication type, the following configuration can establish the API Key to be used.
98+
* <p/>
99+
* quarkus.openapi-generator.petstore_json.auth.petstore_apikey_auth.api-key=${MY_SECRET_KEY_IN_AN_ENV_VAR}
100+
* <p/>
101+
* Ignored if the given securityScheme is not API Key Authentication
102+
*
103+
* @return the token
104+
* @see <a href="https://spec.openapis.org/oas/v3.1.0.html#api-key-sample">4.8.27.2.2 API Key Samplee</a>
105+
*/
106+
Optional<String> apiKey();
85107

86-
@Override
87-
public String toString() {
88-
return "AuthConfig{" +
89-
"tokenPropagation=" + tokenPropagation +
90-
", headerName=" + headerName +
91-
", authConfigParams=" + authConfigParams +
92-
'}';
93-
}
108+
/**
109+
* Only valid for API Key Authentication.
110+
* <p/>
111+
* When to add the `Authorization` value to the API Key in the authentication header.
112+
* <p/>
113+
* For example, if this property is set to `true`, the API Key will be sent to the server in the header along with
114+
* `Authorization`:
115+
* <p/>
116+
* [source]
117+
* ---
118+
* Authentication: Authorization MY-API-KEY
119+
* ---
120+
* <p/>
121+
* If set to `false`, the header should be:
122+
* <p/>
123+
* [source]
124+
* ---
125+
* Authentication: MY-API-KEY
126+
* ---
127+
*
128+
* @return whether to use the prefix `Authorization` when sending an API Key using headers.
129+
*/
130+
Optional<Boolean> useAuthorizationHeaderValue();
94131
}

0 commit comments

Comments
 (0)