Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validateApiDoc props in OpenApiValidatorOpts #525

Merged
merged 2 commits into from Feb 3, 2021

Conversation

ZhouJian26
Copy link
Contributor

Hi, i added validateApiDoc props in OpenApiValidatorOpts interface. I noticed that it was missing, watching these few lines:

const validateApiDoc =
'validateApiDoc' in args ? !!args.validateApiDoc : true;
const validator = new OpenAPISchemaValidator({
version: apiDoc.openapi,
// extensions: this.apiDoc[`x-${args.name}-schema-extension`],
});
if (validateApiDoc) {
const apiDocValidation = validator.validate(apiDoc);
if (apiDocValidation.errors.length) {
console.error(`${this.loggingPrefix}Validating schema`);
console.error(
`${this.loggingPrefix}validation errors`,
JSON.stringify(apiDocValidation.errors, null, ' '),
);
throw new Error(
`${this.loggingPrefix}args.apiDoc was invalid. See the output.`,
);
}
}

Now it is possible to disable the OpenAPI specification validation.

app.use(
  OpenApiValidator.middleware({
    apiSpec: './openapi.yaml',
    validateApiDoc: false // true by default
  }),
);

Copy link
Owner

@cdimascio cdimascio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @ZhouJian26!
i modified this some to rename the new option to validateApiSpec for consistency with the apiSpec option

@cdimascio cdimascio merged commit cfb9fb7 into cdimascio:master Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants