Skip to content

Commit

Permalink
fix: type are not determined in cyclic models (#1906)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored May 6, 2024
1 parent d1e64d6 commit 6ff9698
Show file tree
Hide file tree
Showing 25 changed files with 1,347 additions and 689 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
34 changes: 18 additions & 16 deletions examples/file-uri-input/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@ 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.

24 changes: 23 additions & 1 deletion src/generators/cplusplus/CplusplusGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import {
defaultGeneratorOptions
} from '../AbstractGenerator';
import {
ConstrainedAnyModel,
ConstrainedBooleanModel,
ConstrainedEnumModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedMetaModel,
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedStringModel,
InputMetaModel,
MetaModel,
RenderOutput
Expand Down Expand Up @@ -52,6 +58,21 @@ export type CplusplusPropertyKeyConstraint =

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface CplusplusRenderCompleteModelOptions {}

/**
* All the constrained models that do not depend on others to determine the type
*/
const SAFE_MODEL_TYPES: any[] = [
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedAnyModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedStringModel,
ConstrainedBooleanModel,
ConstrainedEnumModel
];

export class CplusplusGenerator extends AbstractGenerator<
CplusplusOptions,
CplusplusRenderCompleteModelOptions
Expand Down Expand Up @@ -126,7 +147,8 @@ export class CplusplusGenerator extends AbstractGenerator<
dependencyManager: dependencyManagerToUse,
options: this.options,
constrainedName: '' //This is just a placeholder, it will be constrained within the function
}
},
SAFE_MODEL_TYPES
);
}

Expand Down
25 changes: 24 additions & 1 deletion src/generators/csharp/CSharpGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ import {
defaultGeneratorOptions
} from '../AbstractGenerator';
import {
ConstrainedAnyModel,
ConstrainedBooleanModel,
ConstrainedEnumModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedMetaModel,
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedStringModel,
ConstrainedUnionModel,
InputMetaModel,
MetaModel,
RenderOutput
Expand Down Expand Up @@ -61,6 +68,21 @@ export interface CSharpRenderCompleteModelOptions {
namespace: string;
}

/**
* All the constrained models that do not depend on others to determine the type
*/
const SAFE_MODEL_TYPES: any[] = [
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedAnyModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedStringModel,
ConstrainedBooleanModel,
ConstrainedEnumModel,
ConstrainedUnionModel
];

/**
* Generator for CSharp
*/
Expand Down Expand Up @@ -144,7 +166,8 @@ export class CSharpGenerator extends AbstractGenerator<
dependencyManager: dependencyManagerToUse,
options: this.options,
constrainedName: '' //This is just a placeholder, it will be constrained within the function,
}
},
SAFE_MODEL_TYPES
);
}

Expand Down
29 changes: 27 additions & 2 deletions src/generators/dart/DartGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ import {
MetaModel,
ConstrainedObjectModel,
ConstrainedEnumModel,
InputMetaModel
InputMetaModel,
ConstrainedAnyModel,
ConstrainedBooleanModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedReferenceModel,
ConstrainedStringModel,
ConstrainedTupleModel,
ConstrainedUnionModel
} from '../../models';
import {
ConstantConstraint,
Expand Down Expand Up @@ -52,6 +60,22 @@ export interface DartRenderCompleteModelOptions {
packageName: string;
}

/**
* All the constrained models that do not depend on others to determine the type
*/
const SAFE_MODEL_TYPES: any[] = [
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedAnyModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedStringModel,
ConstrainedBooleanModel,
ConstrainedTupleModel,
ConstrainedEnumModel,
ConstrainedUnionModel
];

export class DartGenerator extends AbstractGenerator<
DartOptions,
DartRenderCompleteModelOptions
Expand Down Expand Up @@ -123,7 +147,8 @@ export class DartGenerator extends AbstractGenerator<
dependencyManager: dependencyManagerToUse,
options: this.options,
constrainedName: '' //This is just a placeholder, it will be constrained within the function
}
},
SAFE_MODEL_TYPES
);
}
/**
Expand Down
32 changes: 29 additions & 3 deletions src/generators/go/GoGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ import {
ConstrainedObjectModel,
ConstrainedEnumModel,
ConstrainedMetaModel,
ConstrainedUnionModel,
MetaModel
MetaModel,
ConstrainedAnyModel,
ConstrainedBooleanModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedReferenceModel,
ConstrainedStringModel,
ConstrainedTupleModel,
ConstrainedUnionModel
} from '../../models';
import {
ConstantConstraint,
Expand Down Expand Up @@ -59,6 +66,24 @@ export interface GoRenderCompleteModelOptions {
packageName: string;
}

/**
* All the constrained models that do not depend on others to determine the type
*/
const SAFE_MODEL_TYPES: any[] = [
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedAnyModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedStringModel,
ConstrainedBooleanModel,
ConstrainedTupleModel,
ConstrainedEnumModel
];

