Package io.smallrye.openapi.api
Class SmallRyeOpenAPI.Builder
java.lang.Object
io.smallrye.openapi.api.SmallRyeOpenAPI.Builder
- Enclosing class:
SmallRyeOpenAPI
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddFilter
(String filterName, ClassLoader classLoader, org.jboss.jandex.IndexView index) Add an OASFilter implementation class name to apply to the final OpenAPI model.addFilter
(org.eclipse.microprofile.openapi.OASFilter filter) Add an OASFilter instances to apply to the final OpenAPI model.addFilterName
(String filterName) Add an OASFilter implementation class name to apply to the final OpenAPI model.<V,
A extends V, O extends V, AB, OB>
SmallRyeOpenAPIbuild()
Build a new SmallRyeOpenAPI instance based on the current state of this builder.protected <V,
A extends V, O extends V, AB, OB>
voidbuildAnnotationModel
(SmallRyeOpenAPI.Builder.BuildContext<V, A, O, AB, OB> ctx) protected <V> SmallRyeOpenAPI
buildFinalize
(SmallRyeOpenAPI.Builder.BuildContext<V, ?, ?, ?, ?> ctx) protected void
buildPrepare
(SmallRyeOpenAPI.Builder.BuildContext<?, ?, ?, ?, ?> ctx) protected void
buildReaderModel
(SmallRyeOpenAPI.Builder.BuildContext<?, ?, ?, ?, ?> ctx) protected void
buildStandardFilter
(SmallRyeOpenAPI.Builder.BuildContext<?, ?, ?, ?, ?> ctx) protected <V,
A extends V, O extends V, AB, OB>
voidbuildStaticModel
(SmallRyeOpenAPI.Builder.BuildContext<V, A, O, AB, OB> ctx) defaultRequiredProperties
(boolean defaultRequiredProperties) Enable (true) or disable (false) setting default values for the OpenAPI properties listed below.enableAnnotationScan
(boolean enableAnnotationScan) Enable (true) or disable (false) annotation scanning.enableModelReader
(boolean enableModelReader) Enable (true) or disable (false) the lookup and use of an OASModelReader.enableStandardFilter
(boolean enableStandardFilter) Enable (true) or disable (false) the lookup and use of the standard OASFilter.enableStandardStaticFiles
(boolean enableStandardStaticFiles) Enable (true) or disable (false) the lookup and use of the standard static OpenAPI files (e.g.enableUnannotatedPathParameters
(boolean enableUnannotatedPathParameters) Enable (true) or disable (false) path parameters to be optionally annotated.protected <V,
A extends V, O extends V, AB, OB>
SmallRyeOpenAPI.Builder.BuildContext<V, A, O, AB, OB> protected void
withApplicationClassLoader
(ClassLoader classLoader) Set the application ClassLoader to be used when building the OpenAPI model.withConfig
(org.eclipse.microprofile.config.Config config) Set the MicroProfile Config to be used when building the OpenAPI model.withContextRootResolver
(Function<Collection<org.jboss.jandex.ClassInfo>, String> contextRootResolver) Provide function that when given the collection of all known Jakarta REST Application ClassInfo instances, resolves the context root (path prefix) to be applied to all paths in the OpenAPI document.withCustomStaticFile
(Supplier<InputStream> customStaticFile) Provide a supplier of a custom static file that is not one of those in the standard locations or with a standard name.withFilterNames
(Collection<String> filterNames) Provide a collection of OASFilter implementation class names to apply to the final OpenAPI model.withFilterNames
(Collection<String> filterNames, ClassLoader classLoader, org.jboss.jandex.IndexView index) AProvide a collection of OASFilter implementation class names to apply to the final OpenAPI model.withFilters
(Collection<org.eclipse.microprofile.openapi.OASFilter> filters) Provide a collection of OASFilter instances to apply to the final OpenAPI model.withIndex
(org.jboss.jandex.IndexView index) Provide an IndexView for use in annotation scanning.withInitialModel
(org.eclipse.microprofile.openapi.models.OpenAPI initialModel) Set an initial model used when building the OpenAPI model.withJsonParser
(Function<String, Object> jsonParser) Provide a function that when given a JSON-formatted string, returns a parsed Java object equivalent.withOperationHandler
(OperationHandler handler) Provide anOperationHandler
to be called for each operation discovered during annotation scanning.withResourceLocator
(Function<String, URL> resourceLocator) Provide a resource locator function that when given a String path for a static file will return a URL that may be used to load the resource.withScannerClassLoader
(ClassLoader scannerClassLoader) Provide a class loader used to load AnnotationScanner instances via theServiceLoader
.withScannerFilter
(Predicate<String> scannerFilter) Provide a filter predicate used to include/exclude AnnotationScaner instances found via theServiceLoader
.withSchemaParser
(Function<String, org.eclipse.microprofile.openapi.models.media.Schema> schemaParser) Provide a function that when given a JSON-formatted schema, returns a MicroProfile OpenAPISchema
instance.withTypeConverter
(UnaryOperator<org.jboss.jandex.Type> typeConverter) Provide a function that when given a Jandex Type, returns an alternate type if necessary.
-
Constructor Details
-
Builder
protected Builder()
-
-
Method Details
-
removeContext
protected void removeContext() -
getContext
protected <V,A extends V, SmallRyeOpenAPI.Builder.BuildContext<V,O extends V, AB, OB> A, getContext()O, AB, OB> -
withConfig
Set the MicroProfile Config to be used when building the OpenAPI model. When not set, the builder will obtain a Config instance usingConfigProvider.getConfig()
with the application class loader.- Parameters:
config
- Config instance, nulls not allowed- Returns:
- this builder
-
withApplicationClassLoader
Set the application ClassLoader to be used when building the OpenAPI model.- Parameters:
classLoader
- ClassLoader instance, nulls not allowed- Returns:
- this builder
-
withInitialModel
public SmallRyeOpenAPI.Builder withInitialModel(org.eclipse.microprofile.openapi.models.OpenAPI initialModel) Set an initial model used when building the OpenAPI model. The elements in this model will be overridden by any conflicting elements in models generated by the builder.- Parameters:
initialModel
- initial OpenAPI model- Returns:
- this builder
-
enableModelReader
Enable (true) or disable (false) the lookup and use of an OASModelReader. Default is true.- Parameters:
enableModelReader
- true if the model reader should be loaded and called, otherwise false.- Returns:
- this builder
-
enableStandardStaticFiles
Enable (true) or disable (false) the lookup and use of the standard static OpenAPI files (e.g.META-INF/openapi.(json|yaml|yml)
. Default is true.- Parameters:
enableStandardStaticFiles
- true if the standard static files should be loaded and included, otherwise false.- Returns:
- this builder
-
enableStandardFilter
Enable (true) or disable (false) the lookup and use of the standard OASFilter. Default is true.- Parameters:
enableStandardFilter
- true if the filter should be loaded and called, otherwise false.- Returns:
- this builder
-
defaultRequiredProperties
Enable (true) or disable (false) setting default values for the OpenAPI properties listed below. Default is true.- Create an empty
paths
object if none specified - Set a generated value for
info.title
if none specified - Set a generated value for
info.version
if none specified - Set a default value for
openapi
(the specification version) if none specified. E.g. 3.1.0
- Parameters:
defaultRequiredProperties
- true if default values should be set when necessary, otherwise false.- Returns:
- this builder
- Create an empty
-
withResourceLocator
Provide a resource locator function that when given a String path for a static file will return a URL that may be used to load the resource. This function is intended to support environments where the resource is not on the class path and an alternate loading approach is necessary, for example using a ServletContext.- Parameters:
resourceLocator
-- Returns:
- this builder
-
withCustomStaticFile
Provide a supplier of a custom static file that is not one of those in the standard locations or with a standard name. The user of this builder is responsible for closing the stream afterbuild
has been invoked. Repeated calls tobuild
must ensure the supplied stream is open and readable.- Parameters:
customStaticFile
- a supplier of an input stream used to read a custom static file, null not allowed- Returns:
- this builder
-
withIndex
Provide an IndexView for use in annotation scanning.- Parameters:
index
- a Jandex IndexView for use by the annotation scanner, null not allowed- Returns:
- this builder
-
withContextRootResolver
public SmallRyeOpenAPI.Builder withContextRootResolver(Function<Collection<org.jboss.jandex.ClassInfo>, String> contextRootResolver) Provide function that when given the collection of all known Jakarta REST Application ClassInfo instances, resolves the context root (path prefix) to be applied to all paths in the OpenAPI document. If the function returns a null value, the context root is not set.The function is only used during annotation scanning.
- Parameters:
contextRootResolver
- a function to return the context root (global path prefix) for the OpenAPI document, null not allowed- Returns:
- this builder
-
withTypeConverter
public SmallRyeOpenAPI.Builder withTypeConverter(UnaryOperator<org.jboss.jandex.Type> typeConverter) Provide a function that when given a Jandex Type, returns an alternate type if necessary. This method may be used by platforms that require special type unwrapping or conversion functionality.The function is only used during annotation scanning.
- Parameters:
typeConverter
- a function to convert a type to another type, null not allowed- Returns:
- this builder
-
withJsonParser
Provide a function that when given a JSON-formatted string, returns a parsed Java object equivalent. The parsed object should be limited to Java Lists, Maps, and basic terminal types such as Java primitives, Numbers, and Strings.The function is only used during annotation scanning.
- Parameters:
jsonParser
- a function to convert JSON string to a Java object- Returns:
- this builder
-
withSchemaParser
public SmallRyeOpenAPI.Builder withSchemaParser(Function<String, org.eclipse.microprofile.openapi.models.media.Schema> schemaParser) Provide a function that when given a JSON-formatted schema, returns a MicroProfile OpenAPISchema
instance.The function is only used during annotation scanning.
- Parameters:
schemaParser
- a function to convert a JSON string to a Schema instance- Returns:
- this builder
-
enableAnnotationScan
Enable (true) or disable (false) annotation scanning. Default is true.- Parameters:
enableAnnotationScan
- true if annotation scanning is enabled, otherwise false.- Returns:
- this builder
-
enableUnannotatedPathParameters
public SmallRyeOpenAPI.Builder enableUnannotatedPathParameters(boolean enableUnannotatedPathParameters) Enable (true) or disable (false) path parameters to be optionally annotated. Default is false.- Parameters:
enableUnannotatedPathParameters
- true if annotation use on path parameters is optional, otherwise false.- Returns:
- this builder
-
withScannerClassLoader
Provide a class loader used to load AnnotationScanner instances via theServiceLoader
. If not set, instances will be loaded using the application class loader, or the context class loader of the thread used to invokebuild
.The function is only used during annotation scanning.
- Parameters:
scannerClassLoader
- class loader used for loading AnnotationScanners- Returns:
- this builder
-
withScannerFilter
Provide a filter predicate used to include/exclude AnnotationScaner instances found via theServiceLoader
.- Parameters:
scannerFilter
-- Returns:
- this builder
-
withOperationHandler
Provide anOperationHandler
to be called for each operation discovered during annotation scanning.- Parameters:
handler
- a non-null implementation of anOperationHandler
- Returns:
- this builder
-
withFilters
public SmallRyeOpenAPI.Builder withFilters(Collection<org.eclipse.microprofile.openapi.OASFilter> filters) Provide a collection of OASFilter instances to apply to the final OpenAPI model. The filters will be executed in the same order as given in the collection.- Parameters:
filters
- collection of OASFilter instances- Returns:
- this builder
-
withFilterNames
Provide a collection of OASFilter implementation class names to apply to the final OpenAPI model. New instances of the named classes will be instantiated at run time using the application class loader provided, or the context class loader of the thread used to invokebuild
. The filters will be executed in the same order as given in the collection.- Parameters:
filterNames
- collection of OASFilter implementation class names- Returns:
- this builder
-
withFilterNames
public SmallRyeOpenAPI.Builder withFilterNames(Collection<String> filterNames, ClassLoader classLoader, org.jboss.jandex.IndexView index) AProvide a collection of OASFilter implementation class names to apply to the final OpenAPI model. New instances of the named classes will be instantiated immediately using the ClassLoader provided. If the given index is null, the filters will be created with a non-null, empty index. The filters will be executed in the same order as given in the collection.- Parameters:
filterNames
- collection of OASFilter implementation class namesclassLoader
- CLassLoader use to load the filterindex
- IndexView passed to the filter, possibly null- Returns:
- this builder
-
addFilter
Add an OASFilter instances to apply to the final OpenAPI model. Filters will be executed in the order they are added.- Parameters:
filter
- OASFilter instance- Returns:
- this builder
-
addFilterName
Add an OASFilter implementation class name to apply to the final OpenAPI model. A new instance of the named class will be instantiated at run time using the application class loader provided, or the context class loader of the thread used to invokebuild
. Filters will be executed in the order they are added.- Parameters:
filterName
- OASFilter implementation class name- Returns:
- this builder
-
addFilter
public SmallRyeOpenAPI.Builder addFilter(String filterName, ClassLoader classLoader, org.jboss.jandex.IndexView index) Add an OASFilter implementation class name to apply to the final OpenAPI model. A new instance of the named class will be instantiated immediately using the ClassLoader provided. If the given index is null, the filter will be created with a non-null, empty index. Filters will be executed in the order they are added.- Parameters:
filterName
- OASFilter implementation class nameclassLoader
- CLassLoader use to load the filterindex
- IndexView passed to the filter, possibly null- Returns:
- this builder
-
buildReaderModel
-
buildStaticModel
protected <V,A extends V, void buildStaticModelO extends V, AB, OB> (SmallRyeOpenAPI.Builder.BuildContext<V, A, O, AB, OB> ctx) -
buildAnnotationModel
protected <V,A extends V, void buildAnnotationModelO extends V, AB, OB> (SmallRyeOpenAPI.Builder.BuildContext<V, A, O, AB, OB> ctx) -
buildStandardFilter
-
buildPrepare
-
buildFinalize
-
build
Build a new SmallRyeOpenAPI instance based on the current state of this builder.- Type Parameters:
V
- JSON value typeA
- JSON array typeO
- JSON object typeAB
- JSON array builder typeOB
- JSON object builder type- Returns:
- a new SmallRyeOpenAPI instance
-