swagger-cli icon indicating copy to clipboard operation
swagger-cli copied to clipboard

Should `bundle` run `validate` first?

Open philcluff opened this issue 6 years ago • 2 comments

I've been working with OpenAPI 3 for the last couple of months, and swagger-cli is an important part of our toolchain.

Our toolchain (like several I've seen) currently runs validate first, followed by a status check, then a bundle if the validate was OK.

bundle currently works fine against a lot of invalid OpenAPI definitions because it doesn't validate first.

To me it would make sense for bundle to also validate, and not attempt to bundle if the file fails validation. I'd also suggest having a --ignore-validation-failures mode too.

It seems wrong to have a tool which produces broken output when provided with a broken input which it already has a way of validating.

I'd love to hear feedback on if this has been thought about / discussed before.

Thanks!

philcluff avatar Feb 13 '19 12:02 philcluff

My preference would be to keep them as separate commands. Many people find the validate command to be too strict, so they just use bundle. But I've also built swagger-cli to be easy for people who want to use both commands. The validate command returns a non-zero exit code if validation fails, which allows you to chain the two commands using the && operator, which is supported by all platforms (Windows, Mac, Linux, etc.):

swagger-cli validate && swagger cli bundle

JamesMessinger avatar Feb 14 '19 10:02 JamesMessinger

I agree you can run the two commands that way.

In my mind, tooling should encourage compliance to the specification wherever possible rather than encouraging engineers to build invalid definitions because the tooling isn't validating, when it has the ability to do so.

What about running the validation and warning to STDERR when an invalid file is detected during bundling?

philcluff avatar Feb 20 '19 12:02 philcluff