Class OpenApi.Builder

java.lang.Object
com.jsgalactic.axiom.openapi.OpenApi.Builder
Enclosing class:
OpenApi

public static final class OpenApi.Builder extends Object
Configures an OpenApi. Not thread-safe; build once at startup.
  • Method Details

    • description

      public OpenApi.Builder description(String description)
      Sets the API description.
      Parameters:
      description - text
      Returns:
      this builder
    • server

      public OpenApi.Builder server(String url, String description)
      Adds a server the API is reachable at. A Swagger 2.0 document uses only the first.
      Parameters:
      url - absolute URL or a path such as /api
      description - what the server is, or null
      Returns:
      this builder
    • securityScheme

      public OpenApi.Builder securityScheme(String name, SecurityScheme scheme)
      Defines a security scheme that routes can require by name.
      Parameters:
      name - scheme name, letters, digits and . _ -
      scheme - the scheme
      Returns:
      this builder
    • schemaName

      public OpenApi.Builder schemaName(Class<?> type, String name)
      Names the schema of a record, bean or enum, instead of its simple class name. Use it to hide an internal name or to resolve two classes that share a simple name. For a generic class the name is the prefix of the generated one.
      Parameters:
      type - described class
      name - schema name, letters, digits and . _ -
      Returns:
      this builder
    • rules

      public <T> OpenApi.Builder rules(Class<T> type, Rules<T> rules)
      Maps the built-in rules of a rule set to schema constraints on type's properties: not-null becomes required, length and size become min/max length and items, min/max/range become minimum and maximum, pattern, e-mail and one-of become pattern, format: email and enum. A rule that cannot constrain its property's type, or a property the type does not have, fails generation. Custom rules are not described. Only the rules declared with field and each are mapped; register the rule set of a nested type separately.
      Type Parameters:
      T - the type
      Parameters:
      type - described class
      rules - its rule set
      Returns:
      this builder
    • defaults

      public OpenApi.Builder defaults(String pathPrefix, RouteDoc defaults)
      Adds defaults for every route whose path equals pathPrefix or lies below it, for example the tags, the security requirement or a 401 response of a whole group. Tags are added to the route's own; security applies only to routes that declare none; responses and parameters apply where the route has none with the same status or name. Other settings of defaults are ignored. Defaults apply in the order added.
      Parameters:
      pathPrefix - "" for all routes, or a template prefix such as /api/v1
      defaults - the defaults
      Returns:
      this builder
    • maxDepth

      public OpenApi.Builder maxDepth(int maxDepth)
      Limits how deeply described types may nest before generation fails; cycles never count because a type that refers to itself becomes a reference.
      Parameters:
      maxDepth - at least 1, 32 by default
      Returns:
      this builder
    • build

      public OpenApi build()
      Builds the configuration.
      Returns:
      an immutable OpenApi