Unverified Commit 0bef36c6 authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Smithy 1.7 upgrade (#340)

* Upgrade to Smithy 1.7

Two changes:
1. Add support for shape renaming. Since renaming doesn't apply to operations, errors, or resources, this was actually a fairly narrow change. I intentionally
maintained the ability to generate a model without a service shape, I expect at some point, some one will just want to make some Rust structs.
2. Add support for map-driven query params.

* Update APIGW model

* Fix bugs in httpParams implementation

* Cleanup logic and add one more test
parent c36afd61
Loading
Loading
Loading
Loading
+40 −4
Original line number Diff line number Diff line
@@ -5251,7 +5251,8 @@
                "parameters": {
                    "target": "com.amazonaws.apigateway#MapOfStringToString",
                    "traits": {
                        "smithy.api#documentation": "<p>A key-value map of query string parameters that specify properties of the export, depending on the requested <code>exportType</code>. For <code>exportType</code> <code>oas30</code> and <code>swagger</code>, any combination of the following parameters are supported: <code>extensions='integrations'</code> or <code>extensions='apigateway'</code> will export the API with x-amazon-apigateway-integration extensions. <code>extensions='authorizers'</code> will export the API with  x-amazon-apigateway-authorizer extensions. <code>postman</code> will export the API with Postman extensions, allowing for import to the Postman tool</p>"
                        "smithy.api#documentation": "<p>A key-value map of query string parameters that specify properties of the export, depending on the requested <code>exportType</code>. For <code>exportType</code> <code>oas30</code> and <code>swagger</code>, any combination of the following parameters are supported: <code>extensions='integrations'</code> or <code>extensions='apigateway'</code> will export the API with x-amazon-apigateway-integration extensions. <code>extensions='authorizers'</code> will export the API with  x-amazon-apigateway-authorizer extensions. <code>postman</code> will export the API with Postman extensions, allowing for import to the Postman tool</p>",
                        "smithy.api#httpQueryParams": {}
                    }
                },
                "accepts": {
@@ -6226,7 +6227,8 @@
                "parameters": {
                    "target": "com.amazonaws.apigateway#MapOfStringToString",
                    "traits": {
                        "smithy.api#documentation": "<p>A string-to-string key-value map of query parameters <code>sdkType</code>-dependent properties of the SDK. For <code>sdkType</code> of <code>objectivec</code> or <code>swift</code>,  a parameter named <code>classPrefix</code> is required. For <code>sdkType</code> of <code>android</code>, parameters named <code>groupId</code>, <code>artifactId</code>, <code>artifactVersion</code>, and <code>invokerPackage</code> are required. For <code>sdkType</code> of <code>java</code>, parameters named <code>serviceName</code> and <code>javaPackageName</code> are required. </p>"
                        "smithy.api#documentation": "<p>A string-to-string key-value map of query parameters <code>sdkType</code>-dependent properties of the SDK. For <code>sdkType</code> of <code>objectivec</code> or <code>swift</code>,  a parameter named <code>classPrefix</code> is required. For <code>sdkType</code> of <code>android</code>, parameters named <code>groupId</code>, <code>artifactId</code>, <code>artifactVersion</code>, and <code>invokerPackage</code> are required. For <code>sdkType</code> of <code>java</code>, parameters named <code>serviceName</code> and <code>javaPackageName</code> are required. </p>",
                        "smithy.api#httpQueryParams": {}
                    }
                }
            },
@@ -6965,6 +6967,14 @@
        "com.amazonaws.apigateway#ImportApiKeysRequest": {
            "type": "structure",
            "members": {
                "body": {
                    "target": "com.amazonaws.apigateway#Blob",
                    "traits": {
                        "smithy.api#documentation": "<p>The payload of the POST request to import API keys. For the payload format, see <a href=\"https://docs.aws.amazon.com/apigateway/latest/developerguide/api-key-file-format.html\">API Key File Format</a>.</p>",
                        "smithy.api#httpPayload": {},
                        "smithy.api#required": {}
                    }
                },
                "format": {
                    "target": "com.amazonaws.apigateway#ApiKeysFormat",
                    "traits": {
@@ -7042,6 +7052,14 @@
                        "smithy.api#documentation": "<p>A query parameter to specify whether to rollback the documentation importation (<code>true</code>) or not (<code>false</code>) when a warning is encountered. The default value is <code>false</code>.</p>",
                        "smithy.api#httpQuery": "failonwarnings"
                    }
                },
                "body": {
                    "target": "com.amazonaws.apigateway#Blob",
                    "traits": {
                        "smithy.api#documentation": "<p>[Required] Raw byte array representing the to-be-imported documentation parts. To import from an OpenAPI file, this is a JSON object.</p>",
                        "smithy.api#httpPayload": {},
                        "smithy.api#required": {}
                    }
                }
            },
            "traits": {
@@ -7095,7 +7113,16 @@
                "parameters": {
                    "target": "com.amazonaws.apigateway#MapOfStringToString",
                    "traits": {
                        "smithy.api#documentation": "<p>A key-value map of context-specific query string parameters specifying the behavior of different API importing operations. The following shows operation-specific parameters and their supported values.</p>\n        <p> To exclude <a>DocumentationParts</a> from the import, set <code>parameters</code> as <code>ignore=documentation</code>.</p>\n      <p> To configure the endpoint type, set <code>parameters</code> as <code>endpointConfigurationTypes=EDGE</code>, <code>endpointConfigurationTypes=REGIONAL</code>, or <code>endpointConfigurationTypes=PRIVATE</code>. The default endpoint type is <code>EDGE</code>.</p>\n        <p> To handle imported <code>basepath</code>, set <code>parameters</code> as <code>basepath=ignore</code>, <code>basepath=prepend</code> or <code>basepath=split</code>.</p>\n        <p>For example, the AWS CLI command to exclude documentation from the imported API is:</p> \n        <pre><code>aws apigateway import-rest-api --parameters ignore=documentation --body 'file:///path/to/imported-api-body.json'</code></pre>\n        <p>The AWS CLI command to set the regional endpoint on the imported API is:</p>\n        <pre><code>aws apigateway import-rest-api --parameters endpointConfigurationTypes=REGIONAL --body 'file:///path/to/imported-api-body.json'</code></pre>"
                        "smithy.api#documentation": "<p>A key-value map of context-specific query string parameters specifying the behavior of different API importing operations. The following shows operation-specific parameters and their supported values.</p>\n        <p> To exclude <a>DocumentationParts</a> from the import, set <code>parameters</code> as <code>ignore=documentation</code>.</p>\n      <p> To configure the endpoint type, set <code>parameters</code> as <code>endpointConfigurationTypes=EDGE</code>, <code>endpointConfigurationTypes=REGIONAL</code>, or <code>endpointConfigurationTypes=PRIVATE</code>. The default endpoint type is <code>EDGE</code>.</p>\n        <p> To handle imported <code>basepath</code>, set <code>parameters</code> as <code>basepath=ignore</code>, <code>basepath=prepend</code> or <code>basepath=split</code>.</p>\n        <p>For example, the AWS CLI command to exclude documentation from the imported API is:</p> \n        <pre><code>aws apigateway import-rest-api --parameters ignore=documentation --body 'file:///path/to/imported-api-body.json'</code></pre>\n        <p>The AWS CLI command to set the regional endpoint on the imported API is:</p>\n        <pre><code>aws apigateway import-rest-api --parameters endpointConfigurationTypes=REGIONAL --body 'file:///path/to/imported-api-body.json'</code></pre>",
                        "smithy.api#httpQueryParams": {}
                    }
                },
                "body": {
                    "target": "com.amazonaws.apigateway#Blob",
                    "traits": {
                        "smithy.api#documentation": "<p>[Required] The POST request body containing external API definitions. Currently, only OpenAPI definition JSON/YAML files are supported. The maximum size of the API definition file is 6MB.</p>",
                        "smithy.api#httpPayload": {},
                        "smithy.api#required": {}
                    }
                }
            },
@@ -8569,7 +8596,16 @@
                "parameters": {
                    "target": "com.amazonaws.apigateway#MapOfStringToString",
                    "traits": {
                        "smithy.api#documentation": "<p>Custom header parameters as part of the request. For example, to exclude <a>DocumentationParts</a> from an imported API, set <code>ignore=documentation</code> as a <code>parameters</code> value, as in the AWS CLI command of <code>aws apigateway import-rest-api --parameters ignore=documentation --body 'file:///path/to/imported-api-body.json'</code>.</p>"
                        "smithy.api#documentation": "<p>Custom header parameters as part of the request. For example, to exclude <a>DocumentationParts</a> from an imported API, set <code>ignore=documentation</code> as a <code>parameters</code> value, as in the AWS CLI command of <code>aws apigateway import-rest-api --parameters ignore=documentation --body 'file:///path/to/imported-api-body.json'</code>.</p>",
                        "smithy.api#httpQueryParams": {}
                    }
                },
                "body": {
                    "target": "com.amazonaws.apigateway#Blob",
                    "traits": {
                        "smithy.api#documentation": "<p>[Required] The PUT request body containing external API definitions. Currently, only OpenAPI definition JSON/YAML files are supported. The maximum size of the API definition file is 6MB.</p>",
                        "smithy.api#httpPayload": {},
                        "smithy.api#required": {}
                    }
                }
            },
+1 −6
Original line number Diff line number Diff line
@@ -48,11 +48,10 @@ structure ReservedWords {
        protocol: awsJson1_1,
        params: {
            "regular_string": "hello!",
            "punned_string": { "ps_member": true },
        },
        method: "POST",
        uri: "/",
        body: "{\"regular_string\": \"hello!\", \"punned_string\": { \"ps_member\": true }}",
        body: "{\"regular_string\": \"hello!\"}",
        bodyMediaType: "application/json"
    }
])
@@ -62,7 +61,6 @@ operation StructureNamePunning {

structure StructureNamePunningInput {
    regular_string: smithy.api#String,
    punned_string: crate#String,
    punned_vec: Vec
}

@@ -70,9 +68,6 @@ structure Vec {
    pv_member: Boolean
}

structure String {
    ps_member: Boolean
}

operation ErrCollisions {
    errors: [
+40 −0
Original line number Diff line number Diff line
@@ -7,6 +7,46 @@ use aws.api#service
use smithy.test#httpRequestTests
use smithy.test#httpResponseTests

apply QueryPrecedence @httpRequestTests([
    {
        id: "UrlParamsKeyEncoding",
        documentation: "Keys and values must be url encoded",
        protocol: restJson1,
        method: "POST",
        uri: "/Precedence",
        body: "",
        queryParams: ["bar=%26%F0%9F%90%B1", "hello%20there=how's%20your%20encoding?", "a%20%26%20b%20%26%20c=better%20encode%20%3D%20this"],
        params: {
            foo: "&🐱",
            baz: {
                "hello there": "how's your encoding?",
                "a & b & c": "better encode = this"
            }
        },
        appliesTo: "client",
    },
    {
        id: "RestJsonQueryPrecedenceForbid",
        documentation: "Prefer named query parameters when serializing",
        protocol: restJson1,
        method: "POST",
        uri: "/Precedence",
        body: "",
        queryParams: [
            "bar=named",
            "qux=alsoFromMap"
        ],
        forbidQueryParams: ["bar=fromMap"],
        params: {
            foo: "named",
            baz: {
                bar: "fromMap",
                qux: "alsoFromMap"
            }
        },
        appliesTo: "client",
    }]
)

/// A REST JSON service that sends JSON requests and responses.
@service(sdkId: "Rest Json Protocol")
+1 −1
Original line number Diff line number Diff line
@@ -283,7 +283,7 @@ class RustWriter private constructor(
        }
    }

    fun ListForEach(
    fun listForEach(
        target: Shape,
        outerField: String,
        block: CodeWriter.(field: String, target: ShapeId) -> Unit
+1 −1
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ class CodegenVisitor(context: PluginContext, private val codegenDecorator: RustC
        ).protocolFor(context.model, service)
        protocolGenerator = generator
        model = generator.transformModel(baseModel)
        val baseProvider = RustCodegenPlugin.BaseSymbolProvider(model, symbolVisitorConfig)
        val baseProvider = RustCodegenPlugin.baseSymbolProvider(model, service, symbolVisitorConfig)
        symbolProvider = codegenDecorator.symbolProvider(generator.symbolProvider(model, baseProvider))

        protocolConfig =
Loading