Skip to content

Commit 9099825

Browse files
Fix optional Content-Type header detection by unifying parameter processing (#9528)
- [x] Understand the issue: The previous fix in PR #9495 added Content-Type header detection in `type-converter.ts`, but it relies on `sdkProperty` being passed to `fromSdkType`. The `fromHeaderParameter` function in `operation-converter.ts` doesn't pass the header parameter to `fromSdkType`, so the fix doesn't work. - [x] Fix `fromHeaderParameter` to pass the header parameter `p` to `fromSdkType` so the Content-Type detection can work - [x] Unify all parameter-processing functions to pass property instance to `fromSdkType`: - `fromQueryParameter` - `fromPathParameter` - `fromHeaderParameter` - `fromBodyParameter` - `updateMethodParameter` - [x] Investigated making `sdkProperty` required - not feasible as many callers have no property context (model base types, array/dict value types, etc.) - [x] Run existing tests to verify the fix works (all 177 tests pass) - [x] Fix CI formatting issues - [x] Run code review and security checks <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Fix optional contentType issue</issue_title> > <issue_description>As described in Azure/azure-sdk-for-net#55300, but the issue belongs in this repo.</issue_description> > > <agent_instructions>The previous [fix ](#9495) does not really fix the issue entirely. > Please fix this again following the root cause in this comment: https://github.com/microsoft/typespec/issues/9494#issuecomment-3822513806</agent_instructions> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > <comment_new><author>@ArcturusZhang</author><body> > I think this is not fixed. > The fix introduced an extra check to see if it is a content type header, by checking if the `sdkProperty` is not undefined, but in our code, when the `fromSdkType` is called converting the method parameters (for instance [here](https://github.com/microsoft/typespec/blob/f1a7649b3b53ab7d30488cf7274f813696cdf2d0/packages/http-client-csharp/emitter/src/lib/operation-converter.ts#L482)), the `sdkProperty` argument is never passed in. Therefore the fix is not actually running.</body></comment_new> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #9494 <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ArcturusZhang <10554446+ArcturusZhang@users.noreply.github.com>
1 parent f1a7649 commit 9099825

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

packages/http-client-csharp/emitter/src/lib/operation-converter.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,11 @@ function updateMethodParameter(
327327
if (methodParameter.location === RequestLocation.Body) {
328328
// Convert constants to enums
329329
if (methodParameter.type.kind === "constant") {
330-
methodParameter.type = fromSdkType(sdkContext, operationHttpParameter.type);
330+
methodParameter.type = fromSdkType(
331+
sdkContext,
332+
operationHttpParameter.type,
333+
operationHttpParameter,
334+
);
331335
}
332336
}
333337
}
@@ -419,7 +423,7 @@ function fromQueryParameter(
419423
p: SdkQueryParameter,
420424
rootApiVersions: string[],
421425
): InputQueryParameter {
422-
const parameterType = fromSdkType(sdkContext, p.type);
426+
const parameterType = fromSdkType(sdkContext, p.type, p);
423427

424428
const retVar: InputQueryParameter = {
425429
kind: "query",
@@ -448,7 +452,7 @@ function fromPathParameter(
448452
p: SdkPathParameter,
449453
rootApiVersions: string[],
450454
): InputPathParameter {
451-
const parameterType = fromSdkType(sdkContext, p.type);
455+
const parameterType = fromSdkType(sdkContext, p.type, p);
452456

453457
const retVar: InputPathParameter = {
454458
kind: "path",
@@ -479,7 +483,7 @@ function fromHeaderParameter(
479483
p: SdkHeaderParameter,
480484
rootApiVersions: string[],
481485
): InputHeaderParameter {
482-
const parameterType = fromSdkType(sdkContext, p.type);
486+
const parameterType = fromSdkType(sdkContext, p.type, p);
483487

484488
const retVar: InputHeaderParameter = {
485489
kind: "header",
@@ -509,7 +513,7 @@ function fromBodyParameter(
509513
p: SdkBodyParameter,
510514
rootApiVersions: string[],
511515
): InputBodyParameter {
512-
const parameterType = fromSdkType(sdkContext, p.type);
516+
const parameterType = fromSdkType(sdkContext, p.type, p);
513517

514518
const retVar: InputBodyParameter = {
515519
kind: "body",

0 commit comments

Comments
 (0)