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

Revisit our user experience for allow customer to set contentType in Modular

Open qiaozha opened this issue 1 year ago • 6 comments

https://github.com/Azure/azure-sdk-for-js/pull/27343#discussion_r1471731162

Current RLC experience:

  1. with contentType
      const result = await client.path(somepath, pathParam).put({
        body: {...bodyContent },
        contentType: "application/json"
      });
  1. with headers
      const result = await client.path(somepath, pathParam).put({
        body: {...bodyContent },
        headers: { "content-type": "application/json" }
      });

Current Modular experience:

  1. 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"
           }
        }
      });

qiaozha avatar Jan 31 '24 08:01 qiaozha

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.

jeremymeng avatar Jan 31 '24 17:01 jeremymeng

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

qiaozha avatar Feb 01 '24 02:02 qiaozha

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

jeremymeng avatar Feb 01 '24 03:02 jeremymeng

I updated the user experience in the PR description, I would say, it's an option but not sure ?

qiaozha avatar Feb 01 '24 03:02 qiaozha

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?

jeremymeng avatar Feb 01 '24 17:02 jeremymeng

the only difference is customHeader and header between HLC and Modular.

qiaozha avatar Feb 21 '24 07:02 qiaozha