Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Apr 29, 2024
1 parent 1736757 commit 16990b4
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 67 deletions.
4 changes: 2 additions & 2 deletions examples/file-uri-input/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
37 changes: 20 additions & 17 deletions examples/file-uri-input/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});

});
4 changes: 2 additions & 2 deletions modelina-cli/package-lock.json

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

13 changes: 5 additions & 8 deletions src/interpreter/InterpretAdditionalItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions test/generators/cplusplus/CplusplusGenerator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ describe('CplusplusGenerator', () => {
'#include <string>',
'#include <optional>',
'#include <variant>',
'#include <tuple>',
'#include <vector>',
'#include <any>',
'#include <vector>',
'#include <map>'
];
const models = await generator.generate(doc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports[`CplusplusGenerator Class should render \`class\` type 1`] = `
double house_number;
std::optional<bool> marriage;
std::optional<std::variant<std::string, double, bool>> members;
std::optional<std::tuple<std::string, double>> tuple_type;
std::optional<std::vector<std::variant<std::string, double, std::any>>> tuple_type;
std::vector<std::variant<std::string, double>> array_type;
std::optional<std::map<std::string, std::variant<std::any, std::string>>> additional_properties;
};"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, dynamic>? additionalProperties;
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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<string, dynamic>? AdditionalProperties { get; init; }
}"
Expand Down Expand Up @@ -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<string, dynamic>? additionalProperties;
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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<string, dynamic>? additionalProperties;
Expand Down Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,7 @@ exports[`JavaGenerator should not render reserved keyword 1`] = `

exports[`JavaGenerator should render \`class\` type 1`] = `
Array [
"",
"",
"",
"public class Address {
Expand Down
6 changes: 3 additions & 3 deletions test/generators/php/__snapshots__/PhpGenerator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any | string>;
Expand All @@ -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<string, any | string>,
}) {
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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<string, any | string>;
}"
Expand Down Expand Up @@ -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<string, any | string>;
Expand All @@ -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<string, any | string>,
}) {
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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<string, any | string>;
Expand All @@ -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<string, any | string>,
}) {
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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<string, any | string>;
Expand All @@ -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<string, any | string>,
}) {
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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<string, any | string>;
Expand All @@ -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<string, any | string>,
}) {
Expand Down Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/ConstrainHelpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 16990b4

Please sign in to comment.