From d9dd38927ce5c7901ce46bfe439454935b2053fa Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 3 Nov 2025 07:39:35 +0800 Subject: [PATCH] feat(sdk): add paramsStructure option --- .changeset/nine-cats-cross.md | 5 + .changeset/tidy-poets-peel.md | 5 + dev/openapi-ts.config.ts | 12 +- dev/playground.ts | 56 +++++++ packages/codegen-core/src/symbols/types.d.ts | 2 +- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../2.0.x/form-data/client/types.gen.ts | 2 +- .../2.0.x/form-data/core/params.gen.ts | 66 +++++--- .../common/default-class/client/types.gen.ts | 2 +- .../common/default-class/core/params.gen.ts | 66 +++++--- .../common/default/client/types.gen.ts | 2 +- .../common/default/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../sdk-nested-classes/client/types.gen.ts | 2 +- .../sdk-nested-classes/core/params.gen.ts | 66 +++++--- .../@hey-api/sdk/default/client/types.gen.ts | 2 +- .../@hey-api/sdk/default/core/params.gen.ts | 66 +++++--- .../@hey-api/sdk/instance/client/types.gen.ts | 2 +- .../@hey-api/sdk/instance/core/params.gen.ts | 66 +++++--- .../sdk/throwOnError/client/types.gen.ts | 2 +- .../sdk/throwOnError/core/params.gen.ts | 66 +++++--- .../type-format-valibot/client/types.gen.ts | 2 +- .../type-format-valibot/core/params.gen.ts | 66 +++++--- .../type-format-zod/client/types.gen.ts | 2 +- .../type-format-zod/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../@pinia/colada/asClass/client/types.gen.ts | 2 +- .../@pinia/colada/asClass/core/params.gen.ts | 66 +++++--- .../@pinia/colada/fetch/client/types.gen.ts | 2 +- .../@pinia/colada/fetch/core/params.gen.ts | 66 +++++--- .../asClass/client/types.gen.ts | 2 +- .../asClass/core/params.gen.ts | 66 +++++--- .../axios/client/types.gen.ts | 2 +- .../axios/core/params.gen.ts | 66 +++++--- .../fetch/client/types.gen.ts | 2 +- .../fetch/core/params.gen.ts | 66 +++++--- .../name-builder/client/types.gen.ts | 2 +- .../name-builder/core/params.gen.ts | 66 +++++--- .../react-query/asClass/client/types.gen.ts | 2 +- .../react-query/asClass/core/params.gen.ts | 66 +++++--- .../react-query/axios/client/types.gen.ts | 2 +- .../react-query/axios/core/params.gen.ts | 66 +++++--- .../react-query/fetch/client/types.gen.ts | 2 +- .../react-query/fetch/core/params.gen.ts | 66 +++++--- .../name-builder/client/types.gen.ts | 2 +- .../name-builder/core/params.gen.ts | 66 +++++--- .../solid-query/asClass/client/types.gen.ts | 2 +- .../solid-query/asClass/core/params.gen.ts | 66 +++++--- .../solid-query/axios/client/types.gen.ts | 2 +- .../solid-query/axios/core/params.gen.ts | 66 +++++--- .../solid-query/fetch/client/types.gen.ts | 2 +- .../solid-query/fetch/core/params.gen.ts | 66 +++++--- .../name-builder/client/types.gen.ts | 2 +- .../name-builder/core/params.gen.ts | 66 +++++--- .../svelte-query/asClass/client/types.gen.ts | 2 +- .../svelte-query/asClass/core/params.gen.ts | 66 +++++--- .../svelte-query/axios/client/types.gen.ts | 2 +- .../svelte-query/axios/core/params.gen.ts | 66 +++++--- .../svelte-query/fetch/client/types.gen.ts | 2 +- .../svelte-query/fetch/core/params.gen.ts | 66 +++++--- .../name-builder/client/types.gen.ts | 2 +- .../name-builder/core/params.gen.ts | 66 +++++--- .../vue-query/asClass/client/types.gen.ts | 2 +- .../vue-query/asClass/core/params.gen.ts | 66 +++++--- .../vue-query/axios/client/types.gen.ts | 2 +- .../vue-query/axios/core/params.gen.ts | 66 +++++--- .../vue-query/fetch/client/types.gen.ts | 2 +- .../vue-query/fetch/core/params.gen.ts | 66 +++++--- .../name-builder/client/types.gen.ts | 2 +- .../vue-query/name-builder/core/params.gen.ts | 66 +++++--- .../2.0.x/schema-unknown/client/types.gen.ts | 2 +- .../2.0.x/schema-unknown/core/params.gen.ts | 66 +++++--- .../security-api-key/client/types.gen.ts | 2 +- .../2.0.x/security-api-key/core/params.gen.ts | 66 +++++--- .../2.0.x/security-basic/client/types.gen.ts | 2 +- .../2.0.x/security-basic/core/params.gen.ts | 66 +++++--- .../2.0.x/security-false/client/types.gen.ts | 2 +- .../2.0.x/security-false/core/params.gen.ts | 66 +++++--- .../2.0.x/security-oauth2/client/types.gen.ts | 2 +- .../2.0.x/security-oauth2/core/params.gen.ts | 66 +++++--- .../servers-base-path/client/types.gen.ts | 2 +- .../servers-base-path/core/params.gen.ts | 66 +++++--- .../2.0.x/servers-host/client/types.gen.ts | 2 +- .../2.0.x/servers-host/core/params.gen.ts | 66 +++++--- .../2.0.x/servers/client/types.gen.ts | 2 +- .../2.0.x/servers/core/params.gen.ts | 66 +++++--- .../transforms-read-write/client/types.gen.ts | 2 +- .../transforms-read-write/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../3.0.x/content-types/client/types.gen.ts | 2 +- .../3.0.x/content-types/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../internal-name-conflict/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../common/default-class/client/types.gen.ts | 2 +- .../common/default-class/core/params.gen.ts | 66 +++++--- .../common/default/client/types.gen.ts | 2 +- .../common/default/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../sdk-nested-classes/client/types.gen.ts | 2 +- .../sdk-nested-classes/core/params.gen.ts | 66 +++++--- .../@hey-api/sdk/default/client/types.gen.ts | 2 +- .../@hey-api/sdk/default/core/params.gen.ts | 66 +++++--- .../@hey-api/sdk/instance/client/types.gen.ts | 2 +- .../@hey-api/sdk/instance/core/params.gen.ts | 66 +++++--- .../sdk/throwOnError/client/types.gen.ts | 2 +- .../sdk/throwOnError/core/params.gen.ts | 66 +++++--- .../type-format-valibot/client/types.gen.ts | 2 +- .../type-format-valibot/core/params.gen.ts | 66 +++++--- .../type-format-zod/client/types.gen.ts | 2 +- .../type-format-zod/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../@pinia/colada/asClass/client/types.gen.ts | 2 +- .../@pinia/colada/asClass/core/params.gen.ts | 66 +++++--- .../@pinia/colada/fetch/client/types.gen.ts | 2 +- .../@pinia/colada/fetch/core/params.gen.ts | 66 +++++--- .../asClass/client/types.gen.ts | 2 +- .../asClass/core/params.gen.ts | 66 +++++--- .../axios/client/types.gen.ts | 2 +- .../axios/core/params.gen.ts | 66 +++++--- .../fetch/client/types.gen.ts | 2 +- .../fetch/core/params.gen.ts | 66 +++++--- .../name-builder/client/types.gen.ts | 2 +- .../name-builder/core/params.gen.ts | 66 +++++--- .../react-query/asClass/client/types.gen.ts | 2 +- .../react-query/asClass/core/params.gen.ts | 66 +++++--- .../react-query/axios/client/types.gen.ts | 2 +- .../react-query/axios/core/params.gen.ts | 66 +++++--- .../react-query/fetch/client/types.gen.ts | 2 +- .../react-query/fetch/core/params.gen.ts | 66 +++++--- .../name-builder/client/types.gen.ts | 2 +- .../name-builder/core/params.gen.ts | 66 +++++--- .../solid-query/asClass/client/types.gen.ts | 2 +- .../solid-query/asClass/core/params.gen.ts | 66 +++++--- .../solid-query/axios/client/types.gen.ts | 2 +- .../solid-query/axios/core/params.gen.ts | 66 +++++--- .../solid-query/fetch/client/types.gen.ts | 2 +- .../solid-query/fetch/core/params.gen.ts | 66 +++++--- .../name-builder/client/types.gen.ts | 2 +- .../name-builder/core/params.gen.ts | 66 +++++--- .../svelte-query/asClass/client/types.gen.ts | 2 +- .../svelte-query/asClass/core/params.gen.ts | 66 +++++--- .../svelte-query/axios/client/types.gen.ts | 2 +- .../svelte-query/axios/core/params.gen.ts | 66 +++++--- .../svelte-query/fetch/client/types.gen.ts | 2 +- .../svelte-query/fetch/core/params.gen.ts | 66 +++++--- .../name-builder/client/types.gen.ts | 2 +- .../name-builder/core/params.gen.ts | 66 +++++--- .../vue-query/asClass/client/types.gen.ts | 2 +- .../vue-query/asClass/core/params.gen.ts | 66 +++++--- .../vue-query/axios/client/types.gen.ts | 2 +- .../vue-query/axios/core/params.gen.ts | 66 +++++--- .../vue-query/fetch/client/types.gen.ts | 2 +- .../vue-query/fetch/core/params.gen.ts | 66 +++++--- .../name-builder/client/types.gen.ts | 2 +- .../vue-query/name-builder/core/params.gen.ts | 66 +++++--- .../security-api-key/client/types.gen.ts | 2 +- .../3.0.x/security-api-key/core/params.gen.ts | 66 +++++--- .../3.0.x/security-false/client/types.gen.ts | 2 +- .../3.0.x/security-false/core/params.gen.ts | 66 +++++--- .../security-http-bearer/client/types.gen.ts | 2 +- .../security-http-bearer/core/params.gen.ts | 66 +++++--- .../3.0.x/security-oauth2/client/types.gen.ts | 2 +- .../3.0.x/security-oauth2/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../3.0.x/servers/client/types.gen.ts | 2 +- .../3.0.x/servers/core/params.gen.ts | 66 +++++--- .../transformers-all-of/client/types.gen.ts | 2 +- .../transformers-all-of/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../transformers-array/client/types.gen.ts | 2 +- .../transformers-array/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../transformers-recursive/core/params.gen.ts | 66 +++++--- .../transforms-read-write/client/types.gen.ts | 2 +- .../transforms-read-write/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../base-url-false/client/types.gen.ts | 2 +- .../base-url-false/core/params.gen.ts | 66 +++++--- .../base-url-number/client/types.gen.ts | 2 +- .../base-url-number/core/params.gen.ts | 66 +++++--- .../base-url-strict/client/types.gen.ts | 2 +- .../base-url-strict/core/params.gen.ts | 66 +++++--- .../base-url-string/client/types.gen.ts | 2 +- .../base-url-string/core/params.gen.ts | 66 +++++--- .../clean-false/client/types.gen.ts | 2 +- .../clean-false/core/params.gen.ts | 66 +++++--- .../client-axios/default/client/types.gen.ts | 2 +- .../client-axios/default/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../sdk-client-optional/client/types.gen.ts | 2 +- .../sdk-client-optional/core/params.gen.ts | 66 +++++--- .../sdk-client-required/client/types.gen.ts | 2 +- .../sdk-client-required/core/params.gen.ts | 66 +++++--- .../tsconfig-nodenext-sdk/client/types.gen.ts | 2 +- .../tsconfig-nodenext-sdk/core/params.gen.ts | 66 +++++--- .../base-url-false/client/types.gen.ts | 2 +- .../base-url-false/core/params.gen.ts | 66 +++++--- .../base-url-number/client/types.gen.ts | 2 +- .../base-url-number/core/params.gen.ts | 66 +++++--- .../base-url-strict/client/types.gen.ts | 2 +- .../base-url-strict/core/params.gen.ts | 66 +++++--- .../base-url-string/client/types.gen.ts | 2 +- .../base-url-string/core/params.gen.ts | 66 +++++--- .../clean-false/client/types.gen.ts | 2 +- .../clean-false/core/params.gen.ts | 66 +++++--- .../client-fetch/default/client/types.gen.ts | 2 +- .../client-fetch/default/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../sdk-client-optional/client/types.gen.ts | 2 +- .../sdk-client-optional/core/params.gen.ts | 66 +++++--- .../sdk-client-required/client/types.gen.ts | 2 +- .../sdk-client-required/core/params.gen.ts | 66 +++++--- .../tsconfig-nodenext-sdk/client/types.gen.ts | 2 +- .../tsconfig-nodenext-sdk/core/params.gen.ts | 66 +++++--- .../base-url-false/client/types.gen.ts | 2 +- .../base-url-false/core/params.gen.ts | 66 +++++--- .../base-url-number/client/types.gen.ts | 2 +- .../base-url-number/core/params.gen.ts | 66 +++++--- .../base-url-strict/client/types.gen.ts | 2 +- .../base-url-strict/core/params.gen.ts | 66 +++++--- .../base-url-string/client/types.gen.ts | 2 +- .../base-url-string/core/params.gen.ts | 66 +++++--- .../clean-false/client/types.gen.ts | 2 +- .../clean-false/core/params.gen.ts | 66 +++++--- .../client-next/default/client/types.gen.ts | 2 +- .../client-next/default/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../sdk-client-optional/client/types.gen.ts | 2 +- .../sdk-client-optional/core/params.gen.ts | 66 +++++--- .../sdk-client-required/client/types.gen.ts | 2 +- .../sdk-client-required/core/params.gen.ts | 66 +++++--- .../tsconfig-nodenext-sdk/client/types.gen.ts | 2 +- .../tsconfig-nodenext-sdk/core/params.gen.ts | 66 +++++--- .../base-url-false/client/types.gen.ts | 2 +- .../base-url-false/core/params.gen.ts | 66 +++++--- .../base-url-number/client/types.gen.ts | 2 +- .../base-url-number/core/params.gen.ts | 66 +++++--- .../base-url-strict/client/types.gen.ts | 2 +- .../base-url-strict/core/params.gen.ts | 66 +++++--- .../base-url-string/client/types.gen.ts | 2 +- .../base-url-string/core/params.gen.ts | 66 +++++--- .../clean-false/client/types.gen.ts | 2 +- .../clean-false/core/params.gen.ts | 66 +++++--- .../client-nuxt/default/client/types.gen.ts | 2 +- .../client-nuxt/default/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../sdk-client-optional/client/types.gen.ts | 2 +- .../sdk-client-optional/core/params.gen.ts | 66 +++++--- .../sdk-client-required/client/types.gen.ts | 2 +- .../sdk-client-required/core/params.gen.ts | 66 +++++--- .../tsconfig-nodenext-sdk/client/types.gen.ts | 2 +- .../tsconfig-nodenext-sdk/core/params.gen.ts | 66 +++++--- .../base-url-false/client/types.gen.ts | 2 +- .../base-url-false/core/params.gen.ts | 66 +++++--- .../base-url-number/client/types.gen.ts | 2 +- .../base-url-number/core/params.gen.ts | 66 +++++--- .../base-url-strict/client/types.gen.ts | 2 +- .../base-url-strict/core/params.gen.ts | 66 +++++--- .../base-url-string/client/types.gen.ts | 2 +- .../base-url-string/core/params.gen.ts | 66 +++++--- .../clean-false/client/types.gen.ts | 2 +- .../clean-false/core/params.gen.ts | 66 +++++--- .../client-ofetch/default/client/types.gen.ts | 2 +- .../client-ofetch/default/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../sdk-client-optional/client/types.gen.ts | 2 +- .../sdk-client-optional/core/params.gen.ts | 66 +++++--- .../sdk-client-required/client/types.gen.ts | 2 +- .../sdk-client-required/core/params.gen.ts | 66 +++++--- .../tsconfig-nodenext-sdk/client/types.gen.ts | 2 +- .../tsconfig-nodenext-sdk/core/params.gen.ts | 66 +++++--- .../3.1.x/content-types/client/types.gen.ts | 2 +- .../3.1.x/content-types/core/params.gen.ts | 66 +++++--- .../3.1.x/headers/client/types.gen.ts | 2 +- .../3.1.x/headers/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../internal-name-conflict/core/params.gen.ts | 66 +++++--- .../3.1.x/pagination-ref/client/types.gen.ts | 2 +- .../3.1.x/pagination-ref/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../common/default-class/client/types.gen.ts | 2 +- .../common/default-class/core/params.gen.ts | 66 +++++--- .../common/default/client/types.gen.ts | 2 +- .../common/default/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../sdk-nested-classes/client/types.gen.ts | 2 +- .../sdk-nested-classes/core/params.gen.ts | 66 +++++--- .../@hey-api/sdk/default/client/types.gen.ts | 2 +- .../@hey-api/sdk/default/core/params.gen.ts | 66 +++++--- .../@hey-api/sdk/instance/client/types.gen.ts | 2 +- .../@hey-api/sdk/instance/core/params.gen.ts | 66 +++++--- .../sdk/throwOnError/client/types.gen.ts | 2 +- .../sdk/throwOnError/core/params.gen.ts | 66 +++++--- .../type-format-valibot/client/types.gen.ts | 2 +- .../type-format-valibot/core/params.gen.ts | 66 +++++--- .../type-format-zod/client/types.gen.ts | 2 +- .../type-format-zod/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../@pinia/colada/asClass/client/types.gen.ts | 2 +- .../@pinia/colada/asClass/core/params.gen.ts | 66 +++++--- .../@pinia/colada/fetch/client/types.gen.ts | 2 +- .../@pinia/colada/fetch/core/params.gen.ts | 66 +++++--- .../asClass/client/types.gen.ts | 2 +- .../asClass/core/params.gen.ts | 66 +++++--- .../axios/client/types.gen.ts | 2 +- .../axios/core/params.gen.ts | 66 +++++--- .../fetch/client/types.gen.ts | 2 +- .../fetch/core/params.gen.ts | 66 +++++--- .../name-builder/client/types.gen.ts | 2 +- .../name-builder/core/params.gen.ts | 66 +++++--- .../react-query/asClass/client/types.gen.ts | 2 +- .../react-query/asClass/core/params.gen.ts | 66 +++++--- .../react-query/axios/client/types.gen.ts | 2 +- .../react-query/axios/core/params.gen.ts | 66 +++++--- .../react-query/fetch/client/types.gen.ts | 2 +- .../react-query/fetch/core/params.gen.ts | 66 +++++--- .../name-builder/client/types.gen.ts | 2 +- .../name-builder/core/params.gen.ts | 66 +++++--- .../solid-query/asClass/client/types.gen.ts | 2 +- .../solid-query/asClass/core/params.gen.ts | 66 +++++--- .../solid-query/axios/client/types.gen.ts | 2 +- .../solid-query/axios/core/params.gen.ts | 66 +++++--- .../solid-query/fetch/client/types.gen.ts | 2 +- .../solid-query/fetch/core/params.gen.ts | 66 +++++--- .../name-builder/client/types.gen.ts | 2 +- .../name-builder/core/params.gen.ts | 66 +++++--- .../svelte-query/asClass/client/types.gen.ts | 2 +- .../svelte-query/asClass/core/params.gen.ts | 66 +++++--- .../svelte-query/axios/client/types.gen.ts | 2 +- .../svelte-query/axios/core/params.gen.ts | 66 +++++--- .../svelte-query/fetch/client/types.gen.ts | 2 +- .../svelte-query/fetch/core/params.gen.ts | 66 +++++--- .../name-builder/client/types.gen.ts | 2 +- .../name-builder/core/params.gen.ts | 66 +++++--- .../vue-query/asClass/client/types.gen.ts | 2 +- .../vue-query/asClass/core/params.gen.ts | 66 +++++--- .../vue-query/axios/client/types.gen.ts | 2 +- .../vue-query/axios/core/params.gen.ts | 66 +++++--- .../vue-query/fetch/client/types.gen.ts | 2 +- .../vue-query/fetch/core/params.gen.ts | 66 +++++--- .../name-builder/client/types.gen.ts | 2 +- .../vue-query/name-builder/core/params.gen.ts | 66 +++++--- .../security-api-key/client/types.gen.ts | 2 +- .../3.1.x/security-api-key/core/params.gen.ts | 66 +++++--- .../3.1.x/security-false/client/types.gen.ts | 2 +- .../3.1.x/security-false/core/params.gen.ts | 66 +++++--- .../security-http-bearer/client/types.gen.ts | 2 +- .../security-http-bearer/core/params.gen.ts | 66 +++++--- .../3.1.x/security-oauth2/client/types.gen.ts | 2 +- .../3.1.x/security-oauth2/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../3.1.x/servers/client/types.gen.ts | 2 +- .../3.1.x/servers/core/params.gen.ts | 66 +++++--- .../3.1.x/sse-angular/client/types.gen.ts | 2 +- .../3.1.x/sse-angular/core/params.gen.ts | 66 +++++--- .../3.1.x/sse-axios/client/types.gen.ts | 2 +- .../3.1.x/sse-axios/core/params.gen.ts | 66 +++++--- .../3.1.x/sse-fetch/client/types.gen.ts | 2 +- .../3.1.x/sse-fetch/core/params.gen.ts | 66 +++++--- .../3.1.x/sse-next/client/types.gen.ts | 2 +- .../3.1.x/sse-next/core/params.gen.ts | 66 +++++--- .../3.1.x/sse-nuxt/client/types.gen.ts | 2 +- .../3.1.x/sse-nuxt/core/params.gen.ts | 66 +++++--- .../3.1.x/sse-ofetch/client/types.gen.ts | 2 +- .../3.1.x/sse-ofetch/core/params.gen.ts | 66 +++++--- .../transformers-all-of/client/types.gen.ts | 2 +- .../transformers-all-of/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../core/params.gen.ts | 66 +++++--- .../transformers-array/client/types.gen.ts | 2 +- .../transformers-array/core/params.gen.ts | 66 +++++--- .../client/types.gen.ts | 2 +- .../transformers-recursive/core/params.gen.ts | 66 +++++--- .../transforms-read-write/client/types.gen.ts | 2 +- .../transforms-read-write/core/params.gen.ts | 66 +++++--- .../@tanstack/meta/client/types.gen.ts | 2 +- .../plugins/@tanstack/meta/core/params.gen.ts | 66 +++++--- .../v3_no_index/client/types.gen.ts.snap | 2 +- .../v3_no_index/core/params.gen.ts.snap | 66 +++++--- packages/openapi-ts/src/generate/renderer.ts | 15 +- .../@hey-api/client-angular/bundle/types.ts | 2 +- .../@hey-api/client-axios/bundle/types.ts | 2 +- .../client-core/__tests__/params.test.ts | 17 ++ .../@hey-api/client-core/bundle/params.ts | 67 +++++--- .../@hey-api/client-fetch/bundle/types.ts | 2 +- .../@hey-api/client-next/bundle/types.ts | 2 +- .../@hey-api/client-nuxt/bundle/types.ts | 2 +- .../@hey-api/client-ofetch/bundle/types.ts | 2 +- .../src/plugins/@hey-api/sdk/config.ts | 2 +- .../src/plugins/@hey-api/sdk/shared/class.ts | 8 + .../plugins/@hey-api/sdk/shared/operation.ts | 125 ++++++-------- .../plugins/@hey-api/sdk/shared/signature.ts | 155 ++++++++++++------ .../src/plugins/@hey-api/sdk/types.d.ts | 26 ++- .../src/plugins/shared/utils/operation.ts | 14 +- 424 files changed, 9435 insertions(+), 4822 deletions(-) create mode 100644 .changeset/nine-cats-cross.md create mode 100644 .changeset/tidy-poets-peel.md create mode 100644 dev/playground.ts diff --git a/.changeset/nine-cats-cross.md b/.changeset/nine-cats-cross.md new file mode 100644 index 000000000..748ecf200 --- /dev/null +++ b/.changeset/nine-cats-cross.md @@ -0,0 +1,5 @@ +--- +'@hey-api/openapi-ts': patch +--- + +fix(sdk): add paramsStructure field diff --git a/.changeset/tidy-poets-peel.md b/.changeset/tidy-poets-peel.md new file mode 100644 index 000000000..3f7e01377 --- /dev/null +++ b/.changeset/tidy-poets-peel.md @@ -0,0 +1,5 @@ +--- +'@hey-api/codegen-core': patch +--- + +fix: update types diff --git a/dev/openapi-ts.config.ts b/dev/openapi-ts.config.ts index 818d7a905..7ca575a03 100644 --- a/dev/openapi-ts.config.ts +++ b/dev/openapi-ts.config.ts @@ -41,8 +41,8 @@ export default defineConfig(() => { // 'invalid', // 'openai.yaml', // 'full.yaml', - // 'opencode.yaml', - 'sdk-instance.yaml', + 'opencode.yaml', + // 'sdk-instance.yaml', // 'string-with-format.yaml', // 'transformers.json', // 'type-format.yaml', @@ -248,10 +248,10 @@ export default defineConfig(() => { // }, }, { - asClass: true, + // asClass: true, // auth: false, // classNameBuilder: '{{name}}', - classNameBuilder: '{{name}}Service', + // classNameBuilder: '{{name}}Service', // classStructure: 'off', // client: false, // getSignature: ({ fields, signature, operation }) => { @@ -259,10 +259,10 @@ export default defineConfig(() => { // fields.unwrap('path') // }, // include... - // instance: true, + instance: true, name: '@hey-api/sdk', // operationId: false, - // params_EXPERIMENTAL: 'experiment', + paramsStructure: 'flat', // responseStyle: 'data', // signature: 'auto', // signature: 'client', diff --git a/dev/playground.ts b/dev/playground.ts new file mode 100644 index 000000000..3678c8a1e --- /dev/null +++ b/dev/playground.ts @@ -0,0 +1,56 @@ +import { Sdk } from './.gen/sdk.gen'; + +const opencode = new Sdk(); +opencode.session.create( + { + parentID: '', + title: '', + }, + { + headers: { + 'X-Custom-Header': 'value', + }, + }, +); +opencode.session.init({ + id: '', + messageID: '', + modelID: '', + providerID: '', +}); +opencode.session.chat({ + agent: '', + id: '', + messageID: '', + modelID: '', + parts: [ + { + name: '', + type: 'agent', + }, + ], + providerID: '', + system: '', + tools: {}, +}); +opencode.auth.set({ + auth: { + // access: '', + // expires: 1, + key: '', + // refresh: '', + // token: '', + type: 'api', + }, + id: '123', +}); +opencode.postSessionByIdPermissionsByPermissionId({ + id: 'session-id', + permissionID: 'permission-id', + response: 'always', +}); +opencode.tui.showToast({ + message: '', + title: '', + variant: 'error', +}); diff --git a/packages/codegen-core/src/symbols/types.d.ts b/packages/codegen-core/src/symbols/types.d.ts index cb87ed675..2faaea158 100644 --- a/packages/codegen-core/src/symbols/types.d.ts +++ b/packages/codegen-core/src/symbols/types.d.ts @@ -39,7 +39,7 @@ export interface ISymbolIn { /** * Kind of symbol. */ - readonly kind?: 'type'; + readonly kind?: 'class' | 'function' | 'type'; /** * Arbitrary metadata about the symbol. * diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/body-response-text-plain/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/body-response-text-plain/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/body-response-text-plain/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/body-response-text-plain/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/body-response-text-plain/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/body-response-text-plain/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/body-response-text-plain/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/body-response-text-plain/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/form-data/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/form-data/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/form-data/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/form-data/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/form-data/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/form-data/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/form-data/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/form-data/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/client/types.gen.ts index 6cdf8ad48..9ae3dc653 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/client/types.gen.ts @@ -253,7 +253,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/client/types.gen.ts index 6cdf8ad48..9ae3dc653 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/client/types.gen.ts @@ -253,7 +253,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/default/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/default/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/default/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/default/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/default/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/default/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/default/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/default/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/instance/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/instance/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/instance/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/instance/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/instance/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/instance/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/instance/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/instance/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/throwOnError/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/throwOnError/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/throwOnError/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/throwOnError/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/throwOnError/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/throwOnError/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/throwOnError/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/throwOnError/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/asClass/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/asClass/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/asClass/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/asClass/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/asClass/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/asClass/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/fetch/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/fetch/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/fetch/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/fetch/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/fetch/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/fetch/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/asClass/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/asClass/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/asClass/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/asClass/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/asClass/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/asClass/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/name-builder/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/name-builder/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/name-builder/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/name-builder/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/name-builder/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/name-builder/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/name-builder/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/name-builder/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/asClass/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/asClass/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/asClass/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/asClass/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/asClass/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/asClass/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/name-builder/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/name-builder/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/name-builder/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/name-builder/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/name-builder/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/name-builder/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/name-builder/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/name-builder/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/asClass/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/asClass/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/asClass/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/asClass/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/asClass/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/asClass/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/name-builder/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/name-builder/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/name-builder/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/name-builder/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/name-builder/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/name-builder/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/name-builder/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/name-builder/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/asClass/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/asClass/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/asClass/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/asClass/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/asClass/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/asClass/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/name-builder/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/name-builder/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/name-builder/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/name-builder/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/name-builder/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/name-builder/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/name-builder/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/name-builder/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/asClass/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/asClass/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/asClass/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/asClass/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/asClass/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/asClass/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/name-builder/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/name-builder/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/name-builder/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/name-builder/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/name-builder/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/name-builder/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/name-builder/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/name-builder/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/schema-unknown/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/schema-unknown/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/schema-unknown/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/schema-unknown/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/schema-unknown/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/schema-unknown/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/schema-unknown/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/schema-unknown/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-api-key/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-api-key/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-api-key/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-api-key/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-api-key/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-api-key/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-api-key/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-api-key/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-basic/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-basic/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-basic/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-basic/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-basic/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-basic/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-basic/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-basic/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-false/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-false/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-false/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-false/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-false/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-false/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-false/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-false/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-oauth2/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-oauth2/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-oauth2/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-oauth2/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-oauth2/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-oauth2/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-oauth2/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-oauth2/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-base-path/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-base-path/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-base-path/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-base-path/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-base-path/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-base-path/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-base-path/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-base-path/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-host/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-host/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-host/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-host/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-host/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-host/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-host/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-host/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/transforms-read-write/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/transforms-read-write/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/transforms-read-write/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/transforms-read-write/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/transforms-read-write/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/transforms-read-write/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/transforms-read-write/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/transforms-read-write/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/body-response-text-plain/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/body-response-text-plain/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/body-response-text-plain/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/body-response-text-plain/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/body-response-text-plain/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/body-response-text-plain/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/body-response-text-plain/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/body-response-text-plain/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/content-types/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/content-types/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/content-types/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/content-types/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/content-types/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/content-types/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/content-types/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/content-types/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/internal-name-conflict/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/internal-name-conflict/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/internal-name-conflict/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/internal-name-conflict/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/internal-name-conflict/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/internal-name-conflict/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/internal-name-conflict/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/internal-name-conflict/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false-axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false-axios/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false-axios/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false-axios/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false-axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false-axios/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false-axios/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false-axios/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default-class/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default-class/client/types.gen.ts index 6cdf8ad48..9ae3dc653 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default-class/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default-class/client/types.gen.ts @@ -253,7 +253,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default-class/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default-class/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default-class/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default-class/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default/client/types.gen.ts index 6cdf8ad48..9ae3dc653 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default/client/types.gen.ts @@ -253,7 +253,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/default/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/default/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/default/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/default/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/default/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/default/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/default/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/default/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/instance/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/instance/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/instance/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/instance/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/instance/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/instance/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/instance/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/instance/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/throwOnError/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/throwOnError/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/throwOnError/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/throwOnError/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/throwOnError/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/throwOnError/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/throwOnError/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/throwOnError/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/asClass/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/asClass/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/asClass/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/asClass/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/asClass/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/asClass/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/fetch/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/fetch/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/fetch/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/fetch/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/fetch/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/fetch/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/name-builder/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/name-builder/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/name-builder/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/name-builder/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/name-builder/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/name-builder/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/name-builder/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/name-builder/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/name-builder/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/name-builder/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/name-builder/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/name-builder/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/name-builder/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/name-builder/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/name-builder/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/name-builder/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/name-builder/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/name-builder/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/name-builder/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/name-builder/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/name-builder/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/name-builder/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/name-builder/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/name-builder/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/name-builder/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/name-builder/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/name-builder/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/name-builder/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/name-builder/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/name-builder/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/name-builder/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/name-builder/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/name-builder/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/name-builder/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/name-builder/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/name-builder/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/name-builder/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/name-builder/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/name-builder/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/name-builder/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-api-key/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-api-key/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-api-key/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-api-key/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-api-key/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-api-key/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-api-key/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-api-key/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-false/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-false/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-false/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-false/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-false/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-false/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-false/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-false/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-http-bearer/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-http-bearer/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-http-bearer/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-http-bearer/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-http-bearer/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-http-bearer/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-http-bearer/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-http-bearer/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-oauth2/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-oauth2/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-oauth2/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-oauth2/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-oauth2/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-oauth2/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-oauth2/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-oauth2/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-open-id-connect/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-open-id-connect/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-open-id-connect/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-open-id-connect/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-open-id-connect/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-open-id-connect/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-open-id-connect/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-open-id-connect/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/servers/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/servers/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/servers/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/servers/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/servers/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/servers/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/servers/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/servers/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-all-of/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-all-of/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-all-of/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-all-of/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-all-of/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-all-of/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-all-of/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-all-of/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-any-of-null/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-any-of-null/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-any-of-null/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-any-of-null/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-any-of-null/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-any-of-null/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-any-of-null/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-any-of-null/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-array/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-array/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-array/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-array/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-array/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-array/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-array/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-array/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-recursive/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-recursive/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-recursive/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-recursive/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-recursive/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-recursive/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-recursive/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-recursive/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transforms-read-write/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transforms-read-write/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transforms-read-write/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transforms-read-write/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transforms-read-write/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transforms-read-write/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transforms-read-write/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transforms-read-write/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/body-response-text-plain/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/body-response-text-plain/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/body-response-text-plain/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/body-response-text-plain/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/body-response-text-plain/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/body-response-text-plain/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/body-response-text-plain/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/body-response-text-plain/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-false/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-false/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-false/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-false/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-false/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-false/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-false/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-false/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-number/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-number/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-number/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-number/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-number/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-number/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-number/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-number/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-strict/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-strict/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-strict/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-strict/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-strict/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-strict/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-strict/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-strict/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-string/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-string/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-string/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-string/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-string/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-string/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-string/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-string/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/default/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/default/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/default/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/default/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/default/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/default/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/default/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/default/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/import-file-extension-ts/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/import-file-extension-ts/client/types.gen.ts index a3c7589fe..a6044e9d7 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/import-file-extension-ts/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/import-file-extension-ts/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/import-file-extension-ts/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/import-file-extension-ts/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/import-file-extension-ts/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/import-file-extension-ts/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-optional/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-optional/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-optional/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-optional/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-optional/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-optional/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-optional/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-optional/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-required/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-required/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-required/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-required/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-required/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-required/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-required/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-required/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/tsconfig-nodenext-sdk/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/tsconfig-nodenext-sdk/client/types.gen.ts index 451c1c494..3afc19c5b 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/tsconfig-nodenext-sdk/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/tsconfig-nodenext-sdk/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/tsconfig-nodenext-sdk/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/tsconfig-nodenext-sdk/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/tsconfig-nodenext-sdk/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/tsconfig-nodenext-sdk/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-false/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-false/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-false/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-false/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-false/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-false/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-false/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-false/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-number/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-number/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-number/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-number/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-number/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-number/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-number/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-number/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-strict/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-strict/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-strict/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-strict/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-strict/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-strict/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-strict/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-strict/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-string/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-string/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-string/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-string/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-string/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-string/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-string/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-string/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/default/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/default/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/default/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/default/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/default/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/default/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/default/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/default/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/import-file-extension-ts/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/import-file-extension-ts/client/types.gen.ts index b222d70fc..de327b72e 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/import-file-extension-ts/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/import-file-extension-ts/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/import-file-extension-ts/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/import-file-extension-ts/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/import-file-extension-ts/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/import-file-extension-ts/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-optional/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-optional/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-optional/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-optional/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-optional/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-optional/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-optional/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-optional/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-required/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-required/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-required/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-required/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-required/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-required/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-required/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-required/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/tsconfig-nodenext-sdk/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/tsconfig-nodenext-sdk/client/types.gen.ts index d68ab68c4..e8c499f3d 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/tsconfig-nodenext-sdk/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/tsconfig-nodenext-sdk/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/tsconfig-nodenext-sdk/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/tsconfig-nodenext-sdk/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/tsconfig-nodenext-sdk/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/tsconfig-nodenext-sdk/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-false/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-false/client/types.gen.ts index 76f0bf322..74d064b71 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-false/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-false/client/types.gen.ts @@ -195,7 +195,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-false/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-false/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-false/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-false/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-number/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-number/client/types.gen.ts index 76f0bf322..74d064b71 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-number/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-number/client/types.gen.ts @@ -195,7 +195,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-number/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-number/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-number/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-number/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-strict/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-strict/client/types.gen.ts index 76f0bf322..74d064b71 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-strict/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-strict/client/types.gen.ts @@ -195,7 +195,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-strict/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-strict/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-strict/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-strict/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-string/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-string/client/types.gen.ts index 76f0bf322..74d064b71 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-string/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-string/client/types.gen.ts @@ -195,7 +195,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-string/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-string/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-string/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/base-url-string/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/clean-false/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/clean-false/client/types.gen.ts index 76f0bf322..74d064b71 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/clean-false/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/clean-false/client/types.gen.ts @@ -195,7 +195,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/clean-false/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/clean-false/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/clean-false/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/clean-false/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/default/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/default/client/types.gen.ts index 76f0bf322..74d064b71 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/default/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/default/client/types.gen.ts @@ -195,7 +195,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/default/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/default/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/default/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/default/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/import-file-extension-ts/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/import-file-extension-ts/client/types.gen.ts index b3e07236c..def985fc1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/import-file-extension-ts/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/import-file-extension-ts/client/types.gen.ts @@ -195,7 +195,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/import-file-extension-ts/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/import-file-extension-ts/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/import-file-extension-ts/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/import-file-extension-ts/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/sdk-client-optional/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/sdk-client-optional/client/types.gen.ts index 76f0bf322..74d064b71 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/sdk-client-optional/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/sdk-client-optional/client/types.gen.ts @@ -195,7 +195,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/sdk-client-optional/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/sdk-client-optional/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/sdk-client-optional/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/sdk-client-optional/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/sdk-client-required/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/sdk-client-required/client/types.gen.ts index 76f0bf322..74d064b71 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/sdk-client-required/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/sdk-client-required/client/types.gen.ts @@ -195,7 +195,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/sdk-client-required/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/sdk-client-required/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/sdk-client-required/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/sdk-client-required/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/tsconfig-nodenext-sdk/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/tsconfig-nodenext-sdk/client/types.gen.ts index 907e6c9ee..9e9075615 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/tsconfig-nodenext-sdk/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/tsconfig-nodenext-sdk/client/types.gen.ts @@ -195,7 +195,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/tsconfig-nodenext-sdk/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/tsconfig-nodenext-sdk/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/tsconfig-nodenext-sdk/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/tsconfig-nodenext-sdk/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-false/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-false/client/types.gen.ts index ac663764d..179a463d7 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-false/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-false/client/types.gen.ts @@ -189,7 +189,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - WithRefs>; + ([TData] extends [never] ? unknown : WithRefs>); export type OptionsLegacyParser = TData extends { body?: any } ? TData extends { headers?: any } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-false/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-false/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-false/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-false/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-number/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-number/client/types.gen.ts index ac663764d..179a463d7 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-number/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-number/client/types.gen.ts @@ -189,7 +189,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - WithRefs>; + ([TData] extends [never] ? unknown : WithRefs>); export type OptionsLegacyParser = TData extends { body?: any } ? TData extends { headers?: any } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-number/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-number/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-number/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-number/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-strict/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-strict/client/types.gen.ts index ac663764d..179a463d7 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-strict/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-strict/client/types.gen.ts @@ -189,7 +189,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - WithRefs>; + ([TData] extends [never] ? unknown : WithRefs>); export type OptionsLegacyParser = TData extends { body?: any } ? TData extends { headers?: any } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-strict/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-strict/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-strict/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-strict/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-string/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-string/client/types.gen.ts index ac663764d..179a463d7 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-string/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-string/client/types.gen.ts @@ -189,7 +189,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - WithRefs>; + ([TData] extends [never] ? unknown : WithRefs>); export type OptionsLegacyParser = TData extends { body?: any } ? TData extends { headers?: any } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-string/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-string/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-string/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/base-url-string/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/clean-false/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/clean-false/client/types.gen.ts index ac663764d..179a463d7 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/clean-false/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/clean-false/client/types.gen.ts @@ -189,7 +189,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - WithRefs>; + ([TData] extends [never] ? unknown : WithRefs>); export type OptionsLegacyParser = TData extends { body?: any } ? TData extends { headers?: any } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/clean-false/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/clean-false/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/clean-false/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/clean-false/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/default/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/default/client/types.gen.ts index ac663764d..179a463d7 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/default/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/default/client/types.gen.ts @@ -189,7 +189,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - WithRefs>; + ([TData] extends [never] ? unknown : WithRefs>); export type OptionsLegacyParser = TData extends { body?: any } ? TData extends { headers?: any } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/default/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/default/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/default/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/default/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/import-file-extension-ts/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/import-file-extension-ts/client/types.gen.ts index 20204d63e..255ddf438 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/import-file-extension-ts/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/import-file-extension-ts/client/types.gen.ts @@ -189,7 +189,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - WithRefs>; + ([TData] extends [never] ? unknown : WithRefs>); export type OptionsLegacyParser = TData extends { body?: any } ? TData extends { headers?: any } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/import-file-extension-ts/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/import-file-extension-ts/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/import-file-extension-ts/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/import-file-extension-ts/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/sdk-client-optional/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/sdk-client-optional/client/types.gen.ts index ac663764d..179a463d7 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/sdk-client-optional/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/sdk-client-optional/client/types.gen.ts @@ -189,7 +189,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - WithRefs>; + ([TData] extends [never] ? unknown : WithRefs>); export type OptionsLegacyParser = TData extends { body?: any } ? TData extends { headers?: any } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/sdk-client-optional/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/sdk-client-optional/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/sdk-client-optional/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/sdk-client-optional/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/sdk-client-required/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/sdk-client-required/client/types.gen.ts index ac663764d..179a463d7 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/sdk-client-required/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/sdk-client-required/client/types.gen.ts @@ -189,7 +189,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - WithRefs>; + ([TData] extends [never] ? unknown : WithRefs>); export type OptionsLegacyParser = TData extends { body?: any } ? TData extends { headers?: any } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/sdk-client-required/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/sdk-client-required/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/sdk-client-required/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/sdk-client-required/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/tsconfig-nodenext-sdk/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/tsconfig-nodenext-sdk/client/types.gen.ts index 588c13b49..b42db4f37 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/tsconfig-nodenext-sdk/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/tsconfig-nodenext-sdk/client/types.gen.ts @@ -189,7 +189,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - WithRefs>; + ([TData] extends [never] ? unknown : WithRefs>); export type OptionsLegacyParser = TData extends { body?: any } ? TData extends { headers?: any } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/tsconfig-nodenext-sdk/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/tsconfig-nodenext-sdk/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/tsconfig-nodenext-sdk/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/tsconfig-nodenext-sdk/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-false/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-false/client/types.gen.ts index b44644598..0ca5b6009 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-false/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-false/client/types.gen.ts @@ -305,7 +305,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-false/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-false/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-false/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-false/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-number/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-number/client/types.gen.ts index b44644598..0ca5b6009 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-number/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-number/client/types.gen.ts @@ -305,7 +305,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-number/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-number/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-number/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-number/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-strict/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-strict/client/types.gen.ts index b44644598..0ca5b6009 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-strict/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-strict/client/types.gen.ts @@ -305,7 +305,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-strict/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-strict/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-strict/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-strict/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-string/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-string/client/types.gen.ts index b44644598..0ca5b6009 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-string/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-string/client/types.gen.ts @@ -305,7 +305,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-string/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-string/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-string/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-string/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/client/types.gen.ts index b44644598..0ca5b6009 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/client/types.gen.ts @@ -305,7 +305,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/default/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/default/client/types.gen.ts index b44644598..0ca5b6009 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/default/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/default/client/types.gen.ts @@ -305,7 +305,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/default/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/default/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/default/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/default/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/import-file-extension-ts/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/import-file-extension-ts/client/types.gen.ts index 8783ae498..3193669eb 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/import-file-extension-ts/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/import-file-extension-ts/client/types.gen.ts @@ -305,7 +305,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/import-file-extension-ts/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/import-file-extension-ts/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/import-file-extension-ts/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/import-file-extension-ts/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-optional/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-optional/client/types.gen.ts index b44644598..0ca5b6009 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-optional/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-optional/client/types.gen.ts @@ -305,7 +305,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-optional/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-optional/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-optional/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-optional/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-required/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-required/client/types.gen.ts index b44644598..0ca5b6009 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-required/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-required/client/types.gen.ts @@ -305,7 +305,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-required/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-required/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-required/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-required/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/tsconfig-nodenext-sdk/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/tsconfig-nodenext-sdk/client/types.gen.ts index 3dc1783a7..503371b37 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/tsconfig-nodenext-sdk/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/tsconfig-nodenext-sdk/client/types.gen.ts @@ -305,7 +305,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/tsconfig-nodenext-sdk/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/tsconfig-nodenext-sdk/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/tsconfig-nodenext-sdk/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/tsconfig-nodenext-sdk/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/content-types/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/content-types/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/content-types/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/content-types/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/content-types/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/content-types/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/content-types/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/content-types/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/headers/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/headers/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/headers/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/headers/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/headers/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/headers/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/headers/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/headers/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/internal-name-conflict/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/internal-name-conflict/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/internal-name-conflict/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/internal-name-conflict/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/internal-name-conflict/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/internal-name-conflict/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/internal-name-conflict/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/internal-name-conflict/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pagination-ref/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pagination-ref/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pagination-ref/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pagination-ref/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pagination-ref/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pagination-ref/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pagination-ref/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pagination-ref/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false-axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false-axios/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false-axios/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false-axios/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false-axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false-axios/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false-axios/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false-axios/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default-class/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default-class/client/types.gen.ts index 6cdf8ad48..9ae3dc653 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default-class/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default-class/client/types.gen.ts @@ -253,7 +253,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default-class/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default-class/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default-class/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default-class/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default/client/types.gen.ts index 6cdf8ad48..9ae3dc653 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default/client/types.gen.ts @@ -253,7 +253,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/default/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/default/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/default/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/default/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/default/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/default/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/default/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/default/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/instance/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/instance/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/instance/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/instance/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/instance/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/instance/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/instance/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/instance/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/throwOnError/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/throwOnError/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/throwOnError/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/throwOnError/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/throwOnError/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/throwOnError/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/throwOnError/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/throwOnError/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-ignore/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-ignore/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-ignore/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-ignore/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/asClass/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/asClass/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/asClass/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/asClass/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/asClass/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/asClass/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/fetch/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/fetch/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/fetch/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/fetch/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/fetch/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/fetch/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/name-builder/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/name-builder/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/name-builder/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/name-builder/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/name-builder/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/name-builder/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/name-builder/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/name-builder/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/name-builder/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/name-builder/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/name-builder/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/name-builder/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/name-builder/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/name-builder/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/name-builder/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/name-builder/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/name-builder/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/name-builder/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/name-builder/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/name-builder/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/name-builder/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/name-builder/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/name-builder/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/name-builder/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/name-builder/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/name-builder/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/name-builder/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/name-builder/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/name-builder/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/name-builder/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/name-builder/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/name-builder/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/name-builder/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/name-builder/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/name-builder/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/name-builder/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/name-builder/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/name-builder/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/name-builder/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/name-builder/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-api-key/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-api-key/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-api-key/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-api-key/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-api-key/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-api-key/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-api-key/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-api-key/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-false/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-false/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-false/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-false/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-false/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-false/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-false/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-false/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-http-bearer/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-http-bearer/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-http-bearer/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-http-bearer/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-http-bearer/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-http-bearer/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-http-bearer/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-http-bearer/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-oauth2/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-oauth2/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-oauth2/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-oauth2/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-oauth2/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-oauth2/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-oauth2/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-oauth2/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-open-id-connect/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-open-id-connect/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-open-id-connect/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-open-id-connect/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-open-id-connect/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-open-id-connect/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-open-id-connect/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-open-id-connect/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/servers/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/servers/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/servers/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/servers/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/servers/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/servers/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/servers/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/servers/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-angular/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-angular/client/types.gen.ts index 6cdf8ad48..9ae3dc653 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-angular/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-angular/client/types.gen.ts @@ -253,7 +253,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-angular/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-angular/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-angular/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-angular/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-axios/client/types.gen.ts index d59239b9a..436002013 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-axios/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-axios/client/types.gen.ts @@ -194,7 +194,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-axios/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-axios/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-axios/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-fetch/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-fetch/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-fetch/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-fetch/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-fetch/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-fetch/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-next/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-next/client/types.gen.ts index 76f0bf322..74d064b71 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-next/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-next/client/types.gen.ts @@ -195,7 +195,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-next/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-next/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-next/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-next/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-nuxt/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-nuxt/client/types.gen.ts index ac663764d..179a463d7 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-nuxt/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-nuxt/client/types.gen.ts @@ -189,7 +189,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - WithRefs>; + ([TData] extends [never] ? unknown : WithRefs>); export type OptionsLegacyParser = TData extends { body?: any } ? TData extends { headers?: any } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-nuxt/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-nuxt/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-nuxt/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-nuxt/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-ofetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-ofetch/client/types.gen.ts index b44644598..0ca5b6009 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-ofetch/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-ofetch/client/types.gen.ts @@ -305,7 +305,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-ofetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-ofetch/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-ofetch/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-ofetch/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-all-of/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-all-of/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-all-of/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-all-of/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-all-of/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-all-of/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-all-of/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-all-of/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-any-of-null/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-any-of-null/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-any-of-null/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-any-of-null/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-any-of-null/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-any-of-null/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-any-of-null/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-any-of-null/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-array/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-array/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-array/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-array/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-array/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-array/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-array/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-array/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-recursive/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-recursive/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-recursive/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-recursive/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-recursive/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-recursive/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-recursive/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-recursive/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transforms-read-write/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transforms-read-write/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transforms-read-write/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transforms-read-write/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transforms-read-write/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transforms-read-write/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transforms-read-write/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transforms-read-write/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/client/types.gen.ts index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/client/types.gen.ts @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/core/params.gen.ts index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/core/params.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/core/params.gen.ts @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/test/generated/v3_no_index/client/types.gen.ts.snap b/packages/openapi-ts-tests/main/test/__snapshots__/test/generated/v3_no_index/client/types.gen.ts.snap index 1a005b51e..63c4e5f5f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/test/generated/v3_no_index/client/types.gen.ts.snap +++ b/packages/openapi-ts-tests/main/test/__snapshots__/test/generated/v3_no_index/client/types.gen.ts.snap @@ -238,7 +238,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/test/generated/v3_no_index/core/params.gen.ts.snap b/packages/openapi-ts-tests/main/test/__snapshots__/test/generated/v3_no_index/core/params.gen.ts.snap index 71c88e852..92f1e61a1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/test/generated/v3_no_index/core/params.gen.ts.snap +++ b/packages/openapi-ts-tests/main/test/__snapshots__/test/generated/v3_no_index/core/params.gen.ts.snap @@ -2,6 +2,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +type KeyMap = Map< + string, + { + in: Slot; + map?: string; + } | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -22,6 +40,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -39,14 +68,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -111,7 +129,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -120,8 +140,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -132,10 +156,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts/src/generate/renderer.ts b/packages/openapi-ts/src/generate/renderer.ts index f51a2bd67..aa976eb5e 100644 --- a/packages/openapi-ts/src/generate/renderer.ts +++ b/packages/openapi-ts/src/generate/renderer.ts @@ -482,11 +482,16 @@ export class TypeScriptRenderer implements Renderer { const conflictId = file.resolvedNames.getKey(name); if (conflictId !== undefined) { const conflictSymbol = project.symbols.get(conflictId); - if ( - (conflictSymbol?.kind === 'type' && symbol.kind === 'type') || - (conflictSymbol?.kind !== 'type' && symbol.kind !== 'type') - ) { - name = this.getUniqueName(name, file.resolvedNames); + if (conflictSymbol) { + const kinds = [conflictSymbol.kind, symbol.kind]; + if ( + kinds.every((kind) => kind === 'type') || + kinds.every((kind) => kind !== 'type') || + // avoid conflicts between class and type of the same name + (kinds.includes('class') && kinds.includes('type')) + ) { + name = this.getUniqueName(name, file.resolvedNames); + } } } file.resolvedNames.set(symbol.id, name); diff --git a/packages/openapi-ts/src/plugins/@hey-api/client-angular/bundle/types.ts b/packages/openapi-ts/src/plugins/@hey-api/client-angular/bundle/types.ts index 1eb603e4b..0d737ff52 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-angular/bundle/types.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-angular/bundle/types.ts @@ -251,7 +251,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts/src/plugins/@hey-api/client-axios/bundle/types.ts b/packages/openapi-ts/src/plugins/@hey-api/client-axios/bundle/types.ts index c8c039158..f176b7120 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-axios/bundle/types.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-axios/bundle/types.ts @@ -192,7 +192,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts/src/plugins/@hey-api/client-core/__tests__/params.test.ts b/packages/openapi-ts/src/plugins/@hey-api/client-core/__tests__/params.test.ts index 278c76f51..7f8ac2ecf 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-core/__tests__/params.test.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-core/__tests__/params.test.ts @@ -243,6 +243,23 @@ describe('buildClientParams', () => { body: 1, }, }, + { + args: [ + { + foo: 1, + }, + ], + config: [ + { + key: 'foo', + map: 'body', + }, + ], + description: 'alias flat body', + params: { + body: 1, + }, + }, { args: [ { diff --git a/packages/openapi-ts/src/plugins/@hey-api/client-core/bundle/params.ts b/packages/openapi-ts/src/plugins/@hey-api/client-core/bundle/params.ts index ba35263d8..ddf0bfc17 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-core/bundle/params.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-core/bundle/params.ts @@ -1,5 +1,24 @@ type Slot = 'body' | 'headers' | 'path' | 'query'; +type Params = { + body: unknown; + headers: Record; + path: Record; + query: Record; +}; + +type KeyMap = Map< + string, + | { + in: Slot; + map?: string; + } + | { + in?: never; + map: Slot; + } +>; + export type Field = | { in: Exclude; @@ -20,6 +39,17 @@ export type Field = */ key?: string; map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; }; export interface Fields { @@ -37,14 +67,6 @@ const extraPrefixesMap: Record = { }; const extraPrefixes = Object.entries(extraPrefixesMap); -type KeyMap = Map< - string, - { - in: Slot; - map?: string; - } ->; - const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { if (!map) { map = new Map(); @@ -58,6 +80,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }); } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); } else if (config.args) { buildKeyMap(config.args, map); } @@ -66,13 +92,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { return map; }; -interface Params { - body: unknown; - headers: Record; - path: Record; - query: Record; -} - const stripEmptySlots = (params: Params) => { for (const [slot, value] of Object.entries(params)) { if (value && typeof value === 'object' && !Object.keys(value).length) { @@ -109,7 +128,9 @@ export const buildClientParams = ( if (config.key) { const field = map.get(config.key)!; const name = field.map || config.key; - (params[field.in] as Record)[name] = arg; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } } else { params.body = arg; } @@ -118,8 +139,12 @@ export const buildClientParams = ( const field = map.get(key); if (field) { - const name = field.map || key; - (params[field.in] as Record)[name] = value; + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix), @@ -130,10 +155,8 @@ export const buildClientParams = ( (params[slot] as Record)[ key.slice(prefix.length) ] = value; - } else { - for (const [slot, allowed] of Object.entries( - config.allowExtra ?? {}, - )) { + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { if (allowed) { (params[slot as Slot] as Record)[key] = value; break; diff --git a/packages/openapi-ts/src/plugins/@hey-api/client-fetch/bundle/types.ts b/packages/openapi-ts/src/plugins/@hey-api/client-fetch/bundle/types.ts index 456f59dcf..31bfeeb7d 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-fetch/bundle/types.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-fetch/bundle/types.ts @@ -236,7 +236,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts/src/plugins/@hey-api/client-next/bundle/types.ts b/packages/openapi-ts/src/plugins/@hey-api/client-next/bundle/types.ts index c61ad1f22..9672c2b08 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-next/bundle/types.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-next/bundle/types.ts @@ -193,7 +193,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts/src/plugins/@hey-api/client-nuxt/bundle/types.ts b/packages/openapi-ts/src/plugins/@hey-api/client-nuxt/bundle/types.ts index 0290d9ec4..fdbb10447 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-nuxt/bundle/types.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-nuxt/bundle/types.ts @@ -187,7 +187,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - WithRefs>; + ([TData] extends [never] ? unknown : WithRefs>); export type OptionsLegacyParser = TData extends { body?: any } ? TData extends { headers?: any } diff --git a/packages/openapi-ts/src/plugins/@hey-api/client-ofetch/bundle/types.ts b/packages/openapi-ts/src/plugins/@hey-api/client-ofetch/bundle/types.ts index 3864bae84..de191861b 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-ofetch/bundle/types.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-ofetch/bundle/types.ts @@ -303,7 +303,7 @@ export type Options< RequestOptions, 'body' | 'path' | 'query' | 'url' > & - Omit; + ([TData] extends [never] ? unknown : Omit); export type OptionsLegacyParser< TData = unknown, diff --git a/packages/openapi-ts/src/plugins/@hey-api/sdk/config.ts b/packages/openapi-ts/src/plugins/@hey-api/sdk/config.ts index 85e8d4ca6..c1bce3e62 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/sdk/config.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/sdk/config.ts @@ -16,7 +16,7 @@ export const defaultConfig: HeyApiSdkPlugin['Config'] = { exportFromIndex: true, instance: false, operationId: true, - params_EXPERIMENTAL: 'default', + paramsStructure: 'grouped', response: 'body', responseStyle: 'fields', transformer: false, diff --git a/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/class.ts b/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/class.ts index d5359be80..2e954fa6b 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/class.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/class.ts @@ -291,6 +291,13 @@ export const generateClassSdk = ({ const symbolHeyApiClient = plugin.registerSymbol({ exported: false, + kind: 'class', + meta: { + category: 'utility', + resource: 'class', + resourceId: '_HeyApiClient', + tool: 'sdk', + }, name: '_HeyApiClient', }); @@ -361,6 +368,7 @@ export const generateClassSdk = ({ const symbol = plugin.registerSymbol({ exported: true, + kind: 'class', meta: { category: 'utility', resource: 'class', diff --git a/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts b/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts index b34932a59..42ed9c269 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts @@ -4,8 +4,9 @@ import type ts from 'typescript'; import { statusCodeToGroup } from '~/ir/operation'; import type { IR } from '~/ir/types'; import { sanitizeNamespaceIdentifier } from '~/openApi'; -import { ensureValidIdentifier } from '~/openApi/shared/utils/identifier'; import { getClientPlugin } from '~/plugins/@hey-api/client-core/utils'; +import { toRefs } from '~/plugins/shared/utils/refs'; +import type { Property } from '~/tsc'; import { tsc } from '~/tsc'; import type { FunctionParameter, ObjectValue } from '~/tsc/types'; import { reservedJavaScriptKeywordsRegExp } from '~/utils/regexp'; @@ -13,10 +14,10 @@ import { stringCase } from '~/utils/stringCase'; import { transformClassName } from '~/utils/transform'; import type { Field, Fields } from '../../client-core/bundle/params'; -// import { getSignatureParameters } from './signature'; import type { HeyApiSdkPlugin } from '../types'; import { operationAuth } from './auth'; import { nuxtTypeComposable, nuxtTypeDefault } from './constants'; +import { getSignatureParameters } from './signature'; import { createRequestValidator, createResponseValidator } from './validator'; interface ClassNameEntry { @@ -147,11 +148,14 @@ export const operationClasses = ({ return classNames; }; +/** TODO: needs complete refactor */ export const operationOptionsType = ({ + isDataAllowed = true, operation, plugin, throwOnError, }: { + isDataAllowed?: boolean; operation: IR.OperationObject; plugin: HeyApiSdkPlugin['Instance']; throwOnError?: string; @@ -159,14 +163,15 @@ export const operationOptionsType = ({ const client = getClientPlugin(plugin.context.config); const isNuxtClient = client.name === '@hey-api/client-nuxt'; - const symbolDataType = plugin.querySymbol({ - category: 'type', - resource: 'operation', - resourceId: operation.id, - role: 'data', - tool: 'typescript', - }); - const dataType = symbolDataType?.placeholder || 'unknown'; + const symbolDataType = isDataAllowed + ? plugin.querySymbol({ + category: 'type', + resource: 'operation', + resourceId: operation.id, + role: 'data', + tool: 'typescript', + }) + : undefined; const symbolOptions = plugin.referenceSymbol({ category: 'type', @@ -181,16 +186,23 @@ export const operationOptionsType = ({ resourceId: operation.id, role: 'response', }); + const dataType = isDataAllowed + ? symbolDataType?.placeholder || 'unknown' + : 'never'; const responseType = symbolResponseType?.placeholder || 'unknown'; return `${symbolOptions.placeholder}<${nuxtTypeComposable}, ${dataType}, ${responseType}, ${nuxtTypeDefault}>`; } // TODO: refactor this to be more generic, works for now if (throwOnError) { + const dataType = isDataAllowed + ? symbolDataType?.placeholder || 'unknown' + : 'never'; return `${symbolOptions.placeholder}<${dataType}, ${throwOnError}>`; } - return symbolDataType - ? `${symbolOptions.placeholder}<${symbolDataType.placeholder}>` + const dataType = isDataAllowed ? symbolDataType?.placeholder : 'never'; + return dataType + ? `${symbolOptions.placeholder}<${dataType}>` : symbolOptions.placeholder; }; @@ -209,8 +221,6 @@ export const operationParameters = ({ operation: IR.OperationObject; plugin: HeyApiSdkPlugin['Instance']; }): OperationParameters => { - // getSignatureParameters({ operation }); - const result: OperationParameters = { argNames: [], fields: [], @@ -221,75 +231,42 @@ export const operationParameters = ({ const client = getClientPlugin(plugin.context.config); const isNuxtClient = client.name === '@hey-api/client-nuxt'; - if (plugin.config.params_EXPERIMENTAL === 'experiment') { - if (operation.parameters?.path) { - for (const key in operation.parameters.path) { - const parameter = operation.parameters.path[key]!; - const name = ensureValidIdentifier(parameter.name); - // TODO: detect duplicates - result.argNames.push(name); - result.fields.push({ - in: 'path', - key: name, - }); - result.parameters.push({ - isRequired: parameter.required, - name, + if (plugin.config.paramsStructure === 'flat') { + const signature = getSignatureParameters({ operation, plugin }); + const flatParamsTypeProperties: Array = []; + + if (signature) { + let isParametersRequired = false; + + for (const key in signature.parameters) { + const parameter = signature.parameters[key]!; + if (parameter.isRequired) { + isParametersRequired = true; + } + flatParamsTypeProperties.push({ + isRequired: parameter.isRequired, + name: parameter.name, type: pluginTypeScript.api.schemaToType({ plugin: pluginTypeScript, schema: parameter.schema, - state: { - path: { - value: [], - }, - }, + state: toRefs({ + path: [], + }), }), }); } - } - if (operation.parameters?.query) { - for (const key in operation.parameters.query) { - const parameter = operation.parameters.query[key]!; - const name = ensureValidIdentifier(parameter.name); - // TODO: detect duplicates - result.argNames.push(name); - result.fields.push({ - in: 'path', - key: name, - }); - result.parameters.push({ - isRequired: parameter.required, - name, - type: pluginTypeScript.api.schemaToType({ - plugin: pluginTypeScript, - schema: parameter.schema, - state: { - path: { - value: [], - }, - }, - }), - }); + result.argNames.push('parameters'); + for (const field of signature.fields) { + result.fields.push(field); } - } - if (operation.body) { - const name = 'body'; - // TODO: detect duplicates - result.argNames.push(name); - result.fields.push({ in: 'body' }); result.parameters.push({ - isRequired: operation.body.required, - name, - type: pluginTypeScript.api.schemaToType({ - plugin: pluginTypeScript, - schema: operation.body.schema, - state: { - path: { - value: [], - }, - }, + isRequired: isParametersRequired, + name: 'parameters', + type: tsc.typeInterfaceNode({ + properties: flatParamsTypeProperties, + useLegacyResolution: false, }), }); } @@ -298,8 +275,8 @@ export const operationParameters = ({ result.parameters.push({ isRequired: isRequiredOptions, name: 'options', - // TODO: ensure no path, body, query type: operationOptionsType({ + isDataAllowed: plugin.config.paramsStructure === 'grouped', operation, plugin, throwOnError: isNuxtClient ? undefined : 'ThrowOnError', diff --git a/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/signature.ts b/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/signature.ts index fbd6042e6..cbd7f7a68 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/signature.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/signature.ts @@ -1,57 +1,37 @@ import type { IR } from '~/ir/types'; +import type { PluginInstance } from '~/plugins/shared/utils/instance'; +import { refToName } from '~/utils/ref'; +import { stringCase } from '~/utils/stringCase'; + +import type { Field } from '../../client-core/bundle/params'; type Location = keyof IR.ParametersObject | 'body'; type SignatureParameter = { + /** + * Is this parameter required in the SDK method signature? + */ + isRequired: boolean; + /** + * Parameter name in the SDK method signature. + */ name: string; /** * If the name was modified due to conflicts, this holds the original name. */ originalName?: string; /** - * JSON Path to the parameter within the operation object. + * Parameter schema object. */ - path: ReadonlyArray; + schema: IR.SchemaObject; }; type SignatureParameters = Record; -type SignatureField = - | { - kind: 'inline'; - value: SignatureParameter; - } - | { - kind: 'object'; - value: SignatureParameters; - }; - -export type Signature = ReadonlyArray; - -export const sig1 = [ - { - kind: 'value', - name: 'id', - value: { - name: 'id', - path: ['path', 'id'], - }, - }, - { - kind: 'object', - name: '', - value: { - limit: { - name: 'limit', - path: ['query', 'limit'], - }, - search: { - name: 'search', - path: ['query', 'search'], - }, - }, - }, -]; +type Signature = { + fields: ReadonlyArray; + parameters: SignatureParameters; +}; /** * Collects and resolves all operation parameters for flattened SDK signatures. @@ -62,7 +42,8 @@ export const getSignatureParameters = ({ operation, }: { operation: IR.OperationObject; -}): SignatureParameters | undefined => { + plugin: PluginInstance; +}): Signature | undefined => { // TODO: add cookies const locations = [ 'header', @@ -89,10 +70,24 @@ export const getSignatureParameters = ({ } if (operation.body) { - // TODO: we might want to spread body too if there's only a single object - // TODO: we might want to alias body for more ergonomic naming, e.g. user - // if the type is User - addParameter('body', 'body'); + // spread body if there's only a single object + if ( + !operation.body.schema.logicalOperator && + operation.body.schema.type === 'object' && + operation.body.schema.properties + ) { + const properties = operation.body.schema.properties; + for (const key in properties) { + addParameter(key, 'body'); + } + } else if (operation.body.schema.$ref) { + // alias body for more ergonomic naming, e.g. user if the type is User + const name = refToName(operation.body.schema.$ref); + const key = stringCase({ case: 'camelCase', value: name }); + addParameter(key, 'body'); + } else { + addParameter('body', 'body'); + } } const conflicts = new Set(); @@ -103,6 +98,7 @@ export const getSignatureParameters = ({ } const signatureParameters: SignatureParameters = {}; + const fields: Array = []; for (const location of locations) { const parameters = operation.parameters?.[location]; @@ -114,29 +110,84 @@ export const getSignatureParameters = ({ ? `${location}_${originalName}` : originalName; const signatureParameter: SignatureParameter = { + isRequired: parameter.required ?? false, name, - path: [location, key], + schema: parameter.schema, }; if (name !== originalName) { signatureParameter.originalName = originalName; } signatureParameters[name] = signatureParameter; + fields.push({ + in: location === 'header' ? 'headers' : location, + key: name, + ...(name !== originalName ? { map: originalName } : {}), + }); } } } if (operation.body) { - // never alias body - signatureParameters.body = { - name: 'body', - path: ['body'], - }; + const location = 'body'; + if ( + !operation.body.schema.logicalOperator && + operation.body.schema.type === 'object' && + operation.body.schema.properties + ) { + const properties = operation.body.schema.properties; + for (const originalName in properties) { + const property = properties[originalName]!; + const name = conflicts.has(originalName) + ? `${location}_${originalName}` + : originalName; + const signatureParameter: SignatureParameter = { + isRequired: property.required?.includes(originalName) ?? false, + name, + schema: property, + }; + if (name !== originalName) { + signatureParameter.originalName = originalName; + } + signatureParameters[name] = signatureParameter; + fields.push({ + in: location, + key: name, + ...(name !== originalName ? { map: originalName } : {}), + }); + } + } else if (operation.body.schema.$ref) { + const value = refToName(operation.body.schema.$ref); + const originalName = stringCase({ case: 'camelCase', value }); + const name = conflicts.has(originalName) + ? `${location}_${originalName}` + : originalName; + const signatureParameter: SignatureParameter = { + isRequired: operation.body.required ?? false, + name, + schema: operation.body.schema, + }; + if (name !== originalName) { + signatureParameter.originalName = originalName; + } + signatureParameters[name] = signatureParameter; + fields.push({ + key: name, + map: 'body', + }); + } else { + // never alias body + signatureParameters.body = { + isRequired: operation.body.required ?? false, + name: 'body', + schema: operation.body.schema, + }; + fields.push({ in: 'body' }); + } } if (!Object.keys(signatureParameters).length) { - return undefined; + return; } - console.log(signatureParameters); - return signatureParameters; + return { fields, parameters: signatureParameters }; }; diff --git a/packages/openapi-ts/src/plugins/@hey-api/sdk/types.d.ts b/packages/openapi-ts/src/plugins/@hey-api/sdk/types.d.ts index 76d8fef87..0ae872362 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/sdk/types.d.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/sdk/types.d.ts @@ -88,8 +88,17 @@ export type UserConfig = Plugin.Name<'@hey-api/sdk'> & * @default true */ operationId?: boolean; - /** @deprecated - this is an experimental feature, do not use */ - params_EXPERIMENTAL?: 'default' | 'experiment'; + /** + * Define how request parameters are structured in generated SDK methods. + * + * - `'flat'` merges parameters into a single object. + * - `'grouped'` separates parameters by transport layer. + * + * Use `'flat'` for simpler calls or `'grouped'` for stricter typing and code clarity. + * + * @default 'grouped' + */ + paramsStructure?: 'flat' | 'grouped'; /** * **This feature works only with the Fetch client** * @@ -258,8 +267,17 @@ export type Config = Plugin.Name<'@hey-api/sdk'> & * @default true */ operationId: boolean; - /** @deprecated - this is an experimental feature, do not use */ - params_EXPERIMENTAL: 'default' | 'experiment'; + /** + * Define how request parameters are structured in generated SDK methods. + * + * - `'flat'` merges parameters into a single object. + * - `'grouped'` separates parameters by transport layer. + * + * Use `'flat'` for simpler calls or `'grouped'` for stricter typing and code clarity. + * + * @default 'grouped' + */ + paramsStructure: 'flat' | 'grouped'; /** * **This feature works only with the Fetch client** * diff --git a/packages/openapi-ts/src/plugins/shared/utils/operation.ts b/packages/openapi-ts/src/plugins/shared/utils/operation.ts index 7b6ac7055..a31aa9fbd 100644 --- a/packages/openapi-ts/src/plugins/shared/utils/operation.ts +++ b/packages/openapi-ts/src/plugins/shared/utils/operation.ts @@ -48,11 +48,15 @@ export const isOperationOptionsRequired = ({ const client = getClientPlugin(context.config); const isNuxtClient = client.name === '@hey-api/client-nuxt'; const plugin = context.config.plugins['@hey-api/sdk']; - return ( - (plugin && !plugin.config.client && !plugin.config.instance) || - isNuxtClient || - hasOperationDataRequired(operation) - ); + if (plugin) { + if (!plugin.config.client && !plugin.config.instance) { + return true; + } + if (plugin.config.paramsStructure === 'flat') { + return false; + } + } + return isNuxtClient || hasOperationDataRequired(operation); }; export const hasOperationSse = ({ -- 2.51.2