Skip to content

Commit 24094a6

Browse files
authored
Always fall back to wire name for json serialization (#5390)
* always fall back to wire name for json serialization * regen
1 parent fee084d commit 24094a6

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

src/TypeSpec.Extension/Emitter.Csharp/src/mtgEmitter/lib/type-converter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ function fromSdkModelProperty(
227227
const serializedName =
228228
sdkProperty.serializationOptions?.json?.name ??
229229
sdkProperty.serializationOptions?.xml?.name ??
230-
sdkProperty.serializationOptions?.multipart?.name;
230+
sdkProperty.serializationOptions?.multipart?.name ??
231+
sdkProperty.__raw?.name; // we always fall back to wire name for json serialization
231232
property = {
232233
kind: isHttpMetadata(sdkContext, sdkProperty)
233234
? "header"

test/CadlRanchProjects/payload/multipart/tspCodeModel.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,7 @@
10481048
"$id": "95",
10491049
"kind": "property",
10501050
"name": "contentType",
1051+
"serializedName": "contentType",
10511052
"summary": "The allowed media (MIME) types of the file contents.",
10521053
"doc": "The allowed media (MIME) types of the file contents.\n\nIn file bodies, this value comes from the `Content-Type` header of the request or response. In JSON bodies,\nthis value is serialized as a field in the response.\n\nNOTE: this is not _necessarily_ the same as the `Content-Type` header of the request or response, but\nit will be for file bodies. It may be different if the file is serialized as a JSON object. It always refers to the\n_contents_ of the file, and not necessarily the way the file itself is transmitted or serialized.",
10531054
"type": {
@@ -1070,6 +1071,7 @@
10701071
"$id": "97",
10711072
"kind": "property",
10721073
"name": "filename",
1074+
"serializedName": "filename",
10731075
"summary": "The name of the file, if any.",
10741076
"doc": "The name of the file, if any.\n\nIn file bodies, this value comes from the `filename` parameter of the `Content-Disposition` header of the response\nor multipart payload. In JSON bodies, this value is serialized as a field in the response.\n\nNOTE: By default, `filename` cannot be sent in request payloads and can only be sent in responses and multipart\npayloads, as the `Content-Disposition` header is not valid in requests. If you want to send the `filename` in a request,\nyou must extend the `File` model and override the `filename` property with a different location defined by HTTP metadata\ndecorators.",
10751077
"type": {
@@ -1092,6 +1094,7 @@
10921094
"$id": "99",
10931095
"kind": "property",
10941096
"name": "contents",
1097+
"serializedName": "contents",
10951098
"summary": "The contents of the file.",
10961099
"doc": "The contents of the file.\n\nIn file bodies, this value comes from the body of the request, response, or multipart payload. In JSON bodies,\nthis value is serialized as a field in the response.",
10971100
"type": {
@@ -1118,6 +1121,7 @@
11181121
"$id": "101",
11191122
"kind": "property",
11201123
"name": "filename",
1124+
"serializedName": "filename",
11211125
"type": {
11221126
"$id": "102",
11231127
"kind": "string",
@@ -1138,6 +1142,7 @@
11381142
"$id": "103",
11391143
"kind": "property",
11401144
"name": "contentType",
1145+
"serializedName": "contentType",
11411146
"type": {
11421147
"$id": "104",
11431148
"kind": "string",
@@ -1353,6 +1358,7 @@
13531358
"$id": "116",
13541359
"kind": "property",
13551360
"name": "filename",
1361+
"serializedName": "filename",
13561362
"type": {
13571363
"$id": "117",
13581364
"kind": "string",
@@ -1373,6 +1379,7 @@
13731379
"$id": "118",
13741380
"kind": "property",
13751381
"name": "contentType",
1382+
"serializedName": "contentType",
13761383
"type": {
13771384
"$ref": "4"
13781385
},
@@ -1559,6 +1566,7 @@
15591566
"$id": "129",
15601567
"kind": "property",
15611568
"name": "filename",
1569+
"serializedName": "filename",
15621570
"type": {
15631571
"$id": "130",
15641572
"kind": "string",

test/CadlRanchProjectsNonAzure/payload/multipart/tspCodeModel.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,7 @@
10481048
"$id": "95",
10491049
"kind": "property",
10501050
"name": "contentType",
1051+
"serializedName": "contentType",
10511052
"summary": "The allowed media (MIME) types of the file contents.",
10521053
"doc": "The allowed media (MIME) types of the file contents.\n\nIn file bodies, this value comes from the `Content-Type` header of the request or response. In JSON bodies,\nthis value is serialized as a field in the response.\n\nNOTE: this is not _necessarily_ the same as the `Content-Type` header of the request or response, but\nit will be for file bodies. It may be different if the file is serialized as a JSON object. It always refers to the\n_contents_ of the file, and not necessarily the way the file itself is transmitted or serialized.",
10531054
"type": {
@@ -1070,6 +1071,7 @@
10701071
"$id": "97",
10711072
"kind": "property",
10721073
"name": "filename",
1074+
"serializedName": "filename",
10731075
"summary": "The name of the file, if any.",
10741076
"doc": "The name of the file, if any.\n\nIn file bodies, this value comes from the `filename` parameter of the `Content-Disposition` header of the response\nor multipart payload. In JSON bodies, this value is serialized as a field in the response.\n\nNOTE: By default, `filename` cannot be sent in request payloads and can only be sent in responses and multipart\npayloads, as the `Content-Disposition` header is not valid in requests. If you want to send the `filename` in a request,\nyou must extend the `File` model and override the `filename` property with a different location defined by HTTP metadata\ndecorators.",
10751077
"type": {
@@ -1092,6 +1094,7 @@
10921094
"$id": "99",
10931095
"kind": "property",
10941096
"name": "contents",
1097+
"serializedName": "contents",
10951098
"summary": "The contents of the file.",
10961099
"doc": "The contents of the file.\n\nIn file bodies, this value comes from the body of the request, response, or multipart payload. In JSON bodies,\nthis value is serialized as a field in the response.",
10971100
"type": {
@@ -1118,6 +1121,7 @@
11181121
"$id": "101",
11191122
"kind": "property",
11201123
"name": "filename",
1124+
"serializedName": "filename",
11211125
"type": {
11221126
"$id": "102",
11231127
"kind": "string",
@@ -1138,6 +1142,7 @@
11381142
"$id": "103",
11391143
"kind": "property",
11401144
"name": "contentType",
1145+
"serializedName": "contentType",
11411146
"type": {
11421147
"$id": "104",
11431148
"kind": "string",
@@ -1353,6 +1358,7 @@
13531358
"$id": "116",
13541359
"kind": "property",
13551360
"name": "filename",
1361+
"serializedName": "filename",
13561362
"type": {
13571363
"$id": "117",
13581364
"kind": "string",
@@ -1373,6 +1379,7 @@
13731379
"$id": "118",
13741380
"kind": "property",
13751381
"name": "contentType",
1382+
"serializedName": "contentType",
13761383
"type": {
13771384
"$ref": "4"
13781385
},
@@ -1559,6 +1566,7 @@
15591566
"$id": "129",
15601567
"kind": "property",
15611568
"name": "filename",
1569+
"serializedName": "filename",
15621570
"type": {
15631571
"$id": "130",
15641572
"kind": "string",

test/TestProjects/Authoring-TypeSpec/tspCodeModel.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,7 @@
14961496
"$id": "132",
14971497
"kind": "property",
14981498
"name": "projectName",
1499+
"serializedName": "projectName",
14991500
"type": {
15001501
"$id": "133",
15011502
"kind": "string",
@@ -1516,6 +1517,7 @@
15161517
"$id": "134",
15171518
"kind": "property",
15181519
"name": "projectKind",
1520+
"serializedName": "projectKind",
15191521
"doc": "The project kind.",
15201522
"type": {
15211523
"$ref": "13"
@@ -1533,6 +1535,7 @@
15331535
"$id": "135",
15341536
"kind": "property",
15351537
"name": "storageInputContainerName",
1538+
"serializedName": "storageInputContainerName",
15361539
"doc": "The storage container name.",
15371540
"type": {
15381541
"$id": "136",
@@ -1554,6 +1557,7 @@
15541557
"$id": "137",
15551558
"kind": "property",
15561559
"name": "settings",
1560+
"serializedName": "settings",
15571561
"doc": "The project settings.",
15581562
"type": {
15591563
"$id": "138",
@@ -1586,6 +1590,7 @@
15861590
"$id": "140",
15871591
"kind": "property",
15881592
"name": "multilingual",
1593+
"serializedName": "multilingual",
15891594
"doc": "Whether the project would be used for multiple languages or not.",
15901595
"type": {
15911596
"$id": "141",
@@ -1607,6 +1612,7 @@
16071612
"$id": "142",
16081613
"kind": "property",
16091614
"name": "description",
1615+
"serializedName": "description",
16101616
"doc": "The project description.",
16111617
"type": {
16121618
"$id": "143",
@@ -1628,6 +1634,7 @@
16281634
"$id": "144",
16291635
"kind": "property",
16301636
"name": "language",
1637+
"serializedName": "language",
16311638
"doc": "The project language. This is BCP-47 representation of a language. For example, use \"en\" for English, \"en-gb\" for English (UK), \"es\" for Spanish etc.",
16321639
"type": {
16331640
"$id": "145",
@@ -1649,6 +1656,7 @@
16491656
"$id": "146",
16501657
"kind": "property",
16511658
"name": "createdDateTime",
1659+
"serializedName": "createdDateTime",
16521660
"doc": "Represents the project creation datetime.",
16531661
"type": {
16541662
"$id": "147",
@@ -1678,6 +1686,7 @@
16781686
"$id": "149",
16791687
"kind": "property",
16801688
"name": "lastModifiedDateTime",
1689+
"serializedName": "lastModifiedDateTime",
16811690
"doc": "Represents the project last modification datetime.",
16821691
"type": {
16831692
"$id": "150",
@@ -1707,6 +1716,7 @@
17071716
"$id": "152",
17081717
"kind": "property",
17091718
"name": "lastTrainedDateTime",
1719+
"serializedName": "lastTrainedDateTime",
17101720
"doc": "Represents the project last training datetime.",
17111721
"type": {
17121722
"$id": "153",
@@ -1736,6 +1746,7 @@
17361746
"$id": "155",
17371747
"kind": "property",
17381748
"name": "lastDeployedDateTime",
1749+
"serializedName": "lastDeployedDateTime",
17391750
"doc": "Represents the project last deployment datetime.",
17401751
"type": {
17411752
"$id": "156",
@@ -1780,6 +1791,7 @@
17801791
"$id": "159",
17811792
"kind": "property",
17821793
"name": "id",
1794+
"serializedName": "id",
17831795
"doc": "The unique ID of the operation.",
17841796
"type": {
17851797
"$id": "160",
@@ -1801,6 +1813,7 @@
18011813
"$id": "161",
18021814
"kind": "property",
18031815
"name": "status",
1816+
"serializedName": "status",
18041817
"doc": "The status of the operation",
18051818
"type": {
18061819
"$ref": "18"
@@ -1818,6 +1831,7 @@
18181831
"$id": "162",
18191832
"kind": "property",
18201833
"name": "error",
1834+
"serializedName": "error",
18211835
"doc": "Error object that describes the error when status is \"Failed\".",
18221836
"type": {
18231837
"$ref": "75"
@@ -1847,6 +1861,7 @@
18471861
"$id": "164",
18481862
"kind": "property",
18491863
"name": "value",
1864+
"serializedName": "value",
18501865
"doc": "The Project items on this page",
18511866
"type": {
18521867
"$id": "165",
@@ -1871,6 +1886,7 @@
18711886
"$id": "166",
18721887
"kind": "property",
18731888
"name": "nextLink",
1889+
"serializedName": "nextLink",
18741890
"doc": "The link to the next page of items",
18751891
"type": {
18761892
"$id": "167",
@@ -1911,6 +1927,7 @@
19111927
"$id": "170",
19121928
"kind": "property",
19131929
"name": "modelLabel",
1930+
"serializedName": "modelLabel",
19141931
"type": {
19151932
"$id": "171",
19161933
"kind": "string",
@@ -1942,6 +1959,7 @@
19421959
"$id": "173",
19431960
"kind": "property",
19441961
"name": "name",
1962+
"serializedName": "name",
19451963
"type": {
19461964
"$id": "174",
19471965
"kind": "string",
@@ -1974,6 +1992,7 @@
19741992
"$id": "176",
19751993
"kind": "property",
19761994
"name": "value",
1995+
"serializedName": "value",
19771996
"doc": "The Deployment items on this page",
19781997
"type": {
19791998
"$id": "177",
@@ -1998,6 +2017,7 @@
19982017
"$id": "178",
19992018
"kind": "property",
20002019
"name": "nextLink",
2020+
"serializedName": "nextLink",
20012021
"doc": "The link to the next page of items",
20022022
"type": {
20032023
"$id": "179",
@@ -2037,6 +2057,7 @@
20372057
"$id": "182",
20382058
"kind": "property",
20392059
"name": "firstDeploymentName",
2060+
"serializedName": "firstDeploymentName",
20402061
"doc": "Represents the first deployment name.",
20412062
"type": {
20422063
"$id": "183",
@@ -2058,6 +2079,7 @@
20582079
"$id": "184",
20592080
"kind": "property",
20602081
"name": "secondDeploymentName",
2082+
"serializedName": "secondDeploymentName",
20612083
"doc": "Represents the second deployment name.",
20622084
"type": {
20632085
"$id": "185",
@@ -2091,6 +2113,7 @@
20912113
"$id": "187",
20922114
"kind": "property",
20932115
"name": "value",
2116+
"serializedName": "value",
20942117
"doc": "The SupportedLanguage items on this page",
20952118
"type": {
20962119
"$id": "188",
@@ -2110,6 +2133,7 @@
21102133
"$id": "190",
21112134
"kind": "property",
21122135
"name": "languageName",
2136+
"serializedName": "languageName",
21132137
"doc": "The language name.",
21142138
"type": {
21152139
"$id": "191",
@@ -2131,6 +2155,7 @@
21312155
"$id": "192",
21322156
"kind": "property",
21332157
"name": "languageCode",
2158+
"serializedName": "languageCode",
21342159
"doc": "The language code. This is BCP-47 representation of a language. For example, \"en\" for English, \"en-gb\" for English (UK), \"es\" for Spanish etc.",
21352160
"type": {
21362161
"$id": "193",
@@ -2166,6 +2191,7 @@
21662191
"$id": "194",
21672192
"kind": "property",
21682193
"name": "nextLink",
2194+
"serializedName": "nextLink",
21692195
"doc": "The link to the next page of items",
21702196
"type": {
21712197
"$id": "195",
@@ -2209,6 +2235,7 @@
22092235
"$id": "198",
22102236
"kind": "property",
22112237
"name": "value",
2238+
"serializedName": "value",
22122239
"doc": "The TrainingConfigVersion items on this page",
22132240
"type": {
22142241
"$id": "199",
@@ -2228,6 +2255,7 @@
22282255
"$id": "201",
22292256
"kind": "property",
22302257
"name": "trainingConfigVersionStr",
2258+
"serializedName": "trainingConfigVersionStr",
22312259
"doc": "Represents the version of the config.",
22322260
"type": {
22332261
"$id": "202",
@@ -2249,6 +2277,7 @@
22492277
"$id": "203",
22502278
"kind": "property",
22512279
"name": "modelExpirationDate",
2280+
"serializedName": "modelExpirationDate",
22522281
"doc": "Represents the training config version expiration date.",
22532282
"type": {
22542283
"$id": "204",
@@ -2284,6 +2313,7 @@
22842313
"$id": "205",
22852314
"kind": "property",
22862315
"name": "nextLink",
2316+
"serializedName": "nextLink",
22872317
"doc": "The link to the next page of items",
22882318
"type": {
22892319
"$id": "206",

test/TestProjects/MgmtTypeSpec/tspCodeModel.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,6 +1967,7 @@
19671967
"$id": "160",
19681968
"kind": "property",
19691969
"name": "body",
1970+
"serializedName": "body",
19701971
"doc": "SAP Application server instance start request body.",
19711972
"type": {
19721973
"$id": "161",

0 commit comments

Comments
 (0)