@@ -69,50 +69,61 @@ export function createBarParserFromDiscriminatorValue(parseNode: ParseNode | und
69
69
return deserializeBarParser ;
70
70
}
71
71
72
+ export function createTestObjectFromDiscriminatorValue ( parseNode : ParseNode | undefined ) {
73
+ if ( ! parseNode ) throw new Error ( "parseNode cannot be undefined" ) ;
74
+ return deserializeTestObject ;
75
+ }
76
+ export function deserializeTestObject ( testObject : { additionalData ?: Record < string , unknown > } | undefined = { } ) : Record < string , ( node : ParseNode ) => void > {
77
+ return { } ;
78
+ }
79
+
72
80
export function deserializeTestParser ( testParser : TestParser | undefined = { } ) : Record < string , ( node : ParseNode ) => void > {
73
81
return {
74
- testCollection : ( n ) => {
82
+ "testObject" : ( n ) => {
83
+ testParser . testObject = n . getObjectValue < { additionalData ?: Record < string , unknown > } > ( createTestObjectFromDiscriminatorValue ) ;
84
+ } ,
85
+ "testCollection" : ( n ) => {
75
86
testParser . testCollection = n . getCollectionOfPrimitiveValues ( ) ;
76
87
} ,
77
- testString : ( n ) => {
88
+ " testString" : ( n ) => {
78
89
testParser . testString = n . getStringValue ( ) ;
79
90
} ,
80
- testBoolean : ( n ) => {
91
+ " testBoolean" : ( n ) => {
81
92
testParser . testBoolean = n . getBooleanValue ( ) ;
82
93
} ,
83
- textComplexString : ( n ) => {
94
+ "testComplexString" : ( n ) => {
84
95
testParser . testComplexString = n . getStringValue ( ) ;
85
96
} ,
86
- testDate : ( n ) => {
97
+ " testDate" : ( n ) => {
87
98
testParser . testDate = n . getDateValue ( ) ;
88
99
} ,
89
- foos : ( n ) => {
100
+ " foos" : ( n ) => {
90
101
testParser . foos = n . getCollectionOfObjectValues ( createFooParserFromDiscriminatorValue ) ;
91
102
} ,
92
- id : ( n ) => {
103
+ "id" : ( n ) => {
93
104
testParser . id = n . getStringValue ( ) ;
94
105
} ,
95
- testNumber : ( n ) => {
106
+ " testNumber" : ( n ) => {
96
107
testParser . testNumber = n . getNumberValue ( ) ;
97
108
} ,
98
- testGuid : ( n ) => {
109
+ " testGuid" : ( n ) => {
99
110
testParser . testGuid = n . getGuidValue ( ) ;
100
111
} ,
101
- testUnionObject : ( n ) => {
112
+ " testUnionObject" : ( n ) => {
102
113
testParser . testUnionObject = n . getStringValue ( ) ?? n . getNumberValue ( ) ?? n . getObjectValue ( createTestUnionObjectFromDiscriminatorValue ) ;
103
114
} ,
104
- status : ( n ) => {
115
+ " status" : ( n ) => {
105
116
testParser . status = n . getEnumValue < LongRunningOperationStatus > ( LongRunningOperationStatusObject ) ;
106
117
} ,
107
- nextStatuses : ( n ) => {
118
+ " nextStatuses" : ( n ) => {
108
119
testParser . nextStatuses = n . getCollectionOfEnumValues < LongRunningOperationStatus > ( LongRunningOperationStatusObject ) ;
109
120
} ,
110
121
} ;
111
122
}
112
123
113
124
export function deserializeTestBackedModel ( testParser : TestBackedModel | undefined = { } ) : Record < string , ( node : ParseNode ) => void > {
114
125
return {
115
- backingStoreEnabled : ( n ) => {
126
+ " backingStoreEnabled" : ( n ) => {
116
127
testParser . backingStoreEnabled = true ;
117
128
} ,
118
129
...deserializeTestParser ( testParser ) ,
@@ -121,33 +132,39 @@ export function deserializeTestBackedModel(testParser: TestBackedModel | undefin
121
132
122
133
export function deserializeFooParser ( fooResponse : FooResponse | undefined = { } ) : Record < string , ( node : ParseNode ) => void > {
123
134
return {
124
- id : ( n ) => {
135
+ "id" : ( n ) => {
125
136
fooResponse . id = n . getStringValue ( ) ;
126
137
} ,
127
- bars : ( n ) => {
138
+ " bars" : ( n ) => {
128
139
fooResponse . bars = n . getCollectionOfObjectValues ( createBarParserFromDiscriminatorValue ) ;
129
140
} ,
130
141
} ;
131
142
}
132
143
133
144
export function deserializeBarParser ( barResponse : BarResponse | undefined = { } ) : Record < string , ( node : ParseNode ) => void > {
134
145
return {
135
- propA : ( n ) => {
146
+ " propA" : ( n ) => {
136
147
barResponse . propA = n . getStringValue ( ) ;
137
148
} ,
138
- propB : ( n ) => {
149
+ " propB" : ( n ) => {
139
150
barResponse . propB = n . getStringValue ( ) ;
140
151
} ,
141
- propC : ( n ) => {
152
+ " propC" : ( n ) => {
142
153
barResponse . propC = n . getDateValue ( ) ;
143
154
} ,
144
155
} ;
145
156
}
146
157
147
- export function serializeTestObject ( writer : SerializationWriter , entity : { additionalData ?: Record < string , unknown > } | undefined = { } ) : void {
158
+ export function serializeTestObject ( writer : SerializationWriter , entity : { additionalData ?: Record < string , unknown > } | undefined | null = { } ) : void {
159
+ if ( ! entity ) {
160
+ return ;
161
+ }
148
162
writer . writeAdditionalData ( entity . additionalData ) ;
149
163
}
150
- export function serializeTestParser ( writer : SerializationWriter , entity : TestParser | undefined = { } ) : void {
164
+ export function serializeTestParser ( writer : SerializationWriter , entity : TestParser | undefined | null = { } ) : void {
165
+ if ( ! entity ) {
166
+ return ;
167
+ }
151
168
writer . writeStringValue ( "id" , entity . id ) ;
152
169
writer . writeCollectionOfPrimitiveValues ( "testCollection" , entity . testCollection ) ;
153
170
writer . writeStringValue ( "testString" , entity . testString ) ;
@@ -170,18 +187,27 @@ export function serializeTestParser(writer: SerializationWriter, entity: TestPar
170
187
writer . writeCollectionOfEnumValues ( "nextStatuses" , entity . nextStatuses ) ;
171
188
}
172
189
173
- export function serializeFoo ( writer : SerializationWriter , entity : FooResponse | undefined = { } ) : void {
190
+ export function serializeFoo ( writer : SerializationWriter , entity : FooResponse | undefined | null = { } ) : void {
191
+ if ( ! entity ) {
192
+ return ;
193
+ }
174
194
writer . writeStringValue ( "id" , entity . id ) ;
175
195
writer . writeCollectionOfObjectValues ( "bars" , entity . bars , serializeBar ) ;
176
196
}
177
197
178
- export function serializeBar ( writer : SerializationWriter , entity : BarResponse | undefined = { } ) : void {
198
+ export function serializeBar ( writer : SerializationWriter , entity : BarResponse | undefined | null = { } ) : void {
199
+ if ( ! entity ) {
200
+ return ;
201
+ }
179
202
writer . writeStringValue ( "propA" , entity . propA ) ;
180
203
writer . writeStringValue ( "propB" , entity . propB ) ;
181
204
writer . writeDateValue ( "propC" , entity . propC ) ;
182
205
}
183
206
184
- export function serializeTestBackModel ( writer : SerializationWriter , entity : TestBackedModel | undefined = { } ) : void {
207
+ export function serializeTestBackModel ( writer : SerializationWriter , entity : TestBackedModel | undefined | null = { } ) : void {
208
+ if ( ! entity ) {
209
+ return ;
210
+ }
185
211
serializeTestParser ( writer , entity ) ;
186
212
}
187
213
@@ -198,7 +224,10 @@ export function deserializeIntoTestUnionObject(fooBar: Partial<TestUnionObject>
198
224
} ;
199
225
}
200
226
201
- export function serializeTestUnionObject ( writer : SerializationWriter , fooBar : Partial < TestUnionObject > | undefined = { } ) : void {
227
+ export function serializeTestUnionObject ( writer : SerializationWriter , fooBar : Partial < TestUnionObject > | undefined | null = { } ) : void {
228
+ if ( ! fooBar ) {
229
+ return ;
230
+ }
202
231
serializeFoo ( writer , fooBar as FooResponse ) ;
203
232
serializeBar ( writer , fooBar as BarResponse ) ;
204
233
}
0 commit comments