Skip to content

Commit b2019bf

Browse files
Add base http trait support
1 parent a850ad3 commit b2019bf

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
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.HttpInterceptor;
1819
import software.amazon.smithy.docgen.core.interceptors.IdempotencyInterceptor;
1920
import software.amazon.smithy.docgen.core.interceptors.InternalInterceptor;
2021
import software.amazon.smithy.docgen.core.interceptors.JsonNameInterceptor;
@@ -87,6 +88,7 @@ public List<? extends CodeInterceptor<? extends CodeSection, DocWriter>> interce
8788
new XmlAttributeInterceptor(),
8889
new XmlNameInterceptor(),
8990
new XmlFlattenedInterceptor(),
91+
new HttpInterceptor(),
9092
new PaginationInterceptor(),
9193
new RequestCompressionInterceptor(),
9294
new NoReplaceBindingInterceptor(),
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.HttpTrait;
12+
import software.amazon.smithy.utils.SmithyInternalApi;
13+
14+
/**
15+
* Adds information to operations from the
16+
* <a href="https://smithy.io/2.0/spec/http-bindings.html#http-trait">
17+
* http trait</a>.
18+
*/
19+
@SmithyInternalApi
20+
public final class HttpInterceptor extends ProtocolTraitInterceptor<HttpTrait> {
21+
@Override
22+
protected Class<HttpTrait> getTraitClass() {
23+
return HttpTrait.class;
24+
}
25+
26+
@Override
27+
protected ShapeId getTraitId() {
28+
return HttpTrait.ID;
29+
}
30+
31+
@Override
32+
void write(DocWriter writer, String previousText, ProtocolSection section, HttpTrait trait) {
33+
writer.write("""
34+
$B $`
35+
36+
$B $`
37+
38+
$L""", "HTTP Method:", trait.getMethod(), "URI:", trait.getUri(), previousText);
39+
}
40+
}

