Skip to content

feat: update with master #2161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -73,7 +73,6 @@ public class TestConverter : JsonConverter<Test>
if(jo[\\"string prop\\"] is null){
throw new JsonSerializationException(\\"Required property 'string prop' is missing\\");
}

value.StringProp = jo[\\"string prop\\"].ToObject<string>(serializer);

if(jo[\\"const string prop\\"] != null) {
Expand Down
Loading