Skip to content

Commit cb9e61a

Browse files
committed
adding impl documentation
Signed-off-by: Ricardo Zanini <[email protected]>
1 parent b07173f commit cb9e61a

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

README.md

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,17 @@ See the [integration-tests](integration-tests) module for more information of ho
100100

101101
## Authentication Support
102102

103-
If your OpenAPI specification file has `securitySchemes` [definitions](https://spec.openapis.org/oas/v3.1.0#security-scheme-object), the inner generator will [register `ClientRequestFilter`s providers](https://download.eclipse.org/microprofile/microprofile-rest-client-2.0/microprofile-rest-client-spec-2.0.html#_provider_declaration) for you to implement the given authentication mechanism.
103+
If your OpenAPI specification file has `securitySchemes` [definitions](https://spec.openapis.org/oas/v3.1.0#security-scheme-object), the inner generator
104+
will [register `ClientRequestFilter`s providers](https://download.eclipse.org/microprofile/microprofile-rest-client-2.0/microprofile-rest-client-spec-2.0.html#_provider_declaration) for you to
105+
implement the given authentication mechanism.
104106

105-
To provide the credentials for your application, you can use the [Quarkus configuration support](https://quarkus.io/guides/config). The configuration key is composed using this pattern: `[base_package].security.auth.[security_scheme_name]/[auth_property_name]`. Where:
107+
To provide the credentials for your application, you can use the [Quarkus configuration support](https://quarkus.io/guides/config). The configuration key is composed using this
108+
pattern: `[base_package].security.auth.[security_scheme_name]/[auth_property_name]`. Where:
106109

107110
- `base_package` is the package name you gave when configuring the code generation using `quarkus.openapi-generator.codegen.spec.[open_api_file].base-package` property.
108-
- `security_scheme_name` is the name of the [security scheme object definition](https://spec.openapis.org/oas/v3.1.0#security-scheme-object) in the OpenAPI file. Given the following excerpt, we have `api_key` and `basic_auth` security schemes:
111+
- `security_scheme_name` is the name of the [security scheme object definition](https://spec.openapis.org/oas/v3.1.0#security-scheme-object) in the OpenAPI file. Given the following excerpt, we
112+
have `api_key` and `basic_auth` security schemes:
113+
109114
```json
110115
{
111116
"securitySchemes": {
@@ -121,6 +126,7 @@ To provide the credentials for your application, you can use the [Quarkus config
121126
}
122127
}
123128
```
129+
124130
- `auth_property_name` varies depending on the authentication provider. For example, for Basic Authentication we have `username` and `password`. See the following sections for more details.
125131

126132
> Tip: on production environments you will likely to use [HashiCorp Vault](https://quarkiverse.github.io/quarkiverse-docs/quarkus-vault/dev/index.html) or [Kubernetes Secrets](https://kubernetes.io/docs/concepts/configuration/secret/) to provide this information for your application.
@@ -150,14 +156,15 @@ Similarly to bearer token, the API Key Authentication also has the token entry k
150156
| -------------| --------------------------------------------------------------| --------------------------------------------------- |
151157
| API Key | `[base_package].security.auth.[security_scheme_name]/api-key` | `org.acme.openapi.security.auth.apikey/api-key` |
152158

153-
The API Key scheme has an additional property that requires where to add the API key in the request token: header, cookie or query. The inner provider takes care of that for you.
159+
The API Key scheme has an additional property that requires where to add the API key in the request token: header, cookie or query. The inner provider takes care of that for you.
154160

155161
## Circuit Breaker
156162

157163
You can define the [CircuitBreaker annotation from MicroProfile Fault Tolerance](https://microprofile.io/project/eclipse/microprofile-fault-tolerance/spec/src/main/asciidoc/circuitbreaker.asciidoc)
158164
in your generated classes by setting the desired configuration in `application.properties`.
159165

160166
Let's say you have the following OpenAPI definition:
167+
161168
````json
162169
{
163170
"openapi": "3.0.3",
@@ -207,17 +214,17 @@ And you want to configure Circuit Breaker for the `/bye` endpoint, you can do it
207214
Add the [SmallRye Fault Tolerance extension](https://quarkus.io/guides/smallrye-fault-tolerance) to your project's `pom.xml` file:
208215

209216
````xml
217+
210218
<dependency>
211-
<groupId>io.quarkus</groupId>
212-
<artifactId>quarkus-smallrye-fault-tolerance</artifactId>
219+
<groupId>io.quarkus</groupId>
220+
<artifactId>quarkus-smallrye-fault-tolerance</artifactId>
213221
</dependency>
214222
````
215223

216224
Assuming your Open API spec file is in `src/main/openapi/simple-openapi.json`, add the following configuration to your `application.properties` file:
217225

218226
````properties
219227
quarkus.openapi-generator.codegen.spec."simple-openapi.json".base-package=org.acme.openapi.simple
220-
221228
# Enables the CircuitBreaker extension for the byeGet method from the DefaultApi class
222229
org.acme.openapi.simple.api.DefaultApi/byeGet/CircuitBreaker/enabled=true
223230
````
@@ -233,6 +240,7 @@ import java.io.InputStream;
233240
import java.io.OutputStream;
234241
import java.util.List;
235242
import java.util.Map;
243+
236244
import javax.ws.rs.*;
237245
import javax.ws.rs.core.Response;
238246
import javax.ws.rs.core.MediaType;
@@ -243,30 +251,38 @@ public interface DefaultApi {
243251

244252
@GET
245253
@Path("/bye")
246-
@Produces({"text/plain"})
254+
@Produces({ "text/plain" })
247255
@org.eclipse.microprofile.faulttolerance.CircuitBreaker
248256
public String byeGet();
249257

250258
@GET
251259
@Path("/hello")
252-
@Produces({"text/plain"})
260+
@Produces({ "text/plain" })
253261
public String helloGet();
254262

255263
}
256264
````
257265

258-
You can also override the default Circuit Breaker configuration by setting the properties in `application.properties` [just as you would for a traditional MicroProfile application](https://quarkus.io/guides/smallrye-fault-tolerance#runtime-configuration):
266+
You can also override the default Circuit Breaker configuration by setting the properties
267+
in `application.properties` [just as you would for a traditional MicroProfile application](https://quarkus.io/guides/smallrye-fault-tolerance#runtime-configuration):
259268

260269
````properties
261-
org.acme.openapi.simple.api.DefaultApi/byeGet/CircuitBreaker/failOn = java.lang.IllegalArgumentException,java.lang.NullPointerException
262-
org.acme.openapi.simple.api.DefaultApi/byeGet/CircuitBreaker/skipOn = java.lang.NumberFormatException
263-
org.acme.openapi.simple.api.DefaultApi/byeGet/CircuitBreaker/delay = 33
264-
org.acme.openapi.simple.api.DefaultApi/byeGet/CircuitBreaker/delayUnit = MILLIS
265-
org.acme.openapi.simple.api.DefaultApi/byeGet/CircuitBreaker/requestVolumeThreshold = 42
266-
org.acme.openapi.simple.api.DefaultApi/byeGet/CircuitBreaker/failureRatio = 3.14
267-
org.acme.openapi.simple.api.DefaultApi/byeGet/CircuitBreaker/successThreshold = 22
270+
org.acme.openapi.simple.api.DefaultApi/byeGet/CircuitBreaker/failOn=java.lang.IllegalArgumentException,java.lang.NullPointerException
271+
org.acme.openapi.simple.api.DefaultApi/byeGet/CircuitBreaker/skipOn=java.lang.NumberFormatException
272+
org.acme.openapi.simple.api.DefaultApi/byeGet/CircuitBreaker/delay=33
273+
org.acme.openapi.simple.api.DefaultApi/byeGet/CircuitBreaker/delayUnit=MILLIS
274+
org.acme.openapi.simple.api.DefaultApi/byeGet/CircuitBreaker/requestVolumeThreshold=42
275+
org.acme.openapi.simple.api.DefaultApi/byeGet/CircuitBreaker/failureRatio=3.14
276+
org.acme.openapi.simple.api.DefaultApi/byeGet/CircuitBreaker/successThreshold=22
268277
````
269278

279+
## Generating files via InputStream
280+
281+
Having the files in the `src/main/openapi` directory will generate the REST stubs by default. Alternatively, you can implement the `io.quarkiverse.openapi.generator.codegen.OpenApiSpecInputProvider`
282+
interface to provide a list of `InputStream`s of OpenAPI specification files. This is useful in scenarios where you want to dynamically generate the client code without having the target spec file
283+
saved locally in your project.
284+
285+
See the example implementation [here](test-utils/src/main/java/io/quarkiverse/openapi/generator/testutils/codegen/ClassPathPetstoreOpenApiSpecInputProvider.java)
270286

271287
## Known Limitations
272288

0 commit comments

Comments
 (0)