swagger-api / validator-badge

Validate your Swagger JSON/YAML today!
http://swagger.io
Apache License 2.0
210 stars 85 forks source link

Enable validation of contents and not only via URL #41

Closed ricardo-de-andrade closed 8 years ago

ricardo-de-andrade commented 9 years ago

It would be nice if the tool would allow the user to invoke the validator tool and pass the contents of the yaml/json (even if only the /debug).

For example (some other method of achieving it would be just as good): curl -X POST /validator/debug --data-binary @{fileName}

This would simplify the integration of the tool in to build automation processes for example, where the API definition may not be available online.

Today a workaround would be to start the tool locally, and then start a local webserver just for the validation, which is a bit heavy.

jessedc commented 9 years ago

+1 using this tool within a CI/command line environment would be great

fehguy commented 9 years ago

Hi, you mean like this?

curl -X POST -H "accept:application/json" -d @petstore.json http://online.swagger.io/validator/debug
jessedc commented 9 years ago

Something like that would be handy, yeah. Then the json doesn't need to be publicly accessible.

fehguy commented 9 years ago

OK got it. Then you're in luck! The validator supports this already. See here:

https://github.com/swagger-api/validator-badge/blob/master/src/main/java/io/swagger/validator/resources/ValidatorResource.java#L62-L78

and per my last comment, it's supported in the online codegen. Please close if this covers your concerns...

jessedc commented 9 years ago

That's great for my purposes, thanks! It would be great if it was documented in the README. I will endeavour to submit a PR.

jeff9finger commented 8 years ago

What is the content type for a yaml file? I'v tried

url -X POST -H "accept:text/x-yaml" -d @abc.yaml http://online.swagger.io/validator/debug

But get

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Error 406 Not Acceptable</title>
</head>
<body><h2>HTTP ERROR 406</h2>
<p>Problem accessing /validator/debug. Reason:
<pre>    Not Acceptable</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>

</body>
</html>

Maybe I have the incorrect media type? not sure what to use for yaml

webron commented 8 years ago

application/yaml

jeff9finger commented 8 years ago

Thanks,

OK. I tried

url -X POST -H "accept:application/yaml" -d @abc.yaml http://online.swagger.io/validator/debug

And still get the 406 response code.

I tried it from postman and it seems to work. Any other suggestions?

webron commented 8 years ago

It's not the accept header you need to send, it's the content-type.

jeff9finger commented 8 years ago

OK.

I used the example from above to start with. However, I tried Content-Type as well.

curl -v -X POST -H "Accept:application/yaml" -H "Content-Type:application/yaml" --data @abc.yaml "http://online.swagger.io/validator/debug"

I still get a 406. When I send just the content-type I get 500.

Here is the verbose output.

*   Trying 52.3.245.229...
* Connected to online.swagger.io (52.3.245.229) port 80 (#0)
> POST /validator/debug HTTP/1.1
> Host: online.swagger.io
> User-Agent: curl/7.43.0
> Accept:application/yaml
> Content-Type:application/yaml
> Content-Length: 3574
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
< HTTP/1.1 406 Not Acceptable
< Date: Fri, 11 Mar 2016 21:05:06 GMT
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, POST, DELETE, PUT
< Access-Control-Allow-Headers: Content-Type
< Content-Type: text/html; charset=ISO-8859-1
< Cache-Control: must-revalidate,no-cache,no-store
< Content-Length: 309
< Connection: close
< Server: Jetty(9.2.9.v20150224)
<
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Error 406 Not Acceptable</title>
</head>
<body><h2>HTTP ERROR 406</h2>
<p>Problem accessing /validator/debug. Reason:
<pre>    Not Acceptable</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>

</body>
</html>
* Closing connection 0
webron commented 8 years ago

The following works for me, can you try that?

curl -X POST -H "content-type:application/yaml" --data-binary @swagger.yaml "http://online.swagger.io/validator/debug"
jeff9finger commented 8 years ago

That works. looks like the key is --data-binary instead on --data

Thanks