Skip to content

Commit 4237104

Browse files
authored
Merge branch 'master' into all-contributors/add-TertiumOrganum1
2 parents 7075903 + 565f92d commit 4237104

File tree

7 files changed

+43
-6
lines changed

7 files changed

+43
-6
lines changed

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,15 @@
10631063
"doc",
10641064
"test"
10651065
]
1066+
},
1067+
{
1068+
"login": "Shriya-Chauhan",
1069+
"name": "Shriya Chauhan",
1070+
"avatar_url": "https://avatars.githubusercontent.com/u/78415084?v=4",
1071+
"profile": "https://github.com/Shriya-Chauhan",
1072+
"contributions": [
1073+
"code"
1074+
]
10661075
}
10671076
],
10681077
"contributorsPerLine": 7,

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[![Discussions](https://img.shields.io/github/discussions/asyncapi/modelina)](https://github.com/asyncapi/modelina/discussions)
1010
[![Website](https://img.shields.io/website?label=website&url=https%3A%2F%2Fwww.modelina.org)](https://www.modelina.org)
1111
[![Playground](https://img.shields.io/website?label=playground&url=https%3A%2F%2Fwww.modelina.org%2Fplayground)](https://www.modelina.org/playground) <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
12-
[![All Contributors](https://img.shields.io/badge/all_contributors-98-orange.svg?style=flat-square)](#contributors-)
12+
[![All Contributors](https://img.shields.io/badge/all_contributors-99-orange.svg?style=flat-square)](#contributors-)
1313
<!-- ALL-CONTRIBUTORS-BADGE:END -->
1414

1515
Your one-stop tool for generating accurate and well-tested models for representing the message payloads. Use it as a tool in your development workflow, or a library in a larger integrations, entirely in your control.
@@ -449,6 +449,9 @@ Thanks go out to these wonderful people ([emoji key](https://allcontributors.org
449449
<td align="center" valign="top" width="14.28%"><a href="https://jonjomckay.com"><img src="https://avatars.githubusercontent.com/u/456645?v=4?s=100" width="100px;" alt="Jonjo McKay"/><br /><sub><b>Jonjo McKay</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=jonjomckay" title="Code">💻</a> <a href="https://github.com/asyncapi/modelina/issues?q=author%3Ajonjomckay" title="Bug reports">🐛</a> <a href="https://github.com/asyncapi/modelina/commits?author=jonjomckay" title="Tests">⚠️</a></td>
450450
<td align="center" valign="top" width="14.28%"><a href="https://github.com/TertiumOrganum1"><img src="https://avatars.githubusercontent.com/u/51286827?v=4?s=100" width="100px;" alt="TertiumOrganum1"/><br /><sub><b>TertiumOrganum1</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=TertiumOrganum1" title="Code">💻</a> <a href="https://github.com/asyncapi/modelina/commits?author=TertiumOrganum1" title="Documentation">📖</a> <a href="https://github.com/asyncapi/modelina/commits?author=TertiumOrganum1" title="Tests">⚠️</a></td>
451451
</tr>
452+
<tr>
453+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Shriya-Chauhan"><img src="https://avatars.githubusercontent.com/u/78415084?v=4?s=100" width="100px;" alt="Shriya Chauhan"/><br /><sub><b>Shriya Chauhan</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=Shriya-Chauhan" title="Code">💻</a></td>
454+
</tr>
452455
</tbody>
453456
</table>
454457

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@asyncapi/modelina",
3-
"version": "3.10.0",
3+
"version": "3.10.1",
44
"description": "Library for generating data models based on inputs such as AsyncAPI, OpenAPI, or JSON Schema documents",
55
"license": "Apache-2.0",
66
"homepage": "https://www.modelina.org",

src/generators/typescript/presets/utils/UnmarshalFunction.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ function renderUnmarshalProperty(
2727

2828
if (
2929
model instanceof ConstrainedArrayModel &&
30+
model.valueModel instanceof ConstrainedReferenceModel &&
31+
!(model.valueModel.ref instanceof ConstrainedEnumModel) &&
3032
!(model.valueModel instanceof ConstrainedUnionModel)
3133
) {
3234
return `${modelInstanceVariable} == null

test/generators/typescript/preset/MarshallingPreset.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ const doc = {
5757
$ref: '#/definitions/NestedTest'
5858
}
5959
},
60+
primitiveArrayTest: {
61+
type: 'array',
62+
additionalItems: false,
63+
items: {
64+
type: 'string'
65+
}
66+
},
6067
tupleTest: {
6168
type: 'array',
6269
additionalItems: false,

test/generators/typescript/preset/__snapshots__/MarshallingPreset.spec.ts.snap

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ exports[`Marshalling preset should render un/marshal code 1`] = `
99
private _unionTest?: NestedTest | string;
1010
private _unionArrayTest?: (NestedTest | string)[];
1111
private _arrayTest?: NestedTest[];
12+
private _primitiveArrayTest?: string[];
1213
private _tupleTest?: [NestedTest, string];
1314
private _constTest?: 'TEST' = 'TEST';
1415
private _additionalProperties?: Map<string, NestedTest | string>;
@@ -21,6 +22,7 @@ exports[`Marshalling preset should render un/marshal code 1`] = `
2122
unionTest?: NestedTest | string,
2223
unionArrayTest?: (NestedTest | string)[],
2324
arrayTest?: NestedTest[],
25+
primitiveArrayTest?: string[],
2426
tupleTest?: [NestedTest, string],
2527
additionalProperties?: Map<string, NestedTest | string>,
2628
}) {
@@ -31,6 +33,7 @@ exports[`Marshalling preset should render un/marshal code 1`] = `
3133
this._unionTest = input.unionTest;
3234
this._unionArrayTest = input.unionArrayTest;
3335
this._arrayTest = input.arrayTest;
36+
this._primitiveArrayTest = input.primitiveArrayTest;
3437
this._tupleTest = input.tupleTest;
3538
this._additionalProperties = input.additionalProperties;
3639
}
@@ -56,6 +59,9 @@ exports[`Marshalling preset should render un/marshal code 1`] = `
5659
get arrayTest(): NestedTest[] | undefined { return this._arrayTest; }
5760
set arrayTest(arrayTest: NestedTest[] | undefined) { this._arrayTest = arrayTest; }
5861
62+
get primitiveArrayTest(): string[] | undefined { return this._primitiveArrayTest; }
63+
set primitiveArrayTest(primitiveArrayTest: string[] | undefined) { this._primitiveArrayTest = primitiveArrayTest; }
64+
5965
get tupleTest(): [NestedTest, string] | undefined { return this._tupleTest; }
6066
set tupleTest(tupleTest: [NestedTest, string] | undefined) { this._tupleTest = tupleTest; }
6167
@@ -103,6 +109,13 @@ exports[`Marshalling preset should render un/marshal code 1`] = `
103109
}
104110
json += \`\\"arrayTest\\": [\${arrayTestJsonValues.join(',')}],\`;
105111
}
112+
if(this.primitiveArrayTest !== undefined) {
113+
let primitiveArrayTestJsonValues: any[] = [];
114+
for (const unionItem of this.primitiveArrayTest) {
115+
primitiveArrayTestJsonValues.push(\`\${typeof unionItem === 'number' || typeof unionItem === 'boolean' ? unionItem : JSON.stringify(unionItem)}\`);
116+
}
117+
json += \`\\"primitiveArrayTest\\": [\${primitiveArrayTestJsonValues.join(',')}],\`;
118+
}
106119
if(this.tupleTest !== undefined) {
107120
const serializedTuple = [];
108121
if(this.tupleTest[0]) {
@@ -123,7 +136,7 @@ exports[`Marshalling preset should render un/marshal code 1`] = `
123136
if(this.additionalProperties !== undefined) {
124137
for (const [key, value] of this.additionalProperties.entries()) {
125138
//Only unwrap those that are not already a property in the JSON object
126-
if([\\"string prop\\",\\"enumProp\\",\\"numberProp\\",\\"nestedObject\\",\\"unionTest\\",\\"unionArrayTest\\",\\"arrayTest\\",\\"tupleTest\\",\\"constTest\\",\\"additionalProperties\\"].includes(String(key))) continue;
139+
if([\\"string prop\\",\\"enumProp\\",\\"numberProp\\",\\"nestedObject\\",\\"unionTest\\",\\"unionArrayTest\\",\\"arrayTest\\",\\"primitiveArrayTest\\",\\"tupleTest\\",\\"constTest\\",\\"additionalProperties\\"].includes(String(key))) continue;
127140
if(value instanceof NestedTest) {
128141
json += \`\\"\${key}\\": \${value.marshal()},\`;
129142
} else {
@@ -162,13 +175,16 @@ exports[`Marshalling preset should render un/marshal code 1`] = `
162175
? null
163176
: obj[\\"arrayTest\\"].map((item: any) => NestedTest.unmarshal(item));
164177
}
178+
if (obj[\\"primitiveArrayTest\\"] !== undefined) {
179+
instance.primitiveArrayTest = obj[\\"primitiveArrayTest\\"];
180+
}
165181
if (obj[\\"tupleTest\\"] !== undefined) {
166182
instance.tupleTest = obj[\\"tupleTest\\"];
167183
}
168184
169185
170186
instance.additionalProperties = new Map();
171-
const propsToCheck = Object.entries(obj).filter((([key,]) => {return ![\\"string prop\\",\\"enumProp\\",\\"numberProp\\",\\"nestedObject\\",\\"unionTest\\",\\"unionArrayTest\\",\\"arrayTest\\",\\"tupleTest\\",\\"constTest\\",\\"additionalProperties\\"].includes(key);}));
187+
const propsToCheck = Object.entries(obj).filter((([key,]) => {return ![\\"string prop\\",\\"enumProp\\",\\"numberProp\\",\\"nestedObject\\",\\"unionTest\\",\\"unionArrayTest\\",\\"arrayTest\\",\\"primitiveArrayTest\\",\\"tupleTest\\",\\"constTest\\",\\"additionalProperties\\"].includes(key);}));
172188
for (const [key, value] of propsToCheck) {
173189
instance.additionalProperties.set(key, value as any);
174190
}

0 commit comments

Comments
 (0)