Validate response against openapi schema
timo-klarshift opened this issue · comments
Description
Hey, first of all thanks for the great library. I am so happy to finally drop openapi-generator :)
I have the use-case that I am developing an SDK/client against a legacy API. During tests we find cases where the provided schema does not match the actual backend responses. What I would like to have is schema validation when a response is returned. I do of course have the openapi schema available, but my attempt using Interceptors is not successful because when I receive the response I have no access to the request, therefore I do not know what method was called on the url which means I cannot match the response to an operation without ambiguity.
I see it would be possible by replacing the whole request.ts file which is possible via config. But actually I would only need to alter the sendRequest
method for this purpose. Here I do have the RequestInit
and could process the returned Response
from fetch
. Then get my schema and validate whether the returned response for said operation is valid against the provided schema. If not I would want to log a warning.
Another way to solve it would be not on request implementation layer (fetch in this case) but on library layer. We could add a similar interceptor concept but extend the Response
interface so it would contain a reference to RequestInit
. Also adding some meta-data could be helpful, for example operationId
from the schema.
I hope this use-case is clear, maybe there is already some way to implement this which I cannot see yet.
Welcome @timo-klarshift! 🚀 pretty sure I've heard this request a few times already, it's going to get addressed, but it will take a while as there's a lot to build!