Skip to content

Commit

Permalink
move spec read to framework
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmine DiMascio committed Mar 22, 2019
1 parent 85a7513 commit f30f0b6
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions index.ts
Expand Up @@ -7,7 +7,6 @@ import OpenAPIFramework, {
import OpenAPIRequestValidator from 'openapi-request-validator';
import OpenAPIRequestCoercer from 'openapi-request-coercer';
import { OpenAPIFrameworkAPIContext } from './fw/types';
import { handleYaml, loadSpecFile } from './fw/util';
import { methodNotAllowed, notFoundError } from './errors';

// import { OpenAPIResponseValidatorError } from 'openapi-response-validator';
Expand All @@ -26,15 +25,11 @@ export interface OpenApiMiddlewareOpts extends OpenAPIFrameworkArgs {

export function OpenApiMiddleware(opts: OpenApiMiddlewareOpts) {
if (!opts.apiSpecPath) throw new Error('apiSpecPath required');
const apiContents = loadSpecFile(opts.apiSpecPath);
if (!apiContents)
throw new Error(`spec could not be read at ${opts.apiSpecPath}`);

opts.enableObjectCoercion = opts.enableObjectCoercion || true;
opts.name = opts.name || 'express-middleware-openapi';

const apiDoc = handleYaml(apiContents);
const framework = createFramework({ ...opts, apiDoc });
const framework = createFramework({ ...opts, apiDoc: opts.apiSpecPath });

this.opts = opts;
this.apiDoc = framework.apiDoc;
Expand Down

0 comments on commit f30f0b6

Please sign in to comment.