-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for OperationContextParams (#1680)
* Add OperationContextParams handling to endpoint params construction codegen. * Update endpoint param and endpoint middleware codegen tests & test smithy model. * Add the Smithy model provided by SEP for testing string array endpoint params. * Add runtime test for the endpoint resolver generated for mock service, using existing protocol test structure, similar to how waiters used the existing protocol structure, except with endpoint the test gets generated as well. * Tweak endpoint test generator to correctly generate endpoint params initializer for string array values. * Add default value handling for operation context params value codegen. * Fix ktlint --------- Co-authored-by: Sichan Yoo <[email protected]>
- Loading branch information
Showing
8 changed files
with
354 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
197 changes: 197 additions & 0 deletions
197
codegen/protocol-test-codegen-local/model/endpoints-string-array.smithy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
$version: "2.0" | ||
|
||
namespace aws.endpointtests.stringarray | ||
|
||
use smithy.rules#endpointRuleSet | ||
use smithy.rules#endpointTests | ||
use smithy.rules#staticContextParams | ||
use smithy.rules#operationContextParams | ||
use aws.api#service | ||
use aws.protocols#restJson1 | ||
|
||
@endpointRuleSet({ | ||
version: "1.0", | ||
parameters: { | ||
stringArrayParam: { | ||
type: "stringArray", | ||
required: true, | ||
default: ["defaultValue1", "defaultValue2"], | ||
documentation: "docs" | ||
} | ||
}, | ||
rules: [ | ||
{ | ||
"documentation": "Template first array value into URI if set", | ||
"conditions": [ | ||
{ | ||
"fn": "getAttr", | ||
"argv": [ | ||
{ | ||
"ref": "stringArrayParam" | ||
}, | ||
"[0]" | ||
], | ||
"assign": "arrayValue" | ||
} | ||
], | ||
"endpoint": { | ||
"url": "https://example.com/{arrayValue}" | ||
}, | ||
"type": "endpoint" | ||
}, | ||
{ | ||
"conditions": [], | ||
"documentation": "error fallthrough", | ||
"error": "no array values set", | ||
"type": "error" | ||
} | ||
] | ||
}) | ||
@endpointTests({ | ||
"version": "1.0", | ||
"testCases": [ | ||
{ | ||
"documentation": "Default array values used" | ||
"params": {} | ||
"expect": { | ||
"endpoint": { | ||
"url": "https://example.com/defaultValue1" | ||
} | ||
}, | ||
"operationInputs": [ | ||
{ | ||
"operationName": "NoBindingsOperation", | ||
} | ||
] | ||
}, | ||
{ | ||
"documentation": "Empty array", | ||
"params": { | ||
"stringArrayParam": [] | ||
} | ||
"expect": { | ||
"error": "no array values set" | ||
}, | ||
"operationInputs": [ | ||
{ | ||
"operationName": "EmptyStaticContextOperation", | ||
} | ||
] | ||
}, | ||
{ | ||
"documentation": "Static value", | ||
"params": { | ||
"stringArrayParam": ["staticValue1"] | ||
} | ||
"expect": { | ||
"endpoint": { | ||
"url": "https://example.com/staticValue1" | ||
} | ||
}, | ||
"operationInputs": [ | ||
{ | ||
"operationName": "StaticContextOperation", | ||
} | ||
] | ||
}, | ||
{ | ||
"documentation": "bound value from input", | ||
"params": { | ||
"stringArrayParam": ["key1"] | ||
} | ||
"expect": { | ||
"endpoint": { | ||
"url": "https://example.com/key1" | ||
} | ||
}, | ||
"operationInputs": [ | ||
{ | ||
"operationName": "ListOfObjectsOperation", | ||
"operationParams": { | ||
"nested": { | ||
"listOfObjects": [{"key": "key1"}] | ||
} | ||
}, | ||
}, | ||
{ | ||
"operationName": "MapOperation", | ||
"operationParams": { | ||
"map": { | ||
"key1": "value1" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
}) | ||
@service(sdkId: "EndpointStringArray") | ||
@restJson1 | ||
service EndpointStringArray { | ||
version: "2022-01-01", | ||
operations: [ | ||
NoBindingsOperation, | ||
EmptyStaticContextOperation, | ||
StaticContextOperation, | ||
ListOfObjectsOperation, | ||
MapOperation | ||
] | ||
} | ||
|
||
@http(uri: "/1", method: "POST") | ||
operation NoBindingsOperation { | ||
input:= {} | ||
} | ||
|
||
@staticContextParams( | ||
"stringArrayParam": {value: []} | ||
) | ||
@http(uri: "/2", method: "POST") | ||
operation EmptyStaticContextOperation { | ||
input := {} | ||
} | ||
|
||
@staticContextParams( | ||
"stringArrayParam": {value: ["staticValue1"]} | ||
) | ||
@http(uri: "/3", method: "POST") | ||
operation StaticContextOperation { | ||
input := {} | ||
} | ||
|
||
@operationContextParams( | ||
"stringArrayParam": {path: "nested.listOfObjects[*].key"} | ||
) | ||
@http(uri: "/4", method: "POST") | ||
operation ListOfObjectsOperation { | ||
input:= { | ||
nested: Nested | ||
} | ||
} | ||
|
||
@operationContextParams( | ||
"stringArrayParam": {path: "keys(map)"} | ||
) | ||
@http(uri: "/5", method: "POST") | ||
operation MapOperation { | ||
input:= { | ||
map: Map | ||
} | ||
} | ||
|
||
structure Nested { | ||
listOfObjects: ListOfObjects | ||
} | ||
|
||
list ListOfObjects { | ||
member: ObjectMember | ||
} | ||
|
||
structure ObjectMember { | ||
key: String, | ||
} | ||
|
||
map Map { | ||
key: String, | ||
value: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.