Sign in

    smithy-jsonschema

    Convert assembled Smithy models to JSON Schema

    smithy
    json-schema
    moonbit
    Download zip
    Author
    Version
    0.3.0
    License
    Apache-2.0
    Last updated
    6 hours ago
    Downloads
    4

    #Smithy JSON Schema

    Converts an assembled Smithy model into a JSON Schema document.

    #Library

    ///|
    test {
    let loaded = @smithy.Loader::new()
    .add_idl(
    "example.smithy", "$version: \"2\"\nnamespace example\nstructure Value { name: String }",
    )
    .assemble()
    let document = @jsonschema.convert(loaded.model.unwrap())
    assert_true(document is { "definitions": { "Value": _, .. }, .. })
    }

    Pass service="example#Api" to keep the service's connected value shapes. Services, operations, resources and prelude definitions are omitted. Mixins are flattened before conversion. Simple shapes and lists are inlined where the reference converter inlines them; shared aggregate shapes use $ref. Conflicting exported names and invalid configuration raise JsonSchemaError.

    #Build plugin

    The Smithy CLI registers the jsonSchema plugin. Put this in smithy-build.json, then run smithy build:

    { "version": "1.0", "sources": ["model"], "projections": { "schema": { "plugins": { "jsonSchema": { "service": "example#Api", "useJsonName": true } } } } }

    The document is written to build/smithy/schema/jsonSchema/schema.json.

    Plugin settingLibrary Config::new argumentDefault
    useJsonNameuse_json_namefalse
    unionStrategyunion_strategyoneOf; also object, structure
    enumStrategyenum_strategyenum; also oneOf
    mapStrategymap_strategypropertyNames; also patternProperties
    defaultTimestampFormatdefault_timestamp_formatdate-time; also http-date, epoch-seconds
    supportNonNumericFloatssupport_non_numeric_floatsfalse
    definitionPointerdefinition_pointer#/definitions
    schemaDocumentExtensionsschema_document_extensions{}
    addReferenceDescriptionsadd_reference_descriptionsfalse
    disableDefaultValuesdisable_default_valuesfalse
    disableIntEnumsdisable_int_enumsfalse
    useIntegerTypeuse_integer_typefalse

    definitionPointer starts with #/ and supports nested paths such as #/components/schemas. As in the reference, pointer escaping is unsupported. The plugin's jsonSchemaVersion accepts draft07 or draft2020-12; the latter defaults the definition pointer to #/$defs.

    JsonSchemaError

    pub(all) suberror JsonSchemaError {
    ConflictingShapeName(String)
    InvalidConfiguration(String)
    } derive(
    Debug
    )

    Config

    pub(all) struct Config {
    map_strategy : String
    union_strategy : String
    enum_strategy : String
    use_json_name : Bool
    default_timestamp_format : String
    support_non_numeric_floats : Bool
    schema_document_extensions : Json
    definition_pointer : String
    add_reference_descriptions : Bool
    disable_default_values : Bool
    disable_int_enums : Bool
    use_integer_type : Bool
    }

    Conversion settings shared with the JSON Schema build plugin.

    Config::new

    fn Config::new(map_strategy? : String, union_strategy? : String, enum_strategy? : String, use_json_name? : Bool, default_timestamp_format? : String, support_non_numeric_floats? : Bool, schema_document_extensions? : Json, definition_pointer? : String, add_reference_descriptions? : Bool, disable_default_values? : Bool, disable_int_enums? : Bool, use_integer_type? : Bool) -> Config

    convert

    fn convert(model :
    Model
    , service? : String, config? : Config) -> Json raise

    Convert value shapes in an assembled model to a JSON Schema document.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io