Skip to content

Commit

Permalink
Merge branch 'master' into all-contributors/add-TertiumOrganum1
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored Jan 25, 2025
2 parents 7075903 + 565f92d commit 4237104
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 6 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,15 @@
"doc",
"test"
]
},
{
"login": "Shriya-Chauhan",
"name": "Shriya Chauhan",
"avatar_url": "https://avatars.githubusercontent.com/u/78415084?v=4",
"profile": "https://github.com/Shriya-Chauhan",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![Discussions](https://img.shields.io/github/discussions/asyncapi/modelina)](https://github.com/asyncapi/modelina/discussions)
[![Website](https://img.shields.io/website?label=website&url=https%3A%2F%2Fwww.modelina.org)](https://www.modelina.org)
[![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 -->
[![All Contributors](https://img.shields.io/badge/all_contributors-98-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-99-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

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.
Expand Down Expand Up @@ -449,6 +449,9 @@ Thanks go out to these wonderful people ([emoji key](https://allcontributors.org
<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>
<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>
</tr>
<tr>
<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>
</tr>
</tbody>
</table>

Expand Down
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.10.0",
"version": "3.10.1",
"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: 2 additions & 0 deletions src/generators/typescript/presets/utils/UnmarshalFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function renderUnmarshalProperty(

if (
model instanceof ConstrainedArrayModel &&
model.valueModel instanceof ConstrainedReferenceModel &&
!(model.valueModel.ref instanceof ConstrainedEnumModel) &&
!(model.valueModel instanceof ConstrainedUnionModel)
) {
return `${modelInstanceVariable} == null
Expand Down
7 changes: 7 additions & 0 deletions test/generators/typescript/preset/MarshallingPreset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ const doc = {
$ref: '#/definitions/NestedTest'
}
},
primitiveArrayTest: {
type: 'array',
additionalItems: false,
items: {
type: 'string'
}
},
tupleTest: {
type: 'array',
additionalItems: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exports[`Marshalling preset should render un/marshal code 1`] = `
private _unionTest?: NestedTest | string;
private _unionArrayTest?: (NestedTest | string)[];
private _arrayTest?: NestedTest[];
private _primitiveArrayTest?: string[];
private _tupleTest?: [NestedTest, string];
private _constTest?: 'TEST' = 'TEST';
private _additionalProperties?: Map<string, NestedTest | string>;
Expand All @@ -21,6 +22,7 @@ exports[`Marshalling preset should render un/marshal code 1`] = `
unionTest?: NestedTest | string,
unionArrayTest?: (NestedTest | string)[],
arrayTest?: NestedTest[],
primitiveArrayTest?: string[],
tupleTest?: [NestedTest, string],
additionalProperties?: Map<string, NestedTest | string>,
}) {
Expand All @@ -31,6 +33,7 @@ exports[`Marshalling preset should render un/marshal code 1`] = `
this._unionTest = input.unionTest;
this._unionArrayTest = input.unionArrayTest;
this._arrayTest = input.arrayTest;
this._primitiveArrayTest = input.primitiveArrayTest;
this._tupleTest = input.tupleTest;
this._additionalProperties = input.additionalProperties;
}
Expand All @@ -56,6 +59,9 @@ exports[`Marshalling preset should render un/marshal code 1`] = `
get arrayTest(): NestedTest[] | undefined { return this._arrayTest; }
set arrayTest(arrayTest: NestedTest[] | undefined) { this._arrayTest = arrayTest; }
get primitiveArrayTest(): string[] | undefined { return this._primitiveArrayTest; }
set primitiveArrayTest(primitiveArrayTest: string[] | undefined) { this._primitiveArrayTest = primitiveArrayTest; }
get tupleTest(): [NestedTest, string] | undefined { return this._tupleTest; }
set tupleTest(tupleTest: [NestedTest, string] | undefined) { this._tupleTest = tupleTest; }
Expand Down Expand Up @@ -103,6 +109,13 @@ exports[`Marshalling preset should render un/marshal code 1`] = `
}
json += \`\\"arrayTest\\": [\${arrayTestJsonValues.join(',')}],\`;
}
if(this.primitiveArrayTest !== undefined) {
let primitiveArrayTestJsonValues: any[] = [];
for (const unionItem of this.primitiveArrayTest) {
primitiveArrayTestJsonValues.push(\`\${typeof unionItem === 'number' || typeof unionItem === 'boolean' ? unionItem : JSON.stringify(unionItem)}\`);
}
json += \`\\"primitiveArrayTest\\": [\${primitiveArrayTestJsonValues.join(',')}],\`;
}
if(this.tupleTest !== undefined) {
const serializedTuple = [];
if(this.tupleTest[0]) {
Expand All @@ -123,7 +136,7 @@ exports[`Marshalling preset should render un/marshal code 1`] = `
if(this.additionalProperties !== undefined) {
for (const [key, value] of this.additionalProperties.entries()) {
//Only unwrap those that are not already a property in the JSON object
if([\\"string prop\\",\\"enumProp\\",\\"numberProp\\",\\"nestedObject\\",\\"unionTest\\",\\"unionArrayTest\\",\\"arrayTest\\",\\"tupleTest\\",\\"constTest\\",\\"additionalProperties\\"].includes(String(key))) continue;
if([\\"string prop\\",\\"enumProp\\",\\"numberProp\\",\\"nestedObject\\",\\"unionTest\\",\\"unionArrayTest\\",\\"arrayTest\\",\\"primitiveArrayTest\\",\\"tupleTest\\",\\"constTest\\",\\"additionalProperties\\"].includes(String(key))) continue;
if(value instanceof NestedTest) {
json += \`\\"\${key}\\": \${value.marshal()},\`;
} else {
Expand Down Expand Up @@ -162,13 +175,16 @@ exports[`Marshalling preset should render un/marshal code 1`] = `
? null
: obj[\\"arrayTest\\"].map((item: any) => NestedTest.unmarshal(item));
}
if (obj[\\"primitiveArrayTest\\"] !== undefined) {
instance.primitiveArrayTest = obj[\\"primitiveArrayTest\\"];
}
if (obj[\\"tupleTest\\"] !== undefined) {
instance.tupleTest = obj[\\"tupleTest\\"];
}
instance.additionalProperties = new Map();
const propsToCheck = Object.entries(obj).filter((([key,]) => {return ![\\"string prop\\",\\"enumProp\\",\\"numberProp\\",\\"nestedObject\\",\\"unionTest\\",\\"unionArrayTest\\",\\"arrayTest\\",\\"tupleTest\\",\\"constTest\\",\\"additionalProperties\\"].includes(key);}));
const propsToCheck = Object.entries(obj).filter((([key,]) => {return ![\\"string prop\\",\\"enumProp\\",\\"numberProp\\",\\"nestedObject\\",\\"unionTest\\",\\"unionArrayTest\\",\\"arrayTest\\",\\"primitiveArrayTest\\",\\"tupleTest\\",\\"constTest\\",\\"additionalProperties\\"].includes(key);}));
for (const [key, value] of propsToCheck) {
instance.additionalProperties.set(key, value as any);
}
Expand Down

0 comments on commit 4237104

Please sign in to comment.