[typescript-fetch] Add option to exclude RequestOpts from API interfaces#23181
Conversation
…estOpts from API interfaces The *RequestOpts methods are implementation details that build request options before sending the fetch call. Most consumers using the API interfaces don't need these methods exposed in the contract. Add a new `withRequestOptsInInterface` boolean option (default: true for backward compatibility) that controls whether *RequestOpts methods appear in the generated API interface declarations. When set to false, the methods remain as public methods on the class but are excluded from the interface.
There was a problem hiding this comment.
1 issue found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java">
<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java:473">
P2: `testRequestOptsInInterfaceByDefault` can pass even when RequestOpts is missing from interface due to un-scoped file search</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
The previous test used indexOf("}") to find the interface end, which
matched the } inside @throws {RequiredError} JSDoc instead of the
actual closing brace. Use the class declaration position as the
boundary instead.
Replace new String(byte[]) with new String(byte[], StandardCharsets.UTF_8) to satisfy the forbiddenapis Maven plugin check.
|
The The same check is also failing on All checks relevant to the typescript-fetch changes are passing. |
|
agreed circleci failure not related to this change, which looks good to me thanks for the contribution |
|
cc @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02) @davidgamero (2022/03) @mkusaka (2022/04) @joscha (2024/10) @dennisameling (2026/02) |
…ces (OpenAPITools#23181) * [typescript-fetch] Add withRequestOptsInInterface option to hide RequestOpts from API interfaces The *RequestOpts methods are implementation details that build request options before sending the fetch call. Most consumers using the API interfaces don't need these methods exposed in the contract. Add a new `withRequestOptsInInterface` boolean option (default: true for backward compatibility) that controls whether *RequestOpts methods appear in the generated API interface declarations. When set to false, the methods remain as public methods on the class but are excluded from the interface. * Fix test: scope RequestOpts assertion to interface section The previous test used indexOf("}") to find the interface end, which matched the } inside @throws {RequiredError} JSDoc instead of the actual closing brace. Use the class declaration position as the boundary instead. * Fix forbiddenapis violation: use explicit UTF-8 charset Replace new String(byte[]) with new String(byte[], StandardCharsets.UTF_8) to satisfy the forbiddenapis Maven plugin check. * Add withRequestOptsInInterface to options test and regenerate docs
Summary
withRequestOptsInInterfaceboolean option (default:truefor backward compatibility) to the TypeScript Fetch client generatorfalse, the*RequestOptsmethods are excluded from the generated API interface declarations while remaining as public methods on the API class*RequestOptsmethods are implementation details that build request options before the fetch call -- most consumers using the API interfaces don't need them in the contractChanges
TypeScriptFetchClientCodegen.java: AddedWITH_REQUEST_OPTS_IN_INTERFACEconstant, field, getter/setter, CLI option registration, and processing inprocessOpts()apis.mustache: Wrapped the*RequestOptsmethod declaration in the interface block with a{{#withRequestOptsInInterface}}conditionalTypeScriptFetchClientCodegenTest.java: Added two tests:testRequestOptsInInterfaceByDefault: verifies the default behavior (RequestOpts in both interface and class)testRequestOptsNotInInterfaceWhenDisabled: verifies that withwithRequestOptsInInterface=false, RequestOpts methods appear only on the class, not in the interfaceUsage
Test plan
testRequestOptsInInterfaceByDefault-- verifies default behavior preserves backward compatibilitytestRequestOptsNotInInterfaceWhenDisabled-- verifies RequestOpts exclusion from interface while keeping them on the classSummary by cubic
Adds an option to hide
*RequestOptsmethods from generatedtypescript-fetchAPI interfaces, keeping them only on the class. Default behavior stays the same to preserve backward compatibility.New Features
withRequestOptsInInterface(default: true) to control whether*RequestOptsappear in API interfaces.*RequestOptsare excluded from interfaces but remain public on the API class.additionalProperties: { withInterfaces: true, withRequestOptsInInterface: false }.Bug Fixes
StandardCharsets.UTF_8.Written for commit f4afe8e. Summary will update on new commits.