Skip to content

feat: enhance endpoint response handling and add optional parameter support#64

Open
gent124 wants to merge 1 commit into
mainfrom
fix/codegen-zod-response-and-query-params
Open

feat: enhance endpoint response handling and add optional parameter support#64
gent124 wants to merge 1 commit into
mainfrom
fix/codegen-zod-response-and-query-params

Conversation

@gent124
Copy link
Copy Markdown
Collaborator

@gent124 gent124 commented May 15, 2026

This pull request improves the handling of OpenAPI endpoint parameter and response generation, especially for optional parameters and response schema resolution, and updates the code generation templates for better developer experience. The most significant changes are grouped below:

OpenAPI Response Handling Improvements:

  • Enhanced logic in getEndpointsFromOpenAPIDoc to prefer response content entries with a schema, even if the media type is non-standard, and to fall back to the default response if the 200 status has no content but default has a JSON body. This ensures more accurate response schema inference and fixes issues with APIs that use non-standard response structures. [1] [2] [3] [4] [5]
  • Adjusted test cases to reflect the improved response schema selection, ensuring that endpoints return the correct response type and description. [1] [2] [3]

Optional Parameter Handling:

  • Updated getEndpointParameter to avoid duplicating .optional() on root object-shaped query/header parameters, preventing incorrect schema generation for optional object params. [1] [2]
  • Added the endpointParamsAllOptional utility to check if all endpoint parameters are optional, enabling safer defaulting of parameter objects in generated code.

Code Generation Template Enhancements:

  • Modified the query-use-query.hbs and query-use-infinite-query.hbs templates to use a single params object with a default value of {} when all parameters are optional, simplifying the function signature and usage for consumers. [1] [2]
  • Registered a new Handlebars helper endpointParamsAllOptional to support the above template changes, and integrated it into the Handlebars helper registration logic. [1] [2] [3] [4]

These changes collectively improve the robustness and usability of the OpenAPI endpoint code generation, especially for APIs with complex or non-standard parameter and response definitions.

  • Updated response handling in getEndpointsFromOpenAPIDoc to prefer schemas with body content over void responses.
  • Introduced a new utility function endpointParamsAllOptional to check if all endpoint parameters are optional.
  • Modified query and infinite query templates to handle optional parameters correctly.
  • Added tests to verify the behavior of endpoints with default responses and optional parameters.

…upport

- Updated response handling in `getEndpointsFromOpenAPIDoc` to prefer schemas with body content over void responses.
- Introduced a new utility function `endpointParamsAllOptional` to check if all endpoint parameters are optional.
- Modified query and infinite query templates to handle optional parameters correctly.
- Added tests to verify the behavior of endpoints with default responses and optional parameters.
@gent124 gent124 requested a review from shyqerigashi May 15, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant