Skip to main content

Import a Smithy model

The Smithy importer (smithy) reads a Smithy model into the Catalog. Structures, unions, enums, lists and maps become types, and each service's operations become operations. You can then search, version, diff and convert it like any other catalog item.

When to use it​

Use the Smithy importer for a Smithy 2.0 model: .smithy IDL files or the equivalent JSON AST, one file or a model split across many. On a server with the Smithy CLI, Apiome assembles, validates and compares the model with Smithy's own tools, so what you see in the catalog matches your Smithy build.

At a glance​

StepWhereDetails
Import a .smithy file or a JSON ASTImport to catalog → Smithy, or apiome import smithyImport it
Import a model split across filesUpload a .zip, .tar.gz or .tar, or apiome import smithy ./folder/Multi-file models
See what the model became: shapes, traits, resources, errorsThe catalog itemWhat the catalog item holds
Lint it with Smithy validation and smithy-lintersAutomatic on every import; events show in lintLint: Smithy validation and smithy-linters
Compare two versions with smithy diffTick two versions on the catalog item's Versions tabBreaking changes between versions
Fix a refused modelThe error code the import returnsWhen the import refuses a model
Convert to an OpenAPI projectConvert to OpenAPI on the catalog itemPer-format conversion packs
Export back to SmithyExport on the catalog itemSmithy from any source

Import it​

Import the model like any other catalog format: in the import wizard (Import to catalog → Smithy), over the REST API (see Import a specification), or from the CLI.

You can bring the model in three ways:

What you haveHow it is read
One .smithy fileAssembled by the Smithy CLI like a multi-file set, so inline := input and output members are read too. If this server has no Smithy CLI, or the CLI cannot load the file, the built-in Smithy reader reads it instead.
One JSON AST file (.json)Read as is. A JSON AST already holds every shape by its absolute id.
Several model files (a .zip, .tar.gz or .tar)Assembled by the Smithy CLI into one JSON AST, then read.

What the catalog item holds​

A model read from its JSON AST (with the Smithy CLI, or uploaded as a JSON AST) keeps its traits:

SmithyCatalog item
@http(method: "GET", uri: "/cities/{cityId}", code: 200)The operation's method and path, and the binding Convert to OpenAPI uses; the code in smithy_http_code
@httpLabel, @httpQuery("pageSize"), @httpHeader("X-Request-Id") on an input memberA path, query or header parameter, named as the request names it
An operation's errors, and the service's errorsAn error message on the operation, for each one, with the error's @httpError status
@error("client"), @httpError(404), @retryableRecorded on the error structure (smithy_error, smithy_http_error, smithy_retryable)
@readonly, @idempotent, @paginated(…)Recorded on the operation (smithy_readonly, smithy_idempotent, smithy_paginated)
@deprecatedThe operation or member is marked deprecated
A resource: identifiers, properties, read / list / create / …, child resourcesA type with the identifiers and properties as fields, its lifecycle in smithy_resource; each operation it binds is tagged with the resource's name
@documentation on a memberThe field's description
@default, @length, @range, @patternThe field's default and constraints; a list's @length bounds its items
A member targeting a simple shape with constraints (CityId with a @pattern)The member gets those constraints too, its own winning
@enumValue("capital"), an intEnum's numbersEach enum value's wire value
Any other trait (@timestampFormat, @jsonName …)Kept in the field's smithy_trait_values

