@@ -14,6 +14,7 @@ import type {
1414 SerdeFunctions ,
1515 ShapeDeserializer ,
1616 ShapeSerializer ,
17+ StaticStructureSchema ,
1718 StringSchema ,
1819 TimestampDefaultSchema ,
1920 TimestampEpochSecondsSchema ,
@@ -206,4 +207,41 @@ describe(HttpBindingProtocol.name, () => {
206207 header : "header-value" ,
207208 } ) ;
208209 } ) ;
210+
211+ it ( "should fill in undefined idempotency tokens" , async ( ) => {
212+ const protocol = new StringRestProtocol ( ) ;
213+ const request = await protocol . serializeRequest (
214+ op (
215+ "" ,
216+ "" ,
217+ {
218+ http : [ "GET" , "/{labelToken}/Operation" , 200 ] ,
219+ } ,
220+ [
221+ 3 ,
222+ "ns" ,
223+ "Struct" ,
224+ 0 ,
225+ [ "name" , "queryToken" , "labelToken" , "headerToken" ] ,
226+ [
227+ 0 ,
228+ [ 0 , { idempotencyToken : 1 , httpQuery : "token" } ] ,
229+ [ 0 , { idempotencyToken : 1 , httpLabel : 1 } ] ,
230+ [ 0 , { idempotencyToken : 1 , httpHeader : "header-token" } ] ,
231+ ] ,
232+ ] satisfies StaticStructureSchema ,
233+ "unit"
234+ ) ,
235+ {
236+ Name : "my-name" ,
237+ } ,
238+ {
239+ endpoint : async ( ) => parseUrl ( "https://localhost/custom" ) ,
240+ } as any
241+ ) ;
242+
243+ expect ( request . query ?. token ) . toMatch ( / ^ [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 12 } $ / ) ;
244+ expect ( request . path ) . toMatch ( / [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 12 } / ) ;
245+ expect ( request . headers ?. [ "header-token" ] ) . toMatch ( / ^ [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 12 } $ / ) ;
246+ } ) ;
209247} ) ;
0 commit comments