Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OpenAPI tag configuration #570

Merged
merged 1 commit into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public enum HttpPrefixHeadersStrategy {
private ShapeId service;
private ShapeId protocol;
private boolean tags;
private List<String> supportedTags = Collections.emptyList();
private List<String> supportedTags;
private String defaultBlobFormat = "byte";
private boolean keepUnusedComponents;
private String jsonContentType = "application/json";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
Original file line number Diff line number Diff line change
@@ -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": { }
}