Skip to content

Commit

Permalink
linter updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmine DiMascio committed Jul 20, 2019
1 parent fd014dd commit 9fff6ce
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/framework/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import OpenAPISchemaValidator from './openapi.schema.validator';
import { OpenAPISchemaValidator } from './openapi.schema.validator';
import BasePath from './base.path';
import {
ConsoleDebugAdapterLogger,
Expand Down
53 changes: 24 additions & 29 deletions src/framework/openapi.schema.validator.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
import * as Ajv from 'ajv';
import * as merge from 'lodash.merge'
import * as merge from 'lodash.merge';
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
import * as openapi3Schema from './openapi.v3.schema.json';

export default class OpenAPISchemaValidator{
private validator: Ajv.ValidateFunction;
constructor({
version,
extensions,
}) {
const v = new Ajv({ schemaId: 'auto', allErrors: true });
v.addMetaSchema(draftSchema);
const ver = (version && parseInt(String(version), 10));
if (!ver) throw Error('version missing from OpenAPI specification.');
if (ver != 3) throw Error('OpenAPI v3 specification version is required.')
const schema = merge(
{},
openapi3Schema,
extensions || {}
);
v.addSchema(schema);
this.validator = v.compile(schema);
}

public validate(openapiDoc) {
const valid = this.validator(openapiDoc);
if (!valid) {
return { errors: this.validator.errors };
} else {
return { errors: [] };
}
export class OpenAPISchemaValidator {
private validator: Ajv.ValidateFunction;
constructor({ version, extensions }) {
const v = new Ajv({ schemaId: 'auto', allErrors: true });
v.addMetaSchema(draftSchema);

const ver = version && parseInt(String(version), 10);
if (!ver) throw Error('version missing from OpenAPI specification.');
if (ver != 3) throw Error('OpenAPI v3 specification version is required.');

const schema = merge({}, openapi3Schema, extensions || {});
v.addSchema(schema);
this.validator = v.compile(schema);
}

public validate(openapiDoc) {
const valid = this.validator(openapiDoc);
if (!valid) {
return { errors: this.validator.errors };
} else {
return { errors: [] };
}
}
}
}

0 comments on commit 9fff6ce

Please sign in to comment.