Skip to content

Commit b0271e5

Browse files
author
Luis Fernando Planella Gonzalez
committed
Added another test case
1 parent 1b9729e commit b0271e5

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

test/all-types.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
{
4848
"$ref": "#/components/schemas/InlineObject"
4949
},
50+
{
51+
"$ref": "#/components/schemas/Circle"
52+
},
5053
{
5154
"$ref": "#/components/schemas/AuditCdr"
5255
}
@@ -603,6 +606,28 @@
603606
}
604607
}
605608
]
609+
},
610+
"Shape": {
611+
"type": "object",
612+
"properties": {
613+
"name": {
614+
"type": "string"
615+
}
616+
}
617+
},
618+
"Circle": {
619+
"type": "object",
620+
"allOf": [
621+
{
622+
"$ref": "#/components/schemas/Shape"
623+
}
624+
],
625+
"properties": {
626+
"radius": {
627+
"type": "integer"
628+
}
629+
},
630+
"additionalProperties": false
606631
}
607632
}
608633
}

test/all-types.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,4 +508,22 @@ describe('Generation tests using all-types.json', () => {
508508
done();
509509
});
510510
});
511+
512+
it('Circle model', done => {
513+
const audit = gen.models.get('Circle');
514+
const ts = gen.templates.apply('model', audit);
515+
const parser = new TypescriptParser();
516+
parser.parseSource(ts).then(ast => {
517+
expect(ast.imports.length).toBe(1);
518+
expect(ast.imports.find(i => i.libraryName === './shape')).withContext('shape import').toBeDefined();
519+
expect(ast.declarations.length).toBe(1);
520+
expect(ast.declarations[0]).toEqual(jasmine.any(TypeAliasDeclaration));
521+
const decl = ast.declarations[0] as TypeAliasDeclaration;
522+
expect(decl.name).toBe('Circle');
523+
const text = ts.substring(decl.start || 0, decl.end || ts.length);
524+
expect(text).toContain('Circle = Shape & {');
525+
expect(text).toContain('\'radius\'?: number');
526+
done();
527+
});
528+
});
511529
});

0 commit comments

Comments
 (0)