Skip to content

Commit

Permalink
Merge branch 'master' into fix_auto_implemnt_example
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored Feb 19, 2024
2 parents 8f614d6 + 17c4fda commit c38e261
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@asyncapi/modelina",
"version": "3.3.0",
"version": "3.3.2",
"description": "Library for generating data models based on inputs such as AsyncAPI, OpenAPI, or JSON Schema documents",
"license": "Apache-2.0",
"homepage": "https://www.modelina.org",
Expand Down
2 changes: 1 addition & 1 deletion src/generators/csharp/presets/JsonSerializerPreset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function renderSerializeProperty(
model.property instanceof ConstrainedReferenceModel &&
model.property.ref instanceof ConstrainedEnumModel
) {
value = `${modelInstanceVariable}?.GetValue()`;
value = `${modelInstanceVariable}${model.required ? '' : '?'}.GetValue()`;
}
return `JsonSerializer.Serialize(writer, ${value}, options);`;
}
Expand Down
4 changes: 3 additions & 1 deletion src/generators/csharp/presets/NewtonsoftSerializerPreset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ function renderDeserialize({
prop.property instanceof ConstrainedReferenceModel &&
prop.property.ref instanceof ConstrainedEnumModel
) {
toValue = `${prop.property.name}Extensions.To${prop.property.name}(jo["${prop.unconstrainedPropertyName}"].ToString())`;
toValue = `${prop.property.name}Extensions.To${prop.property.name}(jo["${
prop.unconstrainedPropertyName
}"].ToString())${prop.required ? '.Value' : ''}`;
}
return `if(jo["${prop.unconstrainedPropertyName}"] != null) {
value.${propertyAccessor} = ${toValue};
Expand Down
3 changes: 2 additions & 1 deletion src/generators/python/PythonGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import {
import { DeepPartial, mergePartialAndDefault } from '../../utils/Partials';
import { PythonDependencyManager } from './PythonDependencyManager';

export interface PythonOptions extends CommonGeneratorOptions<PythonPreset> {
export interface PythonOptions
extends CommonGeneratorOptions<PythonPreset, PythonDependencyManager> {
typeMapping: TypeMapping<PythonOptions, PythonDependencyManager>;
constraints: Constraints<PythonOptions>;
importsStyle: 'explicit' | 'implicit';
Expand Down
75 changes: 75 additions & 0 deletions test/runtime/generic-input-csharp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"$id": "Address",
"description": "This object contains all types of MetaModel generations",
"type": "object",
"properties": {
"street_name": {
"type": "string"
},
"house_number": {
"type": "number"
},
"marriage": {
"type": "boolean",
"description": "Status if marriage live in given house"
},
"members": {
"oneOf": [
{
"type": "string"
},
{
"type": "number"
},
{
"type": "boolean"
}
]
},
"array_type": {
"type": "array",
"items": [
{
"type": "string"
},
{
"type": "number"
}
]
},
"nestedObject": {
"type": "object",
"properties": {
"test": {
"type": "string"
}
}
},
"enumTest": {
"enum": ["test", "test2"]
},
"houseType": {
"$ref": "#/$defs/housing-types"
},
"roofType": {
"$id": "TypeOfRoof",
"enum": ["tile", "straw", "wood", "metal"]
}
},
"patternProperties": {
"^S(.?*)test&": {
"type": "string"
}
},
"required": [
"house_number",
"array_type",
"houseType"
],
"$defs": {
"housing-types": {
"$id": "HousingType",
"enum": ["detached", "terraced", "bungalow", "flat"]
}
}
}
2 changes: 1 addition & 1 deletion test/runtime/runtime-csharp.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CSHARP_JSON_SERIALIZER_PRESET, CSHARP_NEWTONSOFT_SERIALIZER_PRESET, CSharpFileGenerator } from '../../';
import path from 'path';
import input from './generic-input.json';
import input from './generic-input-csharp.json';

async function generateJsonSerializer() {
const generator = new CSharpFileGenerator({
Expand Down

0 comments on commit c38e261

Please sign in to comment.