Class Model

java.lang.Object
software.amazon.smithy.model.Model
All Implemented Interfaces:
ToSmithyBuilder<Model>

public final class Model extends Object implements ToSmithyBuilder<Model>
A Smithy model that contains shapes, traits, metadata, and various computed information used to interpret the model.
  • Field Details

    • MODEL_VERSION

      public static final String MODEL_VERSION
      Specifies the highest supported version of the IDL.
      See Also:
  • Method Details

    • builder

      public static Model.Builder builder()
      Builds an explicitly configured Smithy model.

      Note that the builder does not validate the correctness of the model. Use the assembler() method to build and validate a model.

      Returns:
      Returns a model builder.
      See Also:
    • assembler

      public static ModelAssembler assembler()
      Assembles and validates a Smithy model from files, nodes, and other disparate sources.
      Returns:
      Returns a model assembler.
    • assembler

      public static ModelAssembler assembler(ClassLoader classLoader)
      Creates a ModelAssembler that is configured to discover traits, validators, and built-in validators using the given ClassLoader.
      Parameters:
      classLoader - Class loader used to discover services.
      Returns:
      Returns a model assembler.
    • getMetadataProperty

      public Optional<Node> getMetadataProperty(String name)
      Gets a metadata property by namespace and name.
      Parameters:
      name - Name of the property to retrieve.
      Returns:
      Returns the optional property.
    • getMetadata

      public Map<String,Node> getMetadata()
      Returns:
      Gets the unmodifiable metadata of the model across all namespaces.
    • getTraitDefinition

      public Optional<TraitDefinition> getTraitDefinition(ToShapeId traitId)
      Gets the trait definition of a specific trait shape ID.
      Parameters:
      traitId - ID of the shape to get the trait definition of.
      Returns:
      Returns the optionally found trait definition.
    • getShapesWithTrait

      public Set<Shape> getShapesWithTrait(ToShapeId trait)
      Gets a set of shapes in the model marked with a specific trait.
      Parameters:
      trait - Trait shape ID to look for on shapes.
      Returns:
      Returns the immutable set of matching shapes.
    • getShapeIds

      public Set<ShapeId> getShapeIds()
      Gets the immutable set of ShapeId in the model.
      Returns:
      Returns the shape IDs.
    • getShapesWithTrait

      public Set<Shape> getShapesWithTrait(Class<? extends Trait> trait)
      Gets a set of shapes in the model marked with a specific trait.

      The result is an exact match on trait classes and does not utilize any kind of polymorphic instance of checks.

      Parameters:
      trait - Trait class to look for on shapes.
      Returns:
      Returns the immutable set of matching shapes.
    • getBigDecimalShapes

      public Set<BigDecimalShape> getBigDecimalShapes()
      Gets an immutable set of all bigDecimals in the Model.
      Returns:
      Returns the Set of bigDecimalss.
    • getBigDecimalShapesWithTrait

      public Set<BigDecimalShape> getBigDecimalShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all bigDecimals in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of bigdecimals that have a specific trait.
    • getBigIntegerShapes

      public Set<BigIntegerShape> getBigIntegerShapes()
      Gets an immutable set of all bigIntegers in the Model.
      Returns:
      Returns the Set of bigIntegerss.
    • getBigIntegerShapesWithTrait

      public Set<BigIntegerShape> getBigIntegerShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all bigIntegers in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of bigIntegerss that have a specific trait.
    • getBlobShapes

      public Set<BlobShape> getBlobShapes()
      Gets an immutable set of all blobs in the Model.
      Returns:
      Returns the Set of blobs.
    • getBlobShapesWithTrait

      public Set<BlobShape> getBlobShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all blobs in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of blobs that have a specific trait.
    • getBooleanShapes

      public Set<BooleanShape> getBooleanShapes()
      Gets an immutable set of all booleans in the Model.
      Returns:
      Returns the Set of booleans.
    • getBooleanShapesWithTrait

      public Set<BooleanShape> getBooleanShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all booleans in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of booleans that have a specific trait.
    • getByteShapes

      public Set<ByteShape> getByteShapes()
      Gets an immutable set of all bytes in the Model.
      Returns:
      Returns the Set of bytes.
    • getByteShapesWithTrait

      public Set<ByteShape> getByteShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all bytes in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of bytes that have a specific trait.
    • getDocumentShapes

      public Set<DocumentShape> getDocumentShapes()
      Gets an immutable set of all documents in the Model.
      Returns:
      Returns the Set of documents.
    • getDocumentShapesWithTrait

      public Set<DocumentShape> getDocumentShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all documents in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of documents that have a specific trait.
    • getDoubleShapes

      public Set<DoubleShape> getDoubleShapes()
      Gets an immutable set of all doubles in the Model.
      Returns:
      Returns the Set of doubles.
    • getDoubleShapesWithTrait

      public Set<DoubleShape> getDoubleShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all doubles in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of doubles that have a specific trait.
    • getFloatShapes

      public Set<FloatShape> getFloatShapes()
      Gets an immutable set of all floats in the Model.
      Returns:
      Returns the Set of floats.
    • getFloatShapesWithTrait

      public Set<FloatShape> getFloatShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all floats in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of floats that have a specific trait.
    • getIntegerShapes

      public Set<IntegerShape> getIntegerShapes()
      Gets an immutable set of all integers in the Model.
      Returns:
      Returns the Set of integers.
    • getIntegerShapesWithTrait

      public Set<IntegerShape> getIntegerShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all integers in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of integers that have a specific trait.
    • getIntEnumShapes

      public Set<IntEnumShape> getIntEnumShapes()
      Gets an immutable set of all intEnums in the Model.
      Returns:
      Returns the Set of intEnums.
    • getIntEnumShapesWithTrait

      public Set<IntEnumShape> getIntEnumShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all intEnums in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of intEnums that have a specific trait.
    • getListShapes

      public Set<ListShape> getListShapes()
      Gets an immutable set of all lists in the Model.
      Returns:
      Returns the Set of lists.
    • getListShapesWithTrait

      public Set<ListShape> getListShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all lists in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of lists that have a specific trait.
    • getLongShapes

      public Set<LongShape> getLongShapes()
      Gets an immutable set of all longs in the Model.
      Returns:
      Returns the Set of longs.
    • getLongShapesWithTrait

      public Set<LongShape> getLongShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all longs in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of longs that have a specific trait.
    • getMapShapes

      public Set<MapShape> getMapShapes()
      Gets an immutable set of all maps in the Model.
      Returns:
      Returns the Set of maps.
    • getMapShapesWithTrait

      public Set<MapShape> getMapShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all maps in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of maps that have a specific trait.
    • getMemberShapes

      public Set<MemberShape> getMemberShapes()
      Gets an immutable set of all members in the Model.
      Returns:
      Returns the Set of members.
    • getMemberShapesWithTrait

      public Set<MemberShape> getMemberShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all members in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of members that have a specific trait.
    • getOperationShapes

      public Set<OperationShape> getOperationShapes()
      Gets an immutable set of all operations in the Model.
      Returns:
      Returns the Set of operations.
    • getOperationShapesWithTrait

      public Set<OperationShape> getOperationShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all operations in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of operations that have a specific trait.
    • getResourceShapes

      public Set<ResourceShape> getResourceShapes()
      Gets an immutable set of all resources in the Model.
      Returns:
      Returns the Set of resources.
    • getResourceShapesWithTrait

      public Set<ResourceShape> getResourceShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all resources in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of resources that have a specific trait.
    • getServiceShapes

      public Set<ServiceShape> getServiceShapes()
      Gets an immutable set of all services in the Model.
      Returns:
      Returns the Set of services.
    • getServiceShapesWithTrait

      public Set<ServiceShape> getServiceShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all services in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of services that have a specific trait.
    • getSetShapes

      @Deprecated public Set<SetShape> getSetShapes()
      Deprecated.
      Gets an immutable set of all sets in the Model.
      Returns:
      Returns the Set of sets.
    • getSetShapesWithTrait

      @Deprecated public Set<SetShape> getSetShapesWithTrait(Class<? extends Trait> trait)
      Deprecated.
      Gets an immutable set of all sets in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of sets that have a specific trait.
    • getShortShapes

      public Set<ShortShape> getShortShapes()
      Gets an immutable set of all shorts in the Model.
      Returns:
      Returns the Set of shorts.
    • getShortShapesWithTrait

      public Set<ShortShape> getShortShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all shorts in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of shorts that have a specific trait.
    • getStringShapes

      public Set<StringShape> getStringShapes()
      Gets an immutable set of all strings in the Model.
      Returns:
      Returns the Set of strings.
    • getStringShapesWithTrait

      public Set<StringShape> getStringShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all strings in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of strings that have a specific trait.
    • getEnumShapes

      public Set<EnumShape> getEnumShapes()
      Gets an immutable set of all enums in the Model.
      Returns:
      Returns the Set of enums.
    • getEnumShapesWithTrait

      public Set<EnumShape> getEnumShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all enums in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of enums that have a specific trait.
    • getStructureShapes

      public Set<StructureShape> getStructureShapes()
      Gets an immutable set of all structures in the Model.
      Returns:
      Returns the Set of structures.
    • getStructureShapesWithTrait

      public Set<StructureShape> getStructureShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all structures in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of structures that have a specific trait.
    • getTimestampShapes

      public Set<TimestampShape> getTimestampShapes()
      Gets an immutable set of all timestamps in the Model.
      Returns:
      Returns the Set of timestamps.
    • getTimestampShapesWithTrait

      public Set<TimestampShape> getTimestampShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all timestamps in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of timestamps that have a specific trait.
    • getUnionShapes

      public Set<UnionShape> getUnionShapes()
      Gets an immutable set of all unions in the Model.
      Returns:
      Returns the Set of unions.
    • getUnionShapesWithTrait

      public Set<UnionShape> getUnionShapesWithTrait(Class<? extends Trait> trait)
      Gets an immutable set of all unions in the Model that have a specific trait.
      Parameters:
      trait - The exact trait class to look for on shapes.
      Returns:
      Returns the set of unions that have a specific trait.
    • getAppliedTraits

      public Set<ShapeId> getAppliedTraits()
      Gets a set of every trait shape ID that is used in the model.
      Returns:
      Returns the shape IDs of traits used in the model.
    • isTraitApplied

      public boolean isTraitApplied(Class<? extends Trait> trait)
      Returns true if the given trait shape ID was used in the model.
      Parameters:
      trait - The trait class to check.
      Returns:
      Returns true if the trait was used in the model.
    • getShape

      public Optional<Shape> getShape(ShapeId id)
      Attempts to retrieve a Shape by ShapeId.
      Parameters:
      id - Shape to retrieve by ID.
      Returns:
      Returns the optional shape.
    • expectShape

      public Shape expectShape(ShapeId id)
      Attempts to retrieve a Shape by ShapeId and throws if not found.
      Parameters:
      id - Shape to retrieve by ID.
      Returns:
      Returns the shape.
      Throws:
      ExpectationNotMetException - if the shape is not found.
    • expectShape

      public <T extends Shape> T expectShape(ShapeId id, Class<T> type)
      Attempts to retrieve a Shape by ShapeId and throws if not found or if the shape is not of the expected type.
      Type Parameters:
      T - Expected shape type.
      Parameters:
      id - Shape to retrieve by ID.
      type - Shape type to expect and convert to.
      Returns:
      Returns the shape.
      Throws:
      ExpectationNotMetException - if the shape is not found or is not the expected type.
    • shapes

      public Stream<Shape> shapes()
      Gets a stream of Shapes in the index.
      Returns:
      Returns a stream of shapes.
    • shapes

      public <T extends Shape> Stream<T> shapes(Class<T> shapeType)
      Gets a stream of shapes in the index of a specific type T.

      The provided shapeType class must exactly match the class of a shape in the model in order to be returned from this method; that is, the provided class must be a concrete subclass of Shape and not an abstract class like NumberShape.

      Type Parameters:
      T - Shape type to stream from the index.
      Parameters:
      shapeType - Shape type T to retrieve.
      Returns:
      A stream of shapes of T matching shapeType.
    • toSet

      public <T extends Shape> Set<T> toSet(Class<T> shapeType)
      Gets an immutable Set of shapes of a specific type.
      Type Parameters:
      T - Shape type to get from the index.
      Parameters:
      shapeType - Type of shape to get a set of.
      Returns:
      Returns an unmodifiable set of shapes.
    • toSet

      public Set<Shape> toSet()
      Converts the model to an immutable Set of shapes.
      Returns:
      Returns an unmodifiable set of shapes.
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toBuilder

      public Model.Builder toBuilder()
      Description copied from interface: ToSmithyBuilder
      Take this object and create a builder that contains all of the current property values of this object.
      Specified by:
      toBuilder in interface ToSmithyBuilder<Model>
      Returns:
      a builder for type T
    • getKnowledge

      @Deprecated public <T extends KnowledgeIndex> T getKnowledge(Class<T> type)
      Deprecated.
      This method is deprecated. Use the of method of the KnowledgeIndex you wish to create instead.
      Type Parameters:
      T - The type of knowledge index to retrieve.
      Parameters:
      type - Type of knowledge index to retrieve.
      Returns:
      Returns the computed knowledge index.
    • getKnowledge

      public <T extends KnowledgeIndex> T getKnowledge(Class<T> type, Function<Model,T> constructor)
      Gets a computed "knowledge index" of a specific type for the model and caches it for subsequent retrieval.

      This method should not typically be called directly because KnowledgeIndex classes should all provide a public static of method that accepts a Model and returns an instance of the index by invoking getKnowledge.

      If a KnowledgeIndex of the given type has not yet been computed, one will be created using the provided constructor function that accepts a Model. Computed knowledge indexes are cached and returned on subsequent retrievals.

      Type Parameters:
      T - The type of knowledge index to retrieve.
      Parameters:
      type - Type of knowledge index to retrieve.
      constructor - The method used to create type.
      Returns:
      Returns the computed knowledge index.