From 2bdc849b74c06b39eb627696f09ebe221311a27e Mon Sep 17 00:00:00 2001 From: miguel-vila Date: Fri, 29 Mar 2024 17:17:00 +0000 Subject: [PATCH 01/14] Add failing test for deprecated on a field --- .../OpenApiJsonSchemaMapperTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java index eb87b08b69d..8aa88ca2b47 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java @@ -22,6 +22,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Map; +import java.util.Optional; + import org.junit.jupiter.api.Test; import software.amazon.smithy.jsonschema.JsonSchemaConfig; import software.amazon.smithy.jsonschema.JsonSchemaConverter; @@ -39,6 +41,7 @@ import software.amazon.smithy.model.shapes.LongShape; import software.amazon.smithy.model.shapes.MapShape; import software.amazon.smithy.model.shapes.MemberShape; +import software.amazon.smithy.model.shapes.ShapeId; import software.amazon.smithy.model.shapes.ShortShape; import software.amazon.smithy.model.shapes.StringShape; import software.amazon.smithy.model.shapes.StructureShape; @@ -131,6 +134,29 @@ public void supportsDeprecatedTrait() { assertThat(document.getRootSchema().getExtension("deprecated").get(), equalTo(Node.from(true))); } + @Test + public void supportsDeprecatedTraitOnAMember() { + StringShape string = StringShape.builder().id("smithy.api#String").build(); + StructureShape shape = StructureShape.builder() + .id(ShapeId.from("a.b#C")) + .addMember( + MemberShape.builder().id(ShapeId.from("a.b#C$member")) + .target(string.getId()) + .addTrait(DeprecatedTrait.builder().message( + "I'm deprecated" + ).since("sinceVersion").build()).build() + ).build(); + Model model = Model.builder().addShapes(shape, string).build(); + SchemaDocument document = JsonSchemaConverter.builder() + .addMapper(new OpenApiJsonSchemaMapper()) + .model(model) + .build() + .convertShape(shape); + + Schema memberSchema = document.getRootSchema().getProperties().get("member"); + assertThat(memberSchema.getProperty("deprecated"), equalTo(Optional.of(Node.from(true)))); + } + @Test public void supportsInt32() { IntegerShape shape = IntegerShape.builder().id("a.b#C").build(); From 66b34621044a2d56d6b4e31890ed7a27546129e5 Mon Sep 17 00:00:00 2001 From: miguel-vila Date: Mon, 1 Apr 2024 15:21:47 +0100 Subject: [PATCH 02/14] Set deprecated for fields in the json schema conversion --- .../jsonschema/JsonSchemaShapeVisitor.java | 12 +++++++++--- .../amazon/smithy/jsonschema/Schema.java | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaShapeVisitor.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaShapeVisitor.java index 46550dfff93..8abcd962de4 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaShapeVisitor.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaShapeVisitor.java @@ -43,6 +43,7 @@ import software.amazon.smithy.model.shapes.TimestampShape; import software.amazon.smithy.model.shapes.UnionShape; import software.amazon.smithy.model.traits.DefaultTrait; +import software.amazon.smithy.model.traits.DeprecatedTrait; import software.amazon.smithy.model.traits.DocumentationTrait; import software.amazon.smithy.model.traits.EnumTrait; import software.amazon.smithy.model.traits.LengthTrait; @@ -100,13 +101,16 @@ private Schema createRef(MemberShape member) { if (converter.isInlined(member)) { return member.accept(this); } else { + Schema.Builder refBuilder = Schema.builder().ref(converter.toPointer(member.getTarget())); + if (member.hasTrait(DeprecatedTrait.class)) { + refBuilder.deprecated(true); + } // Wrap the ref and default in an allOf if disableDefaultValues has been not been disabled on config. if (member.hasTrait(DefaultTrait.class) && !converter.getConfig().getDisableDefaultValues()) { - Schema ref = Schema.builder().ref(converter.toPointer(member.getTarget())).build(); Schema def = Schema.builder().defaultValue(member.expectTrait(DefaultTrait.class).toNode()).build(); - return Schema.builder().allOf(ListUtils.of(ref, def)).build(); + return Schema.builder().allOf(ListUtils.of(refBuilder.build(), def)).build(); } - return Schema.builder().ref(converter.toPointer(member.getTarget())).build(); + return refBuilder.build(); } } @@ -329,6 +333,8 @@ private Schema.Builder updateBuilder(Shape shape, Schema.Builder builder) { builder.defaultValue(shape.expectTrait(DefaultTrait.class).toNode()); } + shape.getTrait(DeprecatedTrait.class).ifPresent(t -> builder.deprecated(true)); + return builder; } diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/Schema.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/Schema.java index 08a33ccf826..814fae618f9 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/Schema.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/Schema.java @@ -102,6 +102,7 @@ public final class Schema implements ToNode, ToSmithyBuilder { private final boolean writeOnly; private final String comment; private final Node examples; + private final boolean deprecated; private final String contentEncoding; private final String contentMediaType; @@ -153,6 +154,7 @@ private Schema(Builder builder) { writeOnly = builder.writeOnly; comment = builder.comment; examples = builder.examples; + deprecated = builder.deprecated; contentEncoding = builder.contentEncoding; contentMediaType = builder.contentMediaType; @@ -312,6 +314,10 @@ public Optional getExamples() { return Optional.ofNullable(examples); } + public boolean isDeprecated() { + return deprecated; + } + public Optional getContentEncoding() { return Optional.ofNullable(contentEncoding); } @@ -364,6 +370,7 @@ public Node toNode() { .withOptionalMember("comment", getComment().map(Node::from)) .withOptionalMember("examples", getExamples()) + .withOptionalMember("deprecated", this.deprecated ? Optional.of(Node.from(true)) : Optional.empty()) .withOptionalMember("title", getTitle().map(Node::from)) .withOptionalMember("description", getDescription().map(Node::from)) .withOptionalMember("format", getFormat().map(Node::from)) @@ -540,6 +547,7 @@ public Builder toBuilder() { .writeOnly(writeOnly) .comment(comment) .examples(examples) + .deprecated(deprecated) .contentEncoding(contentEncoding) .contentMediaType(contentMediaType); @@ -611,6 +619,7 @@ public static final class Builder implements SmithyBuilder { private boolean writeOnly; private String comment; private Node examples; + private boolean deprecated; private String contentEncoding; private String contentMediaType; @@ -853,6 +862,11 @@ public Builder examples(Node examples) { return this; } + public Builder deprecated(boolean deprecated) { + this.deprecated = deprecated; + return this; + } + public Builder extensions(Map extensions) { this.extensions.clear(); this.extensions.putAll(extensions); @@ -945,6 +959,8 @@ public Builder disableProperty(String propertyName) { return this.contentMediaType(null); case "examples": return this.examples(null); + case "deprecated": + return this.deprecated(false); default: LOGGER.warning("Unknown JSON Schema config 'disable' property: " + propertyName); return this; From 2a8bd49141889a2259b45c3a667339fceb378a02 Mon Sep 17 00:00:00 2001 From: miguel-vila Date: Wed, 3 Apr 2024 11:57:54 +0100 Subject: [PATCH 03/14] add `deprecated` to sample cfn template --- .../schema/fromsmithy/simple-service-aws.cfn.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/smithy-aws-cloudformation/src/test/resources/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/simple-service-aws.cfn.json b/smithy-aws-cloudformation/src/test/resources/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/simple-service-aws.cfn.json index 2c61b7979ed..83884c3af97 100644 --- a/smithy-aws-cloudformation/src/test/resources/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/simple-service-aws.cfn.json +++ b/smithy-aws-cloudformation/src/test/resources/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/simple-service-aws.cfn.json @@ -19,7 +19,8 @@ }, "properties": { "FooDeprecatedMutableProperty": { - "type": "string" + "type": "string", + "deprecated": true }, "FooId": { "type": "string" From fe42a1ba06bd58e8abbcdbdf591c014dbcbcf47f Mon Sep 17 00:00:00 2001 From: miguel-vila Date: Wed, 10 Apr 2024 13:54:46 +0100 Subject: [PATCH 04/14] move test to right place, fix it and only do this for later json schema versions --- .../fromsmithy/simple-service-aws.cfn.json | 3 +-- .../jsonschema/JsonSchemaShapeVisitor.java | 10 +++++-- .../amazon/smithy/jsonschema/Schema.java | 4 +++ .../jsonschema/JsonSchemaConverterTest.java | 26 +++++++++++++++++++ .../OpenApiJsonSchemaMapperTest.java | 23 ---------------- 5 files changed, 39 insertions(+), 27 deletions(-) diff --git a/smithy-aws-cloudformation/src/test/resources/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/simple-service-aws.cfn.json b/smithy-aws-cloudformation/src/test/resources/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/simple-service-aws.cfn.json index 83884c3af97..2c61b7979ed 100644 --- a/smithy-aws-cloudformation/src/test/resources/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/simple-service-aws.cfn.json +++ b/smithy-aws-cloudformation/src/test/resources/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/simple-service-aws.cfn.json @@ -19,8 +19,7 @@ }, "properties": { "FooDeprecatedMutableProperty": { - "type": "string", - "deprecated": true + "type": "string" }, "FooId": { "type": "string" diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaShapeVisitor.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaShapeVisitor.java index 8abcd962de4..5ac28a2474a 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaShapeVisitor.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaShapeVisitor.java @@ -102,7 +102,7 @@ private Schema createRef(MemberShape member) { return member.accept(this); } else { Schema.Builder refBuilder = Schema.builder().ref(converter.toPointer(member.getTarget())); - if (member.hasTrait(DeprecatedTrait.class)) { + if (member.hasTrait(DeprecatedTrait.class) && getJsonSchemaVersion() != JsonSchemaVersion.DRAFT07) { refBuilder.deprecated(true); } // Wrap the ref and default in an allOf if disableDefaultValues has been not been disabled on config. @@ -333,7 +333,9 @@ private Schema.Builder updateBuilder(Shape shape, Schema.Builder builder) { builder.defaultValue(shape.expectTrait(DefaultTrait.class).toNode()); } - shape.getTrait(DeprecatedTrait.class).ifPresent(t -> builder.deprecated(true)); + shape.getTrait(DeprecatedTrait.class) + .filter(t -> getJsonSchemaVersion() != JsonSchemaVersion.DRAFT07) + .ifPresent(t -> builder.deprecated(true)); return builder; } @@ -357,4 +359,8 @@ private Schema buildSchema(Shape shape, Schema.Builder builder) { return builder.build(); } + + private JsonSchemaVersion getJsonSchemaVersion() { + return converter.getConfig().getJsonSchemaVersion(); + } } diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/Schema.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/Schema.java index 814fae618f9..7d820b970cd 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/Schema.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/Schema.java @@ -428,6 +428,10 @@ public Node toNode() { result.withMember("writeOnly", Node.from(true)); } + if (deprecated) { + result.withMember("deprecated", Node.from(true)); + } + for (Map.Entry entry : extensions.entrySet()) { result.withMember(entry.getKey(), entry.getValue().toNode()); } diff --git a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java index c65c8b9b353..83e84eb20a9 100644 --- a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java +++ b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java @@ -54,6 +54,7 @@ import software.amazon.smithy.model.shapes.StringShape; import software.amazon.smithy.model.shapes.StructureShape; import software.amazon.smithy.model.shapes.UnionShape; +import software.amazon.smithy.model.traits.DeprecatedTrait; import software.amazon.smithy.model.traits.DocumentationTrait; import software.amazon.smithy.model.traits.EnumDefinition; import software.amazon.smithy.model.traits.EnumTrait; @@ -780,4 +781,29 @@ public void intEnumsCanBeDisabled() { IoUtils.toUtf8String(getClass().getResourceAsStream("int-enums-disabled.jsonschema.v07.json"))); Node.assertEquals(document.toNode(), expected); } + + @Test + public void supportsDeprecatedTraitOnAMember() { + StringShape string = StringShape.builder().id("smithy.api#String").build(); + StructureShape shape = StructureShape.builder() + .id(ShapeId.from("a.b#C")) + .addMember( + MemberShape.builder().id(ShapeId.from("a.b#C$member")) + .target(string.getId()) + .addTrait(DeprecatedTrait.builder().message( + "I'm deprecated" + ).since("sinceVersion").build()).build() + ).build(); + Model model = Model.builder().addShapes(shape, string).build(); + JsonSchemaConfig config = new JsonSchemaConfig(); + config.setJsonSchemaVersion(JsonSchemaVersion.DRAFT2020_12); + SchemaDocument document = JsonSchemaConverter.builder() + .model(model) + .config(config) + .build() + .convertShape(shape); + + Schema memberSchema = document.getRootSchema().getProperties().get("member"); + assertThat(memberSchema.isDeprecated(), equalTo(true)); + } } diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java index 8aa88ca2b47..bf8072bbc1f 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java @@ -134,29 +134,6 @@ public void supportsDeprecatedTrait() { assertThat(document.getRootSchema().getExtension("deprecated").get(), equalTo(Node.from(true))); } - @Test - public void supportsDeprecatedTraitOnAMember() { - StringShape string = StringShape.builder().id("smithy.api#String").build(); - StructureShape shape = StructureShape.builder() - .id(ShapeId.from("a.b#C")) - .addMember( - MemberShape.builder().id(ShapeId.from("a.b#C$member")) - .target(string.getId()) - .addTrait(DeprecatedTrait.builder().message( - "I'm deprecated" - ).since("sinceVersion").build()).build() - ).build(); - Model model = Model.builder().addShapes(shape, string).build(); - SchemaDocument document = JsonSchemaConverter.builder() - .addMapper(new OpenApiJsonSchemaMapper()) - .model(model) - .build() - .convertShape(shape); - - Schema memberSchema = document.getRootSchema().getProperties().get("member"); - assertThat(memberSchema.getProperty("deprecated"), equalTo(Optional.of(Node.from(true)))); - } - @Test public void supportsInt32() { IntegerShape shape = IntegerShape.builder().id("a.b#C").build(); From 6b44211aceccffcb475f38690121a6b56dcbdf18 Mon Sep 17 00:00:00 2001 From: miguel-vila Date: Wed, 10 Apr 2024 14:01:08 +0100 Subject: [PATCH 05/14] add another test --- .../jsonschema/JsonSchemaConverterTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java index 83e84eb20a9..00bee222d48 100644 --- a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java +++ b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java @@ -782,6 +782,32 @@ public void intEnumsCanBeDisabled() { Node.assertEquals(document.toNode(), expected); } + @Test + public void supportsDeprecatedTraitOnAStruct() { + StringShape string = StringShape.builder().id("smithy.api#String").build(); + StructureShape shape = StructureShape.builder() + .id(ShapeId.from("a.b#C")) + .addMember( + MemberShape.builder().id(ShapeId.from("a.b#C$member")) + .target(string.getId()) + .build() + ) + .addTrait(DeprecatedTrait.builder().message( + "I'm deprecated" + ).since("sinceVersion").build()) + .build(); + Model model = Model.builder().addShapes(shape, string).build(); + JsonSchemaConfig config = new JsonSchemaConfig(); + config.setJsonSchemaVersion(JsonSchemaVersion.DRAFT2020_12); + SchemaDocument document = JsonSchemaConverter.builder() + .model(model) + .config(config) + .build() + .convertShape(shape); + + assertThat(document.getRootSchema().isDeprecated(), equalTo(true)); + } + @Test public void supportsDeprecatedTraitOnAMember() { StringShape string = StringShape.builder().id("smithy.api#String").build(); From 81c057473571096c79fea18e268d6d4479a8d5c7 Mon Sep 17 00:00:00 2001 From: miguel-vila Date: Wed, 10 Apr 2024 14:08:27 +0100 Subject: [PATCH 06/14] undo import changes --- .../smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java index bf8072bbc1f..60aebf980f7 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java @@ -22,7 +22,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Map; -import java.util.Optional; import org.junit.jupiter.api.Test; import software.amazon.smithy.jsonschema.JsonSchemaConfig; @@ -41,7 +40,6 @@ import software.amazon.smithy.model.shapes.LongShape; import software.amazon.smithy.model.shapes.MapShape; import software.amazon.smithy.model.shapes.MemberShape; -import software.amazon.smithy.model.shapes.ShapeId; import software.amazon.smithy.model.shapes.ShortShape; import software.amazon.smithy.model.shapes.StringShape; import software.amazon.smithy.model.shapes.StructureShape; From f3d499d29298659d7d4f5f7c4f0610b140782dbc Mon Sep 17 00:00:00 2001 From: miguel-vila Date: Wed, 10 Apr 2024 19:25:35 +0100 Subject: [PATCH 07/14] undo change --- .../smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java index 60aebf980f7..eb87b08b69d 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java @@ -22,7 +22,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Map; - import org.junit.jupiter.api.Test; import software.amazon.smithy.jsonschema.JsonSchemaConfig; import software.amazon.smithy.jsonschema.JsonSchemaConverter; From 0ebe0063cbc7844e1d67cf07712306a84028b5cc Mon Sep 17 00:00:00 2001 From: miguel-vila Date: Wed, 10 Apr 2024 19:25:50 +0100 Subject: [PATCH 08/14] use more consistent style --- .../amazon/smithy/jsonschema/JsonSchemaShapeVisitor.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaShapeVisitor.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaShapeVisitor.java index 5ac28a2474a..0bd36b43532 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaShapeVisitor.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaShapeVisitor.java @@ -333,9 +333,9 @@ private Schema.Builder updateBuilder(Shape shape, Schema.Builder builder) { builder.defaultValue(shape.expectTrait(DefaultTrait.class).toNode()); } - shape.getTrait(DeprecatedTrait.class) - .filter(t -> getJsonSchemaVersion() != JsonSchemaVersion.DRAFT07) - .ifPresent(t -> builder.deprecated(true)); + if (shape.hasTrait(DeprecatedTrait.class) && getJsonSchemaVersion() != JsonSchemaVersion.DRAFT07) { + builder.deprecated(true); + } return builder; } From 9c7fde97fb8150d195ad126727b6c5d6af4c2565 Mon Sep 17 00:00:00 2001 From: miguel-vila Date: Wed, 10 Apr 2024 19:26:02 +0100 Subject: [PATCH 09/14] add negative tests --- .../jsonschema/JsonSchemaConverterTest.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java index 00bee222d48..a7bd4d347ad 100644 --- a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java +++ b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java @@ -807,6 +807,32 @@ public void supportsDeprecatedTraitOnAStruct() { assertThat(document.getRootSchema().isDeprecated(), equalTo(true)); } + + @Test + public void dontAddDeprecatedTraitOnAStructWhenOldVersion() { + StringShape string = StringShape.builder().id("smithy.api#String").build(); + StructureShape shape = StructureShape.builder() + .id(ShapeId.from("a.b#C")) + .addMember( + MemberShape.builder().id(ShapeId.from("a.b#C$member")) + .target(string.getId()) + .build() + ) + .addTrait(DeprecatedTrait.builder().message( + "I'm deprecated" + ).since("sinceVersion").build()) + .build(); + Model model = Model.builder().addShapes(shape, string).build(); + JsonSchemaConfig config = new JsonSchemaConfig(); + config.setJsonSchemaVersion(JsonSchemaVersion.DRAFT07); + SchemaDocument document = JsonSchemaConverter.builder() + .model(model) + .config(config) + .build() + .convertShape(shape); + + assertThat(document.getRootSchema().isDeprecated(), equalTo(false)); + } @Test public void supportsDeprecatedTraitOnAMember() { @@ -832,4 +858,29 @@ public void supportsDeprecatedTraitOnAMember() { Schema memberSchema = document.getRootSchema().getProperties().get("member"); assertThat(memberSchema.isDeprecated(), equalTo(true)); } + + @Test + public void dontAddDeprecatedTraitOnAMemberWhenOldVersion() { + StringShape string = StringShape.builder().id("smithy.api#String").build(); + StructureShape shape = StructureShape.builder() + .id(ShapeId.from("a.b#C")) + .addMember( + MemberShape.builder().id(ShapeId.from("a.b#C$member")) + .target(string.getId()) + .addTrait(DeprecatedTrait.builder().message( + "I'm deprecated" + ).since("sinceVersion").build()).build() + ).build(); + Model model = Model.builder().addShapes(shape, string).build(); + JsonSchemaConfig config = new JsonSchemaConfig(); + config.setJsonSchemaVersion(JsonSchemaVersion.DRAFT2020_12); + SchemaDocument document = JsonSchemaConverter.builder() + .model(model) + .config(config) + .build() + .convertShape(shape); + + Schema memberSchema = document.getRootSchema().getProperties().get("member"); + assertThat(memberSchema.isDeprecated(), equalTo(true)); + } } From 2e21b138769ba0574089c8f43344cf9ef6f57dda Mon Sep 17 00:00:00 2001 From: miguel-vila Date: Wed, 10 Apr 2024 19:48:37 +0100 Subject: [PATCH 10/14] correct test --- .../amazon/smithy/jsonschema/JsonSchemaConverterTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java index a7bd4d347ad..d2abaeb8180 100644 --- a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java +++ b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java @@ -873,7 +873,7 @@ public void dontAddDeprecatedTraitOnAMemberWhenOldVersion() { ).build(); Model model = Model.builder().addShapes(shape, string).build(); JsonSchemaConfig config = new JsonSchemaConfig(); - config.setJsonSchemaVersion(JsonSchemaVersion.DRAFT2020_12); + config.setJsonSchemaVersion(JsonSchemaVersion.DRAFT07); SchemaDocument document = JsonSchemaConverter.builder() .model(model) .config(config) @@ -881,6 +881,6 @@ public void dontAddDeprecatedTraitOnAMemberWhenOldVersion() { .convertShape(shape); Schema memberSchema = document.getRootSchema().getProperties().get("member"); - assertThat(memberSchema.isDeprecated(), equalTo(true)); + assertThat(memberSchema.isDeprecated(), equalTo(false)); } } From 22386d184b0362d44529f0d3470772c46387dd1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Vil=C3=A1?= Date: Thu, 11 Apr 2024 10:26:26 +0100 Subject: [PATCH 11/14] reformat Co-authored-by: Kevin Stich --- .../jsonschema/JsonSchemaConverterTest.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java index d2abaeb8180..01cd1664fc3 100644 --- a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java +++ b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java @@ -786,16 +786,16 @@ public void intEnumsCanBeDisabled() { public void supportsDeprecatedTraitOnAStruct() { StringShape string = StringShape.builder().id("smithy.api#String").build(); StructureShape shape = StructureShape.builder() - .id(ShapeId.from("a.b#C")) - .addMember( - MemberShape.builder().id(ShapeId.from("a.b#C$member")) - .target(string.getId()) - .build() - ) - .addTrait(DeprecatedTrait.builder().message( - "I'm deprecated" - ).since("sinceVersion").build()) - .build(); + .id(ShapeId.from("a.b#C")) + .addMember(MemberShape.builder() + .id(ShapeId.from("a.b#C$member")) + .target(string.getId()) + .build()) + .addTrait(DeprecatedTrait.builder() + .message("I'm deprecated") + .since("sinceVersion") + .build()) + .build(); Model model = Model.builder().addShapes(shape, string).build(); JsonSchemaConfig config = new JsonSchemaConfig(); config.setJsonSchemaVersion(JsonSchemaVersion.DRAFT2020_12); From 59e84508ca0e68bd155498de1c12112733cb2ff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Vil=C3=A1?= Date: Thu, 11 Apr 2024 10:26:35 +0100 Subject: [PATCH 12/14] reformat Co-authored-by: Kevin Stich --- .../jsonschema/JsonSchemaConverterTest.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java index 01cd1664fc3..ffbfec1c373 100644 --- a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java +++ b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java @@ -838,14 +838,16 @@ public void dontAddDeprecatedTraitOnAStructWhenOldVersion() { public void supportsDeprecatedTraitOnAMember() { StringShape string = StringShape.builder().id("smithy.api#String").build(); StructureShape shape = StructureShape.builder() - .id(ShapeId.from("a.b#C")) - .addMember( - MemberShape.builder().id(ShapeId.from("a.b#C$member")) - .target(string.getId()) - .addTrait(DeprecatedTrait.builder().message( - "I'm deprecated" - ).since("sinceVersion").build()).build() - ).build(); + .id(ShapeId.from("a.b#C")) + .addMember(MemberShape.builder() + .id(ShapeId.from("a.b#C$member")) + .target(string.getId()) + .addTrait(DeprecatedTrait.builder() + .message("I'm deprecated") + .since("sinceVersion") + .build()) + .build()) + .build(); Model model = Model.builder().addShapes(shape, string).build(); JsonSchemaConfig config = new JsonSchemaConfig(); config.setJsonSchemaVersion(JsonSchemaVersion.DRAFT2020_12); From 8e9ec7da5cbf8cb651159ed815adf4c7ec511a28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Vil=C3=A1?= Date: Thu, 11 Apr 2024 10:26:48 +0100 Subject: [PATCH 13/14] reformat Co-authored-by: Kevin Stich --- .../jsonschema/JsonSchemaConverterTest.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java index ffbfec1c373..511dba5d0aa 100644 --- a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java +++ b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java @@ -865,14 +865,16 @@ public void supportsDeprecatedTraitOnAMember() { public void dontAddDeprecatedTraitOnAMemberWhenOldVersion() { StringShape string = StringShape.builder().id("smithy.api#String").build(); StructureShape shape = StructureShape.builder() - .id(ShapeId.from("a.b#C")) - .addMember( - MemberShape.builder().id(ShapeId.from("a.b#C$member")) - .target(string.getId()) - .addTrait(DeprecatedTrait.builder().message( - "I'm deprecated" - ).since("sinceVersion").build()).build() - ).build(); + .id(ShapeId.from("a.b#C")) + .addMember(MemberShape.builder() + .id(ShapeId.from("a.b#C$member")) + .target(string.getId()) + .addTrait(DeprecatedTrait.builder() + .message("I'm deprecated") + .since("sinceVersion") + .build()) + .build()) + .build(); Model model = Model.builder().addShapes(shape, string).build(); JsonSchemaConfig config = new JsonSchemaConfig(); config.setJsonSchemaVersion(JsonSchemaVersion.DRAFT07); From 28e57180daa0cc5cb2d211bc1c13ce5b72274a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Vil=C3=A1?= Date: Thu, 11 Apr 2024 10:27:14 +0100 Subject: [PATCH 14/14] reformat Co-authored-by: Kevin Stich --- .../jsonschema/JsonSchemaConverterTest.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java index 511dba5d0aa..21410679d43 100644 --- a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java +++ b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java @@ -812,16 +812,16 @@ public void supportsDeprecatedTraitOnAStruct() { public void dontAddDeprecatedTraitOnAStructWhenOldVersion() { StringShape string = StringShape.builder().id("smithy.api#String").build(); StructureShape shape = StructureShape.builder() - .id(ShapeId.from("a.b#C")) - .addMember( - MemberShape.builder().id(ShapeId.from("a.b#C$member")) - .target(string.getId()) - .build() - ) - .addTrait(DeprecatedTrait.builder().message( - "I'm deprecated" - ).since("sinceVersion").build()) - .build(); + .id(ShapeId.from("a.b#C")) + .addMember(MemberShape.builder() + .id(ShapeId.from("a.b#C$member")) + .target(string.getId()) + .build()) + .addTrait(DeprecatedTrait.builder() + .message("I'm deprecated") + .since("sinceVersion") + .build()) + .build(); Model model = Model.builder().addShapes(shape, string).build(); JsonSchemaConfig config = new JsonSchemaConfig(); config.setJsonSchemaVersion(JsonSchemaVersion.DRAFT07);