-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Codegenerate Python application example and add explicit cast during …
…JSON deserialization (#1520) Co-authored-by: John DiSanti <[email protected]>
- Loading branch information
Showing
4 changed files
with
141 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
40 changes: 40 additions & 0 deletions
40
...lin/software/amazon/smithy/rust/codegen/smithy/protocols/parse/TypeConversionGenerator.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.rust.codegen.smithy.protocols.parse | ||
|
||
import software.amazon.smithy.model.shapes.BlobShape | ||
import software.amazon.smithy.model.shapes.Shape | ||
import software.amazon.smithy.model.shapes.TimestampShape | ||
import software.amazon.smithy.rust.codegen.rustlang.Writable | ||
import software.amazon.smithy.rust.codegen.rustlang.rust | ||
import software.amazon.smithy.rust.codegen.rustlang.writable | ||
import software.amazon.smithy.rust.codegen.smithy.RuntimeConfig | ||
import software.amazon.smithy.rust.codegen.smithy.RuntimeType | ||
import software.amazon.smithy.rust.codegen.smithy.RustSymbolProvider | ||
import software.amazon.smithy.rust.codegen.smithy.rustType | ||
|
||
/* | ||
* Utility class used to force casting a non primitive type into one overriden by a new symbol provider, | ||
* by explicitly calling `from()`. | ||
* | ||
* For example we use this in the server Python implementation, where we override types like [Blob] and [DateTime] | ||
* with wrappers compatible with Python, without touching the original implementation coming from `aws-smithy-types`. | ||
*/ | ||
class TypeConversionGenerator(private val symbolProvider: RustSymbolProvider, private val runtimeConfig: RuntimeConfig) { | ||
fun convertViaFrom(shape: Shape): Writable = | ||
writable { | ||
val oldSymbol = when (shape) { | ||
// TODO(understand what needs to be done for ByteStream) | ||
is BlobShape -> RuntimeType.Blob(runtimeConfig).toSymbol() | ||
is TimestampShape -> RuntimeType.DateTime(runtimeConfig).toSymbol() | ||
else -> symbolProvider.toSymbol(shape) | ||
} | ||
val newSymbol = symbolProvider.toSymbol(shape) | ||
if (oldSymbol.rustType() != newSymbol.rustType()) { | ||
rust(".map($newSymbol::from)") | ||
} | ||
} | ||
} |