-
Notifications
You must be signed in to change notification settings - Fork 69
fix: OpenAPI generator now correctly handles REST endpoints with single complex parameter #4142
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
Conversation
Summary of ChangesHello @xerial, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an inconsistency in the OpenAPI generator where REST endpoints with a single complex body parameter were incorrectly represented. The fix ensures that the generated OpenAPI schema accurately reflects the expected request body structure, improving the fidelity of the API documentation and client code generation. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly adjusts the OpenAPI generator to handle REST endpoints with a single complex parameter. Instead of wrapping the parameter in an object, the schema now directly references the parameter's type, which aligns with the server's behavior. The logic change is sound and is supported by corresponding test updates. I've added one suggestion to refactor the logic for detecting this specific case to be more concise and idiomatic using Scala's pattern matching.
| val primitiveOnlyInputs = | ||
| routeAnalysis.httpClientCallInputs.nonEmpty && routeAnalysis.httpClientCallInputs.forall(x => | ||
| isPrimitive(x.surface) | ||
| ) | ||
| val isUnaryEndpointCall = | ||
| !route.isRPC && routeAnalysis.httpClientCallInputs.size == 1 && !primitiveOnlyInputs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic to determine isUnaryEndpointCall can be simplified and made more idiomatic using pattern matching on httpClientCallInputs. This would make the intent clearer by directly checking for a single, non-primitive parameter, and removes the need for the intermediate primitiveOnlyInputs variable.
| val primitiveOnlyInputs = | |
| routeAnalysis.httpClientCallInputs.nonEmpty && routeAnalysis.httpClientCallInputs.forall(x => | |
| isPrimitive(x.surface) | |
| ) | |
| val isUnaryEndpointCall = | |
| !route.isRPC && routeAnalysis.httpClientCallInputs.size == 1 && !primitiveOnlyInputs | |
| val isUnaryEndpointCall = !route.isRPC && (routeAnalysis.httpClientCallInputs match { | |
| case Seq(p) => !isPrimitive(p.surface) | |
| case _ => false | |
| }) |
f47f9b9 to
18ea6ee
Compare
…le complex parameter For REST endpoints (non-RPC) with a single non-primitive body parameter (unary endpoint calls), the OpenAPI request body schema now directly references the parameter type instead of wrapping it in an object with properties. This makes the OpenAPI spec consistent with how the server actually handles requests - the request body is mapped directly to the parameter. This fix aligns the OpenAPI generator behavior with: - HttpRequestMapper which maps the entire request body to a single parameter for REST endpoints - HttpClientIR which generates client code that passes the parameter directly for unary calls
18ea6ee to
e56860e
Compare
For REST endpoints (non-RPC) with a single non-primitive body parameter (unary endpoint calls),
the OpenAPI request body schema now directly references the parameter type instead of wrapping
it in an object with properties. This makes the OpenAPI spec consistent with how the server
actually handles requests - the request body is mapped directly to the parameter.
This fix aligns the OpenAPI generator behavior with: