feat: enhance endpoint response handling and add optional parameter support#64
Open
gent124 wants to merge 1 commit into
Open
feat: enhance endpoint response handling and add optional parameter support#64gent124 wants to merge 1 commit into
gent124 wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
getEndpointsFromOpenAPIDocto prefer response content entries with a schema, even if the media type is non-standard, and to fall back to thedefaultresponse if the200status has no content butdefaulthas 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]Optional Parameter Handling:
getEndpointParameterto avoid duplicating.optional()on root object-shaped query/header parameters, preventing incorrect schema generation for optional object params. [1] [2]endpointParamsAllOptionalutility to check if all endpoint parameters are optional, enabling safer defaulting of parameter objects in generated code.Code Generation Template Enhancements:
query-use-query.hbsandquery-use-infinite-query.hbstemplates to use a singleparamsobject with a default value of{}when all parameters are optional, simplifying the function signature and usage for consumers. [1] [2]endpointParamsAllOptionalto 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.
getEndpointsFromOpenAPIDocto prefer schemas with body content over void responses.endpointParamsAllOptionalto check if all endpoint parameters are optional.