|
| 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