Class SmallRyeOpenAPI.Builder

java.lang.Object
io.smallrye.openapi.api.SmallRyeOpenAPI.Builder
Enclosing class:
SmallRyeOpenAPI

public static class SmallRyeOpenAPI.Builder extends Object
  • Constructor Details

    • Builder

      protected Builder()
  • Method Details

    • removeContext

      protected void removeContext()
    • getContext

      protected <V, A extends V, O extends V, AB, OB> SmallRyeOpenAPI.Builder.BuildContext<V,A,O,AB,OB> getContext()
    • withConfig

      public SmallRyeOpenAPI.Builder withConfig(org.eclipse.microprofile.config.Config config)
      Set the MicroProfile Config to be used when building the OpenAPI model. When not set, the builder will obtain a Config instance using ConfigProvider.getConfig() with the application class loader.
      Parameters:
      config - Config instance, nulls not allowed
      Returns:
      this builder
    • withApplicationClassLoader

      public SmallRyeOpenAPI.Builder withApplicationClassLoader(ClassLoader classLoader)
      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

      public SmallRyeOpenAPI.Builder enableModelReader(boolean 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

      public SmallRyeOpenAPI.Builder enableStandardStaticFiles(boolean 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

      public SmallRyeOpenAPI.Builder enableStandardFilter(boolean 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

      public SmallRyeOpenAPI.Builder defaultRequiredProperties(boolean 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
    • withResourceLocator

      public SmallRyeOpenAPI.Builder 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. 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

      public SmallRyeOpenAPI.Builder 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. The user of this builder is responsible for closing the stream after build has been invoked. Repeated calls to build 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

      public SmallRyeOpenAPI.Builder withIndex(org.jboss.jandex.IndexView index)
      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

      public SmallRyeOpenAPI.Builder withJsonParser(Function<String,Object> jsonParser)
      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 OpenAPI Schema 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

      public SmallRyeOpenAPI.Builder enableAnnotationScan(boolean 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

      public SmallRyeOpenAPI.Builder withScannerClassLoader(ClassLoader scannerClassLoader)
      Provide a class loader used to load AnnotationScanner instances via the ServiceLoader. If not set, instances will be loaded using the application class loader, or the context class loader of the thread used to invoke build.

      The function is only used during annotation scanning.

      Parameters:
      scannerClassLoader - class loader used for loading AnnotationScanners
      Returns:
      this builder
    • withScannerFilter

      public SmallRyeOpenAPI.Builder withScannerFilter(Predicate<String> scannerFilter)
      Provide a filter predicate used to include/exclude AnnotationScaner instances found via the ServiceLoader.
      Parameters:
      scannerFilter -
      Returns:
      this builder
    • withOperationHandler

      public SmallRyeOpenAPI.Builder withOperationHandler(OperationHandler handler)
      Provide an OperationHandler to be called for each operation discovered during annotation scanning.
      Parameters:
      handler - a non-null implementation of an OperationHandler
      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

      public SmallRyeOpenAPI.Builder withFilterNames(Collection<String> filterNames)
      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 invoke build. 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 names
      classLoader - CLassLoader use to load the filter
      index - IndexView passed to the filter, possibly null
      Returns:
      this builder
    • addFilter

      public SmallRyeOpenAPI.Builder addFilter(org.eclipse.microprofile.openapi.OASFilter filter)
      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

      public SmallRyeOpenAPI.Builder addFilterName(String filterName)
      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 invoke build. 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 name
      classLoader - CLassLoader use to load the filter
      index - IndexView passed to the filter, possibly null
      Returns:
      this builder
    • buildReaderModel

      protected void buildReaderModel(SmallRyeOpenAPI.Builder.BuildContext<?,?,?,?,?> ctx)
    • buildStaticModel

      protected <V, A extends V, O extends V, AB, OB> void buildStaticModel(SmallRyeOpenAPI.Builder.BuildContext<V,A,O,AB,OB> ctx)
    • buildAnnotationModel

      protected <V, A extends V, O extends V, AB, OB> void buildAnnotationModel(SmallRyeOpenAPI.Builder.BuildContext<V,A,O,AB,OB> ctx)
    • buildStandardFilter

      protected void buildStandardFilter(SmallRyeOpenAPI.Builder.BuildContext<?,?,?,?,?> ctx)
    • buildPrepare

      protected void buildPrepare(SmallRyeOpenAPI.Builder.BuildContext<?,?,?,?,?> ctx)
    • buildFinalize

      protected <V> SmallRyeOpenAPI buildFinalize(SmallRyeOpenAPI.Builder.BuildContext<V,?,?,?,?> ctx)
    • build

      public <V, A extends V, O extends V, AB, OB> SmallRyeOpenAPI build()
      Build a new SmallRyeOpenAPI instance based on the current state of this builder.
      Type Parameters:
      V - JSON value type
      A - JSON array type
      O - JSON object type
      AB - JSON array builder type
      OB - JSON object builder type
      Returns:
      a new SmallRyeOpenAPI instance