Class HttpBindingIndex

java.lang.Object
software.amazon.smithy.model.knowledge.HttpBindingIndex
All Implemented Interfaces:
KnowledgeIndex

public final class HttpBindingIndex extends Object implements KnowledgeIndex
Computes and indexes the explicit and implicit HTTP bindings of a model.

This index makes it easy to understand how members of the input or output of a request/response are bound to an HTTP message by providing all of the bindings in the model as a normalized HttpBinding object. This can be used to validate the bindings of an operation, generate code to [de]serialize shapes, diff models to ensure backward compatibility at the wire level, etc.

This index does not perform validation of the underlying model.

  • Constructor Details

    • HttpBindingIndex

      public HttpBindingIndex(Model model)
  • Method Details

    • of

      public static HttpBindingIndex of(Model model)
    • hasHttpRequestBindings

      public static boolean hasHttpRequestBindings(Shape shape)
      Returns true if a shape has any HTTP request trait bindings.
      Parameters:
      shape - Shape to check.
      Returns:
      Returns true if the shape is bound to an HTTP header, payload, prefix headers, query string, or label.
    • hasHttpResponseBindings

      public static boolean hasHttpResponseBindings(Shape shape)
      Returns true if a shape has any HTTP response trait bindings.
      Parameters:
      shape - Shape to check.
      Returns:
      Returns true if the shape is bound to an HTTP header, payload, of prefix headers.
    • getResponseCode

      public int getResponseCode(ToShapeId shapeOrId)
      Gets the computed status code of an operation or error structure.
      Parameters:
      shapeOrId - Operation or error structure shape ID.
      Returns:
      Returns the computed HTTP status code.
      Throws:
      IllegalArgumentException - if the given shape is not an operation or an error structure.
    • getRequestBindings

      public Map<String,HttpBinding> getRequestBindings(ToShapeId operationShapeOrId)
      Gets the request bindings of an operation as a map of member name to the binding.
      Parameters:
      operationShapeOrId - Operation to get the request bindings for.
      Returns:
      Map of unmodifiable bindings.
    • getRequestBindings

      public List<HttpBinding> getRequestBindings(ToShapeId operationShapeOrId, HttpBinding.Location requestLocation)
      Gets the request bindings of an operation as a map of member name to the binding for a specific location type.
      Parameters:
      operationShapeOrId - Operation to get the request bindings for.
      requestLocation - Location of the binding.
      Returns:
      Map of unmodifiable bindings.
    • getResponseBindings

      public Map<String,HttpBinding> getResponseBindings(ToShapeId shapeOrId)
      Gets the computed HTTP message response bindings for an operation or structure with an error trait.
      Parameters:
      shapeOrId - Operation or error structure shape or ID.
      Returns:
      Map of unmodifiable bindings.
    • getResponseBindings

      public List<HttpBinding> getResponseBindings(ToShapeId shapeOrId, HttpBinding.Location bindingLocation)
      Gets the computed HTTP message response bindings for an operation or structure with an error trait for a specific binding type.
      Parameters:
      shapeOrId - Operation or error structure shape or ID.
      bindingLocation - Binding location type.
      Returns:
      List of found bindings.
      Throws:
      IllegalArgumentException - if the given shape is not an operation or error structure.
    • determineTimestampFormat

      public TimestampFormatTrait.Format determineTimestampFormat(ToShapeId member, HttpBinding.Location location, TimestampFormatTrait.Format defaultFormat)
      Determines the appropriate timestamp format for a member shape bound to a specific location.
      Parameters:
      member - Member to derive the timestamp format.
      location - Location the member is bound to.
      defaultFormat - The format to use for the body or a default.
      Returns:
      Returns the determined timestamp format.
    • determineRequestContentType

      public Optional<String> determineRequestContentType(ToShapeId operation, String documentContentType)
      Returns the expected request Content-Type of the given operation.

      See determineRequestContentType(ToShapeId, String, String) for documentation on how the content-type is resolved.

      Parameters:
      operation - Operation to determine the content-type of.
      documentContentType - Content-Type to use for protocol documents.
      Returns:
      Returns the optionally resolved content-type of the request.
    • determineRequestContentType

      public Optional<String> determineRequestContentType(ToShapeId operation, String documentContentType, String eventStreamContentType)
      Returns the expected request Content-Type of the given operation.

      If members are sent in the "document" body, then the default documentContentType value is returned. If a member is bound to the payload, then the following checks are made:

      • If the payload has the StreamingTrait, then the eventStreamContentType is returned.
      • If the targeted shape is a structure or document type, then the documentContentType is returned.
      • If the targeted shape has the MediaTypeTrait, then the value of the trait is returned.
      • If the targeted shape is a blob, then "application/octet-stream" is returned.
      • If the targeted shape is a string, then "text/plain" is returned.

      If no members are sent in the payload, an empty Optional is returned.

      Parameters:
      operation - Operation to determine the content-type of.
      documentContentType - Content-Type to use for protocol documents.
      eventStreamContentType - Content-Type to use for event streams.
      Returns:
      Returns the optionally resolved content-type of the request.
    • determineResponseContentType

      public Optional<String> determineResponseContentType(ToShapeId operationOrError, String documentContentType)
      Returns the expected response Content-Type of the given operation or error.

      See determineResponseContentType(ToShapeId, String, String) for documentation on how the content-type is resolved.

      Parameters:
      operationOrError - Operation or error to determine the content-type of.
      documentContentType - Content-Type to use for protocol documents.
      Returns:
      Returns the optionally resolved content-type of the response.
    • determineResponseContentType

      public Optional<String> determineResponseContentType(ToShapeId operationOrError, String documentContentType, String eventStreamContentType)
      Returns the expected response Content-Type of the given operation or error.

      If members are sent in the "document" body, then the default documentContentType value is returned. If a member is bound to the payload, then the following checks are made:

      • If the payload has the StreamingTrait, then the eventStreamContentType is returned.
      • If the targeted shape is a structure or document type, then the documentContentType is returned.
      • If the targeted shape has the MediaTypeTrait, then the value of the trait is returned.
      • If the targeted shape is a blob, then "application/octet-stream" is returned.
      • If the targeted shape is a string, then "text/plain" is returned.

      If no members are sent in the payload, an empty Optional is returned.

      Parameters:
      operationOrError - Operation or error to determine the content-type of.
      documentContentType - Content-Type to use for protocol documents.
      eventStreamContentType - Content-Type used for event streams.
      Returns:
      Returns the optionally resolved content-type of the response.
    • hasRequestBody

      public boolean hasRequestBody(ToShapeId operation)
      Returns true if the request has a modeled body.
      Parameters:
      operation - Operation to check.
      Returns:
      Returns true if the operation has document or payload bindings.
    • hasResponseBody

      public boolean hasResponseBody(ToShapeId operation)
      Returns true if the response has a modeled body.
      Parameters:
      operation - Operation to check.
      Returns:
      Returns true if the operation has document or payload bindings.