/**
* Generator for Go
*/
export class GoGenerator extends AbstractGenerator<
GoOptions,
GoRenderCompleteModelOptions
Expand Down Expand Up @@ -133,7 +158,8 @@ export class GoGenerator extends AbstractGenerator<
dependencyManager: dependencyManagerToUse,
options: this.options,
constrainedName: '' //This is just a placeholder, it will be constrained within the function
}
},
SAFE_MODEL_TYPES
);
}

Expand Down
27 changes: 26 additions & 1 deletion src/generators/java/JavaGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ import {
defaultGeneratorOptions
} from '../AbstractGenerator';
import {
ConstrainedAnyModel,
ConstrainedBooleanModel,
ConstrainedEnumModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedMetaModel,
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedStringModel,
ConstrainedTupleModel,
ConstrainedUnionModel,
InputMetaModel,
MetaModel,
Expand Down Expand Up @@ -54,6 +61,23 @@ export type JavaTypeMapping = TypeMapping<JavaOptions, JavaDependencyManager>;
export interface JavaRenderCompleteModelOptions {
packageName: string;
}

/**
* All the constrained models that do not depend on others to determine the type
*/
const SAFE_MODEL_TYPES: any[] = [
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedAnyModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedStringModel,
ConstrainedBooleanModel,
ConstrainedTupleModel,
ConstrainedEnumModel,
ConstrainedUnionModel
];

export class JavaGenerator extends AbstractGenerator<
JavaOptions,
JavaRenderCompleteModelOptions
Expand Down Expand Up @@ -126,7 +150,8 @@ export class JavaGenerator extends AbstractGenerator<
dependencyManager: dependencyManagerToUse,
options: this.options,
constrainedName: '' //This is just a placeholder, it will be constrained within the function
}
},
SAFE_MODEL_TYPES
);
}

Expand Down
32 changes: 31 additions & 1 deletion src/generators/javascript/JavaScriptGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@ import {
defaultGeneratorOptions
} from '../AbstractGenerator';
import {
ConstrainedAnyModel,
ConstrainedArrayModel,
ConstrainedBooleanModel,
ConstrainedDictionaryModel,
ConstrainedEnumModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedMetaModel,
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedStringModel,
ConstrainedTupleModel,
ConstrainedUnionModel,
InputMetaModel,
MetaModel,
RenderOutput
Expand Down Expand Up @@ -55,6 +66,24 @@ export type JavaScriptTypeMapping = TypeMapping<
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface JavaScriptRenderCompleteModelOptions {}

/**
* All the constrained models that do not depend on others to determine the type
*/
const SAFE_MODEL_TYPES: any[] = [
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedAnyModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedStringModel,
ConstrainedBooleanModel,
ConstrainedTupleModel,
ConstrainedArrayModel,
ConstrainedEnumModel,
ConstrainedUnionModel,
ConstrainedDictionaryModel
];

/**
* Generator for JavaScript
*/
Expand Down Expand Up @@ -210,7 +239,8 @@ ${modelCode}`;
dependencyManager: dependencyManagerToUse,
options: this.options,
constrainedName: '' //This is just a placeholder, it will be constrained within the function
}
},
SAFE_MODEL_TYPES
);
}

Expand Down
Loading

0 comments on commit 6ff9698

Please sign in to comment.