Skip to content

Commit

Permalink
Add xmlName trait docs
Browse files Browse the repository at this point in the history
  • Loading branch information
JordonPhillips committed Nov 28, 2023
1 parent c643685 commit 306d1ca
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -77,6 +78,7 @@ public List<? extends CodeInterceptor<? extends CodeSection, DocWriter>> interce
new OperationAuthInterceptor(),
new ApiKeyAuthInterceptor(),
new JsonNameInterceptor(),
new XmlNameInterceptor(),
new PaginationInterceptor(),
new RequestCompressionInterceptor(),
new NoReplaceBindingInterceptor(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <a href="https://smithy.io/2.0/spec/protocol-traits.html#xmlname-trait">
* xmlName</a> to the {@link ProtocolSection} if the protocol supports it.
*/
@SmithyInternalApi
public final class XmlNameInterceptor extends ProtocolTraitInterceptor<XmlNameTrait> {
@Override
protected Class<XmlNameTrait> 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);
}
}

0 comments on commit 306d1ca

Please sign in to comment.