Class JsonSchemaConfig

  • Direct Known Subclasses:
    CfnConfig, OpenApiConfig

    public class JsonSchemaConfig
    extends java.lang.Object
    JSON Schema configuration options.
    • Constructor Detail

      • JsonSchemaConfig

        public JsonSchemaConfig()
    • Method Detail

      • 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..
      • 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.
      • setUnionStrategy

        public void setUnionStrategy​(JsonSchemaConfig.UnionStrategy unionStrategy)
        Configures how Smithy union shapes are converted to JSON Schema.
        Parameters:
        unionStrategy - The union strategy to use.
      • 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 java.lang.String getDefinitionPointer()
      • setDefinitionPointer

        public void setDefinitionPointer​(java.lang.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 java.util.Set<java.lang.String> getDisableFeatures()
      • setDisableFeatures

        public void setDisableFeatures​(java.util.Set<java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.String key,
                                 java.lang.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 java.util.Optional<java.lang.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
      • getAddReferenceDescriptions

        public boolean getAddReferenceDescriptions()
        Whether to add the description property to Schema References when converting Smithy member shapes into JSON Schema with the value of the member's documentation.

        Defaults to false.

        Returns:
        Whether to add descriptions to Schema References.
      • setAddReferenceDescriptions

        public void setAddReferenceDescriptions​(boolean addReferenceDescriptions)
        Sets whether the description property should be added to Schema References.
        Parameters:
        addReferenceDescriptions - Whether to add descriptions to Schema References