Skip to content

Commit 049e9a3

Browse files
authored
feat: update with master (#2161)
2 parents ce045db + 8938979 commit 049e9a3

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

examples/csharp-generate-newtonsoft-serializer/__snapshots__/index.spec.ts.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public partial class Root
1919
get { return name; }
2020
set { this.name = value; }
2121
}
22-
2322
public string Serialize()
2423
{
2524
return JsonConvert.SerializeObject(this);

src/generators/csharp/presets/NewtonsoftSerializerPreset.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -87,33 +87,32 @@ function renderDeserialize({
8787
!(prop.property instanceof ConstrainedDictionaryModel) ||
8888
prop.property.serializationType === 'normal'
8989
);
90-
const corePropsRead = coreProps
91-
.map((prop) => {
92-
const propertyAccessor = pascalCase(prop.propertyName);
93-
let toValue = `jo["${prop.unconstrainedPropertyName}"].ToObject<${prop.property.type}>(serializer)`;
94-
if (
95-
prop.property instanceof ConstrainedReferenceModel &&
96-
prop.property.ref instanceof ConstrainedEnumModel
97-
) {
98-
toValue = `${prop.property.name}Extensions.To${prop.property.name}(jo["${
99-
prop.unconstrainedPropertyName
100-
}"].ToString())${prop.required ? '.Value' : ''}`;
101-
}
10290

103-
if (
104-
options?.enforceRequired !== undefined &&
105-
options?.enforceRequired &&
106-
prop.required
107-
) {
108-
return `if(jo["${prop.unconstrainedPropertyName}"] is null){
91+
const corePropsRead = coreProps.map((prop) => {
92+
const propertyAccessor = pascalCase(prop.propertyName);
93+
let toValue = `jo["${prop.unconstrainedPropertyName}"].ToObject<${prop.property.type}>(serializer)`;
94+
if (
95+
prop.property instanceof ConstrainedReferenceModel &&
96+
prop.property.ref instanceof ConstrainedEnumModel
97+
) {
98+
toValue = `${prop.property.name}Extensions.To${prop.property.name}(jo["${
99+
prop.unconstrainedPropertyName
100+
}"].ToString())${prop.required ? '.Value' : ''}`;
101+
}
102+
103+
if (
104+
options?.enforceRequired !== undefined &&
105+
options?.enforceRequired &&
106+
prop.required
107+
) {
108+
return `if(jo["${prop.unconstrainedPropertyName}"] is null){
109109
throw new JsonSerializationException("Required property '${prop.unconstrainedPropertyName}' is missing");
110110
}
111-
112111
value.${propertyAccessor} = ${toValue};
113112
`;
114-
}
113+
}
115114

116-
return `if(jo["${prop.unconstrainedPropertyName}"] != null) {
115+
return `if(jo["${prop.unconstrainedPropertyName}"] != null) {
117116
value.${propertyAccessor} = ${toValue};
118117
}`;
119118
})

test/generators/csharp/presets/__snapshots__/NewtonsoftSerializerPreset.spec.ts.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public class TestConverter : JsonConverter<Test>
7373
if(jo[\\"string prop\\"] is null){
7474
throw new JsonSerializationException(\\"Required property 'string prop' is missing\\");
7575
}
76-
7776
value.StringProp = jo[\\"string prop\\"].ToObject<string>(serializer);
7877
7978
if(jo[\\"const string prop\\"] != null) {

0 commit comments

Comments
 (0)