Skip to content

Conversation

@wickedest
Copy link

Resolves #94. Adds support for multiple Media Type Object content body.

Previously, if requestBody.content defined multiple content types, e.g. application/json and multipart/form-data, then only application/json would be used to validate the request. Now, a request with a content-type of application/json will validate against the schema associated with the application/json media-type, and a request of multipart/form-data will validate against the associated media-type schema.

If no content-type is specified, then the default behaviour remains unchanged - it will default to the first content media-type.

Currently, media-type matching is not supported, e.g. text/*.

}
// TODO: Implement matching on RFC 7231 media-range, e.g. "image/*", "*/*"
// see: https://swagger.io/specification/#request-body-object
if (mediaTypes.includes(contentType)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if I'm missing something, or if this is the wrong place to ask. From my testing (and maybe RFC 2046?) multipart/form-data requests will always include the boundary in the content-type header (example multipart/form-data; boundary=---------.... So I don't think this matches the validator media type for multipart requests. Maybe something like if (mediaTypes.includes(contentType.split(';')[0].trim()) would still work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for multiple content types per route

2 participants