import { InterfaceDeclaration , TypescriptParser } from 'typescript-parser' ; import { NgOpenApiGen } from '../lib/ng-openapi-gen' ; import options from './polymorphic.config.json' ; import selfRef from './polymorphic.json' ; const gen = new NgOpenApiGen ( selfRef , options ) ; gen . generate ( ) ; describe ( 'Generation of derived classes using polymorphic.json (as is generated by Swashbuckle)' , ( ) => { it ( 'Tazk model' , ( done ) => { const tazk = gen . models . get ( 'Foo.Bar.Tazk' ) ; const ts = gen . templates . apply ( 'model' , tazk ) ; const parser = new TypescriptParser ( ) ; parser . parseSource ( ts ) . then ( ( ast ) => { expect ( ast . declarations . length ) . toBe ( 1 ) ; expect ( ast . declarations [ 0 ] ) . toEqual ( jasmine . any ( InterfaceDeclaration ) ) ; const decl = ast . declarations [ 0 ] as InterfaceDeclaration ; expect ( decl . name ) . toBe ( 'Tazk' ) ; expect ( decl . properties ) . toHaveSize ( 1 ) ; expect ( decl . properties [ 0 ] . name ) . toBe ( 'taskNumber' ) ; } ) ; done ( ) ; } ) ; it ( 'Dooz model' , ( done ) => { const tazk = gen . models . get ( 'Foo.Bar.Dooz' ) ; const ts = gen . templates . apply ( 'model' , tazk ) ; const parser = new TypescriptParser ( ) ; parser . parseSource ( ts ) . then ( ( ast ) => { expect ( ast . declarations . length ) . toBe ( 1 ) ; expect ( ast . declarations [ 0 ] ) . toEqual ( jasmine . any ( InterfaceDeclaration ) ) ; const decl = ast . declarations [ 0 ] as InterfaceDeclaration ; expect ( decl . name ) . toBe ( 'Dooz' ) ; expect ( decl . properties ) . toHaveSize ( 1 ) ; expect ( decl . properties [ 0 ] . name ) . toBe ( 'doozObject' ) ; expect ( decl . properties [ 0 ] . type ) . toBe ( 'FooBarTazk & {\n\'doozNumber\'?: number;\n}' ) ; } ) ; done ( ) ; } ) ; } ) ;