lezhnev74 / openapi-psr7-validator

It validates PSR-7 messages (HTTP request/response) against OpenAPI specifications
https://lessthan12ms.com/openapi-with-php-documenting-and-testing-api-automatically/
MIT License
169 stars 10 forks source link

Add body validation for "multipart/form-data" requests #44

Open lezhnev74 opened 5 years ago

lezhnev74 commented 5 years ago

Currently, the body of the request is validated as a string: https://github.com/lezhnev74/openapi-psr7-validator/blob/c6d12609d9990ff2de23343c48ac23b58919f8a1/src/PSR7/Validators/Body.php#L48

This does not work with schema validation at the moment. The problem is that we CAN specify multipart body format with a schema.

Review and decide how to change that.

Refs:

lezhnev74 commented 5 years ago

Initial work is there, but PHP does not let us to access raw HTTP request body, instead we can only access $_POST/$_FILES or ServerRequest::getParsedBody/ServerRequest::getUploadedFiles.

scaytrase commented 5 years ago

Initial work is there, but PHP does not let us to access raw HTTP request body

what about reading stdin directly?

https://php.net/manual/en/wrappers.php.php

php://input is a read-only stream that allows you to read raw data from the request body.

lezhnev74 commented 5 years ago

Well, it would be awesome, but: php://input is not available with enctype="multipart/form-data". as stated in that doc. Webservers won't push raw HTTP body to the PHP, hm?