Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
Add a bit more explainations about the console.log override
Browse files Browse the repository at this point in the history
  • Loading branch information
fabien0102 committed May 17, 2019
1 parent ed78ff2 commit bc4df4b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/scripts/import-open-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,14 +480,17 @@ const validate = async (schema: OpenAPIObject) => {
const log = console.log;

// Catch the internal console.log to add some information if needed
let haveOpenAPIValidatorOutput = false;
// because openApiValidator() calls console.log internally and
// we want to add more context if it's used
let wasConsoleLogCalledFromBlackBox = false;
console.log = (...props: any) => {
haveOpenAPIValidatorOutput = true;
wasConsoleLogCalledFromBlackBox = true;
log(...props);
};
const { errors, warnings } = await openApiValidator(schema);
console.log = log;
if (haveOpenAPIValidatorOutput) {
console.log = log; // reset console.log because we're done with the black box

if (wasConsoleLogCalledFromBlackBox) {
log("More information: https://github.com/IBM/openapi-validator/#configuration");
}
if (warnings.length) {
Expand Down

0 comments on commit bc4df4b

Please sign in to comment.