Class JsonSchemaConfig

java.lang.Object
software.amazon.smithy.jsonschema.JsonSchemaConfig
Direct Known Subclasses:
CfnConfig, OpenApiConfig

public class JsonSchemaConfig extends Object
JSON Schema configuration options.
  • Constructor Details

    • JsonSchemaConfig

      public JsonSchemaConfig()
  • Method Details

    • getAlphanumericOnlyRefs

      public boolean getAlphanumericOnlyRefs()
    • setAlphanumericOnlyRefs

      public void setAlphanumericOnlyRefs(boolean alphanumericOnlyRefs)
      Creates shape name pointers that strip out non-alphanumeric characters.

      This is necessary for compatibility with some vendors like Amazon API Gateway that only allow alphanumeric shape names.

      Parameters:
      alphanumericOnlyRefs - Set to true to strip non-alphanumeric characters.
    • getUseJsonName

      public boolean getUseJsonName()
    • setUseJsonName

      public void setUseJsonName(boolean useJsonName)
      Uses the value of the jsonName trait when creating JSON schema properties for structure and union shapes.

      This property has no effect if a PropertyNamingStrategy is manually configured on a JsonSchemaConverter.

      Parameters:
      useJsonName - Set to true to use jsonName traits when creating refs..
    • getDefaultTimestampFormat

      public TimestampFormatTrait.Format getDefaultTimestampFormat()
    • setDefaultTimestampFormat

      public void setDefaultTimestampFormat(TimestampFormatTrait.Format defaultTimestampFormat)
      Sets the assumed timestampFormat trait for timestamps with no timestampFormat trait. The provided value is expected to be a string.

      Defaults to "date-time" if not set. Can be set to "date-time", "epoch-seconds", or "http-date".

      Parameters:
      defaultTimestampFormat - The default timestamp format to use when none is set.
    • getUnionStrategy

      public JsonSchemaConfig.UnionStrategy getUnionStrategy()
    • setUnionStrategy

      public void setUnionStrategy(JsonSchemaConfig.UnionStrategy unionStrategy)
      Configures how Smithy union shapes are converted to JSON Schema.
      Parameters:
      unionStrategy - The union strategy to use.
    • getMapStrategy

      public JsonSchemaConfig.MapStrategy getMapStrategy()
    • setMapStrategy

      public void setMapStrategy(JsonSchemaConfig.MapStrategy mapStrategy)
      Configures how Smithy map shapes are converted to JSON Schema.
      Parameters:
      mapStrategy - The map strategy to use.
    • getDefinitionPointer

      public String getDefinitionPointer()
    • setDefinitionPointer

      public void setDefinitionPointer(String definitionPointer)
      Configures location of where definitions are written using JSON Pointer.

      The provided String value MUST start with "#/" and can use nested "/" characters to place schemas in nested object properties. The provided JSON Pointer does not support escaping.

      Defaults to "#/definitions" for schema versions less than 2019-09 and "#/$defs" for schema versions 2019-09 and greater. OpenAPI artifacts will want to use "#/components/schemas".

      Parameters:
      definitionPointer - The root definition pointer to use.
    • getSchemaDocumentExtensions

      public ObjectNode getSchemaDocumentExtensions()
    • setSchemaDocumentExtensions

      public void setSchemaDocumentExtensions(ObjectNode schemaDocumentExtensions)
      Adds custom key-value pairs to the JSON Schema document generated from a Smithy model.
      Parameters:
      schemaDocumentExtensions - Custom extensions to merge into the created schema.
    • getDisableFeatures

      public Set<String> getDisableFeatures()
    • setDisableFeatures

      public void setDisableFeatures(Set<String> disableFeatures)
      Disables OpenAPI features by their property name (e.g., "allOf").
      Parameters:
      disableFeatures - Feature names to disable.
    • getExtensions

      public ObjectNode getExtensions()
    • getExtensions

      public <T> T getExtensions(Class<T> as)
      Attempts to deserialize the extensions into the targeted type using a NodeMapper.

      Extraneous properties are ignored and not warned on because many different plugins could be used with different configuration POJOs.

      The result of calling this method is cached for each type, and the cache is cleared when any mutation is made to extensions.

      Type Parameters:
      T - Type to deserialize extensions into.
      Parameters:
      as - Type to deserialize extensions into.
      Returns:
      Returns the deserialized type.
    • setExtensions

      public void setExtensions(ObjectNode extensions)
      Sets an arbitrary map of "extensions" used by plugins that need configuration.
      Parameters:
      extensions - Extensions to set.
    • putExtensions

      public void putExtensions(Object extensionContainer)
      Add an extension to the "extensions" object node using a POJO.
      Parameters:
      extensionContainer - POJO to serialize and merge into extensions.
    • putExtension

      public void putExtension(String key, Node value)
      Add an extension to the "extensions" object node.
      Parameters:
      key - Property name to set.
      value - Value to assigned.
    • putExtension

      public void putExtension(String key, boolean value)
      Add an extension to the "extensions" object node.
      Parameters:
      key - Property name to set.
      value - Value to assigned.
    • putExtension

      public void putExtension(String key, String value)
      Add an extension to the "extensions" object node.
      Parameters:
      key - Property name to set.
      value - Value to assigned.
    • getService

      public ShapeId getService()
      Gets the service shape ID that is used to contextualize the created schemas by using things like the "rename" property of the service.
      Returns:
      the nullable Smithy service shape ID.
    • setService

      public void setService(ShapeId service)
      Sets the service shape ID that is used to contextualize the created schemas by using things like the "rename" property of the service.
      Parameters:
      service - the Smithy service shape ID.
    • detectJsonTimestampFormat

      public Optional<String> detectJsonTimestampFormat(Shape shape)
      Detects the TimestampFormat of the given shape, falling back to the configured default format specified in setDefaultTimestampFormat(TimestampFormatTrait.Format).
      Parameters:
      shape - Shape to extract the timestamp format from.
      Returns:
      Returns the optionally detected format.
    • getSupportNonNumericFloats

      public boolean getSupportNonNumericFloats()
    • setSupportNonNumericFloats

      public void setSupportNonNumericFloats(boolean supportNonNumericFloats)
      Set to true to add support for NaN, Infinity, and -Infinity in float and double shapes. These values will be serialized as strings. The OpenAPI document will be updated to refer to them as a "oneOf" of number and string.

      By default, non-numeric values are not supported.

      Parameters:
      supportNonNumericFloats - True if non-numeric float values should be supported.
    • isEnableOutOfServiceReferences

      public boolean isEnableOutOfServiceReferences()
    • setEnableOutOfServiceReferences

      public void setEnableOutOfServiceReferences(boolean enableOutOfServiceReferences)
      Set to true to enable references to shapes outside the service closure. Setting this to true means that all the shapes in the model must not conflict, whereas leaving it at the default, false, means that only the shapes connected to the configured service via setService(ShapeId) must not conflict.
      Parameters:
      enableOutOfServiceReferences - true if out-of-service references should be allowed. default: false
    • getUseIntegerType

      public boolean getUseIntegerType()
    • setUseIntegerType

      public void setUseIntegerType(boolean useIntegerType)
      Set to true to use the "integer" type when converting byte, short, integer, and long shapes to Json Schema.

      By default, these shape types are converted to Json Schema with a type of "number".

      Parameters:
      useIntegerType - True to use "integer".
    • getDisableDefaultValues

      public boolean getDisableDefaultValues()
    • setDisableDefaultValues

      public void setDisableDefaultValues(boolean disableDefaultValues)
      Set to true to disable default values on schemas, including wrapping $ref pointers in an `allOf`.
      Parameters:
      disableDefaultValues - True to disable setting default values.
    • getDisableIntEnums

      public boolean getDisableIntEnums()
    • setDisableIntEnums

      public void setDisableIntEnums(boolean disableIntEnums)
      Set to true to disable setting an `enum` property for intEnums. When disabled, intEnums are inlined instead of using a $ref.
      Parameters:
      disableIntEnums - True to disable setting `enum` property for intEnums.
    • getJsonSchemaVersion

      public JsonSchemaVersion getJsonSchemaVersion()
      JSON schema version to use when converting Smithy shapes into Json Schema.

      Defaults to JSON Schema version draft07 if no schema version is specified

      Returns:
      JSON Schema version that will be used for generated JSON schema
    • setJsonSchemaVersion

      public void setJsonSchemaVersion(JsonSchemaVersion schemaVersion)
      Set the JSON schema version to use when converting Smithy shapes into Json Schema.
      Parameters:
      schemaVersion - JSON Schema version to use for generated schema