diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiConfig.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiConfig.java index 09ceee893cb..fef31568211 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiConfig.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiConfig.java @@ -74,7 +74,7 @@ public enum HttpPrefixHeadersStrategy { private ShapeId service; private ShapeId protocol; private boolean tags; - private List supportedTags = Collections.emptyList(); + private List supportedTags; private String defaultBlobFormat = "byte"; private boolean keepUnusedComponents; private String jsonContentType = "application/json"; diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverterTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverterTest.java index 361b6d09ecd..43e6f5a4e35 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverterTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverterTest.java @@ -70,7 +70,26 @@ public void convertsModelsToOpenApi() { } @Test - public void passesThroughTags() { + public void passesThroughAllTags() { + Model model = Model.assembler() + .addImport(getClass().getResource("tagged-service.json")) + .discoverModels() + .assemble() + .unwrap(); + OpenApiConfig config = new OpenApiConfig(); + config.setService(ShapeId.from("smithy.example#Service")); + config.setTags(true); + OpenApi result = OpenApiConverter.create() + .config(config) + .convert(model); + Node expectedNode = Node.parse(IoUtils.toUtf8String( + getClass().getResourceAsStream("tagged-service-all-tags.openapi.json"))); + + Node.assertEquals(result, expectedNode); + } + + @Test + public void passesThroughSupportedTags() { Model model = Model.assembler() .addImport(getClass().getResource("tagged-service.json")) .discoverModels() @@ -84,7 +103,27 @@ public void passesThroughTags() { .config(config) .convert(model); Node expectedNode = Node.parse(IoUtils.toUtf8String( - getClass().getResourceAsStream("tagged-service.openapi.json"))); + getClass().getResourceAsStream("tagged-service-supported-tags.openapi.json"))); + + Node.assertEquals(result, expectedNode); + } + + @Test + public void doesNotPassThroughTagsWithEmptySupportedTagList() { + Model model = Model.assembler() + .addImport(getClass().getResource("tagged-service.json")) + .discoverModels() + .assemble() + .unwrap(); + OpenApiConfig config = new OpenApiConfig(); + config.setService(ShapeId.from("smithy.example#Service")); + config.setTags(true); + config.setSupportedTags(ListUtils.of()); + OpenApi result = OpenApiConverter.create() + .config(config) + .convert(model); + Node expectedNode = Node.parse(IoUtils.toUtf8String( + getClass().getResourceAsStream("tagged-service-empty-supported-tags.openapi.json"))); Node.assertEquals(result, expectedNode); } diff --git a/smithy-openapi/src/test/resources/software/amazon/smithy/openapi/fromsmithy/tagged-service-all-tags.openapi.json b/smithy-openapi/src/test/resources/software/amazon/smithy/openapi/fromsmithy/tagged-service-all-tags.openapi.json new file mode 100644 index 00000000000..0663c9fd52e --- /dev/null +++ b/smithy-openapi/src/test/resources/software/amazon/smithy/openapi/fromsmithy/tagged-service-all-tags.openapi.json @@ -0,0 +1,47 @@ +{ + "openapi": "3.0.2", + "info": { + "title": "Service", + "version": "2006-03-01" + }, + "paths": { + "/operation1": { + "get": { + "operationId": "Operation1", + "tags": ["bar", "baz", "foo", "qux"], + "responses": { + "200": { + "description": "Operation1 response" + } + } + } + }, + "/operation2": { + "get": { + "operationId": "Operation2", + "tags": ["qux"], + "responses": { + "200": { + "description": "Operation2 response" + } + } + } + }, + "/operation3": { + "get": { + "operationId": "Operation3", + "responses": { + "200": { + "description": "Operation3 response" + } + } + } + } + }, + "components": { }, + "tags": [ + { + "name": "foo" + } + ] +} diff --git a/smithy-openapi/src/test/resources/software/amazon/smithy/openapi/fromsmithy/tagged-service-empty-supported-tags.openapi.json b/smithy-openapi/src/test/resources/software/amazon/smithy/openapi/fromsmithy/tagged-service-empty-supported-tags.openapi.json new file mode 100644 index 00000000000..c813741a22f --- /dev/null +++ b/smithy-openapi/src/test/resources/software/amazon/smithy/openapi/fromsmithy/tagged-service-empty-supported-tags.openapi.json @@ -0,0 +1,40 @@ +{ + "openapi": "3.0.2", + "info": { + "title": "Service", + "version": "2006-03-01" + }, + "paths": { + "/operation1": { + "get": { + "operationId": "Operation1", + "responses": { + "200": { + "description": "Operation1 response" + } + } + } + }, + "/operation2": { + "get": { + "operationId": "Operation2", + "responses": { + "200": { + "description": "Operation2 response" + } + } + } + }, + "/operation3": { + "get": { + "operationId": "Operation3", + "responses": { + "200": { + "description": "Operation3 response" + } + } + } + } + }, + "components": { } +} diff --git a/smithy-openapi/src/test/resources/software/amazon/smithy/openapi/fromsmithy/tagged-service.openapi.json b/smithy-openapi/src/test/resources/software/amazon/smithy/openapi/fromsmithy/tagged-service-supported-tags.openapi.json similarity index 100% rename from smithy-openapi/src/test/resources/software/amazon/smithy/openapi/fromsmithy/tagged-service.openapi.json rename to smithy-openapi/src/test/resources/software/amazon/smithy/openapi/fromsmithy/tagged-service-supported-tags.openapi.json