From e5cd7d1d8116553ae668cfc4f2731337a8838d2d Mon Sep 17 00:00:00 2001 From: Theo Zourzouvillys Date: Wed, 11 Oct 2023 13:39:50 -0700 Subject: [PATCH] Fix IDL serialization to add resource properties (#1996) * generate resource shape 'properties' with Smithy IDL serialization * properties serialization round trip test adding properties to MyResource triggered validation errors, so had to extend test schema to pass validation. * order the new operations correctly to match output format * keep EmptyResource --- .../shapes/SmithyIdlModelSerializer.java | 6 +++- .../cases/service-shapes.smithy | 28 +++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SmithyIdlModelSerializer.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SmithyIdlModelSerializer.java index 08ae9d87fe9..ec628339089 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SmithyIdlModelSerializer.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SmithyIdlModelSerializer.java @@ -647,7 +647,11 @@ public Void resourceShape(ResourceShape shape) { codeWriter.writeOptionalIdList("operations", shape.getIntroducedOperations()); codeWriter.writeOptionalIdList("collectionOperations", shape.getCollectionOperations()); codeWriter.writeOptionalIdList("resources", shape.getIntroducedResources()); - + if (shape.hasProperties()) { + codeWriter.openBlock("properties: {"); + shape.getProperties().forEach((name, shapeId) -> codeWriter.write("$L: $I", name, shapeId)); + codeWriter.closeBlock("}"); + } codeWriter.closeBlock("}"); codeWriter.write(""); return null; diff --git a/smithy-model/src/test/resources/software/amazon/smithy/model/shapes/idl-serialization/cases/service-shapes.smithy b/smithy-model/src/test/resources/software/amazon/smithy/model/shapes/idl-serialization/cases/service-shapes.smithy index 226d8677832..6dcf0e75a38 100644 --- a/smithy-model/src/test/resources/software/amazon/smithy/model/shapes/idl-serialization/cases/service-shapes.smithy +++ b/smithy-model/src/test/resources/software/amazon/smithy/model/shapes/idl-serialization/cases/service-shapes.smithy @@ -24,20 +24,24 @@ resource MyResource { id: String } put: ResourceOperation - create: ResourceOperation + create: EmptyOperation read: ReadonlyResourceOperation update: ResourceOperation delete: ResourceOperation - list: ReadonlyResourceOperation + list: CollectionResourceOperation operations: [ - ResourceOperation + CollectionResourceOperation ] collectionOperations: [ - ResourceOperation + CollectionResourceOperation ] resources: [ SubResource ] + properties: { + value: String + other: String + } } resource SubResource { @@ -46,6 +50,15 @@ resource SubResource { } } +@readonly +operation CollectionResourceOperation { + input := {} + output := {} + errors: [ + Error + ] +} + operation EmptyOperation { input: Unit output: Unit @@ -62,6 +75,7 @@ operation MyOperation { @readonly operation ReadonlyResourceOperation { input := { + @required id: String } output: Unit @@ -70,9 +84,13 @@ operation ReadonlyResourceOperation { @idempotent operation ResourceOperation { input := { + @required id: String } - output: Unit + output := { + value: String + other: String + } } @error("client")