Convert assembled Smithy HTTP services to OpenAPI
///|
test {
let loader = @smithy.Loader::new()
for input in @openapi.protocol_definitions() {
ignore(loader.add(input))
}
ignore(
loader.add_idl(
"api.smithy",
(
#|$version: "2"
#|namespace example
#|use aws.protocols#restJson1
#|@restJson1
#|service Api { version: "1", operations: [Ping] }
#|@http(method: "GET", uri: "/ping")
#|operation Ping {}
),
),
)
let model = loader.assemble().model.unwrap()
let config = @openapi.Config::new(
@openapi.ServiceId::parse("example#Api").unwrap(),
version=@openapi.V3_1_0,
)
let result = @openapi.convert_result(model, config)
assert_true(
result.document is { "openapi": "3.1.0", "paths": { "/ping": _, .. }, .. },
)
assert_true(result.warnings.is_empty())
}{
"version": "1.0",
"sources": ["model"],
"plugins": {
"openapi": {
"service": "example#Api",
"version": "3.1.0"
}
}
}| Setting | Default and behavior |
|---|---|
| service | Required absolute root shape ID |
| version | 3.0.2; also 3.1.0 |
| protocol | Infer the single applied protocol |
| onHttpPrefixHeaders | FAIL; WARN omits the binding and reports a warning |
| ignoreUnsupportedTraits | false; true warns and omits unsupported traits |
| forbidGreedyLabels | false; true rejects greedy URI labels |
| removeGreedyParameterSuffix | false; true removes + from parameter names |
| onErrorStatusConflict | Unset; oneOf combines errors sharing a status code |
| jsonContentType | application/json for REST document bodies |
| defaultBlobFormat | byte; becomes contentEncoding in 3.1 |
| disableIntegerFormat | false; suppresses int32/int64 formats |
| useStringsForArbitraryPrecision | false; RPC v2 JSON always uses strings |
| alphanumericOnlyRefs | false; strips punctuation from component names |
| tags | false; exports service/operation tags when enabled |
| supportedTags | All tags; restrict with an array of names |
| externalDocs | Ordered preferred documentation labels: Homepage, API Reference, User Guide, Developer Guide, Reference, Guide |
| keepUnusedComponents | false; remove components unreachable from paths/security |
| substitutions | {}; replace matching string values throughout the document |
| jsonAdd | {}; insert JSON values at JSON Pointer paths after substitutions |
pub(all) suberror OpenApiError {
InvalidConfiguration(String)
MissingService(ServiceId)
InvalidService(ServiceId)
ProtocolResolution(ServiceId, String)
UnsupportedProtocol(ProtocolId)
UnsupportedTrait(ShapeId, ShapeId)
PrefixHeaders(ShapeId)
GreedyLabel(ShapeId)
SchemaConversion(String)
} derive(Debug)pub struct Config {
service : ServiceId
protocol : ProtocolId?
version : OpenApiVersion
prefix_headers : PrefixHeadersPolicy
forbid_greedy_labels : Bool
remove_greedy_parameter_suffix : Bool
ignore_unsupported_traits : Bool
tags : Bool
supported_tags : Array[String]?
keep_unused_components : Bool
json_content_type : String
default_blob_format : String
external_docs : Array[String]
disable_integer_format : Bool
alphanumeric_only_refs : Bool
use_strings_for_arbitrary_precision : Bool
combine_error_responses : Bool
schema : Config
substitutions : Map[String, Json]
json_add : Map[String, Json]
}fn Config::new(service : ServiceId, protocol? : ProtocolId?, version? : OpenApiVersion, prefix_headers? : PrefixHeadersPolicy, forbid_greedy_labels? : Bool, remove_greedy_parameter_suffix? : Bool, ignore_unsupported_traits? : Bool, tags? : Bool, supported_tags? : Array[String]?, keep_unused_components? : Bool, json_content_type? : String, default_blob_format? : String, external_docs? : Array[String], disable_integer_format? : Bool, alphanumeric_only_refs? : Bool, use_strings_for_arbitrary_precision? : Bool, combine_error_responses? : Bool, schema? : Config, substitutions? : Map[String, Json], json_add? : Map[String, Json]) -> Configpub(all) struct ConversionWarning {
code : WarningCode
shape : ShapeId
message : String
} derive(Eq, Debug)