@@ -21,86 +21,70 @@ model FunctionsError {
2121 message ? : string ;
2222}
2323
24- // Three response models cover the content types a function can return.
25- // Each @sharedRoute variant is paired with one response model; TypeSpec merges
26- // them into a single OpenAPI operation with multiple response content entries,
27- // which swift-openapi-generator maps to a Body enum with one case per type.
28- model JsonResponse {
24+ // A single response model covers all content types a function can return.
25+ // Using a variable contentType header alongside bytes makes TypeSpec emit
26+ // content-type */* in OpenAPI, which swift-openapi-generator maps to
27+ // case any(HTTPBody)
28+ // This is generic enough for JSON, binary, text, event-stream, etc.
29+ model FunctionResponse {
2930 @ statusCode statusCode : 200 ;
30- @ body body : unknown ;
31- }
32-
33- model OctetStreamResponse {
34- @ statusCode statusCode : 200 ;
35- @ header contentType : "application/octet-stream" ;
31+ @ header contentType : string ;
3632 @ body body : bytes ;
3733}
3834
39- model TextResponse {
40- @ statusCode statusCode : 200 ;
41- @ header contentType : "text/plain" ;
42- @ body body : string ;
43- }
44-
4535// ─── Operations ────────────────────────────────────────────────────────────
4636//
47- // TypeSpec, like Smithy, requires a fixed HTTP method per operation.
48- // FunctionsClient.invoke() dispatches to the appropriate generated method
49- // at runtime based on FunctionInvokeOptions.method.
50- //
51- // Advantage over Smithy: TypeSpec's interface groups these naturally vs
52- // Smithy's flat list at the service level.
37+ // Each HTTP method is a single operation. The request body uses a variable
38+ // contentType header + bytes, which TypeSpec emits as content-type */* in
39+ // OpenAPI → HTTPBody in Swift. Callers set the actual Content-Type header
40+ // via middleware when constructing the request.
5341//
5442// Known limitation: FunctionInvokeOptions.query (dynamic query params)
5543// cannot be modelled here — requires middleware URL-rewriting in each SDK.
56- //
57- // Each HTTP method is expressed as a group of @sharedRoute operations — one per
58- // supported request body content type — that TypeSpec merges into a single OpenAPI
59- // operation with multiple requestBody.content entries. swift-openapi-generator
60- // maps those to a Body enum with one case per content type:
61- // .json(OpenAPIValueContainer)
62- // .binary(HTTPBody)
63- // .plainText(String)
64- // .urlEncoded(String)
65- //
66- // The operationId override (@operationId) avoids the auto-generated
67- // concatenated name TypeSpec would otherwise produce for sharedRoute groups.
6844
6945@ route ("/functions/v1" )
7046interface FunctionInvocations {
71- // GET has no request body — functions called with GET pass params in the URL.
47+ // GET — no request body; params pass in the URL
7248 @ get
7349 @ route ("/{functionName}" )
7450 invokeGet (
7551 @ path functionName : string ,
7652 @ header ("x-region" ) region ? : string ,
77- ): OctetStreamResponse | FunctionsError ;
53+ ): FunctionResponse | FunctionsError ;
7854
79- // POST — one @sharedRoute variant per supported content type.
80- @ sharedRoute @ post @ route ("/{functionName}" ) @ operationId ("FunctionInvocations_invokePost" )
81- invokePostJson (@ path functionName : string , @ header ("x-region" ) region ? : string , @ body body ? : unknown ): JsonResponse | FunctionsError ;
82- @ sharedRoute @ post @ route ("/{functionName}" ) invokePostBinary (@ path functionName : string , @ header ("x-region" ) region ? : string , @ header contentType : "application/octet-stream" , @ body body ? : bytes ): OctetStreamResponse | FunctionsError ;
83- @ sharedRoute @ post @ route ("/{functionName}" ) invokePostText (@ path functionName : string , @ header ("x-region" ) region ? : string , @ header contentType : "text/plain" , @ body body ? : string ): TextResponse | FunctionsError ;
84- @ sharedRoute @ post @ route ("/{functionName}" ) invokePostForm (@ path functionName : string , @ header ("x-region" ) region ? : string , @ header contentType : "application/x-www-form-urlencoded" , @ body body ? : string ): JsonResponse | FunctionsError ;
55+ @ post
56+ @ route ("/{functionName}" )
57+ invokePost (
58+ @ path functionName : string ,
59+ @ header ("x-region" ) region ? : string ,
60+ @ header contentType : string ,
61+ @ body body ? : bytes ,
62+ ): FunctionResponse | FunctionsError ;
8563
86- // PUT
87- @ sharedRoute @ put @ route ("/{functionName}" ) @ operationId ("FunctionInvocations_invokePut" )
88- invokePutJson (@ path functionName : string , @ header ("x-region" ) region ? : string , @ body body ? : unknown ): JsonResponse | FunctionsError ;
89- @ sharedRoute @ put @ route ("/{functionName}" ) invokePutBinary (@ path functionName : string , @ header ("x-region" ) region ? : string , @ header contentType : "application/octet-stream" , @ body body ? : bytes ): OctetStreamResponse | FunctionsError ;
90- @ sharedRoute @ put @ route ("/{functionName}" ) invokePutText (@ path functionName : string , @ header ("x-region" ) region ? : string , @ header contentType : "text/plain" , @ body body ? : string ): TextResponse | FunctionsError ;
91- @ sharedRoute @ put @ route ("/{functionName}" ) invokePutForm (@ path functionName : string , @ header ("x-region" ) region ? : string , @ header contentType : "application/x-www-form-urlencoded" , @ body body ? : string ): JsonResponse | FunctionsError ;
64+ @ put
65+ @ route ("/{functionName}" )
66+ invokePut (
67+ @ path functionName : string ,
68+ @ header ("x-region" ) region ? : string ,
69+ @ header contentType : string ,
70+ @ body body ? : bytes ,
71+ ): FunctionResponse | FunctionsError ;
9272
93- // PATCH
94- @ sharedRoute @ patch @ route ("/{functionName}" ) @ operationId ("FunctionInvocations_invokePatch" )
95- invokePatchJson (@ path functionName : string , @ header ("x-region" ) region ? : string , @ body body ? : unknown ): JsonResponse | FunctionsError ;
96- @ sharedRoute @ patch @ route ("/{functionName}" ) invokePatchBinary (@ path functionName : string , @ header ("x-region" ) region ? : string , @ header contentType : "application/octet-stream" , @ body body ? : bytes ): OctetStreamResponse | FunctionsError ;
97- @ sharedRoute @ patch @ route ("/{functionName}" ) invokePatchText (@ path functionName : string , @ header ("x-region" ) region ? : string , @ header contentType : "text/plain" , @ body body ? : string ): TextResponse | FunctionsError ;
98- @ sharedRoute @ patch @ route ("/{functionName}" ) invokePatchForm (@ path functionName : string , @ header ("x-region" ) region ? : string , @ header contentType : "application/x-www-form-urlencoded" , @ body body ? : string ): JsonResponse | FunctionsError ;
73+ @ patch
74+ @ route ("/{functionName}" )
75+ invokePatch (
76+ @ path functionName : string ,
77+ @ header ("x-region" ) region ? : string ,
78+ @ header contentType : string ,
79+ @ body body ? : bytes ,
80+ ): FunctionResponse | FunctionsError ;
9981
100- // DELETE
101- @ sharedRoute @ delete @ route ("/{functionName}" ) @ operationId ("FunctionInvocations_invokeDelete" )
102- invokeDeleteJson (@ path functionName : string , @ header ("x-region" ) region ? : string , @ body body ? : unknown ): JsonResponse | FunctionsError ;
103- @ sharedRoute @ delete @ route ("/{functionName}" ) invokeDeleteBinary (@ path functionName : string , @ header ("x-region" ) region ? : string , @ header contentType : "application/octet-stream" , @ body body ? : bytes ): OctetStreamResponse | FunctionsError ;
104- @ sharedRoute @ delete @ route ("/{functionName}" ) invokeDeleteText (@ path functionName : string , @ header ("x-region" ) region ? : string , @ header contentType : "text/plain" , @ body body ? : string ): TextResponse | FunctionsError ;
105- @ sharedRoute @ delete @ route ("/{functionName}" ) invokeDeleteForm (@ path functionName : string , @ header ("x-region" ) region ? : string , @ header contentType : "application/x-www-form-urlencoded" , @ body body ? : string ): JsonResponse | FunctionsError ;
82+ @ delete
83+ @ route ("/{functionName}" )
84+ invokeDelete (
85+ @ path functionName : string ,
86+ @ header ("x-region" ) region ? : string ,
87+ @ header contentType : string ,
88+ @ body body ? : bytes ,
89+ ): FunctionResponse | FunctionsError ;
10690}
0 commit comments