Skip to content

Commit

Permalink
use import for json data
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmine DiMascio committed Jul 20, 2019
1 parent 7f41282 commit fd014dd
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/framework/openapi.schema.validator.ts
@@ -1,8 +1,8 @@
import * as Ajv from 'ajv';
import * as merge from 'lodash.merge'
const draftSchema = require('ajv/lib/refs/json-schema-draft-04.json');
import * as draftSchema from 'ajv/lib/refs/json-schema-draft-04.json';
// https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v3.0/schema.json
const openapi3Schema = require('./openapi.v3.schema.json');
import * as openapi3Schema from './openapi.v3.schema.json';

export default class OpenAPISchemaValidator{
private validator: Ajv.ValidateFunction;
Expand Down
14 changes: 9 additions & 5 deletions src/middlewares/openapi.request.validator.ts
@@ -1,9 +1,7 @@
import * as Ajv from 'ajv';

import { validationError } from '../errors';
import ono from 'ono';

const draftSchema = require('ajv/lib/refs/json-schema-draft-04.json');
import * as draftSchema from 'ajv/lib/refs/json-schema-draft-04.json';

const TYPE_JSON = 'application/json';

Expand Down Expand Up @@ -205,7 +203,9 @@ export class RequestValidator {
*/
parameters.parseArray.forEach(item => {
if (req[item.reqField] && req[item.reqField][item.name]) {
req[item.reqField][item.name] = req[item.reqField][item.name].split(item.delimiter);
req[item.reqField][item.name] = req[item.reqField][item.name].split(
item.delimiter,
);
}
});

Expand Down Expand Up @@ -299,7 +299,11 @@ export class RequestValidator {
throw ono(err, message);
}

if (parameter.schema && parameter.schema.type === 'array' && !parameter.explode) {
if (
parameter.schema &&
parameter.schema.type === 'array' &&
!parameter.explode
) {
const delimiter = arrayDelimiter[parameter.style];
if (!delimiter) {
const message = `Parameter 'style' has incorrect value '${parameter.style}' for [${parameter.name}]`;
Expand Down
2 changes: 1 addition & 1 deletion test/headers.spec.ts
@@ -1,9 +1,9 @@
import { expect } from 'chai';
import * as request from 'supertest';
import { createApp } from './app';
import * as packageJson from '../package.json';

const app = createApp({ apiSpecPath: './openapi.yaml' }, 3004);
const packageJson = require('../package.json');
const basePath = (<any>app).basePath;

describe(packageJson.name, () => {
Expand Down
3 changes: 1 addition & 2 deletions test/middleware.spec.ts
@@ -1,7 +1,6 @@
import { expect } from 'chai';
import { OpenApiValidator } from '../src';

const packageJson = require('../package.json');
import * as packageJson from '../package.json';

describe(packageJson.name, () => {
it('should succeed when spec exists and is valid', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/multipart.spec.ts
@@ -1,9 +1,9 @@
import { expect } from 'chai';
import * as request from 'supertest';
import { createApp } from './app';
import * as packageJson from '../package.json';

const app = createApp({ apiSpecPath: './openapi.yaml' }, 3003);
const packageJson = require('../package.json');
const basePath = (<any>app).basePath;

describe(packageJson.name, () => {
Expand Down
3 changes: 2 additions & 1 deletion test/routes.spec.ts
@@ -1,7 +1,8 @@
import { expect } from 'chai';
import * as request from 'supertest';
import { createApp } from './app';
const apiSpec = require('./resources/openapi.json');
import * as apiSpec from './resources/openapi.json';

const app = createApp({ apiSpecPath: './openapi.yaml' }, 3001);
const app2 = createApp({ apiSpec }, 3002);

Expand Down
4 changes: 3 additions & 1 deletion tsconfig.json
Expand Up @@ -5,8 +5,10 @@
"lib": ["es6", "dom"],
"module": "commonjs",
"outDir": "dist",
"sourceMap": true
"sourceMap": true,
"resolveJsonModule": true
},

"exclude": ["node_modules"],
"include": ["typings.d.ts", "src/**/*.ts"]
}

0 comments on commit fd014dd

Please sign in to comment.