Class JsonSchemaConverter
- java.lang.Object
-
- software.amazon.smithy.jsonschema.JsonSchemaConverter
-
- All Implemented Interfaces:
ToSmithyBuilder<JsonSchemaConverter>
public final class JsonSchemaConverter extends java.lang.Object implements ToSmithyBuilder<JsonSchemaConverter>
Converts a Smithy model index to a JSON schema document.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JsonSchemaConverter.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static JsonSchemaConverter.Builder
builder()
SchemaDocument
convert()
Perform the conversion of the entire shape index.SchemaDocument
convertShape(Shape shape)
Perform the conversion of a single shape.JsonSchemaConfig
getConfig()
Gets the configuration object.boolean
isInlined(Shape shape)
Checks if the given shape is inlined into its container when targeted by a member.boolean
isTopLevelPointer(java.lang.String pointer)
Checks if the given JSON pointer points to a top-level definition.void
setConfig(JsonSchemaConfig config)
Set the JSON Schema configuration settings.JsonSchemaConverter.Builder
toBuilder()
Take this object and create a builder that contains all of the current property values of this object.java.lang.String
toPointer(ToShapeId id)
Given a shape ID, returns the value used in a $ref to refer to it.java.lang.String
toPropertyName(MemberShape member)
Gets the property naming strategy of the converter.
-
-
-
Method Detail
-
builder
public static JsonSchemaConverter.Builder builder()
-
getConfig
public JsonSchemaConfig getConfig()
Gets the configuration object.- Returns:
- Returns the config object.
-
setConfig
public void setConfig(JsonSchemaConfig config)
Set the JSON Schema configuration settings.- Parameters:
config
- Config object to set.
-
toPropertyName
public java.lang.String toPropertyName(MemberShape member)
Gets the property naming strategy of the converter.- Parameters:
member
- Member to convert to a property name.- Returns:
- Returns the PropertyNamingStrategy.
-
toPointer
public java.lang.String toPointer(ToShapeId id)
Given a shape ID, returns the value used in a $ref to refer to it.The return value is expected to be a JSON pointer.
- Parameters:
id
- Shape ID to convert to a $ref string.- Returns:
- Returns the $ref string (e.g., "#/responses/MyShape").
-
isTopLevelPointer
public boolean isTopLevelPointer(java.lang.String pointer)
Checks if the given JSON pointer points to a top-level definition.Note that this expects the pointer to exactly start with the same string that is configured as
JsonSchemaConfig.getDefinitionPointer()
, or the default value of "#/definitions". If the number of segments in the provided pointer is also equal to the number of segments in the default pointer + 1, then it is considered a top-level pointer.- Parameters:
pointer
- Pointer to check.- Returns:
- Returns true if this is a top-level definition pointer.
-
isInlined
public boolean isInlined(Shape shape)
Checks if the given shape is inlined into its container when targeted by a member.- Parameters:
shape
- Shape to check.- Returns:
- Returns true if this shape is inlined into its containing shape.
-
convert
public SchemaDocument convert()
Perform the conversion of the entire shape index.- Returns:
- Returns the created SchemaDocument.
-
convertShape
public SchemaDocument convertShape(Shape shape)
Perform the conversion of a single shape.The root shape of the created document is set to the given shape. No schema extensions are added to the converted schema. This conversion also doesn't take the shape predicate or private controls into account.
- Parameters:
shape
- Shape to convert.- Returns:
- Returns the created SchemaDocument.
-
toBuilder
public JsonSchemaConverter.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 interfaceToSmithyBuilder<JsonSchemaConverter>
- Returns:
- a builder for type T
-
-