Skip to content

fix(typescript-fetch): qualify anyToJSON for any-typed form parameters - #24553

Open
donald wants to merge 1 commit into
OpenAPITools:masterfrom
donald:fix/typescript-fetch-any-form-param
Open

fix(typescript-fetch): qualify anyToJSON for any-typed form parameters#24553
donald wants to merge 1 commit into
OpenAPITools:masterfrom
donald:fix/typescript-fetch-any-form-param

Conversation

@donald

@donald donald commented Aug 1, 2026

Copy link
Copy Markdown

Fixes #24552

What

A multipart/form-data parameter with no type at all ("any type") made the generated apis/*.ts call
a bare anyToJSON(...). The file only imports the runtime as * as runtime, so that identifier does not
exist and the output does not compile.

import * as runtime from '../runtime';
...
// before -- TS2304: Cannot find name 'anyToJSON'
formParams.append('meta', new Blob([JSON.stringify(anyToJSON(requestParameters['meta']))], { type: "application/json", }));

// after
formParams.append('meta', new Blob([JSON.stringify(runtime.anyToJSON(requestParameters['meta']))], { type: "application/json", }));

Why

apis.mustache#L288:

{{#isFreeFormObject}}runtime.anyToJSON{{/isFreeFormObject}}{{^isFreeFormObject}}{{{dataType}}}ToJSON{{/isFreeFormObject}}

The free-form object case (added with anyToJSON in #1877) is qualified correctly. The any-type case falls
through to {{dataType}}ToJSON, and for an any-typed parameter dataType is any, so it renders as the
unqualified anyToJSON.

How

Add an isAnyType branch that also uses runtime.anyToJSON. Everything else keeps rendering
{{dataType}}ToJSON exactly as before.

Testing

  • TypeScriptFetchClientCodegenTest.testAnyTypeFormParamUsesQualifiedAnyToJSON — asserts the generated
    call is namespace-qualified and that the bare form is gone. Verified that this test fails without the
    fix
    (does not contain line [runtime.anyToJSON(requestParameters['meta'])]).
  • Full TypeScriptFetchClientCodegenTest (35 tests) passes.
  • Regenerated all 787 sample configs (./bin/generate-samples.sh ./bin/configs/*.yaml) and
    ./bin/utils/export_docs_generators.shno diff. No existing sample has an any-typed form
    parameter, which is why this went unnoticed.

Note on the full test run: mvn test on modules/openapi-generator reports one pre-existing failure,
OpenApiSchemaValidationsTest.testNullTypeInOas31_noWarning. It fails identically on unmodified
master (4aed9c1c635) — verified by reverting the patch and re-running — and is unrelated to this change.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    Commit all changed files.
    (Both scripts were run; neither produced any change, so there is nothing to commit beyond the fix and its test.)
  • File the PR against the correct branch: master
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

TypeScript technical committee:
@TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @topce @akehir @petejohansonxo @amakhrov @davidgamero @mkusaka @joscha

🤖 Generated with Claude Code


Summary by cubic

Fixes a compile error in generated typescript-fetch clients when a multipart/form-data param has no type by qualifying anyToJSON as runtime.anyToJSON. Generated clients now compile in this case.

  • Bug Fixes
    • Update template to use runtime.anyToJSON for isAnyType form params; other cases still use {{dataType}}ToJSON.
    • Add test: testAnyTypeFormParamUsesQualifiedAnyToJSON.
    • Regenerated samples; no diffs.

Written for commit 24291b1. Summary will update on new commits.

Review in cubic

A multipart/form-data parameter with no type at all ("any type") made the
generated apis/*.ts call a bare anyToJSON(...). The file only imports the
runtime as `* as runtime`, so that identifier does not exist and the output
does not compile (TS2304: Cannot find name 'anyToJSON').

    formParams.append('meta', new Blob([JSON.stringify(anyToJSON(...))], ...));

The free-form object case already uses runtime.anyToJSON; the any-type case
fell through to {{dataType}}ToJSON, and dataType is `any` for an any-typed
parameter, so it rendered as `anyToJSON`.

Add an isAnyType branch that uses runtime.anyToJSON as well.

Regenerating all 787 sample configs produces no diff.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

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.

[BUG][typescript-fetch] any-typed multipart form parameter emits unqualified anyToJSON (does not compile)

1 participant