Validate response against openapi schema #719
timo-klarshift
started this conversation in
Ideas
Replies: 1 comment
-
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! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
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 theRequestInit
and could process the returnedResponse
fromfetch
. 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 toRequestInit
. Also adding some meta-data could be helpful, for exampleoperationId
from the schema.I hope this use-case is clear, maybe there is already some way to implement this which I cannot see yet.
Beta Was this translation helpful? Give feedback.
All reactions