Add API Gateway Accept header customization#716
Open
Alan4506 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
While generating an API Gateway client from its model locally and running integration tests, several operations failed to deserialize their responses. For example,
CreateRestApireturns acreatedDatemember modeled as a timestamp (epoch-seconds underrestJson1), but the response returned an ISO-8601 string, so timestamp deserialization failed:The root cause is API Gateway specific. Unless the client sends
Accept: application/json, API Gateway responds withapplication/hal+json, in which timestamps are serialized as ISO-8601 strings instead of the epoch-seconds that therestJson1protocol expects.This is a documented API Gateway client requirement, not general protocol behavior. The Smithy spec calls it out as a service-specific customization: Amazon API Gateway Customizations. Other Smithy SDKs already implement this same customization in their codegen (e.g. smithy-rs, smithy-go, smithy-kotlin). This change adds the equivalent to smithy-python.
Changes
smithy-aws-core): a newApiGatewayAcceptHeaderInterceptorthat setsAccept: application/jsonon every request inmodify_before_signing.codegen/aws/core): a newApiGatewayIntegration, registered with thePythonIntegrationSPI. When the service being generated is API Gateway, it emits a plugin that registers the interceptor on the client; for all other services it does nothing. It lives under a newcustomizations/apigateway/package, leaving room for the other service customizations the Smithy spec lists (e.g. Glacier, S3, Machine Learning).Generated clients for the API Gateway service now include an
accept_header.pyplugin that appends the interceptor.Testing
smithy-aws-core): verify the interceptor setsAccept: application/json, and that it overrides any pre-existingAcceptheader. Both pass.smithy-aws-corestill pass.client.pyregisters theaccept_header_pluginand that the plugin appendsApiGatewayAcceptHeaderInterceptor.Without the customization this raises
JSONTokenError: Expected token of type 'number' at path 'createdDate', but found: 'string'.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.