swagger-api / swagger-editor

Swagger Editor
https://editor.swagger.io
Apache License 2.0
8.94k stars 2.26k forks source link

How can I get the online Swagger editor's validation in a command-line tool? #1629

Closed MartinDelVecchio closed 6 years ago

MartinDelVecchio commented 6 years ago

I am using https://editor.swagger.io to validate my Swagger. I am getting errors like this:

Semantic error at paths./whatever/whatever Read only properties cannot be marked as required by a schema.

Semantic error at definitions.whatever.properties.something.description Sibling values are not allowed alongside $refs

I want to perform this level of validation during my build process. Is there a command-line tool that performs this same level of validation?

Q A
Bug or feature request? Not sure
Which Swagger/OpenAPI version? 2.0
Which Swagger-Editor version? Any
How did you install Swagger-Editor? Online
Which broswer & version? Chrome 63
Which operating system? Windows 10

Demonstration API definition

Configuration (browser query string, constructor, config.yaml)

Expected Behavior

Current Behavior

Possible Solution

Context

shockey commented 6 years ago

There is not, our semantic validation is contained within the Swagger-Editor project.

That being said, thank you for mentioning it! We'll take it into consideration as we continue to improve the project.

Closing for now - if there's anything else, or I misunderstood something, just reply!

shockey commented 6 years ago

PS: there is a library that works as a CLI for extended validation, check out https://github.com/wework/speccy. It's not related to the validators in Swagger-Editor, though.

MartinDelVecchio commented 6 years ago

I have tried several other validators, and they all give thumbs-up to documents that the online Swagger Editor finds fault with.

So for now, I am stuck manually uploading my Swagger to the online editor, and verifying that it still passes. And doing that before my boss does.

Thanks.

webron commented 6 years ago

@MartinDelVecchio do you get the same experience of 'valid' documents using our online validator?

MartinDelVecchio commented 6 years ago

I'm not sure I understand the question.

Is "our online validator" a different tool than the online Swagger editor (https://editor.swagger.io/)?

Thanks.

webron commented 6 years ago

Yes, it's a different tool - it's the one used to validate through swagger-ui. For example, https://online.swagger.io/validator/debug?url=http://petstore.swagger.io/v2/swagger.json.

jsilvagluky commented 6 years ago

I'm using:

docker run --rm -v $PWD:$PWD -w $PWD -it swaggerapi/swagger-codegen-cli validate -i openapi.yaml

Altought its output isn't as good as the one the online editor gives. If I can't decode what that validator says then I copy&paste to online editor, and after I'm finished I also copy it to the editor for final inspection and documentation preview.

FloWi commented 6 years ago

I'd also welcome if you could extract the validations used in swagger-editor into a separate lib. I have the same issue as @MartinDelVecchio - the java-validation says everything's fine but editor.swagger.io finds lots of issues with my generated spec. I'm no javascript expert - would it be a lot of work to create a separate js module?

shockey commented 6 years ago

@FloWi: would it be a lot of work to create a separate js module?

It wouldn't be a nightmare, but the validation system is currently mounted to the Swagger UI plugin system in a few places, so structural changes would need to be made.

FloWi commented 6 years ago

@shockey: It wouldn't be a nightmare, but the validation system is currently mounted to the Swagger UI plugin system in a few places, so structural changes would need to be made.

That sounds great. Looking forward to it. Maybe I can convince some of our javascript guys to chip in :)

mambru commented 5 years ago

@MartinDelVecchio do you get the same experience of 'valid' documents using our online validator?

Currently I'm getting different results using: editor.swagger.io and online.swagger.io, the first one finds errors while the second one reports everything is good.

I'm looking for a way to automate this on my CI/CD, but using online.swagger.io is not finding the issues that I need to avoid.

I appreciate any direction!

shockey commented 5 years ago

hey @mambru, IMO the way you're currently doing it is the best way 😕 Swagger Editor's validation engine is still only available in the Editor itself.

VamshikShetty commented 5 years ago

hey @mambru, IMO the way you're currently doing it is the best way 😕 Swagger Editor's validation engine is still only available in the Editor itself.

@shockey @FloWi Is there any future plan to take out the swagger editor's validation engine and provide it as an independent module ?

viralmodi commented 5 years ago

@shockey I vote +1 for this request. This would be useful for developing automation.

jdiazgon commented 5 years ago

+1 on this. We are also facing the same issue, that other validators doesn't work well.

briterator commented 5 years ago

this would be very helpful

please

andylowry commented 5 years ago

do you get the same experience of 'valid' documents using our online validator

@webron Two examples I've seen recently of errors flagged by swagger-editor but missed by the online validator:

This was when validating v2 models. Not sure if v3 would do the same.

I haven't found anything as reliable as swagger-editor's internal validator. I would love to see the latter available separately from the online editor.