From 16990b4c31be32a68884c4509cb0fba403d45fd1 Mon Sep 17 00:00:00 2001 From: Jonas Lagoni Date: Mon, 29 Apr 2024 09:17:10 +0200 Subject: [PATCH] update tests --- .../__snapshots__/index.spec.ts.snap | 4 +- examples/file-uri-input/index.spec.ts | 37 ++++++++-------- modelina-cli/package-lock.json | 4 +- src/interpreter/InterpretAdditionalItems.ts | 13 +++--- .../cplusplus/CplusplusGenerator.spec.ts | 3 +- .../CplusplusGenerator.spec.ts.snap | 2 +- .../CSharpGenerator.spec.ts.snap | 14 +++---- .../__snapshots__/JavaGenerator.spec.ts.snap | 1 + .../__snapshots__/PhpGenerator.spec.ts.snap | 6 +-- .../PythonGenerator.spec.ts.snap | 6 +-- .../TypeScriptGenerator.spec.ts.snap | 42 +++++++++---------- test/helpers/ConstrainHelpers.spec.ts | 2 +- 12 files changed, 67 insertions(+), 67 deletions(-) diff --git a/examples/file-uri-input/__snapshots__/index.spec.ts.snap b/examples/file-uri-input/__snapshots__/index.spec.ts.snap index a563fe8ae8..5f4a652298 100644 --- a/examples/file-uri-input/__snapshots__/index.spec.ts.snap +++ b/examples/file-uri-input/__snapshots__/index.spec.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Should be able to generate models using file URI as input to output folder and should log expected output to console 1`] = ` +exports[`Should be able to render models using file URI as input with file generator and should log expected output to console 1`] = ` Array [ "class AnonymousSchema_1 { private _displayName?: string; @@ -29,7 +29,7 @@ Array [ ] `; -exports[`Should be able to render models using file URI as input and should log expected output to console 1`] = ` +exports[`Should be able to render models using file URI as input with regular generator and should log expected output to console 1`] = ` Array [ "class AnonymousSchema_1 { private _displayName?: string; diff --git a/examples/file-uri-input/index.spec.ts b/examples/file-uri-input/index.spec.ts index 428b0cf504..d077776074 100644 --- a/examples/file-uri-input/index.spec.ts +++ b/examples/file-uri-input/index.spec.ts @@ -4,23 +4,26 @@ const spy = jest.spyOn(global.console, 'log').mockImplementation(() => { import { generate, generateToFiles } from './index'; describe('Should be able to render models using file URI as input', () => { - afterAll(() => { - jest.restoreAllMocks(); + describe('with regular generator', () => { + afterAll(() => { + jest.restoreAllMocks(); + }); + test('and should log expected output to console', async () => { + await generate(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); + }); }); - test('and should log expected output to console', async () => { - await generate(); - expect(spy.mock.calls.length).toEqual(1); - expect(spy.mock.calls[0]).toMatchSnapshot(); - }); -}); -describe('Should be able to generate models using file URI as input to output folder', () => { - afterAll(() => { - jest.restoreAllMocks(); - }); - test('and should log expected output to console', async () => { - await generateToFiles(); - expect(spy.mock.calls.length).toEqual(1); - expect(spy.mock.calls[0]).toMatchSnapshot(); + describe('with file generator', () => { + afterAll(() => { + jest.restoreAllMocks(); + }); + test('and should log expected output to console', async () => { + await generateToFiles(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); + }); }); -}); + +}); \ No newline at end of file diff --git a/modelina-cli/package-lock.json b/modelina-cli/package-lock.json index eb0101a834..d456e0cda2 100644 --- a/modelina-cli/package-lock.json +++ b/modelina-cli/package-lock.json @@ -185,9 +185,9 @@ } }, "node_modules/@asyncapi/modelina": { - "version": "4.0.0-next.34", + "version": "4.0.0-next.35", "resolved": "file:scripts/modelina-package/asyncapi-modelina.tgz", - "integrity": "sha512-VCa+z+UR34e2l4LHSR3+OEhcg1eVtpfaz86eRurFIK5ehgZzTMru2v9iC7lhCF9ohWesVNvhkqDJ9NWicbs3UQ==", + "integrity": "sha512-obL4nusJo8o6YseNm1g93dc3K0c+CDIbx6fEKRKIah9X3FGu6omP847om+o/5pMQHCrZd4xjr238QoEC/cudSg==", "license": "Apache-2.0", "dependencies": { "@apidevtools/json-schema-ref-parser": "^11.1.0", diff --git a/src/interpreter/InterpretAdditionalItems.ts b/src/interpreter/InterpretAdditionalItems.ts index dde3bbda5e..712cbf84b1 100644 --- a/src/interpreter/InterpretAdditionalItems.ts +++ b/src/interpreter/InterpretAdditionalItems.ts @@ -19,18 +19,15 @@ export default function interpretAdditionalItems( interpreter: Interpreter, interpreterOptions: InterpreterOptions = Interpreter.defaultInterpreterOptions ): void { - const isTuple = model.items !== undefined && Array.isArray(model.items); - if ( - typeof schema === 'boolean' || - model.type?.includes('array') === false || - !isTuple - ) { + if (typeof schema === 'boolean' || model.type?.includes('array') === false) { return; } const hasArrayTypes = schema.items !== undefined; let defaultAdditionalItems = true; - if (hasArrayTypes && interpreterOptions.ignoreAdditionalItems === true) { - defaultAdditionalItems = false; + if (hasArrayTypes && interpreterOptions.ignoreAdditionalItems !== undefined) { + defaultAdditionalItems = interpreterOptions.ignoreAdditionalItems + ? false + : true; } const additionalItemsModel = interpreter.interpret( diff --git a/test/generators/cplusplus/CplusplusGenerator.spec.ts b/test/generators/cplusplus/CplusplusGenerator.spec.ts index 29418d1720..8cc33aa3bd 100644 --- a/test/generators/cplusplus/CplusplusGenerator.spec.ts +++ b/test/generators/cplusplus/CplusplusGenerator.spec.ts @@ -106,9 +106,8 @@ describe('CplusplusGenerator', () => { '#include ', '#include ', '#include ', - '#include ', - '#include ', '#include ', + '#include ', '#include ' ]; const models = await generator.generate(doc); diff --git a/test/generators/cplusplus/__snapshots__/CplusplusGenerator.spec.ts.snap b/test/generators/cplusplus/__snapshots__/CplusplusGenerator.spec.ts.snap index aa9e2ecf4e..7022e35dd1 100644 --- a/test/generators/cplusplus/__snapshots__/CplusplusGenerator.spec.ts.snap +++ b/test/generators/cplusplus/__snapshots__/CplusplusGenerator.spec.ts.snap @@ -14,7 +14,7 @@ exports[`CplusplusGenerator Class should render \`class\` type 1`] = ` double house_number; std::optional marriage; std::optional> members; - std::optional> tuple_type; + std::optional>> tuple_type; std::vector> array_type; std::optional>> additional_properties; };" diff --git a/test/generators/csharp/__snapshots__/CSharpGenerator.spec.ts.snap b/test/generators/csharp/__snapshots__/CSharpGenerator.spec.ts.snap index 5f646a886d..0485cde0a3 100644 --- a/test/generators/csharp/__snapshots__/CSharpGenerator.spec.ts.snap +++ b/test/generators/csharp/__snapshots__/CSharpGenerator.spec.ts.snap @@ -68,7 +68,7 @@ exports[`CSharpGenerator should render \`class\` type 1`] = ` private double houseNumber; private bool? marriage; private dynamic? members; - private (string, double)? tupleType; + private dynamic[]? tupleType; private string[] arrayType; private Dictionary? additionalProperties; @@ -108,7 +108,7 @@ exports[`CSharpGenerator should render \`class\` type 1`] = ` set { this.members = value; } } - public (string, double)? TupleType + public dynamic[]? TupleType { get { return tupleType; } set { this.tupleType = value; } @@ -178,7 +178,7 @@ exports[`CSharpGenerator should render \`record\` type if chosen 1`] = ` public required double HouseNumber { get; init; } public bool? Marriage { get; init; } public dynamic? Members { get; init; } - public (string, double)? TupleType { get; init; } + public dynamic[]? TupleType { get; init; } public required string[] ArrayType { get; init; } public Dictionary? AdditionalProperties { get; init; } }" @@ -238,7 +238,7 @@ exports[`CSharpGenerator should render models and their dependencies 1`] = ` private double houseNumber; private bool? marriage; private dynamic? members; - private (string, double) arrayType; + private dynamic[] arrayType; private OtherModel? otherModel; private Dictionary? additionalProperties; @@ -278,7 +278,7 @@ exports[`CSharpGenerator should render models and their dependencies 1`] = ` set { this.members = value; } } - public (string, double) ArrayType + public dynamic[] ArrayType { get { return arrayType; } set { this.arrayType = value; } @@ -335,7 +335,7 @@ exports[`CSharpGenerator should render null-forgiving operator if handleNullable private HouseType houseType; private TerraceType? terraceType; private dynamic? members; - private (string, double)? tupleType; + private dynamic[]? tupleType; private string[] arrayType = null!; private Dictionary? additionalProperties; @@ -387,7 +387,7 @@ exports[`CSharpGenerator should render null-forgiving operator if handleNullable set { this.members = value; } } - public (string, double)? TupleType + public dynamic[]? TupleType { get { return tupleType; } set { this.tupleType = value; } diff --git a/test/generators/java/__snapshots__/JavaGenerator.spec.ts.snap b/test/generators/java/__snapshots__/JavaGenerator.spec.ts.snap index 0fb174bed1..f031f078bf 100644 --- a/test/generators/java/__snapshots__/JavaGenerator.spec.ts.snap +++ b/test/generators/java/__snapshots__/JavaGenerator.spec.ts.snap @@ -1204,6 +1204,7 @@ exports[`JavaGenerator should not render reserved keyword 1`] = ` exports[`JavaGenerator should render \`class\` type 1`] = ` Array [ + "", "", "", "public class Address { diff --git a/test/generators/php/__snapshots__/PhpGenerator.spec.ts.snap b/test/generators/php/__snapshots__/PhpGenerator.spec.ts.snap index 160138b024..43cfb72677 100644 --- a/test/generators/php/__snapshots__/PhpGenerator.spec.ts.snap +++ b/test/generators/php/__snapshots__/PhpGenerator.spec.ts.snap @@ -24,7 +24,7 @@ exports[`PhpGenerator Class should render \`class\` type 1`] = ` private float $houseNumber; private ?bool $marriage; private mixed $members; - private mixed $arrayType; + private array $arrayType; private mixed $additionalProperties; public function getStreetName(): string { return $this->streetName; } @@ -45,8 +45,8 @@ exports[`PhpGenerator Class should render \`class\` type 1`] = ` public function getMembers(): mixed { return $this->members; } public function setMembers(mixed $members): void { $this->members = $members; } - public function getArrayType(): mixed { return $this->arrayType; } - public function setArrayType(mixed $arrayType): void { $this->arrayType = $arrayType; } + public function getArrayType(): array { return $this->arrayType; } + public function setArrayType(array $arrayType): void { $this->arrayType = $arrayType; } public function getAdditionalProperties(): mixed { return $this->additionalProperties; } public function setAdditionalProperties(mixed $additionalProperties): void { $this->additionalProperties = $additionalProperties; } diff --git a/test/generators/python/__snapshots__/PythonGenerator.spec.ts.snap b/test/generators/python/__snapshots__/PythonGenerator.spec.ts.snap index 1d71794237..cef720df59 100644 --- a/test/generators/python/__snapshots__/PythonGenerator.spec.ts.snap +++ b/test/generators/python/__snapshots__/PythonGenerator.spec.ts.snap @@ -143,7 +143,7 @@ exports[`PythonGenerator Class should render \`class\` type 1`] = ` self._marriage: bool = input['marriage'] if 'members' in input: self._members: str | float | bool = input['members'] - self._array_type: tuple[str, float] = input['array_type'] + self._array_type: List[str | float | Any] = input['array_type'] if 'additional_properties' in input: self._additional_properties: dict[str, Any | str] = input['additional_properties'] @@ -190,10 +190,10 @@ exports[`PythonGenerator Class should render \`class\` type 1`] = ` self._members = members @property - def array_type(self) -> tuple[str, float]: + def array_type(self) -> List[str | float | Any]: return self._array_type @array_type.setter - def array_type(self, array_type: tuple[str, float]): + def array_type(self, array_type: List[str | float | Any]): self._array_type = array_type @property diff --git a/test/generators/typescript/__snapshots__/TypeScriptGenerator.spec.ts.snap b/test/generators/typescript/__snapshots__/TypeScriptGenerator.spec.ts.snap index 3ca4a13860..cdacd89e0c 100644 --- a/test/generators/typescript/__snapshots__/TypeScriptGenerator.spec.ts.snap +++ b/test/generators/typescript/__snapshots__/TypeScriptGenerator.spec.ts.snap @@ -479,7 +479,7 @@ exports[`TypeScriptGenerator should render \`class\` type 1`] = ` private _marriage?: boolean; private _members?: string | number | boolean; private _tupleType?: [string, number]; - private _tupleTypeWithAdditionalItems?: [string, number]; + private _tupleTypeWithAdditionalItems?: (string | number | any)[]; private _arrayType: string[]; private _additionalProperties?: Map; @@ -491,7 +491,7 @@ exports[`TypeScriptGenerator should render \`class\` type 1`] = ` marriage?: boolean, members?: string | number | boolean, tupleType?: [string, number], - tupleTypeWithAdditionalItems?: [string, number], + tupleTypeWithAdditionalItems?: (string | number | any)[], arrayType: string[], additionalProperties?: Map, }) { @@ -528,8 +528,8 @@ exports[`TypeScriptGenerator should render \`class\` type 1`] = ` get tupleType(): [string, number] | undefined { return this._tupleType; } set tupleType(tupleType: [string, number] | undefined) { this._tupleType = tupleType; } - get tupleTypeWithAdditionalItems(): [string, number] | undefined { return this._tupleTypeWithAdditionalItems; } - set tupleTypeWithAdditionalItems(tupleTypeWithAdditionalItems: [string, number] | undefined) { this._tupleTypeWithAdditionalItems = tupleTypeWithAdditionalItems; } + get tupleTypeWithAdditionalItems(): (string | number | any)[] | undefined { return this._tupleTypeWithAdditionalItems; } + set tupleTypeWithAdditionalItems(tupleTypeWithAdditionalItems: (string | number | any)[] | undefined) { this._tupleTypeWithAdditionalItems = tupleTypeWithAdditionalItems; } get arrayType(): string[] { return this._arrayType; } set arrayType(arrayType: string[]) { this._arrayType = arrayType; } @@ -558,7 +558,7 @@ exports[`TypeScriptGenerator should render \`interface\` type 1`] = ` marriage?: boolean; members?: string | number | boolean; tupleType?: [string, number]; - tupleTypeWithAdditionalItems?: [string, number]; + tupleTypeWithAdditionalItems?: (string | number | any)[]; arrayType: string[]; additionalProperties?: Map; }" @@ -603,7 +603,7 @@ class Address { private _houseNumber: number; private _marriage?: boolean; private _members?: string | number | boolean; - private _arrayType: [string, number]; + private _arrayType: (string | number | any)[]; private _otherModel?: OtherModel; private _additionalProperties?: Map; @@ -614,7 +614,7 @@ class Address { houseNumber: number, marriage?: boolean, members?: string | number | boolean, - arrayType: [string, number], + arrayType: (string | number | any)[], otherModel?: OtherModel, additionalProperties?: Map, }) { @@ -647,8 +647,8 @@ class Address { get members(): string | number | boolean | undefined { return this._members; } set members(members: string | number | boolean | undefined) { this._members = members; } - get arrayType(): [string, number] { return this._arrayType; } - set arrayType(arrayType: [string, number]) { this._arrayType = arrayType; } + get arrayType(): (string | number | any)[] { return this._arrayType; } + set arrayType(arrayType: (string | number | any)[]) { this._arrayType = arrayType; } get otherModel(): OtherModel | undefined { return this._otherModel; } set otherModel(otherModel: OtherModel | undefined) { this._otherModel = otherModel; } @@ -691,7 +691,7 @@ class Address { private _houseNumber: number; private _marriage?: boolean; private _members?: string | number | boolean; - private _arrayType: [string, number]; + private _arrayType: (string | number | any)[]; private _otherModel?: OtherModel; private _additionalProperties?: Map; @@ -702,7 +702,7 @@ class Address { houseNumber: number, marriage?: boolean, members?: string | number | boolean, - arrayType: [string, number], + arrayType: (string | number | any)[], otherModel?: OtherModel, additionalProperties?: Map, }) { @@ -735,8 +735,8 @@ class Address { get members(): string | number | boolean | undefined { return this._members; } set members(members: string | number | boolean | undefined) { this._members = members; } - get arrayType(): [string, number] { return this._arrayType; } - set arrayType(arrayType: [string, number]) { this._arrayType = arrayType; } + get arrayType(): (string | number | any)[] { return this._arrayType; } + set arrayType(arrayType: (string | number | any)[]) { this._arrayType = arrayType; } get otherModel(): OtherModel | undefined { return this._otherModel; } set otherModel(otherModel: OtherModel | undefined) { this._otherModel = otherModel; } @@ -779,7 +779,7 @@ class Address { private _houseNumber: number; private _marriage?: boolean; private _members?: string | number | boolean; - private _arrayType: [string, number]; + private _arrayType: (string | number | any)[]; private _otherModel?: OtherModel; private _additionalProperties?: Map; @@ -790,7 +790,7 @@ class Address { houseNumber: number, marriage?: boolean, members?: string | number | boolean, - arrayType: [string, number], + arrayType: (string | number | any)[], otherModel?: OtherModel, additionalProperties?: Map, }) { @@ -823,8 +823,8 @@ class Address { get members(): string | number | boolean | undefined { return this._members; } set members(members: string | number | boolean | undefined) { this._members = members; } - get arrayType(): [string, number] { return this._arrayType; } - set arrayType(arrayType: [string, number]) { this._arrayType = arrayType; } + get arrayType(): (string | number | any)[] { return this._arrayType; } + set arrayType(arrayType: (string | number | any)[]) { this._arrayType = arrayType; } get otherModel(): OtherModel | undefined { return this._otherModel; } set otherModel(otherModel: OtherModel | undefined) { this._otherModel = otherModel; } @@ -869,7 +869,7 @@ class Address { private _houseNumber: number; private _marriage?: boolean; private _members?: string | number | boolean; - private _arrayType: [string, number]; + private _arrayType: (string | number | any)[]; private _otherModel?: OtherModel; private _additionalProperties?: Map; @@ -880,7 +880,7 @@ class Address { houseNumber: number, marriage?: boolean, members?: string | number | boolean, - arrayType: [string, number], + arrayType: (string | number | any)[], otherModel?: OtherModel, additionalProperties?: Map, }) { @@ -913,8 +913,8 @@ class Address { get members(): string | number | boolean | undefined { return this._members; } set members(members: string | number | boolean | undefined) { this._members = members; } - get arrayType(): [string, number] { return this._arrayType; } - set arrayType(arrayType: [string, number]) { this._arrayType = arrayType; } + get arrayType(): (string | number | any)[] { return this._arrayType; } + set arrayType(arrayType: (string | number | any)[]) { this._arrayType = arrayType; } get otherModel(): OtherModel | undefined { return this._otherModel; } set otherModel(otherModel: OtherModel | undefined) { this._otherModel = otherModel; } diff --git a/test/helpers/ConstrainHelpers.spec.ts b/test/helpers/ConstrainHelpers.spec.ts index 8e64b34f83..c8fb7b0172 100644 --- a/test/helpers/ConstrainHelpers.spec.ts +++ b/test/helpers/ConstrainHelpers.spec.ts @@ -146,7 +146,7 @@ describe('ConstrainHelpers', () => { constrainedModel.options.extend?.at(0) instanceof ConstrainedObjectModel ).toEqual(true); expect(mockedConstraints.modelName).toHaveBeenCalledTimes(2); - expect(mockedTypeMapping.Object).toHaveBeenCalledTimes(2); + expect(mockedTypeMapping.Object).toHaveBeenCalledTimes(1); }); }); describe('constrain ReferenceModel', () => {