Class SnippetConfig

java.lang.Object
software.amazon.smithy.codegen.core.docs.SnippetConfig
All Implemented Interfaces:
ToNode, ToSmithyBuilder<SnippetConfig>

public final class SnippetConfig extends Object implements ToSmithyBuilder<SnippetConfig>, ToNode
Represents a file containing generated snippets.

Snippets are generated code based on some trait or other shared definition, such as the ExamplesTrait. These are created by code generators and consumed by documentation tools, such as smithy-docgen.

These are differentiated from typical code gen artifacts in that they are intended to be shared. These may be distributed and aggregated in any manner, but they SHOULD be written to the snippets directory of the shared plugin space by Smithy build plugins. smithy-docgen will discover and include any snippet files in that directory. Smithy build plugins MUST declare a runBefore on "docgen" for their generated snippets to be included.

  • Field Details

  • Method Details

    • getVersion

      public String getVersion()
      Returns:
      Returns the version of the snippet config.
    • getSnippets

      public Map<ShapeId,Map<ShapeId,List<Snippet>>> getSnippets()
      Returns:
      Returns all the snippets in the config.
    • getServiceSnippets

      public Map<ShapeId,List<Snippet>> getServiceSnippets(ShapeId id)
      Gets all the snippets for a particular service.
      Parameters:
      id - The id of the service to get snippets for.
      Returns:
      Returns the snippets for shapes bound to the service.
    • getShapeSnippets

      public List<Snippet> getShapeSnippets(ShapeId serviceId, ShapeId shapeId)
      Gets the snippets for a particular shape in a service.
      Parameters:
      serviceId - The service to search for snippets.
      shapeId - The shape to get snippets for.
      Returns:
      Returns the snippets for a shape from a service.
    • equals

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

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

      public SnippetConfig.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<SnippetConfig>
      Returns:
      a builder for type T
    • builder

      public static SnippetConfig.Builder builder()
      Returns:
      Returns a new SnippetConfig builder.
    • toNode

      public Node toNode()
      Description copied from interface: ToNode
      Converts a value to a Node.
      Specified by:
      toNode in interface ToNode
      Returns:
      Returns the creates Node.
    • fromNode

      public static SnippetConfig fromNode(Node node)
      Parameters:
      node - A node representing a SnippetConfig.
      Returns:
      Returns a SnippetConfig based on the given node.
    • load

      public static SnippetConfig load(Path path)
      Loads a SnippetConfig from a JSON file.
      Parameters:
      path - The path to the JSON snippet config.
      Returns:
      Returns a SnippetConfig based on the given file.