Closed Morgunov-Vitaly closed 3 years ago
I'm glad you like the library. We're in the process of creating version 2 that will have types (it's written in TypeScript) but will also have additional metadata and file and line numbers attached to each error, so you might find that useful too.
I have not seen this library used to validate your OpenAPI document as part of a CI/CD pipeline, but I'd imagine that isn't too hard to set up. Are you using Github actions for your CI/CD?
Hi!
Yes, we use GitLab CI/CD.
I need some info about how to interprite result of the js script
Enforcer('spec/luckyads/openapi-dev.yaml', { fullResult: true }) .then(function ({ error, warning }) { if (!error) { console.log('No errors with your document') if (warning) console.warn(warning) } else { console.error(error) } })
How to fetch in .gitlab-ci.yml script result codes:
I don't know GitLab pipelines too well, but if all you need is an error code then you could write a script like this:
Enforcer('spec/luckyads/openapi-dev.yaml', { fullResult: true })
.then(function ({ error, warning }) {
if (!error) {
console.log('No errors with your document')
process.exit(0) // success exit code
} else if (warning) {
console.warn(warning) // warn uses stderr so I think the text will show red, but it should allow you to continue
process.exit(0)
} else {
console.error(error)
process.exit(1) // any non-zero exit code is an error
}
})
Oh, thanks a lot! I'll tyr it.
Sounds great. Let me know if it ends up working.
Also, if you want to pass arguments into the script you can use process.argv.
Hi! I've tried several libraries for OpenApi docs validating. And it seems that this - is my favorite. It gives very similar result as the Swagger Editor with some additional notices. But could you tell me about using this package for GitHub CI/CD proposes?