thoughtworks / pacto

Pacto settles disputes between JSON providers and consumers
thoughtworks.github.io/pacto
MIT License
401 stars 58 forks source link

Support for CSV and other formats #150

Closed nightscape closed 9 years ago

nightscape commented 9 years ago

Is there support for formats other than JSON? We're using CSV as exchange format in some places and it would be great to be able to use that in pacto as well. If CSV support does not exist yet, what would need to be done to add it? Can this be done by someone who's not very familiar with pacto yet?

Thanks! Martin

maxlinc commented 9 years ago

Pacto is moving towards using Swagger as the way to describe contracts. Swagger does support multiple formats, and there's people figuring out the best ways to use it for JSON & XML. I think as long as we can come up with a good way to model the CSV it could be done.

It would be pretty easy to specify and test that it should be a CSV file. It's just a matter of telling Swagger that the service produces "text/csv" (see the operation and mime type sections of the swagger specification).

Testing that it is a proper CSV - one with the field names you expect and the right types of data (e.g. a field named "zipcode" that contains 5 digit numbers) is a little trickier. I'm not aware of a widely used schema language for CSVs like there is for JSON (json-schema) or XML (xsd or relaxng). There is a CSVSchema, but I'd never heard of it before just now, and I think it might actually be easier to use a format similar to how Swagger describes headers or parameters than to use CSVSchema. That would probably require some slight changes to the Swagger spec though - right now it only allows one body parameter.

I think a good next step is if you send an example CSV and contract (preferably as Swagger 2.0 rather than Pacto's "legacy" contract format) and a short description of what parts of the CSV you'd like Pacto to validate.

nightscape commented 9 years ago

Hi maxlinc,

I did some research on Swagger and CSV but haven't found a lot. Unfortunately I got pulled into other stuff and haven't had time to advance with pacto yet. Shall I close this issue for the time being and reopen when I have time to work on this?

Thanks a lot for your help! Martin

maxlinc commented 9 years ago

Closing, but created #154 for the more general problem.