-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG][typescript-node] The same response type deserialized for all HTTP statuses #2924
Comments
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
Just a quick update, in the latest 5.0.0 snapshots the Posting this just FYI, I know the typescript generators are under a rewrite, waiting patiently for them to be done 😃 return new Promise<{ response: http.IncomingMessage; body: TestResponse; }>((resolve, reject) => {
localVarRequest(localVarRequestOptions, (error, response, body) => {
if (error) {
reject(error);
} else {
body = ObjectSerializer.deserialize(body, "TestResponse");
if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) {
resolve({ response: response, body: body });
} else {
reject(new HttpError(response, body, response.statusCode));
}
}
});
}); |
Not a solution but just kind of thing I found with ObjectSerializer. (typescript only generator)
There are higher chances that openapi schema file is not up to date, and I am not gonna wait for the backend to update their spec. (sometimes it is third party company). And so, the model also wont have attributes which may be present in response. |
I've found this bug in @kubernetes/client-node npm package. By the way, Here is the issue OpenAPITools#2924
Here is the workaround
|
* Fixed http errors deserialization I've found this bug in @kubernetes/client-node npm package. By the way, Here is the issue #2924 * Update typescript-node samples with a fix of error handling * Update samples version Co-authored-by: Bogdan Onischenko <bogdan.onischenko@nixsolutions.com>
Bug Report Checklist
Description
Use case:
HTTP 200 OK
, API returns aTestResponse
ErrorResponse
Bug: the client generated with
typescript-node
always tries to deserialize the successful type only. Because theObjectDeserializer
only deserializes known fields, the generated code rejects with an empty body, and with no access to the actual error body.Here's the offending code snippet generated (it's the same for all paths in spec):
Fix proposition at the bottom.
openapi-generator version
I think all, I've tested:
OpenAPI declaration file content or url
full example on gist
The most important part -- I've tried the second response with
default
,500
and5XX
keys, all yielding the same result.Command line used for generation
java -jar ~/pkg/openapi-generator-cli-5.0.0-20190515.034058-2.jar generate -i test.json -g typescript-node -D supportsES6=true
Steps to reproduce
Suggest a fix
The body should be deserialized to a proper type, depending on the HTTP status code. For example:
The text was updated successfully, but these errors were encountered: