autorest.typescript icon indicating copy to clipboard operation
autorest.typescript copied to clipboard

Client parameters not usable for headers or body

Open ProTip opened this issue 1 year ago • 2 comments
trafficstars

Global parameters under #/components/parameters are meant to be reusable between endpoints via references. Autorest states that these are created as properties on the client for this purpose.

They are for TypeScript, however these parameters are only used useable in the path or query. Client-Core does not resolve these properties before invoking the pipeline and the serializer policy does not have access to or use the client as a fallback object when serializing the headers or body:

https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-client/src/serializationPolicy.ts#L75

The result is the global properties values are never used for the header or body, and an error will be thrown if they were required.

This seems like a bug in client-core however that repo seems more focused on SDK bugs..

ProTip avatar Jan 26 '24 06:01 ProTip

@xirzec @joheredi I think this is related to complex object type parameters being used in path and query, do you think we should support this in the ts emitter at least ? There's a similar ask from another customer before https://github.com/Azure/autorest.typescript/issues/2071

qiaozha avatar Jan 31 '24 09:01 qiaozha

I'm currently working around this by subclassing the generated client and injecting the client parameters into the options object.

ProTip avatar Jan 31 '24 18:01 ProTip