krakenjs / swaggerize-routes

Swagger document driven route builder.
Other
58 stars 57 forks source link

schema validation for consumes property when using Swagger file type needs to be updated. #58

Closed joypeterson closed 8 years ago

joypeterson commented 8 years ago

At the beginning of validator.js where the types var is declared, the value of the consumes property is declared as

                consumes: {
                    type: 'string',
                    pattern: /multipart\/form-data|application\/x-www-form-urlencoded/,
                    required: true
                },

However, with the current version of Swagger, consumes is coming in as an array. e.g.

[ 'multipart/form-data' ]

I think the schema for consumes needs to be updated to

                consumes: {
                    type: 'array',
                    required: true,
                    items: {
                        type: 'string',
                        pattern: /multipart\/form-data|application\/x-www-form-urlencoded/
                    },
                    minItems: 1,
                    uniqueItems: true
                },

This appears to be working correctly in my limited testing, but I am fairly new to Swagger so I might be missing something.

If backwards compatibility is desired, it could be updated to:

                consumes: {
                    oneOf: [
                        {
                            type: 'array',
                            required: true,
                            items: {
                                type: 'string',
                                pattern: /multipart\/form-data|application\/x-www-form-urlencoded/
                            },
                            minItems: 1,
                            uniqueItems: true
                        },
                        {
                            type: 'string',
                            pattern: /multipart\/form-data|application\/x-www-form-urlencoded/,
                            required: true
                        }
                    ]
                },
joypeterson commented 8 years ago

I now see that this was fixed by pull request #55. I will submit a pull request to update the unit tests in order to prevent a regression.

tlivings commented 8 years ago

Resolved, thanks.