Skip to content

Commit 4d51710

Browse files
Limit streaming traits to top level members
A streaming blob on a nested structure doesn't make much sense, so this updates the streaming trait to only apply to members of operation input/output and errors. Fundamentally this doesn't change the way that serde code would be generated, since at the end of the day simple types like blobs will never get generated types.
1 parent 1a962c6 commit 4d51710

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

smithy-model/src/main/resources/software/amazon/smithy/model/loader/prelude-traits.smithy

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ string since
240240
/// Indicates that the the data stored in the shape is very large and should not
241241
/// be stored in memory, or that the size of the data stored in the shape is
242242
/// unknown at the start of a request
243-
@trait(selector: "blob")
243+
@trait(selector: ":each(operation -[input, output]-> structure > :test(member > blob), :test(member:of(structure[trait|error]) > blob))")
244244
@tags(["diff.error.const"])
245245
structure streaming {
246246
/// Indicates that the stream must have a known size.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[ERROR] ns.foo#InvalidStreamingStructure$Body: Trait `streaming` cannot be applied to `ns.foo#InvalidStreamingStructure$Body`. This trait may only be applied to shapes that match the following selector: :each(operation -[input, output]-> structure > :test(member > blob), :test(member:of(structure[trait|error]) > blob)) | TraitTarget
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"smithy": "0.4.0",
3+
"ns.foo": {
4+
"shapes": {
5+
"Blob": {
6+
"type": "blob"
7+
},
8+
"StreamingOperation": {
9+
"type": "operation",
10+
"input": "StreamingInput",
11+
"output": "StreamingOutput"
12+
},
13+
"StreamingInput": {
14+
"type": "structure",
15+
"members": {
16+
"Body": {
17+
"target": "Blob",
18+
"smithy.api#streaming": true
19+
}
20+
}
21+
},
22+
"StreamingOutput": {
23+
"type": "structure",
24+
"members": {
25+
"Body": {
26+
"target": "Blob",
27+
"smithy.api#streaming": true
28+
}
29+
}
30+
},
31+
"StreamingError": {
32+
"type": "structure",
33+
"members": {
34+
"Body": {
35+
"target": "Blob",
36+
"smithy.api#streaming": true
37+
}
38+
},
39+
"smithy.api#error": "client"
40+
},
41+
"InvalidStreamingStructure": {
42+
"type": "structure",
43+
"members": {
44+
"Body": {
45+
"target": "Blob",
46+
"smithy.api#streaming": true
47+
}
48+
}
49+
}
50+
}
51+
}
52+
}

smithy-openapi/src/test/resources/software/amazon/smithy/openapi/fromsmithy/mappers/streaming-service.smithy

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ operation StreamingOperation() -> Output
1212

1313
structure Output {
1414
@httpPayload
15+
@streaming
1516
body: StreamingPayload,
1617
}
1718

18-
@streaming
1919
blob StreamingPayload

0 commit comments

Comments
 (0)