mac- / ratify

A Hapi plugin for validating the schema of path, query, request body, and response body params using JSON-schema
MIT License
71 stars 27 forks source link

Support for file type in swagger #11

Closed dschenkelman closed 10 years ago

dschenkelman commented 10 years ago

It is fairly common for POST endpoints to be able to receive a file as the body parameter. Since JSON schema does not support the 'file' type, it is not possible to specify it when defining the schema.

This PR implements a hack that allows people to specify the 'file' type through the description field.

I don't think it is nice, but I can't think of any other way to support this.

dschenkelman commented 10 years ago

Another alternative would be to define the file format for some type instead of using the description.

Thoughts?

mac- commented 10 years ago

It probably makes sense to allow for extended types that swagger cares about, but would not be validated against JSON schema, and just document the additional types that can be used in your schema definition. I'm starting to look at the swagger 2.0 spec as well, and seeing how much work it'd be to transition to that.

dschenkelman commented 10 years ago

You mean to use this mechanism (i.e. description) for all potential types supported by swagger? Cool :). This will be fairly useful.

mac- commented 10 years ago

I was thinking of just allowing the use of "file" in the type property, and then just checking this before schema validation to see if it's set to "file", and if so, skip the validation.

dschenkelman commented 10 years ago

Oh, that is cool. I did not know you could skip validation for a particular property.

mac- commented 10 years ago

Would you be able to point your package.json at the "pr_11" branch that I just uploaded and see if you can get the swagger documentation that you expect for "file" type payloads?

In other words, use something similar to this for your route config:

plugins: {
    ratify: {
        payload: {
            type: 'file'
        }
    }
}

and see if you get the swagger docs that you expect?

If not, no big deal. I'll try it out later.

dschenkelman commented 10 years ago

I'm currently swamped trying to solve an nginx issue with something else, but will definely give it a try either later today or tomorrow.

Thanks @mac-

dschenkelman commented 10 years ago

Just tried it out. It worked correctly and also all my tests are still passing so :+1: from my side :)

mac- commented 10 years ago

Sweet! I'm going to close this pull request and merge the pr_11 branch in and publish a new version.

dschenkelman commented 10 years ago

That is great :) Will be able to automatically generate correct swagger for our file uploads

mac- commented 10 years ago

I pushed a new version for this: 0.6.3

dschenkelman commented 10 years ago

Great! Just updated our dependencies to it.

Thanks a lot for the fast update

On Fri, Oct 3, 2014 at 12:27 PM, Mac Angell notifications@github.com wrote:

I pushed a new version for this: 0.6.3

— Reply to this email directly or view it on GitHub https://github.com/mac-/ratify/pull/11#issuecomment-57811571.