swagger-api / validator-badge

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

how to POST spec as YAML? #136

Closed dolmen closed 1 year ago

dolmen commented 5 years ago

The README says how to validate a JSON spec by uploading the file with cURL:

curl -X POST -d @swagger.json -H 'Content-Type:application/json' http://online.swagger.io/validator/debug

But how can I do the same using a YAML file? I tried many MIME (application/yaml, text/yaml, application/vnd.yaml) types without success.

kevinoid commented 5 years ago

AFAIK, request Content-Type is currently ignored, so any of those should work. Personally, I use text/x-yaml (with charset as required). However, when uploading YAML, curl's -d option won't work since it strips out newlines. I would suggest trying:

curl -HContent-Type:text/x-yaml --data-binary @swagger.yaml https://online.swagger.io/validator/debug
kevinoid commented 4 years ago

Update: Unlike online.swagger.io, validator.swagger.io does require the request to have Content-Type: application/yaml to validate YAML. Sending text/x-yaml or any of the other YAML types I have tried returns:

HTTP/1.1 400 Bad Request
Content-Type: application/json

{"code":400,"message":"Input error: The input body `...` is required but was provided with an unsupported media type `text/x-yaml`"}

(Suggestion to developers: Consider returning status 415 Unsupported Media Type and mentioning the accepted types in the body.)

Lucasjuv commented 4 years ago

Use --data-binary instead of -d. I was having the same issue. curl -X POST --data-binary @swagger.yml -H 'Content-Type:application/yaml' http://validator.swagger.io/validator/debug