Skip to content

Commit

Permalink
Merge branch 'master' into update_next
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored Jan 27, 2025
2 parents ce045db + c579393 commit a4fac8c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public partial class Root
get { return name; }
set { this.name = value; }
}
public string Serialize()
{
return JsonConvert.SerializeObject(this);
Expand Down
41 changes: 20 additions & 21 deletions src/generators/csharp/presets/NewtonsoftSerializerPreset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,33 +87,32 @@ function renderDeserialize({
!(prop.property instanceof ConstrainedDictionaryModel) ||
prop.property.serializationType === 'normal'
);
const corePropsRead = coreProps
.map((prop) => {
const propertyAccessor = pascalCase(prop.propertyName);
let toValue = `jo["${prop.unconstrainedPropertyName}"].ToObject<${prop.property.type}>(serializer)`;
if (
prop.property instanceof ConstrainedReferenceModel &&
prop.property.ref instanceof ConstrainedEnumModel
) {
toValue = `${prop.property.name}Extensions.To${prop.property.name}(jo["${
prop.unconstrainedPropertyName
}"].ToString())${prop.required ? '.Value' : ''}`;
}

if (
options?.enforceRequired !== undefined &&
options?.enforceRequired &&
prop.required
) {
return `if(jo["${prop.unconstrainedPropertyName}"] is null){
const corePropsRead = coreProps.map((prop) => {
const propertyAccessor = pascalCase(prop.propertyName);
let toValue = `jo["${prop.unconstrainedPropertyName}"].ToObject<${prop.property.type}>(serializer)`;
if (
prop.property instanceof ConstrainedReferenceModel &&
prop.property.ref instanceof ConstrainedEnumModel
) {
toValue = `${prop.property.name}Extensions.To${prop.property.name}(jo["${
prop.unconstrainedPropertyName
}"].ToString())${prop.required ? '.Value' : ''}`;
}

if (
options?.enforceRequired !== undefined &&
options?.enforceRequired &&
prop.required
) {
return `if(jo["${prop.unconstrainedPropertyName}"] is null){
throw new JsonSerializationException("Required property '${prop.unconstrainedPropertyName}' is missing");
}
value.${propertyAccessor} = ${toValue};
`;
}
}

return `if(jo["${prop.unconstrainedPropertyName}"] != null) {
return `if(jo["${prop.unconstrainedPropertyName}"] != null) {
value.${propertyAccessor} = ${toValue};
}`;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ if(jo[\\"objectProp\\"] != null) {
}
var additionalProperties = jo.Properties().Where((prop) => prop.Name != \\"string prop\\" || prop.Name != \\"const string prop\\" || prop.Name != \\"notRequiredStringProp\\" || prop.Name != \\"numberProp\\" || prop.Name != \\"enumProp\\" || prop.Name != \\"objectProp\\");
value.AdditionalProperties = new Dictionary<string, dynamic>();
foreach (var additionalProperty in additionalProperties)
Expand Down

0 comments on commit a4fac8c

Please sign in to comment.