Skip to content

Commit 50e4ce6

Browse files
committed
Fix incorrect links for paginated trait in docgen
1 parent e3835bf commit 50e4ce6

3 files changed

Lines changed: 80 additions & 3 deletions

File tree

smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocSymbolProvider.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ public Symbol structureShape(StructureShape shape) {
209209
var operation = ioToOperation.get(shape.getId());
210210
builder.definitionFile(getDefinitionFile(serviceShape, operation));
211211
builder.putProperty(OPERATION_PROPERTY, operation);
212+
// Input and output structures should use the operation as its link_id
213+
builder.putProperty(LINK_ID_PROPERTY, getLinkId(getShapeName(serviceShape, operation)));
212214
}
213215
return builder.build();
214216
}
@@ -230,16 +232,22 @@ public Symbol unionShape(UnionShape shape) {
230232

231233
@Override
232234
public Symbol memberShape(MemberShape shape) {
233-
var builder = getSymbolBuilder(shape)
234-
.definitionFile(getDefinitionFile(serviceShape, model.expectShape(shape.getId().withoutMember())));
235+
var builder = getSymbolBuilder(shape);
235236

236-
Optional<String> containerLinkId = model.expectShape(shape.getContainer())
237+
ShapeId containerId = shape.getContainer();
238+
Optional<String> containerLinkId = model.expectShape(containerId)
237239
.accept(this)
238240
.getProperty(LINK_ID_PROPERTY, String.class);
239241
if (containerLinkId.isPresent()) {
240242
var linkId = containerLinkId.get() + "-" + getLinkId(getShapeName(serviceShape, shape));
241243
builder.putProperty(LINK_ID_PROPERTY, linkId);
242244
}
245+
// Definition file of input / output structure members should be the operation file.
246+
if (ioToOperation.containsKey(containerId)) {
247+
builder.definitionFile(getDefinitionFile(serviceShape, ioToOperation.get(containerId)));
248+
} else {
249+
builder.definitionFile(getDefinitionFile(serviceShape, model.expectShape(shape.getId().withoutMember())));
250+
}
243251
return builder.build();
244252
}
245253

smithy-docgen/src/test/java/software/amazon/smithy/docgen/generators/OperationGeneratorTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,50 @@ public void testGeneratesSnippetsFromDiscoveredConfig(@TempDir Path tempDir) {
142142
```
143143
:::"""));
144144
}
145+
146+
@Test
147+
public void testPaginatedOperation(@TempDir Path tempDir) {
148+
MockManifest manifest = new MockManifest();
149+
FileManifest sharedManifest = FileManifest.create(tempDir);
150+
ObjectNode settings = settings().toBuilder()
151+
.withoutMember("snippetConfigs")
152+
.build();
153+
sharedManifest.writeFile("snippets/snippets.json", IoUtils.readUtf8Url(SNIPPETS_FILE));
154+
execute(manifest, sharedManifest, settings);
155+
var operationDocs = manifest.expectFileString("/content/operations/PaginatedOperation.md");
156+
System.out.println(operationDocs);
157+
assertThat(operationDocs,
158+
containsString(
159+
"""
160+
(paginatedoperation)=
161+
# PaginatedOperation
162+
163+
Placeholder documentation for `smithy.example#PaginatedOperation`
164+
165+
:::{important}
166+
This operation returns partial results in pages, whose maximum size may be
167+
configured with [pageSize](./PaginatedOperation.md#paginatedoperation-pagesize). Each request may return an [output token](./PaginatedOperation.md#paginatedoperation-nexttoken) that may be used as an [input token](./PaginatedOperation.md#paginatedoperation-nexttoken) in subsequent requests to fetch the next page of results. If the operation does not return an [output token](./PaginatedOperation.md#paginatedoperation-nexttoken), that means that there are no more results. If the operation returns a repeated [output token](./PaginatedOperation.md#paginatedoperation-nexttoken), there MAY be more results later.
168+
:::
169+
170+
(paginatedoperation-request-members)=
171+
## Request Members
172+
173+
**nextToken (String)**
174+
: Placeholder documentation for `smithy.example#PaginatedOperationInput$nextToken`
175+
176+
**pageSize (Integer)**
177+
: Placeholder documentation for `smithy.example#PaginatedOperationInput$pageSize`
178+
179+
180+
(paginatedoperation-response-members)=
181+
## Response Members
182+
183+
**items (List\\<String\\>)**
184+
: Placeholder documentation for `smithy.example#PaginatedOperationOutput$items`
185+
186+
**nextToken (String)**
187+
: Placeholder documentation for `smithy.example#PaginatedOperationOutput$nextToken`
188+
"""));
189+
190+
}
145191
}

smithy-docgen/src/test/resources/software/amazon/smithy/docgen/generators/operation-generator.smithy

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ service TestService {
66
operations: [
77
NoSnippets
88
BasicOperation
9+
PaginatedOperation
910
]
1011
}
1112

@@ -83,3 +84,25 @@ operation NoSnippets {
8384
structure BasicError {
8485
message: String
8586
}
87+
88+
@paginated(inputToken: "nextToken", outputToken: "nextToken", pageSize: "pageSize", items: "items")
89+
operation PaginatedOperation {
90+
input: PaginatedOperationInput
91+
92+
output := {
93+
items: Items
94+
95+
nextToken: String
96+
}
97+
}
98+
99+
@input
100+
structure PaginatedOperationInput {
101+
nextToken: String
102+
103+
pageSize: Integer
104+
}
105+
106+
list Items {
107+
member: String
108+
}

0 commit comments

Comments
 (0)