Skip to content

Commit

Permalink
Support externalDocs when converting operations to OpenAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtansia authored and JordonPhillips committed Jun 2, 2023
1 parent 567d7af commit d693438
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,10 @@ private <T extends Trait> void addPaths(
.map(DocumentationTrait::getValue)
.ifPresent(description -> result.getOperation().description(description));

// The externalDocumentation trait of the operation maps to externalDocs.
OpenApiJsonSchemaMapper.getResolvedExternalDocs(shape, context.getConfig())
.ifPresent(result.getOperation()::externalDocs);

OperationObject builtOperation = result.getOperation().build();

// Pass the operation through the plugin system.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,22 @@ public void convertsDocumentation() {
Node.assertEquals(result, expectedNode);
}

@Test
public void convertsExternalDocumentation() {
Model model = Model.assembler()
.addImport(getClass().getResource("externaldocs-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("externaldocs-test.openapi.json")));

Node.assertEquals(result, expectedNode);
}

@Test
public void properlyDealsWithServiceRenames() {
Model model = Model.assembler()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"openapi": "3.0.2",
"info": {
"title": "MyDocs",
"version": "2018-01-01"
},
"externalDocumentation": {
"description": "API Reference",
"url": "https://localhost/docs/service"
},
"paths": {
"/": {
"get": {
"externalDocs": {
"description": "API Reference",
"url": "https://localhost/docs/operation"
},
"operationId": "MyDocsOperation",
"responses": {
"200": {
"description": "MyDocsOperation 200 response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MyDocsOperationResponseContent"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"MyDocsOperationResponseContent": {
"type": "object",
"properties": {
"foo": {
"type": "string"
}
},
"externalDocs": {
"description": "API Reference",
"url": "https://localhost/docs/output"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
$version: "2.0"

namespace smithy.example

@externalDocumentation(
"API Reference": "https://localhost/docs/service"
)
@aws.protocols#restJson1
service MyDocs {
version: "2018-01-01",
operations: [MyDocsOperation]
}

@externalDocumentation(
"API Reference": "https://localhost/docs/operation"
)
@http(method: "GET", uri: "/")
@readonly
operation MyDocsOperation {
output: Output
}

@externalDocumentation(
"API Reference": "https://localhost/docs/output"
)
structure Output {
foo: String
}

0 comments on commit d693438

Please sign in to comment.