Skip to content

Commit a8a0259

Browse files
Add xmlName trait docs
1 parent 9c683df commit a8a0259

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/integrations/BuiltinsIntegration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import software.amazon.smithy.docgen.core.interceptors.SparseInterceptor;
3434
import software.amazon.smithy.docgen.core.interceptors.UniqueItemsInterceptor;
3535
import software.amazon.smithy.docgen.core.interceptors.UnstableInterceptor;
36+
import software.amazon.smithy.docgen.core.interceptors.XmlNameInterceptor;
3637
import software.amazon.smithy.docgen.core.writers.DocWriter;
3738
import software.amazon.smithy.docgen.core.writers.MarkdownWriter;
3839
import software.amazon.smithy.utils.CodeInterceptor;
@@ -77,6 +78,7 @@ public List<? extends CodeInterceptor<? extends CodeSection, DocWriter>> interce
7778
new OperationAuthInterceptor(),
7879
new ApiKeyAuthInterceptor(),
7980
new JsonNameInterceptor(),
81+
new XmlNameInterceptor(),
8082
new PaginationInterceptor(),
8183
new RequestCompressionInterceptor(),
8284
new NoReplaceBindingInterceptor(),
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.docgen.core.interceptors;
7+
8+
import software.amazon.smithy.docgen.core.sections.ProtocolSection;
9+
import software.amazon.smithy.docgen.core.writers.DocWriter;
10+
import software.amazon.smithy.model.shapes.ShapeId;
11+
import software.amazon.smithy.model.traits.XmlNameTrait;
12+
import software.amazon.smithy.utils.SmithyInternalApi;
13+
14+
/**
15+
* Adds a member's <a href="https://smithy.io/2.0/spec/protocol-traits.html#xmlname-trait">
16+
* xmlName</a> to the {@link ProtocolSection} if the protocol supports it.
17+
*/
18+
@SmithyInternalApi
19+
public final class XmlNameInterceptor extends ProtocolTraitInterceptor<XmlNameTrait> {
20+
@Override
21+
protected Class<XmlNameTrait> getTraitClass() {
22+
return XmlNameTrait.class;
23+
}
24+
25+
@Override
26+
protected ShapeId getTraitId() {
27+
return XmlNameTrait.ID;
28+
}
29+
30+
@Override
31+
public boolean isIntercepted(ProtocolSection section) {
32+
// The xmlName trait uniquely doesn't inherit values from the target as a member.
33+
return super.isIntercepted(section) && section.shape().hasTrait(XmlNameTrait.class);
34+
}
35+
36+
@Override
37+
void write(DocWriter writer, String previousText, ProtocolSection section, XmlNameTrait trait) {
38+
writer.putContext("xmlTagName", "XML tag name:");
39+
writer.write("""
40+
${xmlTagName:B} $`
41+
42+
$L""", trait.getValue(), previousText);
43+
}
44+
}

0 commit comments

Comments
 (0)