Skip to content

Commit a850ad3

Browse files
Add xmlNamespace trait support
1 parent 4f57710 commit a850ad3

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
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
@@ -37,6 +37,7 @@
3737
import software.amazon.smithy.docgen.core.interceptors.XmlAttributeInterceptor;
3838
import software.amazon.smithy.docgen.core.interceptors.XmlFlattenedInterceptor;
3939
import software.amazon.smithy.docgen.core.interceptors.XmlNameInterceptor;
40+
import software.amazon.smithy.docgen.core.interceptors.XmlNamespaceInterceptor;
4041
import software.amazon.smithy.docgen.core.writers.DocWriter;
4142
import software.amazon.smithy.docgen.core.writers.MarkdownWriter;
4243
import software.amazon.smithy.utils.CodeInterceptor;
@@ -82,6 +83,7 @@ public List<? extends CodeInterceptor<? extends CodeSection, DocWriter>> interce
8283
new ApiKeyAuthInterceptor(),
8384
new TimestampFormatInterceptor(),
8485
new JsonNameInterceptor(),
86+
new XmlNamespaceInterceptor(),
8587
new XmlAttributeInterceptor(),
8688
new XmlNameInterceptor(),
8789
new XmlFlattenedInterceptor(),

smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/interceptors/XmlAttributeInterceptor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
/**
1616
* Notes that a member is an
17-
* <a href="https://smithy.io/2.0/spec/protocol-traits.html#xmlnattribute-trait">
17+
* <a href="https://smithy.io/2.0/spec/protocol-traits.html#xmlattribute-trait">
1818
* xml attribute</a> in the {@link ProtocolSection} if the protocol supports it.
1919
*/
2020
@SmithyInternalApi
@@ -31,6 +31,7 @@ protected ShapeId getTraitId() {
3131

3232
@Override
3333
void write(DocWriter writer, String previousText, ProtocolSection section, XmlAttributeTrait trait) {
34+
writer.writeWithNoFormatting(previousText + "\n");
3435
writer.openAdmonition(AdmonitionType.IMPORTANT);
3536
writer.write("This member represents an XML attribute rather than a nested tag.");
3637
writer.closeAdmonition();
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.XmlNamespaceTrait;
13+
import software.amazon.smithy.utils.SmithyInternalApi;
14+
15+
/**
16+
* Notes that a member needs an
17+
* <a href="https://smithy.io/2.0/spec/protocol-traits.html#xmlnamespace-trait">
18+
* xml namespace</a> in the {@link ProtocolSection} if the protocol supports it.
19+
*/
20+
@SmithyInternalApi
21+
public final class XmlNamespaceInterceptor extends ProtocolTraitInterceptor<XmlNamespaceTrait> {
22+
@Override
23+
protected Class<XmlNamespaceTrait> getTraitClass() {
24+
return XmlNamespaceTrait.class;
25+
}
26+
27+
@Override
28+
protected ShapeId getTraitId() {
29+
return XmlNamespaceTrait.ID;
30+
}
31+
32+
@Override
33+
void write(DocWriter writer, String previousText, ProtocolSection section, XmlNamespaceTrait trait) {
34+
writer.writeWithNoFormatting(previousText + "\n");
35+
var namespace = "xmlns";
36+
if (trait.getPrefix().isPresent()) {
37+
namespace += ":" + trait.getPrefix().get();
38+
}
39+
namespace += "=\"" + trait.getUri() + "\"";
40+
writer.openAdmonition(AdmonitionType.IMPORTANT);
41+
writer.write("""
42+
This tag must contain the following XML namespace $`
43+
""", namespace);
44+
writer.closeAdmonition();
45+
}
46+
}

smithy-docgen-test/model/main.smithy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ structure XmlTraits {
182182
/// This map uses the non-default flat map behavior.
183183
@xmlFlattened
184184
flatMap: StringMap
185+
186+
/// This string tag needs an xml namespace added to it.
187+
@xmlNamespace(prefix: "example", uri: "https://example.com")
188+
xmlNamespace: String
185189
}
186190

187191
list StringList {

0 commit comments

Comments
 (0)