-
Notifications
You must be signed in to change notification settings - Fork 64
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
[Proposal] Improve the return type for client generation to handle error status code details and extra details #6099
[Proposal] Improve the return type for client generation to handle error status code details and extra details #6099
Comments
Meeting: 2024/03/14 During the stand-up meeting we discussed the support with
|
Blocked on this: ballerina-platform/ballerina-lang#42404 |
The implementation changes with the above PR: ballerina-platform/openapi-tools#1667
|
@lnash94 @dilanSachi @TharmiganK @shafreenAnfar had a discussion on this feature and concluded a few things.
resource isolated function get albums(string genre = "Rock",
typedesc<OkAlbumArray|NotFoundErrorMessage|BadRequestErrorPayload> targetType = <>)
|
Summary
A well-drafted API specification is essential for outlining the responses to all API operations. Each operation should have a defined response, typically focusing on a successful outcome. However, users may also be interested in details regarding response headers and error status codes.
This redesign aims to effectively manage error status codes and header details across all responses during the client generation process.
Consider the following scenario:
This given operation has two responses, one is 200-ok with successful payload
User
and the header details and the second one is 404 - Not found error response with header details andstring
body payload.[1]OAS sample:
Goal
Motivation
As outlined in the summary, users may have an interest in deeper into the response beyond its payload. However, in the current code generation setup, our provision is limited to providing a successful payload[2].
[2]Current code sample for the above OAS[1]:
Here[2],
User
payload details and drops the response header detailsWith this improvement users can access to the response header details, and error status code details instead of its success response.
Proposed solution
Introduce the
typedescriptor
as the target type in the function to capture all possible response types and make it external. The end user will receive details about the external function to invoke a specific API.[3]Expected ballerina code with improvement for the given OAS sample[1]:
Variations of this status code response access:
To fulfil the above support we required a fix from the HTTP module with HTTP status code response binding support in the HTTP client (#6100)
High-level design implementation
[4]The flow of remote/resource function call
Introducing CLI flag option to generate client code with new improvement
Above diagram[4], java native implementation is to access external functions. This Java native implementation is done inside the openapi repository and will publish a native jar to the WSO2 nexus. This Java implementation should be accessed by adding it to the
Ballerina.toml
Example for Ballerina.toml:
Limitation:
Solution:
Ballerina.toml
with the necessary native dependencies. (If it is not within a Bal package, we can default to the previous code generation process without this improvement. )Note: this
--generate-return-with-error-code
flag is a kind of sample nameRisks and Assumptions
https://docs.google.com/document/d/1MczQ7tYdgkiOVMA5XtHUCIFWRDASWDJJV7NSQh1ag58/edit#heading=h.ljlipgffytpf
Dependencies
https://docs.google.com/document/d/1MczQ7tYdgkiOVMA5XtHUCIFWRDASWDJJV7NSQh1ag58/
The text was updated successfully, but these errors were encountered: