From 641f56eca99ace8ba005cb90eed0228bdc2770bb Mon Sep 17 00:00:00 2001 From: Miles Ziemer Date: Tue, 13 Dec 2022 10:05:40 -0500 Subject: [PATCH] Fix MapMembers grammar and update test In IDL 2, map members can be mixed in, so Smithy grammar should reflect their optionality. https://github.com/awslabs/smithy/pull/1533 incorrectly changed MapMembers grammar to make both MapKey and MapValue optional together, when they are optional separately. This PR fixes the MapMembers grammar to allow MapKey and MapValue to be optional separately, and updates a test case to reflect that. --- docs/source-2.0/spec/idl.rst | 2 +- .../loader/valid/mixins/loads-mixins.flattened.smithy | 5 +++++ .../smithy/model/loader/valid/mixins/loads-mixins.json | 9 +++++++++ .../smithy/model/loader/valid/mixins/loads-mixins.smithy | 4 ++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/source-2.0/spec/idl.rst b/docs/source-2.0/spec/idl.rst index 3449ca56555..63a455d55e1 100644 --- a/docs/source-2.0/spec/idl.rst +++ b/docs/source-2.0/spec/idl.rst @@ -199,7 +199,7 @@ string support defined in :rfc:`7405`. ElidedListMember :%s"$member" ExplicitListMember :%s"member" *`SP` ":" *`SP` `ShapeId` MapStatement :%s"map" `SP` `Identifier` [`Mixins`] *`WS` `MapMembers` - MapMembers :"{" *`WS` [`MapKey` `WS` `MapValue`] *`WS` "}" + MapMembers :"{" *`WS` [`MapKey` / `MapValue` / (`MapKey` `WS` `MapValue`)] *`WS` "}" MapKey :`TraitStatements` (`ElidedMapKey` / `ExplicitMapKey`) MapValue :`TraitStatements` (`ElidedMapValue` / `ExplicitMapValue`) ElidedMapKey :%s"$key" diff --git a/smithy-model/src/test/resources/software/amazon/smithy/model/loader/valid/mixins/loads-mixins.flattened.smithy b/smithy-model/src/test/resources/software/amazon/smithy/model/loader/valid/mixins/loads-mixins.flattened.smithy index 11f9d86c76b..2fbda82d51b 100644 --- a/smithy-model/src/test/resources/software/amazon/smithy/model/loader/valid/mixins/loads-mixins.flattened.smithy +++ b/smithy-model/src/test/resources/software/amazon/smithy/model/loader/valid/mixins/loads-mixins.flattened.smithy @@ -41,6 +41,11 @@ map MixedMap { value: String } +map MixedMapRedefineValue { + key: String + value: String +} + service MixedService {} resource MixedResource {} diff --git a/smithy-model/src/test/resources/software/amazon/smithy/model/loader/valid/mixins/loads-mixins.json b/smithy-model/src/test/resources/software/amazon/smithy/model/loader/valid/mixins/loads-mixins.json index 5321757e186..aae41cbbd29 100644 --- a/smithy-model/src/test/resources/software/amazon/smithy/model/loader/valid/mixins/loads-mixins.json +++ b/smithy-model/src/test/resources/software/amazon/smithy/model/loader/valid/mixins/loads-mixins.json @@ -233,6 +233,15 @@ "target": "smithy.example#MixinMap" }] }, + "smithy.example#MixedMapRedefineValue": { + "type": "map", + "value": { + "target": "smithy.api#String" + }, + "mixins": [{ + "target": "smithy.example#MixinMap" + }] + }, "smithy.example#MixinService": { "type": "service", "traits": { diff --git a/smithy-model/src/test/resources/software/amazon/smithy/model/loader/valid/mixins/loads-mixins.smithy b/smithy-model/src/test/resources/software/amazon/smithy/model/loader/valid/mixins/loads-mixins.smithy index 4ab3ce92d51..7a10d242985 100644 --- a/smithy-model/src/test/resources/software/amazon/smithy/model/loader/valid/mixins/loads-mixins.smithy +++ b/smithy-model/src/test/resources/software/amazon/smithy/model/loader/valid/mixins/loads-mixins.smithy @@ -98,6 +98,10 @@ map MixinMap { map MixedMap with [MixinMap] {} +map MixedMapRedefineValue with [MixinMap] { + value: String +} + @mixin service MixinService {}