Commit 2ddbc37
Propagate tcgc SerializationOptions for body parameters and responses (#10730)
tcgc 0.68.0 added `serializationOptions` to `SdkBodyParameter` and
`SdkHttpResponse`, but the C# emitter and MTG were still inferring wire
format from the content-type header. This PR plumbs that data through so
MTG can consume it directly, and switches the first XML wire-format
detection site to use the new metadata.
### Emitter (TypeScript)
- Added `serializationOptions: SerializationOptions` (required) to
`InputBodyParameter` and `OperationResponse`, matching the existing
shape on `InputModelType` / `InputModelProperty`.
- Populated the field in `fromBodyParameter` and
`fromSdkHttpOperationResponse` by copying straight from tcgc.
### MTG (`Microsoft.TypeSpec.Generator.Input`)
- Added nullable `SerializationOptions` (of type
`InputSerializationOptions`) to `InputBodyParameter` and
`InputOperationResponse`, with constructor parameters defaulted to
`null` for back-compat.
- Updated `InputBodyParameterConverter` and
`InputOperationResponseConverter` to read the new `serializationOptions`
JSON field.
- Added a new `InputBinarySerializationOptions` type (`IsFile`,
`IsText`, `ContentTypes`, `Filename`) and
`InputBinarySerializationOptionsConverter`, plumbed through
`InputSerializationOptions` / `InputSerializationOptionsConverter` so
that binary payload metadata emitted by tcgc on model types can be
deserialized in MTG. `Filename` is typed as `InputModelProperty?`,
matching `InputMultipartOptions.Filename`.
### MTG (`Microsoft.TypeSpec.Generator.ClientModel`)
- `ScmMethodProviderCollection.TryGetXmlCollectionNamesForResponse` now
gates on `response.SerializationOptions?.Xml` instead of scanning
`response.ContentTypes` for `application/xml`, consuming the propagated
metadata directly.
- Extended the test-only `InputFactory.OperationResponse` helper with an
optional `serializationOptions` parameter and updated the affected XML
list response test to supply it.
### Tests
- Emitter unit tests in `model-type.test.ts` covering body parameter
`serializationOptions` propagation:
- `application/json` + `string` body — asserts
`bodyParam.serializationOptions.json` is populated.
- `Http.File` (`application/octet-stream`) body — asserts the body's
model type carries `serializationOptions.binary` with the full set of
properties: `isFile === true`, `isText === false`, `contentTypes ===
["application/octet-stream"]`, and `filename.name === "filename"`. Also
asserts that the body parameter's own `serializationOptions` has neither
`json` nor `xml` set (tcgc only derives `json`/`xml` for body params
from content types; `binary` lives on the model type).
- Added serialization-options deserialization tests directly inside
`TypeSpecInputConverterTests` in
`Microsoft.TypeSpec.Generator.Input.Tests` validating JSON
deserialization of `InputSerializationOptions` (empty, json, xml, binary
with all properties including `filename`, binary defaults, unknown
property tolerance), `InputBodyParameter.SerializationOptions` (json,
binary with `filename`, absent → null), and
`InputOperationResponse.SerializationOptions` (xml, binary with
`filename`, absent → null).
### Follow-up
One header/content-type-based wire-format site remains for a separate
change: `MrwSerializationTypeDefinition.Xml.cs` reads the `Content-Type`
response header at runtime to branch between `application/json` and
`application/xml`; converting that to consume `SerializationOptions` is
the natural next step.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>1 parent f8fc11d commit 2ddbc37
91 files changed
Lines changed: 5606 additions & 1226 deletions
File tree
- packages/http-client-csharp
- emitter
- src
- lib
- type
- test/Unit
- generator
- Microsoft.TypeSpec.Generator.ClientModel
- src/Providers
- test/Providers
- Microsoft.TypeSpec.Generator.Input
- src/InputTypes
- Serialization
- test
- Microsoft.TypeSpec.Generator/test/common
- TestProjects
- Local/Sample-TypeSpec
- Spector/http
- authentication
- api-key
- http/custom
- oauth2
- union
- client/structure
- client-operation-group
- default
- multi-client
- renamed-operation
- two-operation-group
- documentation
- encode
- array
- bytes
- datetime
- duration
- numeric
- parameters
- basic
- body-optionality
- collection-format
- path
- query
- spread
- payload
- content-negotiation
- head
- json-merge-patch
- media-type
- multipart
- pageable
- xml
- resiliency/srv-driven
- v1
- v2
- response/status-code-range
- routes
- serialization/encoded-name/json
- server
- endpoint/not-defined
- path
- multiple
- single
- versions
- not-versioned
- versioned
- service/multiple-services
- special-headers
- conditional-request
- repeatability
- special-words
- type
- array
- dictionary
- enum
- extensible
- fixed
- model
- empty
- inheritance
- enum-discriminator
- nested-discriminator
- not-discriminated
- recursive
- single-discriminator
- usage
- visibility
- property
- additional-properties
- nullable
- optionality
- value-types
- scalar
- union
- versioning
- added
- v1
- v2
- madeOptional
- v1
- v2
- removed
- v1
- v2Preview
- v2
- renamedFrom
- v1
- v2
- returnTypeChangedFrom
- v1
- v2
- typeChangedFrom
- v1
- v2
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
604 | 604 | | |
605 | 605 | | |
606 | 606 | | |
| 607 | + | |
607 | 608 | | |
608 | 609 | | |
609 | 610 | | |
| |||
706 | 707 | | |
707 | 708 | | |
708 | 709 | | |
| 710 | + | |
709 | 711 | | |
710 | 712 | | |
711 | 713 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
| 245 | + | |
245 | 246 | | |
246 | 247 | | |
247 | 248 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| 14 | + | |
13 | 15 | | |
Lines changed: 69 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
1094 | 1095 | | |
1095 | 1096 | | |
1096 | 1097 | | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
1097 | 1166 | | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1380 | 1380 | | |
1381 | 1381 | | |
1382 | 1382 | | |
1383 | | - | |
| 1383 | + | |
1384 | 1384 | | |
1385 | | - | |
| 1385 | + | |
1386 | 1386 | | |
1387 | 1387 | | |
1388 | 1388 | | |
| |||
Lines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1924 | 1924 | | |
1925 | 1925 | | |
1926 | 1926 | | |
1927 | | - | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
1928 | 1933 | | |
1929 | 1934 | | |
1930 | 1935 | | |
| |||
Lines changed: 44 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
32 | 39 | | |
33 | 40 | | |
Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
30 | 36 | | |
31 | 37 | | |
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| 21 | + | |
| 22 | + | |
20 | 23 | | |
21 | 24 | | |
0 commit comments