Validate JSON response against SWAGGER document

Simply,

I have a swagger document for a web-service, I want to validate that the response from the service (JSON) matches the format defined by the SWAGGER doc.

I have found myriad ways of testing to make sure the swagger is valid, and for testing against a JSON Schema, but next to nothing on validating data against the swagger doc.

Thanks in advance
Gary

2 Likes

Have you tried the validation features in https://github.com/xerions/phoenix_swagger? Perhaps the test response validator could be of use?

3 Likes

Thanks, will look there!

1 Like

Which version of swagger are you using?

open_api_spex is a bit like phoenix swagger but targets swagger (open api) 3.0.

It doesn’t support reading the swagger document from file yet, so might not be what you’re looking for.

3 Likes

Thanks will look at that too.

I did come up with a hybrid solution, I found a python app which extract the schema from the swagger and then used ExJsonSchema to validate, works great on my mac, unfortunately not so well on a windows PC for work, I believe it’s the difference in file paths i.e. ‘’ vs ‘/’.

Anyway thanks of the info, I will go read up on it.

Gary

1 Like

Hi @afulki,

Were you able to find something concerte for Validating JSON response against swagger document?
I am having no luck, if you could help a little.

Thanks!

I didn’t find an easy solution, I wrote a small command line app in Elixir which executes the python script as a system call.This results in the swagger being split into a series of JSON Schema files, in a subdirectory, as I know the operation (passed in the command line) I also know which operation I’m testing. So I can open the appropriate JSON schema file and compare that against the response from the web-service.

I’m sorry I can’t share the source, it was written on the company time :slightly_frowning_face: