|
| 1 | +import { OpenAPIObject } from '@loopback/openapi-v3-types'; |
| 2 | +import { InterfaceDeclaration, TypescriptParser } from 'typescript-parser'; |
| 3 | +import { NgOpenApiGen } from '../lib/ng-openapi-gen'; |
| 4 | +import { Options } from '../lib/options'; |
| 5 | +import options from './camelize-model-names.config.json'; |
| 6 | +import camelizeModelNamesSpec from './camelize-model-names.json'; |
| 7 | + |
| 8 | +const gen = new NgOpenApiGen(camelizeModelNamesSpec as OpenAPIObject, options as Options); |
| 9 | +gen.generate(); |
| 10 | + |
| 11 | +describe('Generation tests using camelize-model-names.json', () => { |
| 12 | + it('snake-case model', done => { |
| 13 | + const ref = gen.models.get('snake-case'); |
| 14 | + const ts = gen.templates.apply('model', ref); |
| 15 | + const parser = new TypescriptParser(); |
| 16 | + parser.parseSource(ts).then(ast => { |
| 17 | + expect(ast.imports.length).toBe(0); |
| 18 | + expect(ast.declarations.length).toBe(1); |
| 19 | + expect(ast.declarations[0]).toEqual(jasmine.any(InterfaceDeclaration)); |
| 20 | + const decl = ast.declarations[0] as InterfaceDeclaration; |
| 21 | + expect(decl.name).toBe('PreSnake_casePos'); |
| 22 | + done(); |
| 23 | + }); |
| 24 | + }); |
| 25 | + it('camelCase model', done => { |
| 26 | + const ref = gen.models.get('camelCase'); |
| 27 | + const ts = gen.templates.apply('model', ref); |
| 28 | + const parser = new TypescriptParser(); |
| 29 | + parser.parseSource(ts).then(ast => { |
| 30 | + expect(ast.imports.length).toBe(0); |
| 31 | + expect(ast.declarations.length).toBe(1); |
| 32 | + expect(ast.declarations[0]).toEqual(jasmine.any(InterfaceDeclaration)); |
| 33 | + const decl = ast.declarations[0] as InterfaceDeclaration; |
| 34 | + expect(decl.name).toBe('PreCamelCasePos'); |
| 35 | + done(); |
| 36 | + }); |
| 37 | + }); |
| 38 | +}); |
0 commit comments