smithy-docgen-test/model/main.smithy

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,23 @@ service DocumentedService {
3939

4040
/// This operation does not support any of the service's auth types.
4141
@auth([])
42+
@http(method: "POST", uri: "/UnauthenticatedOperation")
4243
operation UnauthenticatedOperation {}
4344

4445
/// This operation supports all of the service's auth types, but optionally.
4546
@optionalAuth
47+
@http(method: "POST", uri: "/OptionalAuthOperation")
4648
operation OptionalAuthOperation {}
4749

4850
/// This operation supports a limited set of the service's auth.
4951
@auth([httpBasicAuth, httpApiKeyAuth])
52+
@http(method: "POST", uri: "/LimitedAuthOperation")
5053
operation LimitedAuthOperation {}
5154

5255
/// This operation supports a limited set of the service's auth, optionally.
5356
@optionalAuth
5457
@auth([httpBasicAuth, httpDigestAuth])
58+
@http(method: "POST", uri: "/LimitedOptionalAuthOperation")
5559
operation LimitedOptionalAuthOperation {}
5660

5761
@examples(
@@ -81,6 +85,7 @@ operation LimitedOptionalAuthOperation {}
8185
@requestCompression(
8286
encodings: ["gzip"]
8387
)
88+
@http(method: "POST", uri: "/DocumentedOperation")
8489
operation DocumentedOperation {
8590
input := {
8691
/// This is an idempotency token, which will inherently mark this operation
@@ -347,9 +352,11 @@ boolean DocumentationArchived
347352

348353
/// Put operations create a resource with a user-specified identifier.
349354
@idempotent
355+
@http(method: "PUT", uri: "/DocumentationResource/{id}")
350356
operation PutDocumentation {
351357
input := for DocumentationResource {
352358
@required
359+
@httpLabel
353360
$id
354361

355362
@required
@@ -358,6 +365,7 @@ operation PutDocumentation {
358365
}
359366

360367
/// Create operations instead have the service create the identifier.
368+
@http(method: "POST", uri: "/DocumentationResource")
361369
operation CreateDocumentation {
362370
input := for DocumentationResource {
363371
@required
@@ -367,9 +375,11 @@ operation CreateDocumentation {
367375

368376
/// Gets the contents of a documentation resource.
369377
@readonly
378+
@http(method: "GET", uri: "/DocumentationResource/{id}")
370379
operation GetDocumentation {
371380
input := for DocumentationResource {
372381
@required
382+
@httpLabel
373383
$id
374384
}
375385

@@ -388,9 +398,11 @@ operation GetDocumentation {
388398
/// Does an update on the documentation resource. These can often also be the put
389399
/// lifecycle operation.
390400
@idempotent
401+
@http(method: "PUT", uri: "/DocumentationResource")
391402
operation UpdateDocumentation {
392403
input := for DocumentationResource {
393404
@required
405+
@httpQuery("id")
394406
$id
395407

396408
@required
@@ -400,9 +412,11 @@ operation UpdateDocumentation {
400412

401413
/// Deletes documentation.
402414
@idempotent
415+
@http(method: "DELETE", uri: "/DocumentationResource/{id}")
403416
operation DeleteDocumentation {
404417
input := for DocumentationResource {
405418
@required
419+
@httpLabel
406420
$id
407421
}
408422
}
@@ -411,28 +425,36 @@ operation DeleteDocumentation {
411425
/// We need both instance operations and collection operations that aren't lifecycle
412426
/// operations to make sure both cases are being documented.
413427
@idempotent
428+
@http(method: "PUT", uri: "/DocumentationResource/{id}/archive")
414429
operation ArchiveDocumentation {
415430
input := for DocumentationResource {
416431
@required
432+
@httpLabel
417433
$id
418434
}
419435
}
420436

421437
/// Deletes all documentation that's been archived. This is a collection operation that
422438
/// isn't part of a lifecycle operation, which is again needed to make sure everything
423439
/// is being documented as expected.
440+
@http(method: "DELETE", uri: "/DocumentationResource?delete-archived")
441+
@idempotent
424442
operation DeleteArchivedDocumentation {}
425443

426444
/// Lists the avialable documentation resources.
427445
@readonly
446+
@http(method: "GET", uri: "/DocumentationResource")
428447
@paginated(inputToken: "paginationToken", outputToken: "paginationToken", items: "documentation", pageSize: "pageSize")
429448
operation ListDocumentation {
430449
input := {
431-
// Whether to list documentation that has been archived.
450+
/// Whether to list documentation that has been archived.
451+
@httpQuery("showArchived")
432452
showArchived: Boolean = false
433453

454+
@httpHeader("x-example-pagination-token")
434455
paginationToken: String
435456

457+
@httpHeader("x-example-page-size")
436458
pageSize: Integer
437459
}
438460

@@ -476,12 +498,15 @@ string DocumentationArtifactId
476498
blob DocumentationArtifactData
477499

478500
@idempotent
501+
@http(method: "PUT", uri: "/DocumentationResource/{id}/artifact/{artifactId}")
479502
operation PutDocumentationArtifact {
480503
input := for DocumentationArtifact {
481504
@required
505+
@httpLabel
482506
$id
483507

484508
@required
509+
@httpLabel
485510
$artifactId
486511

487512
@required
@@ -490,12 +515,15 @@ operation PutDocumentationArtifact {
490515
}
491516

492517
@readonly
518+
@http(method: "GET", uri: "/DocumentationResource/{id}/artifact/{artifactId}")
493519
operation GetDocumentationArtifact {
494520
input := for DocumentationArtifact {
495521
@required
522+
@httpLabel
496523
$id
497524

498525
@required
526+
@httpLabel
499527
$artifactId
500528
}
501529

@@ -512,12 +540,15 @@ operation GetDocumentationArtifact {
512540
}
513541

514542
@idempotent
543+
@http(method: "DELETE", uri: "/DocumentationResource/{id}/artifact/{artifactId}")
515544
operation DeleteDocumentationArtifact {
516545
input := for DocumentationArtifact {
517546
@required
547+
@httpLabel
518548
$id
519549

520550
@required
551+
@httpLabel
521552
$artifactId
522553
}
523554
}

0 commit comments

Comments
 (0)