Skip to content

Commit f688130

Browse files
Add xmlAttribute trait support
1 parent dc87b07 commit f688130

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-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
@@ -34,6 +34,7 @@
3434
import software.amazon.smithy.docgen.core.interceptors.TimestampFormatInterceptor;
3535
import software.amazon.smithy.docgen.core.interceptors.UniqueItemsInterceptor;
3636
import software.amazon.smithy.docgen.core.interceptors.UnstableInterceptor;
37+
import software.amazon.smithy.docgen.core.interceptors.XmlAttributeInterceptor;
3738
import software.amazon.smithy.docgen.core.interceptors.XmlNameInterceptor;
3839
import software.amazon.smithy.docgen.core.writers.DocWriter;
3940
import software.amazon.smithy.docgen.core.writers.MarkdownWriter;
@@ -80,6 +81,7 @@ public List<? extends CodeInterceptor<? extends CodeSection, DocWriter>> interce
8081
new ApiKeyAuthInterceptor(),
8182
new TimestampFormatInterceptor(),
8283
new JsonNameInterceptor(),
84+
new XmlAttributeInterceptor(),
8385
new XmlNameInterceptor(),
8486
new PaginationInterceptor(),
8587
new RequestCompressionInterceptor(),
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.docgen.core.writers.DocWriter.AdmonitionType;
11+
import software.amazon.smithy.model.shapes.ShapeId;
12+
import software.amazon.smithy.model.traits.XmlAttributeTrait;
13+
import software.amazon.smithy.utils.SmithyInternalApi;
14+
15+
/**
16+
* Notes that a member is an
17+
* <a href="https://smithy.io/2.0/spec/protocol-traits.html#xmlnattribute-trait">
18+
* xml attribute</a> in the {@link ProtocolSection} if the protocol supports it.
19+
*/
20+
@SmithyInternalApi
21+
public final class XmlAttributeInterceptor extends ProtocolTraitInterceptor<XmlAttributeTrait> {
22+
@Override
23+
protected Class<XmlAttributeTrait> getTraitClass() {
24+
return XmlAttributeTrait.class;
25+
}
26+
27+
@Override
28+
protected ShapeId getTraitId() {
29+
return XmlAttributeTrait.ID;
30+
}
31+
32+
@Override
33+
void write(DocWriter writer, String previousText, ProtocolSection section, XmlAttributeTrait trait) {
34+
writer.openAdmonition(AdmonitionType.IMPORTANT);
35+
writer.write("This member represents an XML attribute rather than a nested tag.");
36+
writer.closeAdmonition();
37+
}
38+
}

smithy-docgen-test/model/main.smithy

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,29 @@ structure DocumentedStructure {
147147

148148
@recommended(reason: "Because unions are cool")
149149
union: DocumentedUnion
150+
151+
xmlTraits: XmlTraits
150152
}
151153

152154
/// Timestamp in RFC3339 format
153155
@timestampFormat("date-time")
154156
timestamp DateTime
155157

158+
/// This structure showcases various XML traits
159+
@xmlName("foo")
160+
structure XmlTraits {
161+
/// This shows that the xml name isn't inherited from the target.
162+
nested: XmlTraits
163+
164+
/// This shows an xml name targeting a normal shape.
165+
@xmlName("bar")
166+
xmlName: String
167+
168+
/// This shows how xml attributes are displayed.
169+
@xmlAttribute
170+
xmlAttribute: String
171+
}
172+
156173
/// This in an enum that can have one of the following values:
157174
///
158175
/// - `FOO`

0 commit comments

Comments
 (0)