diff --git a/templates/index.handlebars b/templates/index.handlebars index d592cb1..212b205 100644 --- a/templates/index.handlebars +++ b/templates/index.handlebars @@ -6,7 +6,9 @@ export { {{configurationClass}} } from './{{{configurationFile}}}'; export { {{baseServiceClass}} } from './{{{baseServiceFile}}}'; export { {{requestBuilderClass}} } from './{{{requestBuilderFile}}}'; export { {{responseClass}} } from './{{{responseFile}}}'; +{{#if moduleClass}} export { {{moduleClass}} } from './{{{moduleFile}}}'; +{{/if}} {{#modelIndex.imports}}export { {{{typeName}}}{{#useAlias}} as {{{qualifiedName}}}{{/useAlias}} } from './models{{{file}}}'; {{/modelIndex.imports}} {{#services}}export { {{typeName}} } from './services/{{{fileName}}}'; diff --git a/test/all-types.spec.ts b/test/all-types.spec.ts index 64b94b7..2a556a6 100644 --- a/test/all-types.spec.ts +++ b/test/all-types.spec.ts @@ -1,5 +1,5 @@ import { OpenAPIObject } from '@loopback/openapi-v3-types'; -import { ClassDeclaration, EnumDeclaration, InterfaceDeclaration, TypeAliasDeclaration, TypescriptParser } from 'typescript-parser'; +import { ClassDeclaration, EnumDeclaration, InterfaceDeclaration, NamedExport, TypeAliasDeclaration, TypescriptParser } from 'typescript-parser'; import { NgOpenApiGen } from '../lib/ng-openapi-gen'; import { Options } from '../lib/options'; import options from './all-types.config.json'; @@ -526,4 +526,19 @@ describe('Generation tests using all-types.json', () => { done(); }); }); + + it('index file', done => { + const ref = gen.models.get('InlineObject'); + const ts = gen.templates.apply('index', ref); + const parser = new TypescriptParser(); + parser.parseSource(ts).then(ast => { + expect(ast.exports.length).withContext('Has the correct number of exports').toBe(5); + expect(ast.exports.some((ex: NamedExport) => ex.from === './api-configuration')).withContext('Has an ApiConfiguration export').toBeDefined(); + expect(ast.exports.some((ex: NamedExport) => ex.from === './base-service')).withContext('Has a BaseService export').toBeDefined(); + expect(ast.exports.some((ex: NamedExport) => ex.from === './request-builder')).withContext('Has a RequestBuilder export').toBeDefined(); + expect(ast.exports.some((ex: NamedExport) => ex.from === './strict-http-response')).withContext('Has a StrictHttpResponse export').toBeDefined(); + expect(ast.exports.some((ex: NamedExport) => ex.from === './api.module')).withContext('Has an ApiModule export').toBeDefined(); + done(); + }); + }); }); diff --git a/test/noModule.config.json b/test/noModule.config.json new file mode 100644 index 0000000..c15b0d2 --- /dev/null +++ b/test/noModule.config.json @@ -0,0 +1,8 @@ +{ + "$schema": "../ng-openapi-gen-schema.json", + "input": "test/noModule.json", + "output": "out/noModule", + "useTempDir": true, + "module": false, + "indexFile": true +} diff --git a/test/noModule.json b/test/noModule.json new file mode 100644 index 0000000..fdeb1db --- /dev/null +++ b/test/noModule.json @@ -0,0 +1,25 @@ +{ + "openapi": "3.0", + "info": { + "title": "Test with noModule", + "version": "1.0" + }, + "paths": { + "/foo": { + "get": { + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "type": "string" + } + }, + "text/plain": {} + } + } + } + } + } + } +} diff --git a/test/noModule.spec.ts b/test/noModule.spec.ts new file mode 100644 index 0000000..0deb00e --- /dev/null +++ b/test/noModule.spec.ts @@ -0,0 +1,28 @@ +import { OpenAPIObject } from 'openapi3-ts'; +import { NgOpenApiGen } from '../lib/ng-openapi-gen'; +import options from './noModule.config.json'; +import templatesSpec from './noModule.json'; +import { NamedExport, TypescriptParser } from 'typescript-parser'; + +describe('Generation tests with index and no ApiModule', () => { + const gen = new NgOpenApiGen(templatesSpec as OpenAPIObject, options); + + beforeAll(() => { + gen.generate(); + }); + + it('index file', done => { + const ref = gen.models.get('InlineObject'); + const ts = gen.templates.apply('index', ref); + const parser = new TypescriptParser(); + parser.parseSource(ts).then(ast => { + expect(ast.exports.length).withContext('Has the correct number of exports').toBe(4); + expect(ast.exports.some((ex: NamedExport) => ex.from === './api-configuration')).withContext('Has an ApiConfiguration export').toBeDefined(); + expect(ast.exports.some((ex: NamedExport) => ex.from === './base-service')).withContext('Has a BaseService export').toBeDefined(); + expect(ast.exports.some((ex: NamedExport) => ex.from === './request-builder')).withContext('Has a RequestBuilder export').toBeDefined(); + expect(ast.exports.some((ex: NamedExport) => ex.from === './strict-http-response')).withContext('Has a StrictHttpResponse export').toBeDefined(); + done(); + }); + }); + +});