autorest.typescript
autorest.typescript copied to clipboard
Revisit our user experience for allow customer to set contentType in Modular
https://github.com/Azure/azure-sdk-for-js/pull/27343#discussion_r1471731162
Current RLC experience:
- with contentType
const result = await client.path(somepath, pathParam).put({
body: {...bodyContent },
contentType: "application/json"
});
- with headers
const result = await client.path(somepath, pathParam).put({
body: {...bodyContent },
headers: { "content-type": "application/json" }
});
Current Modular experience:
- with options.contentType
const user = await client.createOrReplace(pathParam, { ...bodyContent }, {
contentType: "application/json"
});
Currently this approach only work when the operation default contentType is not application/json
2. requestOptions.headers
const user = await client.createOrReplace(pathParam, { ...bodyContent }, {
requestOptions: {
headers: {
"content-type": "application/json"
}
}
});
Current HLC experience
const user = await client.createOrReplace(pathParam, { ...bodyContent }, {
requestOptions: {
customHeaders: {
"content-type": "application/json"
}
}
});
If we add it to contentType?: string to OperationRequestOptions, then we don't need to extend OperationOptions anymore? https://github.com/Azure/autorest.typescript/blob/fd3b2301af53644b7902ad001a5d7b54fac8d925/packages/typespec-ts/test/modularIntegration/generated/azure/core/src/models/options.ts#L9
or maybe there's a reason that this would not work but I am not aware of.
You mean to extend from OperationRequestOptions instead ? I think the reason we have to extend from OperationOptions is that we allow those in current track2 SDK. And we don't want to break our customers for that when they migrate from track2 to Modular.
The OperationOptions in @azure/core-client https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-client/src/interfaces.ts#L98-L122
The track2 SDK operation options extends from coreClient.OperationOptions https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/apicenter/arm-apicenter/src/models/index.ts#L340-L341
You mean to extend from OperationRequestOptions instead ? I think the reason we have to extend from OperationOptions
No, we could still extends OperationOptions in code gen. What I mean is that if contentType?: string is added to OperationRequestOptions then it would be available via OperationOptions.requestOptions?.contentType which is optional
I updated the user experience in the PR description, I would say, it's an option but not sure ?
I see, we want to keep some of current customer experiences of specifying contentType in options. It feels that specifying it via headers would mostly work, but not as convenient as using options?
the only difference is customHeader and header between HLC and Modular.