Skip to content

Commit

Permalink
Add a section about openapi filters in the doc
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <[email protected]>
  • Loading branch information
phillip-kruger committed Mar 20, 2024
1 parent fd00af0 commit 853c4a4
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions docs/src/main/asciidoc/openapi-swaggerui.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,46 @@ quarkus.smallrye-openapi.info-license-url=https://www.apache.org/licenses/LICENS

This will give you similar information as the `@OpenAPIDefinition` example above.

Check warning on line 323 in docs/src/main/asciidoc/openapi-swaggerui.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'. Raw Output: {"message": "[Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'.", "location": {"path": "docs/src/main/asciidoc/openapi-swaggerui.adoc", "range": {"start": {"line": 323, "column": 40}}}, "severity": "INFO"}

== Enhancing the OpenAPI Schema with Filters

Check warning on line 325 in docs/src/main/asciidoc/openapi-swaggerui.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Headings] Use sentence-style capitalization in 'Enhancing the OpenAPI Schema with Filters'. Raw Output: {"message": "[Quarkus.Headings] Use sentence-style capitalization in 'Enhancing the OpenAPI Schema with Filters'.", "location": {"path": "docs/src/main/asciidoc/openapi-swaggerui.adoc", "range": {"start": {"line": 325, "column": 4}}}, "severity": "INFO"}

You can change the Generated OpenAPI Schema using one or more filter. Filters can run during build time, or at runtime.

Check warning on line 327 in docs/src/main/asciidoc/openapi-swaggerui.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsSuggestions] Depending on the context, consider using 'by using' or 'that uses' rather than 'using'. Raw Output: {"message": "[Quarkus.TermsSuggestions] Depending on the context, consider using 'by using' or 'that uses' rather than 'using'.", "location": {"path": "docs/src/main/asciidoc/openapi-swaggerui.adoc", "range": {"start": {"line": 327, "column": 44}}}, "severity": "INFO"}

[source,java]
----
/**
* Filter to add custom elements
*/
@OpenApiFilter(OpenApiFilter.RunStage.BUILD) //<1>
public class MyBuildTimeFilter implements OASFilter { //<2>
private IndexView view;
public MyBuildTimeFilter(IndexView view) { //<3>
this.view = view;
}
@Override
public void filterOpenAPI(OpenAPI openAPI) { //<4>
Collection<ClassInfo> knownClasses = this.view.getKnownClasses();
Info info = OASFactory.createInfo();
info.setDescription("Created from Annotated Buildtime filter with " + knownClasses.size() + " known indexed classes");
openAPI.setInfo(info);
}
}
----
<1> Annotate method with `@OpenApiFilter` and the run stage (BUILD,RUN,BOTH)
<2> Implement OASFilter and override any of the methods

Check warning on line 354 in docs/src/main/asciidoc/openapi-swaggerui.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Spelling] Use correct American English spelling. Did you really mean 'OASFilter'? Raw Output: {"message": "[Quarkus.Spelling] Use correct American English spelling. Did you really mean 'OASFilter'?", "location": {"path": "docs/src/main/asciidoc/openapi-swaggerui.adoc", "range": {"start": {"line": 354, "column": 15}}}, "severity": "WARNING"}
<3> For Build stage filters, the index can be passed in (optional)
<4> Get a hold of the generated `OpenAPI` Schema, and enhance as required

Check warning on line 356 in docs/src/main/asciidoc/openapi-swaggerui.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'. Raw Output: {"message": "[Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'.", "location": {"path": "docs/src/main/asciidoc/openapi-swaggerui.adoc", "range": {"start": {"line": 356, "column": 63}}}, "severity": "INFO"}

Remember that setting fields on the schema will override what has been generated, you might want to get and add to (so modify). Also know that the generated values might be null, so you will have to check for that.

=== Runtime filters

Runtime filters by default runs on startup (when the final OpenAPI document gets created). You can change runtime filters to run on every request, making the openapi document dynamic.
To do this you need to set this propery: `quarkus.smallrye-openapi.always-run-filter=true`.

Check warning on line 363 in docs/src/main/asciidoc/openapi-swaggerui.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Fluff] Depending on the context, consider using 'Rewrite the sentence, or use 'must', instead of' rather than 'need to'. Raw Output: {"message": "[Quarkus.Fluff] Depending on the context, consider using 'Rewrite the sentence, or use 'must', instead of' rather than 'need to'.", "location": {"path": "docs/src/main/asciidoc/openapi-swaggerui.adoc", "range": {"start": {"line": 363, "column": 5}}}, "severity": "INFO"}

Check warning on line 363 in docs/src/main/asciidoc/openapi-swaggerui.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Spelling] Use correct American English spelling. Did you really mean 'propery'? Raw Output: {"message": "[Quarkus.Spelling] Use correct American English spelling. Did you really mean 'propery'?", "location": {"path": "docs/src/main/asciidoc/openapi-swaggerui.adoc", "range": {"start": {"line": 363, "column": 22}}}, "severity": "WARNING"}

== Loading OpenAPI Schema From Static Files

Check warning on line 365 in docs/src/main/asciidoc/openapi-swaggerui.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Headings] Use sentence-style capitalization in 'Loading OpenAPI Schema From Static Files'. Raw Output: {"message": "[Quarkus.Headings] Use sentence-style capitalization in 'Loading OpenAPI Schema From Static Files'.", "location": {"path": "docs/src/main/asciidoc/openapi-swaggerui.adoc", "range": {"start": {"line": 365, "column": 4}}}, "severity": "INFO"}

Instead of dynamically creating OpenAPI schemas from annotation scanning, Quarkus also supports serving static OpenAPI documents.
Expand Down

0 comments on commit 853c4a4

Please sign in to comment.