Each shape of the JSON AST is also hashed on its own: smithy_shape_hashes maps every absolute shape id (example.weather#City) to a SHA-256 of that shape, so a tool can see which shapes changed between two imports. The hashes do not decide whether a new catalog version is created.

The built-in Smithy reader, used for a single .smithy file when the server has no Smithy CLI, reads shape names, members and their trait names only, none of the above.

Multi-file models​

A Smithy model is often split across files. A namespace can span several files, and shapes target shapes in other namespaces:

$version: "2"
namespace example.weather

use example.common#Money

structure GetForecastOutput {
priceOfUmbrella: Money
}

Upload every model file in one archive. Apiome runs smithy ast on them, which validates the combined model and assembles it into one JSON AST:

  • Every file counts. .smithy files and JSON AST .json files are assembled together. Other files are ignored. A smithy-build.json is never read, so an upload cannot make the server fetch dependencies.
  • Namespaces stay apart. Shapes in the model's main namespace (the namespace of its first service) keep their plain names. A shape from another namespace keeps its absolute id, such as example.common#Money, and its catalog type is keyed under that namespace.
  • Resources bring their operations. A service's operations include the ones bound to its resources (read, create, list, operations and so on).
  • Simple shapes resolve. A member that targets CityId (a string shape) is typed String.
  • Unknown traits are kept. Traits from packages the server does not bundle, such as aws.protocols#restJson1, do not fail the import.

The catalog item records the model's identity:

FieldWhat it holds
smithy_versionThe model's $version, such as 2.0
smithy_namespacesEvery namespace the model defines shapes in
smithy_ast_sha256A hash of the assembled JSON AST: the same model gives the same hash, however its files are split or ordered
smithy_source_filesThe model files it was assembled from

A set that holds a single model file is read like that one file.

Lint: Smithy validation and smithy-linters​

On a server with the Smithy CLI, every Smithy import (one .smithy file, a JSON AST or a multi-file model) is also run through smithy validate, with these validators from Smithy's smithy-linters package switched on:

ValidatorWhat it catches
CamelCaseMember names that are not lower camel case (pet_id), shape names that are not upper camel case.
MissingPaginatedTraitA List… / Search… operation that returns a list but is not @paginated.
AbbreviationNameNames with all-caps abbreviations (URLValue should be UrlValue).
ShouldHaveUsedTimestampA member named like a time (adoptedAt) whose type is not a timestamp.
MissingSensitiveTraitA member that looks like sensitive data (password) without @sensitive.
InputOutputStructureReuseAn operation input or output structure that is shared or not marked @input / @output.
NoninclusiveTermsNon-inclusive words in shape or member names and documentation.
RepeatedShapeNameA member name that repeats its structure's name (Pet$petName).
StutteredShapeNameA shape name that repeats its namespace.

ReservedWords and StandardOperationVerb need lists only you can provide, so they are not switched on. A model can still configure them, or any other validator, with its own metadata validators.

Each event is a lint finding at smithy:<file>:<line>:<column>, its message starting with the validator name:

smithy.linter smithy:model.smithy:13:1 MissingPaginatedTrait: The verb of this operation, `list`, requires that the operation is marked with the `paginated` trait. …
RuleSeverityReports
smithy.linterwarningThe smithy-linters validators above.
smithy.validation-errorerrorAn ERROR event, such as a member targeting a shape that does not exist. A single .smithy file the built-in reader imported can have one; a multi-file model with errors is refused at import.
smithy.validation-warningwarningDANGER and WARNING events from Smithy's built-in validators or your own metadata validators.
smithy.validation-noteinfoNOTE events.

Suppressions in the model (@suppress, metadata suppressions) are honored. The events are listed on the catalog item (smithy_validation_events, up to 50, with smithy_validation_event_count). Without the Smithy CLI the model imports the same way, with no Smithy lint findings. The linters ship with the server, so validation never fetches anything from the network.

Breaking changes between versions​

When you compare two versions of a Smithy catalog item, Apiome runs Smithy's own compatibility checker, smithy diff, over the two models. It maps each finding's Smithy severity onto Apiome's:

Smithy severityApiome severityTypical findings
ERRORBreakingA shape or member removed, a member's target changed, a required member added without a default, an enum value removed
DANGERDangerousA structure's members reordered
WARNINGDangerousChanges Smithy flags for review
NOTESafeA shape or member added, an enum value appended

Each finding names a shape, such as example.shelter#Pet$size. Apiome attaches it to the change on that shape: the member's field, or else the shape that holds it, such as an enum for its values. The change takes the worst severity of its findings. Its rule is smithy-diff.<finding id>, for example smithy-diff.ChangedMemberTarget, and Smithy's messages explain it.

Some findings belong to no single change in the comparison, such as reordered members or an operation unbound from a service. These are listed as unattributed findings. They still count toward the overall severity, so a Smithy ERROR always makes the comparison breaking.

A multi-file model is compared as a whole, using the model Apiome assembled at import. Without the Smithy CLI, or when smithy diff cannot load a model, Apiome grades the changes with its format-neutral rules: a removed entity is breaking and an added one is safe.

From the CLI​

Point apiome import smithy at a model file, a JSON AST, an archive or a model directory:

apiome import smithy ./weather.smithy
apiome import smithy ./weather-ast.json
apiome import smithy ./weather-model.zip
apiome import smithy ./weather-model/

A directory is packed into an archive and sent as one upload. build, dist and hidden folders are left out. Apiome then assembles the model files the same way as an uploaded archive. Pass --root to choose the file kept as the item's source text; otherwise the server picks one.

When the import refuses a model​

CodeWhyWhat to do
INPUT_SEMANTIC_INVALIDThe Smithy CLI found the model invalid, for example a target that no file defines. The message quotes the CLI's errors with their file and line.Fix the reported shapes, or add the missing file to the archive.
INPUT_REFERENCE_UNRESOLVEDA JSON AST targets a shape it does not define.Upload the files that define it together, as a set.
ADAPTER_UNAVAILABLEThe upload holds several model files and this server has no Smithy CLI.Ask your administrator to deploy the standard image, which ships the Smithy CLI.
INPUT_ARCHIVE_INVALIDThe archive holds no .smithy or JSON AST file.Add the model files to the archive.