Class OpenApi

java.lang.Object
org.apache.juneau.bean.openapi3.OpenApiElement
org.apache.juneau.bean.openapi3.OpenApi

public class OpenApi extends OpenApiElement
This is the root document object for the OpenAPI specification.

The OpenAPI Object is the root document that describes an entire API. It contains metadata about the API, available paths and operations, parameters, responses, authentication methods, and other information.

OpenAPI Specification:

The OpenAPI Object is composed of the following fields:

  • openapi (string, REQUIRED) - The OpenAPI Specification version (e.g., "3.0.0")
  • info (Info, REQUIRED) - Provides metadata about the API
  • servers (array of Server) - An array of Server Objects providing connectivity information
  • paths (map of PathItem) - The available paths and operations for the API
  • components (Components) - An element to hold various schemas for reuse
  • security (array of SecurityRequirement) - Security mechanisms applied to all operations
  • tags (array of Tag) - A list of tags for API documentation control
  • externalDocs (ExternalDocumentation) - Additional external documentation
Example:

// Create an OpenAPI document OpenApi doc = new OpenApi() .setOpenapi("3.0.0") .setInfo( new Info() .setTitle("My API") .setVersion("1.0.0") ) .setPaths( JsonMap.of( "/pets", new PathItem() .setGet(new Operation() .setSummary("List all pets") ) ) );

See Also:
  • Field Details

    • NULL

      public static final OpenApi NULL
      Represents a null OpenAPI document
  • Constructor Details

    • OpenApi

      public OpenApi()
      Default constructor.
    • OpenApi

      public OpenApi(OpenApi copyFrom)
      Copy constructor.
      Parameters:
      copyFrom - The object to copy.
  • Method Details

    • copy

      public OpenApi copy()
      Make a deep copy of this object.
      Returns:
      A deep copy of this object.
    • getOpenapi

      public String getOpenapi()
      Returns the OpenAPI version.
      Returns:
      The OpenAPI version.
    • setOpenapi

      public OpenApi setOpenapi(String value)
      Sets the OpenAPI version.
      Parameters:
      value - The new value for this property.
      Returns:
      This object.
    • getInfo

      public Info getInfo()
      Returns the info object.
      Returns:
      The info object.
    • setInfo

      public OpenApi setInfo(Info value)
      Sets the info object.
      Parameters:
      value - The new value for this property.
      Returns:
      This object.
    • getServers

      public List<Server> getServers()
      Returns the servers list.
      Returns:
      The servers list.
    • setServers

      public OpenApi setServers(List<Server> value)
      Sets the servers list.
      Parameters:
      value - The new value for this property.
      Returns:
      This object.
    • getPaths

      Returns the paths map.
      Returns:
      The paths map.
    • setPaths

      public OpenApi setPaths(Map<String,PathItem> value)
      Sets the paths map.
      Parameters:
      value - The new value for this property.
      Returns:
      This object.
    • addPath

      public OpenApi addPath(String path, PathItem pathItem)
      Adds a path to this OpenAPI document.
      Parameters:
      path - The path string. Must not be null.
      pathItem - The path item. Must not be null.
      Returns:
      This object.
    • getComponents

      Returns the components object.
      Returns:
      The components object.
    • setComponents

      Sets the components object.
      Parameters:
      value - The new value for this property.
      Returns:
      This object.
    • getSecurity

      Returns the security requirements list.
      Returns:
      The security requirements list.
    • setSecurity

      Sets the security requirements list.
      Parameters:
      value - The new value for this property.
      Returns:
      This object.
    • getTags

      public List<Tag> getTags()
      Returns the tags list.
      Returns:
      The tags list.
    • setTags

      public OpenApi setTags(List<Tag> value)
      Sets the tags list.
      Parameters:
      value - The new value for this property.
      Returns:
      This object.
    • setTags

      public OpenApi setTags(Tag... value)
      Bean property setter: tags.

      A list of tags used by the specification with additional metadata.

      Parameters:
      value - The new value for this property.
      Ignored if null.
      Returns:
      This object.
    • addTags

      public OpenApi addTags(Tag... values)
      Bean property appender: tags.

      A list of tags used by the specification with additional metadata.

      Parameters:
      values - The values to add to this property.
      Ignored if null.
      Returns:
      This object.
    • addTags

      public OpenApi addTags(Collection<Tag> values)
      Bean property appender: tags.

      A list of tags used by the specification with additional metadata.

      Parameters:
      values - The values to add to this property.
      Ignored if null.
      Returns:
      This object.
    • addServers

      public OpenApi addServers(Server... values)
      Bean property fluent setter: servers.

      An array of Server Objects, which provide connectivity information to a target server.

      Parameters:
      values - The values to add to this property.
      Ignored if null.
      Returns:
      This object.
    • addServers

      public OpenApi addServers(Collection<Server> values)
      Bean property fluent setter: servers.

      An array of Server Objects, which provide connectivity information to a target server.

      Parameters:
      values - The values to add to this property.
      Ignored if null.
      Returns:
      This object.
    • addSecurity

      Bean property fluent setter: security.

      A declaration of which security mechanisms can be used across the API.

      Parameters:
      values - The values to add to this property.
      Ignored if null.
      Returns:
      This object.
    • addSecurity

      Bean property fluent setter: security.

      A declaration of which security mechanisms can be used across the API.

      Parameters:
      values - The values to add to this property.
      Ignored if null.
      Returns:
      This object.
    • getExternalDocs

      Returns the external documentation.
      Returns:
      The external documentation.
    • setExternalDocs

      Sets the external documentation.
      Parameters:
      value - The new value for this property.
      Returns:
      This object.
    • findRef

      public <T> T findRef(String ref, Class<T> c)
      Finds a reference within this OpenAPI document.
      Parameters:
      ref - The reference string (e.g., "#/components/schemas/User"). Must not be null or blank.
      c - The expected class type. Must not be null.
      Returns:
      The referenced node, or null if not found.
    • toString

      public String toString()
      Overrides:
      toString in class OpenApiElement
    • get

      public <T> T get(String property, Class<T> type)
      Description copied from class: OpenApiElement
      Generic property getter.

      Can be used to retrieve non-standard Swagger fields such as "$ref".

      Overrides:
      get in class OpenApiElement
      Type Parameters:
      T - The datatype to cast the value to.
      Parameters:
      property - The property name to retrieve.
      type - The datatype to cast the value to.
      Returns:
      The property value, or null if the property does not exist or is not set.
    • set

      public OpenApi set(String property, Object value)
      Description copied from class: OpenApiElement
      Generic property setter.

      Can be used to set non-standard Swagger fields such as "$ref".

      Overrides:
      set in class OpenApiElement
      Parameters:
      property - The property name to set. Must not be null.
      value - The new value for the property.
      Returns:
      This object
    • keySet

      public Set<String> keySet()
      Description copied from class: OpenApiElement
      Returns all the keys on this element.
      Overrides:
      keySet in class OpenApiElement
      Returns:
      All the keys on this element.
      Never null.
    • strict

      public OpenApi strict()
      Description copied from class: OpenApiElement
      Sets strict mode on this bean.
      Overrides:
      strict in class OpenApiElement
      Returns:
      This object
    • strict

      public OpenApi strict(Object value)
      Description copied from class: OpenApiElement
      Sets strict mode on this bean.
      Overrides:
      strict in class OpenApiElement
      Parameters:
      value - The new value for this property.
      Non-boolean values will be converted to boolean using Boolean.valueOf(value.toString()).
      Can be null (interpreted as false).
      Returns:
      This object