Skip to content

Commit 0180714

Browse files
Fix the constant vs enum issue in content-type parameter (#9568)
Fixes #9566
1 parent 6f8fd46 commit 0180714

14 files changed

Lines changed: 66 additions & 50 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,14 @@ function updateMethodParameter(
317317
operationHttpParameter: SdkHttpParameter | SdkModelPropertyType,
318318
rootApiVersions: string[],
319319
): void {
320+
// for content type parameter
321+
if (isContentType(operationHttpParameter)) {
322+
methodParameter.type = fromSdkType(
323+
sdkContext,
324+
operationHttpParameter.type,
325+
operationHttpParameter,
326+
);
327+
}
320328
methodParameter.serializedName = getNameInRequest(operationHttpParameter);
321329
methodParameter.location = getParameterLocation(operationHttpParameter);
322330
methodParameter.scope = getParameterScope(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ function createEnumType(
307307
crossLanguageDefinitionId: sdkType.kind === "enum" ? sdkType.crossLanguageDefinitionId : "",
308308
valueType:
309309
sdkType.kind === "enum"
310-
? (fromSdkType(sdkContext, sdkType.valueType) as InputPrimitiveType)
310+
? fromSdkType(sdkContext, sdkType.valueType)
311311
: fromSdkBuiltInType(sdkContext, sdkType.valueType),
312312
values: values,
313313
// constantType.access, TODO - constant type now does not have access. TCGC will add it later

packages/http-client-csharp/emitter/test/Unit/operation-converter.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,14 @@ describe("Operation Converter", () => {
390390
const method = root.clients[0].methods[0];
391391
ok(method);
392392

393+
const contentTypeMethodParam = method.parameters.find((p) => p.name === "contentType");
394+
ok(contentTypeMethodParam, "Content-Type parameter should exist in service method");
395+
strictEqual(
396+
contentTypeMethodParam.type.kind,
397+
"constant",
398+
"Content-type should remain a constant type, not transformed to enum",
399+
);
400+
393401
// validate operation
394402
const operation = method.operation;
395403
ok(operation);

packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/tspCodeModel.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4717,7 +4717,7 @@
47174717
"name": "contentType",
47184718
"serializedName": "Content-Type",
47194719
"type": {
4720-
"$ref": "90"
4720+
"$ref": "86"
47214721
},
47224722
"location": "Header",
47234723
"isApiVersion": false,

packages/http-client-csharp/generator/TestProjects/Spector/http/encode/bytes/tspCodeModel.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,7 +2278,7 @@
22782278
"name": "contentType",
22792279
"serializedName": "Content-Type",
22802280
"type": {
2281-
"$ref": "21"
2281+
"$ref": "19"
22822282
},
22832283
"location": "Header",
22842284
"isApiVersion": false,
@@ -2398,7 +2398,7 @@
23982398
"name": "contentType",
23992399
"serializedName": "Content-Type",
24002400
"type": {
2401-
"$ref": "25"
2401+
"$ref": "23"
24022402
},
24032403
"location": "Header",
24042404
"isApiVersion": false,
@@ -2519,7 +2519,7 @@
25192519
"name": "contentType",
25202520
"serializedName": "Content-Type",
25212521
"type": {
2522-
"$ref": "29"
2522+
"$ref": "27"
25232523
},
25242524
"location": "Header",
25252525
"isApiVersion": false,
@@ -2641,7 +2641,7 @@
26412641
"name": "contentType",
26422642
"serializedName": "Content-Type",
26432643
"type": {
2644-
"$ref": "33"
2644+
"$ref": "31"
26452645
},
26462646
"location": "Header",
26472647
"isApiVersion": false,

packages/http-client-csharp/generator/TestProjects/Spector/http/payload/json-merge-patch/tspCodeModel.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@
876876
"name": "contentType",
877877
"serializedName": "Content-Type",
878878
"type": {
879-
"$ref": "9"
879+
"$ref": "5"
880880
},
881881
"location": "Header",
882882
"isApiVersion": false,
@@ -1033,7 +1033,7 @@
10331033
"name": "contentType",
10341034
"serializedName": "Content-Type",
10351035
"type": {
1036-
"$ref": "15"
1036+
"$ref": "11"
10371037
},
10381038
"location": "Header",
10391039
"isApiVersion": false,

packages/http-client-csharp/generator/TestProjects/Spector/http/payload/media-type/tspCodeModel.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@
265265
"name": "contentType",
266266
"serializedName": "Content-Type",
267267
"type": {
268-
"$ref": "3"
268+
"$ref": "1"
269269
},
270270
"location": "Header",
271271
"isApiVersion": false,
@@ -480,7 +480,7 @@
480480
"name": "contentType",
481481
"serializedName": "Content-Type",
482482
"type": {
483-
"$ref": "11"
483+
"$ref": "9"
484484
},
485485
"location": "Header",
486486
"isApiVersion": false,

packages/http-client-csharp/generator/TestProjects/Spector/http/payload/multipart/tspCodeModel.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,7 +2084,7 @@
20842084
"name": "contentType",
20852085
"serializedName": "Content-Type",
20862086
"type": {
2087-
"$ref": "5"
2087+
"$ref": "3"
20882088
},
20892089
"location": "Header",
20902090
"isApiVersion": false,
@@ -2198,7 +2198,7 @@
21982198
"name": "contentType",
21992199
"serializedName": "Content-Type",
22002200
"type": {
2201-
"$ref": "9"
2201+
"$ref": "7"
22022202
},
22032203
"location": "Header",
22042204
"isApiVersion": false,
@@ -2312,7 +2312,7 @@
23122312
"name": "contentType",
23132313
"serializedName": "Content-Type",
23142314
"type": {
2315-
"$ref": "13"
2315+
"$ref": "11"
23162316
},
23172317
"location": "Header",
23182318
"isApiVersion": false,
@@ -2426,7 +2426,7 @@
24262426
"name": "contentType",
24272427
"serializedName": "Content-Type",
24282428
"type": {
2429-
"$ref": "17"
2429+
"$ref": "15"
24302430
},
24312431
"location": "Header",
24322432
"isApiVersion": false,
@@ -2540,7 +2540,7 @@
25402540
"name": "contentType",
25412541
"serializedName": "Content-Type",
25422542
"type": {
2543-
"$ref": "21"
2543+
"$ref": "19"
25442544
},
25452545
"location": "Header",
25462546
"isApiVersion": false,
@@ -2654,7 +2654,7 @@
26542654
"name": "contentType",
26552655
"serializedName": "Content-Type",
26562656
"type": {
2657-
"$ref": "25"
2657+
"$ref": "23"
26582658
},
26592659
"location": "Header",
26602660
"isApiVersion": false,
@@ -2768,7 +2768,7 @@
27682768
"name": "contentType",
27692769
"serializedName": "Content-Type",
27702770
"type": {
2771-
"$ref": "29"
2771+
"$ref": "27"
27722772
},
27732773
"location": "Header",
27742774
"isApiVersion": false,
@@ -2882,7 +2882,7 @@
28822882
"name": "contentType",
28832883
"serializedName": "Content-Type",
28842884
"type": {
2885-
"$ref": "33"
2885+
"$ref": "31"
28862886
},
28872887
"location": "Header",
28882888
"isApiVersion": false,
@@ -2996,7 +2996,7 @@
29962996
"name": "contentType",
29972997
"serializedName": "Content-Type",
29982998
"type": {
2999-
"$ref": "37"
2999+
"$ref": "35"
30003000
},
30013001
"location": "Header",
30023002
"isApiVersion": false,
@@ -3157,7 +3157,7 @@
31573157
"name": "contentType",
31583158
"serializedName": "Content-Type",
31593159
"type": {
3160-
"$ref": "41"
3160+
"$ref": "39"
31613161
},
31623162
"location": "Header",
31633163
"isApiVersion": false,
@@ -3318,7 +3318,7 @@
33183318
"name": "contentType",
33193319
"serializedName": "Content-Type",
33203320
"type": {
3321-
"$ref": "45"
3321+
"$ref": "43"
33223322
},
33233323
"location": "Header",
33243324
"isApiVersion": false,
@@ -3432,7 +3432,7 @@
34323432
"name": "contentType",
34333433
"serializedName": "Content-Type",
34343434
"type": {
3435-
"$ref": "49"
3435+
"$ref": "47"
34363436
},
34373437
"location": "Header",
34383438
"isApiVersion": false,
@@ -3546,7 +3546,7 @@
35463546
"name": "contentType",
35473547
"serializedName": "Content-Type",
35483548
"type": {
3549-
"$ref": "53"
3549+
"$ref": "51"
35503550
},
35513551
"location": "Header",
35523552
"isApiVersion": false,
@@ -3708,7 +3708,7 @@
37083708
"name": "contentType",
37093709
"serializedName": "Content-Type",
37103710
"type": {
3711-
"$ref": "57"
3711+
"$ref": "55"
37123712
},
37133713
"location": "Header",
37143714
"isApiVersion": false,

packages/http-client-csharp/generator/TestProjects/Spector/http/type/enum/extensible/tspCodeModel.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@
562562
"name": "contentType",
563563
"serializedName": "Content-Type",
564564
"type": {
565-
"$ref": "20"
565+
"$ref": "18"
566566
},
567567
"location": "Header",
568568
"isApiVersion": false,
@@ -674,7 +674,7 @@
674674
"name": "contentType",
675675
"serializedName": "Content-Type",
676676
"type": {
677-
"$ref": "24"
677+
"$ref": "22"
678678
},
679679
"location": "Header",
680680
"isApiVersion": false,

packages/http-client-csharp/generator/TestProjects/Spector/http/type/enum/fixed/tspCodeModel.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@
444444
"name": "contentType",
445445
"serializedName": "Content-Type",
446446
"type": {
447-
"$ref": "16"
447+
"$ref": "14"
448448
},
449449
"location": "Header",
450450
"isApiVersion": false,
@@ -560,7 +560,7 @@
560560
"name": "contentType",
561561
"serializedName": "Content-Type",
562562
"type": {
563-
"$ref": "20"
563+
"$ref": "18"
564564
},
565565
"location": "Header",
566566
"isApiVersion": false,

0 commit comments

Comments
 (0)