Class OpenApiConverter

java.lang.Object
software.amazon.smithy.openapi.fromsmithy.OpenApiConverter

public final class OpenApiConverter extends Object
Converts a Smithy model to OpenAPI.
  • Method Details

    • create

      public static OpenApiConverter create()
    • getConfig

      public OpenApiConfig getConfig()
      Get the OpenAPI configuration settings.
      Returns:
      Returns the config object.
    • config

      public OpenApiConverter config(OpenApiConfig config)
      Set the OpenAPI configuration settings.

      This also updates the configuration object of any previously set JsonSchemaConfig.

      Parameters:
      config - Config object to set.
      Returns:
      Returns the converter.
    • addOpenApiMapper

      public OpenApiConverter addOpenApiMapper(OpenApiMapper mapper)
      Adds an OpenApiMapper to the converter.

      This method is used to add custom OpenApiMappers to a converter that are not automatically added by Smithy2OpenApiExtension objects detected through Java SPI.

      Parameters:
      mapper - Mapper to add.
      Returns:
      Returns the converter.
    • classLoader

      public OpenApiConverter classLoader(ClassLoader classLoader)
      Sets a ClassLoader to use to discover JsonSchemaMapper, OpenApiMapper, and OpenApiProtocol service providers through SPI.

      The OpenApiConverter will use its own ClassLoader by default.

      Parameters:
      classLoader - ClassLoader to use.
      Returns:
      Returns the OpenApiConverter.
    • convert

      public OpenApi convert(software.amazon.smithy.model.Model model)
      Converts the Smithy model to OpenAPI.
      Parameters:
      model - Smithy model to convert.
      Returns:
      Returns the converted model.
    • convertToNode

      public software.amazon.smithy.model.node.ObjectNode convertToNode(software.amazon.smithy.model.Model model)
      Converts the given service shape to a JSON/Node representation of an OpenAPI model using the given Smithy model.

      The result of this method may differ from the result of calling Component.toNode() because this method will pass the Node representation of the OpenAPI through the OpenApiMapper.updateNode(software.amazon.smithy.openapi.fromsmithy.Context<? extends software.amazon.smithy.model.traits.Trait>, software.amazon.smithy.openapi.model.OpenApi, software.amazon.smithy.model.node.ObjectNode) method of each registered OpenApiMapper. This may cause the returned value to no longer be a valid OpenAPI model but still representative of the desired artifact (for example, an OpenAPI model used with Amazon CloudFormation might used intrinsic JSON functions or variable expressions that are replaced when synthesized).

      Parameters:
      model - Smithy model to convert.
      Returns:
      Returns the converted model.