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

Add operation docs to OpenAPI conversion #589

Merged
merged 1 commit into from
Oct 2, 2020
Merged
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
@@ -432,6 +432,12 @@ private <T extends Trait> void addPaths(
}
// Add security requirements to the operation.
addOperationSecurity(context, result.getOperation(), shape, plugin);

// Add the documentation trait to the operation if present.
shape.getTrait(DocumentationTrait.class)
.map(DocumentationTrait::getValue)
.ifPresent(description -> result.getOperation().description(description));

// Pass the operation through the plugin system and then build it.
OperationObject builtOperation = plugin.updateOperation(
context, shape, result.getOperation().build(), method, path);
Original file line number Diff line number Diff line change
@@ -423,4 +423,20 @@ public void convertsUnions() {

Node.assertEquals(result, expectedNode);
}

@Test
public void convertsDocumentation() {
Model model = Model.assembler()
.addImport(getClass().getResource("documentation-test.smithy"))
.discoverModels()
.assemble()
.unwrap();
OpenApiConfig config = new OpenApiConfig();
config.setService(ShapeId.from("smithy.example#MyDocs"));
Node result = OpenApiConverter.create().config(config).convertToNode(model);
Node expectedNode = Node.parse(IoUtils.toUtf8String(
getClass().getResourceAsStream("documentation-test.openapi.json")));

Node.assertEquals(result, expectedNode);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"openapi": "3.0.2",
"info": {
"title": "MyDocs",
"version": "2018-01-01",
"description": "Service"
},
"paths": {
"/": {
"get": {
"description": "Operation",
"operationId": "MyDocsOperation",
"responses": {
"200": {
"description": "MyDocsOperation 200 response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MyDocsOperationResponseContent"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"MyDocsOperationResponseContent": {
"type": "object",
"description": "Output",
"properties": {
"foo": {
"type": "string",
"description": "foo member."
},
"nested": {
"$ref": "#/components/schemas/Nested"
}
}
},
"Nested": {
"type": "object",
"description": "Nested",
"properties": {
"baz": {
"type": "string"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace smithy.example

/// Service
@aws.protocols#restJson1
service MyDocs {
version: "2018-01-01",
operations: [MyDocsOperation]
}

/// Operation
@http(method: "GET", uri: "/")
@readonly
operation MyDocsOperation {
output: Output
}

/// Output
structure Output {
/// foo member.
foo: String,

/// Note: these member docs are ignored and instead only the documentation
/// on the targeted structure is present in the output. This is because our
/// users have told us that it's more important to reuse structure definitions
/// than it is to have 100% fidelity with the original Smithy model. In a
/// previous implementation, we created a unique named shape for every member,
/// but this results in no shape reuse across the generated OpenAPI model.
nested: Nested,
}

/// Nested
structure Nested {
baz: String,
}