diff --git a/smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/integrations/BuiltinsIntegration.java b/smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/integrations/BuiltinsIntegration.java index cc03b96..b6e07d1 100644 --- a/smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/integrations/BuiltinsIntegration.java +++ b/smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/integrations/BuiltinsIntegration.java @@ -33,6 +33,7 @@ import software.amazon.smithy.docgen.core.interceptors.SparseInterceptor; import software.amazon.smithy.docgen.core.interceptors.UniqueItemsInterceptor; import software.amazon.smithy.docgen.core.interceptors.UnstableInterceptor; +import software.amazon.smithy.docgen.core.interceptors.XmlNameInterceptor; import software.amazon.smithy.docgen.core.writers.DocWriter; import software.amazon.smithy.docgen.core.writers.MarkdownWriter; import software.amazon.smithy.utils.CodeInterceptor; @@ -77,6 +78,7 @@ public List> interce new OperationAuthInterceptor(), new ApiKeyAuthInterceptor(), new JsonNameInterceptor(), + new XmlNameInterceptor(), new PaginationInterceptor(), new RequestCompressionInterceptor(), new NoReplaceBindingInterceptor(), diff --git a/smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/interceptors/XmlNameInterceptor.java b/smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/interceptors/XmlNameInterceptor.java new file mode 100644 index 0000000..6be7dbe --- /dev/null +++ b/smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/interceptors/XmlNameInterceptor.java @@ -0,0 +1,44 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.docgen.core.interceptors; + +import software.amazon.smithy.docgen.core.sections.ProtocolSection; +import software.amazon.smithy.docgen.core.writers.DocWriter; +import software.amazon.smithy.model.shapes.ShapeId; +import software.amazon.smithy.model.traits.XmlNameTrait; +import software.amazon.smithy.utils.SmithyInternalApi; + +/** + * Adds a member's + * xmlName to the {@link ProtocolSection} if the protocol supports it. + */ +@SmithyInternalApi +public final class XmlNameInterceptor extends ProtocolTraitInterceptor { + @Override + protected Class getTraitClass() { + return XmlNameTrait.class; + } + + @Override + protected ShapeId getTraitId() { + return XmlNameTrait.ID; + } + + @Override + public boolean isIntercepted(ProtocolSection section) { + // The xmlName trait uniquely doesn't inherit values from the target as a member. + return super.isIntercepted(section) && section.shape().hasTrait(XmlNameTrait.class); + } + + @Override + void write(DocWriter writer, String previousText, ProtocolSection section, XmlNameTrait trait) { + writer.putContext("xmlTagName", "XML tag name:"); + writer.write(""" + ${xmlTagName:B} $` + + $L""", trait.getValue(), previousText); + } +}