Skip to content

Commit 9810c4e

Browse files
Add httpHeader trait support
1 parent 73283df commit 9810c4e

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
@@ -15,6 +15,7 @@
1515
import software.amazon.smithy.docgen.core.interceptors.DeprecatedInterceptor;
1616
import software.amazon.smithy.docgen.core.interceptors.ErrorFaultInterceptor;
1717
import software.amazon.smithy.docgen.core.interceptors.ExternalDocsInterceptor;
18+
import software.amazon.smithy.docgen.core.interceptors.HttpHeaderInterceptor;
1819
import software.amazon.smithy.docgen.core.interceptors.HttpInterceptor;
1920
import software.amazon.smithy.docgen.core.interceptors.HttpLabelInterceptor;
2021
import software.amazon.smithy.docgen.core.interceptors.HttpPrefixHeadersInterceptor;
@@ -92,6 +93,7 @@ public List<? extends CodeInterceptor<? extends CodeSection, DocWriter>> interce
9293
new XmlAttributeInterceptor(),
9394
new XmlNameInterceptor(),
9495
new XmlFlattenedInterceptor(),
96+
new HttpHeaderInterceptor(),
9597
new HttpPrefixHeadersInterceptor(),
9698
new HttpQueryParamsInterceptor(),
9799
new HttpQueryInterceptor(),
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.HttpHeaderTrait;
12+
import software.amazon.smithy.utils.SmithyInternalApi;
13+
14+
/**
15+
* Adds information about header bindings from the
16+
* <a href="https://smithy.io/2.0/spec/http-bindings.html#httpheader-trait">
17+
* httpHeader trait</a> if the protocol supports it.
18+
*/
19+
@SmithyInternalApi
20+
public final class HttpHeaderInterceptor extends ProtocolTraitInterceptor<HttpHeaderTrait> {
21+
@Override
22+
protected Class<HttpHeaderTrait> getTraitClass() {
23+
return HttpHeaderTrait.class;
24+
}
25+
26+
@Override
27+
protected ShapeId getTraitId() {
28+
return HttpHeaderTrait.ID;
29+
}
30+
31+
@Override
32+
void write(DocWriter writer, String previousText, ProtocolSection section, HttpHeaderTrait trait) {
33+
var target = section.context().model().expectShape(section.shape().asMemberShape().get().getTarget());
34+
writer.putContext("key", trait.getValue());
35+
writer.putContext("list", target.isListShape());
36+
writer.write("""
37+
This is bound to the HTTP header ${param:`}.${?list} Each element in \
38+
the list should be sent as its own header using the same key for each \
39+
value. The list may instead be concatenated with commas separating each \
40+
value.${/list}
41+
42+
$L""", previousText);
43+
}
44+
}

0 commit comments

Comments
 (0)