Class Context<T extends Trait>


public final class Context<T extends Trait> extends Object
Smithy to OpenAPI conversion context object.
  • Method Details

    • getModel

      public Model getModel()
      Gets the Smithy model being converted.
      Returns the Smithy model.
    • getService

      public ServiceShape getService()
      Gets the service shape being converted.
      Returns the service shape.
    • getConfig

      public OpenApiConfig getConfig()
      Gets the configuration object used for the conversion.

      Plugins can query this object for configuration values.

      Returns the configuration object.
    • getJsonSchemaConverter

      public JsonSchemaConverter getJsonSchemaConverter()
      Gets the JSON schema converter.
      Returns the JSON Schema converter.
    • getProtocolTrait

      public T getProtocolTrait()
      Gets the protocol trait that is being converted.
      Returns the protocol ID.
    • getOpenApiProtocol

      public OpenApiProtocol<T> getOpenApiProtocol()
      Gets the OpenAPI protocol conversion object.
      Returns the OpenAPI protocol.
    • getSchema

      public Schema getSchema(String pointer)
      Gets a converted schema from the context object by JSON pointer and throws if the schema does not exist.
      pointer - Schema to retrieve by JSON pointer (e.g., "#/components/schemas/foo").
      Returns the found schema.
      OpenApiException - if the schema cannot be found.
    • getPointer

      public String getPointer(ToShapeId shapeId)
      Gets the JSON pointer string to a specific shape.
      shapeId - Shape ID to convert into a JSON pointer to a schema component.
      Returns the JSON pointer to this shape as a schema component.
    • createRef

      public Schema createRef(ToShapeId shapeId)
      Creates a schema that contains a $ref that points to a schema component.
      shapeId - Shape ID to point to with a $ref schema.
      Returns the creates schema.
    • inlineOrReferenceSchema

      public Schema inlineOrReferenceSchema(MemberShape member)
      Gets the exiting schema of the shape if it's meant to be inlined, otherwise creates a $ref to the shape if it is meant to be reused across the generated schema.
      member - Member to inline or reference.
      Returns the schema for the member.
    • getSecuritySchemeConverters

      public List<SecuritySchemeConverter<? extends Trait>> getSecuritySchemeConverters()
      Gets the security scheme converters that are compatible with the selected protocol.
      Returns the security scheme converters.
    • usesHttpCredentials

      public boolean usesHttpCredentials()
      Reports if any authentication mechanisms in the entire model use HTTP credentials, such as cookies, browser-managed usernames and passwords, or TLS client certificates.

      This is useful when integrating with things like CORS.

      Whether any authentication mechanism relies on browser-managed credentials.
      See Also:
    • getAllSecuritySchemeRequestHeaders

      public Set<String> getAllSecuritySchemeRequestHeaders()
      Gets an alphabetically sorted set of request headers used by every security scheme associated with the API.

      This is useful when integrating with things like CORS.

      Returns the set of every request header used by every security scheme.
    • getAllSecuritySchemeResponseHeaders

      public Set<String> getAllSecuritySchemeResponseHeaders()
      Gets an alphabetically sorted set of response headers used by every security scheme associated with the API.

      This is useful when integrating with things like CORS.

      Returns the set of every response header used by every security scheme.
    • getSynthesizedSchemas

      public Map<String,Schema> getSynthesizedSchemas()
      Gets all of the synthesized schemas that needed to be created while generating the OpenAPI artifact.
      Returns the "synthesized" schemas as an immutable map.
    • putSynthesizedSchema

      public String putSynthesizedSchema(String name, Schema schema)
      Puts a new synthesized schema that is needed to convert to OpenAPI.

      Synthesized schemas are used when ad-hoc schemas are necessary in order to materialize some change in OpenAPI while still providing an explicit name. For example, when generating many of the RESTful protocols, members from the input of an operation might come together to form the payload of a request. In Smithy, it's fine to use only part of the input to derive the payload, whereas in OpenAPI, you need a schema that's dedicated to the payload.

      The primary alternative to synthesized schemas is inlined schema definitions. The problem with inline schemas is that they don't have an explicit or even deterministic name when used with other platforms (for example, API Gateway will generate a random name for an object if one is not given).

      This method is thread-safe.

      name - Name of the schema to put into components/schemas. Nested pointers are not supported.
      schema - The schema to put.
      Returns a JSON pointer to the created schema.