Skip to content

Commit 22a712a

Browse files
Add httpErrorCode trait support
1 parent 9810c4e commit 22a712a

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-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.HttpErrorInterceptor;
1819
import software.amazon.smithy.docgen.core.interceptors.HttpHeaderInterceptor;
1920
import software.amazon.smithy.docgen.core.interceptors.HttpInterceptor;
2021
import software.amazon.smithy.docgen.core.interceptors.HttpLabelInterceptor;
@@ -93,6 +94,7 @@ public List<? extends CodeInterceptor<? extends CodeSection, DocWriter>> interce
9394
new XmlAttributeInterceptor(),
9495
new XmlNameInterceptor(),
9596
new XmlFlattenedInterceptor(),
97+
new HttpErrorInterceptor(),
9698
new HttpHeaderInterceptor(),
9799
new HttpPrefixHeadersInterceptor(),
98100
new HttpQueryParamsInterceptor(),
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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.HttpErrorTrait;
12+
13+
/**
14+
* Adds the http response code for errors from the
15+
* <a href="https://smithy.io/2.0/spec/http-bindings.html#httperror-trait">
16+
* httpError trait</a> if the protocol supports it.
17+
*/
18+
public final class HttpErrorInterceptor extends ProtocolTraitInterceptor<HttpErrorTrait> {
19+
@Override
20+
protected Class<HttpErrorTrait> getTraitClass() {
21+
return HttpErrorTrait.class;
22+
}
23+
24+
@Override
25+
protected ShapeId getTraitId() {
26+
return HttpErrorTrait.ID;
27+
}
28+
29+
@Override
30+
void write(DocWriter writer, String previousText, ProtocolSection section, HttpErrorTrait trait) {
31+
writer.putContext("code", trait.getCode());
32+
writer.write("""
33+
$B ${code:`}
34+
35+
$L""", "HTTP Error Code:", previousText);
36+
}
37+
}

0 commit comments

Comments
 (0)