Description
Discussion has begun about how to support request and response streams in the OAS, and express validation assertions in the OAD.
OAI/OpenAPI-Specification#4518
OAI/OpenAPI-Specification#4554
We'd need to provide (possibly as a config option to OpenAPI::Modern::validate_{request,response} ?) a hook that the caller can use to set up access to the message stream. Then, using information in the body specification in the document, as well as the presence of a Transfer-Encoding header, we know that instead of calling $message->body
we should set up some event handlers for processing body chunks.
We would also need to clearly document that this means the validation method is blocking, but possibly it can be wrapped in a promise and then this can be called asynchronously? I would expect that the caller (a handler in the web client processing the response) would expect that validation can happen in tandem with their normal application processing of the chunk data via callbacks that they register on the same events that we (the OAS implementation) would. Of course, if we encounter a validation error earlier on (e.g. in header validation) we can abort immediately and then there is no need to parse the chunks at all.
see Mojolicious: https://metacpan.org/dist/Mojolicious/view/lib/Mojolicious/Guides/Cookbook.pod#Streaming-response
Now that the PR is in...
If itemSchema
is seen, and the media type is indeed a streaming media type, validate_request
and validte_response
should return before validating the entire body (because it is streaming and might not be finite), and also take a callback hook as an input parameter which provides validation results for each incoming item as it arrives.
This would hook into mojo's streaming support somehow to provide both the content and validation in one call, see mojo link above.