-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix/add-error-info-generation' of github.com:awslabs/sm…
…ithy-swift into fix/add-error-info-generation
- Loading branch information
Showing
5 changed files
with
146 additions
and
6 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
72 changes: 72 additions & 0 deletions
72
smithy-swift-codegen/src/test/kotlin/serde/xml/MemberShapeDecodeXMLGeneratorTests.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,72 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
|
||
package serde.xml | ||
|
||
import MockHttpRestXMLProtocolGenerator | ||
import TestContext | ||
import defaultSettings | ||
import getFileContents | ||
import io.kotest.matchers.string.shouldContainOnlyOnce | ||
import org.junit.jupiter.api.Test | ||
|
||
class MemberShapeDecodeXMLGeneratorTests { | ||
|
||
@Test | ||
fun `001 set default value for a missing value of a scalar member`() { | ||
val context = setupTests("Isolated/Restxml/xml-scalarmember-default-value.smithy", "aws.protocoltests.restxml#RestXml") | ||
val contents = getFileContents(context.manifest, "/RestXml/models/SimpleScalarPropertiesOutputResponseBody+Decodable.swift") | ||
val expectedContents = | ||
""" | ||
extension SimpleScalarPropertiesOutputResponseBody: Swift.Decodable { | ||
enum CodingKeys: Swift.String, Swift.CodingKey { | ||
case byteValue | ||
case doubleValue = "DoubleDribble" | ||
case falseBooleanValue | ||
case floatValue | ||
case integerValue | ||
case longValue | ||
case `protocol` = "protocol" | ||
case shortValue | ||
case stringValue | ||
case trueBooleanValue | ||
} | ||
public init(from decoder: Swift.Decoder) throws { | ||
let containerValues = try decoder.container(keyedBy: CodingKeys.self) | ||
let stringValueDecoded = try containerValues.decodeIfPresent(Swift.String.self, forKey: .stringValue) ?? "test" | ||
stringValue = stringValueDecoded | ||
let trueBooleanValueDecoded = try containerValues.decodeIfPresent(Swift.Bool.self, forKey: .trueBooleanValue) ?? false | ||
trueBooleanValue = trueBooleanValueDecoded | ||
let falseBooleanValueDecoded = try containerValues.decodeIfPresent(Swift.Bool.self, forKey: .falseBooleanValue) | ||
falseBooleanValue = falseBooleanValueDecoded | ||
let byteValueDecoded = try containerValues.decodeIfPresent(Swift.Int8.self, forKey: .byteValue) | ||
byteValue = byteValueDecoded | ||
let shortValueDecoded = try containerValues.decodeIfPresent(Swift.Int16.self, forKey: .shortValue) | ||
shortValue = shortValueDecoded | ||
let integerValueDecoded = try containerValues.decodeIfPresent(Swift.Int.self, forKey: .integerValue) ?? 5 | ||
integerValue = integerValueDecoded | ||
let longValueDecoded = try containerValues.decodeIfPresent(Swift.Int.self, forKey: .longValue) | ||
longValue = longValueDecoded | ||
let floatValueDecoded = try containerValues.decodeIfPresent(Swift.Float.self, forKey: .floatValue) ?? 2.4 | ||
floatValue = floatValueDecoded | ||
let protocolDecoded = try containerValues.decodeIfPresent(Swift.String.self, forKey: .protocol) | ||
`protocol` = protocolDecoded | ||
let doubleValueDecoded = try containerValues.decodeIfPresent(Swift.Double.self, forKey: .doubleValue) | ||
doubleValue = doubleValueDecoded | ||
} | ||
} | ||
""".trimIndent() | ||
contents.shouldContainOnlyOnce(expectedContents) | ||
} | ||
private fun setupTests(smithyFile: String, serviceShapeId: String): TestContext { | ||
val context = TestContext.initContextFrom(smithyFile, serviceShapeId, MockHttpRestXMLProtocolGenerator()) { model -> | ||
model.defaultSettings(serviceShapeId, "RestXml", "2023-08-08", "Rest Xml Protocol") | ||
} | ||
context.generator.generateDeserializers(context.generationCtx) | ||
context.generationCtx.delegator.flushWriters() | ||
return context | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...y-swift-codegen/src/test/resources/Isolated/Restxml/xml-scalarmember-default-value.smithy
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,48 @@ | ||
$version: "2.0" | ||
|
||
namespace aws.protocoltests.restxml | ||
|
||
use aws.api#service | ||
use aws.protocols#restXml | ||
use smithy.test#httpRequestTests | ||
use smithy.test#httpResponseTests | ||
|
||
@service(sdkId: "Rest Xml List") | ||
@restXml | ||
service RestXml { | ||
version: "2023-08-08", | ||
operations: [ | ||
SimpleScalarProperties | ||
] | ||
} | ||
|
||
|
||
@idempotent | ||
@http(uri: "/SimpleScalarProperties", method: "PUT") | ||
operation SimpleScalarProperties { | ||
input: SimpleScalarPropertiesInputOutput, | ||
output: SimpleScalarPropertiesInputOutput | ||
} | ||
|
||
|
||
structure SimpleScalarPropertiesInputOutput { | ||
@httpHeader("X-Foo") | ||
foo: String, | ||
|
||
@default("test") | ||
stringValue: String, | ||
@default(false) | ||
trueBooleanValue: Boolean, | ||
falseBooleanValue: Boolean, | ||
byteValue: Byte, | ||
shortValue: Short, | ||
@default(5) | ||
integerValue: Integer, | ||
longValue: Long, | ||
@default(2.4) | ||
floatValue: Float, | ||
protocol: String, | ||
|
||
@xmlName("DoubleDribble") | ||
doubleValue: Double, | ||
} |