Skip to content

Commit

Permalink
handle format binary e.g. application/octet-stream cdimascio#237
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmine DiMascio committed Mar 3, 2020
1 parent 609235d commit 413f100
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/middlewares/openapi.request.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ export class RequestValidator {
const securityQueryParam = Security.queryParam(apiDoc, reqSchema);
const body = bodySchemaParser.parse(path, reqSchema, contentType);

// when the body type is 'application/octet-stream' don't validate the body
const isOctetStream = contentType.contentType === 'application/octet-stream';
const properties: ValidationSchema = { ...parameters, body: ( isOctetStream ? {} : body) };
const required = ((<SchemaObject>body).required && !isOctetStream) ? ['body'] : [];

const isBodyBinary = body?.['format'] === 'binary';
const properties: ValidationSchema = { ...parameters, body: isBodyBinary ? {} : body };
// TODO throw 400 if missing a required binary body
const required = (<SchemaObject>body).required && !isBodyBinary ? ['body'] : [];
// $schema: "http://json-schema.org/draft-04/schema#",
const schema = {
required: ['query', 'headers', 'params'].concat(required),
Expand Down

0 comments on commit 413f100

Please sign in to comment.