Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/olive-buckets-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hey-api/openapi-ts': patch
---

fix: make data types of never "required" so they don't accept undefined
10 changes: 10 additions & 0 deletions .changeset/twenty-numbers-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@hey-api/client-custom': minor
'@hey-api/client-axios': minor
'@hey-api/client-fetch': minor
'@hey-api/client-core': minor
'@hey-api/client-next': minor
'@hey-api/client-nuxt': minor
---

feat: export buildClientParams function
1 change: 1 addition & 0 deletions packages/client-axios/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type {
export { createConfig } from './utils';
export type { Auth, QuerySerializerOptions } from '@hey-api/client-core';
export {
buildClientParams,
formDataBodySerializer,
jsonBodySerializer,
urlSearchParamsBodySerializer,
Expand Down
313 changes: 313 additions & 0 deletions packages/client-core/src/__tests__/params.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,313 @@
import { describe, expect, it } from 'vitest';

import type { Config } from '../params';
import { buildClientParams } from '../params';

describe('buildClientParams', () => {
const scenarios: ReadonlyArray<{
args: ReadonlyArray<unknown>;
config: Config;
description: string;
params: Record<string, unknown>;
}> = [
{
args: [1, 2, 3, 4],
config: [
{
in: 'path',
key: 'foo',
},
{
in: 'query',
key: 'bar',
},
{
in: 'headers',
key: 'baz',
},
{
in: 'body',
key: 'qux',
},
],
description: 'positional arguments',
params: {
body: {
qux: 4,
},
headers: {
baz: 3,
},
path: {
foo: 1,
},
query: {
bar: 2,
},
},
},
{
args: [
{
bar: 2,
baz: 3,
foo: 1,
qux: 4,
},
],
config: [
{
args: [
{
in: 'path',
key: 'foo',
},
{
in: 'query',
key: 'bar',
},
{
in: 'headers',
key: 'baz',
},
{
in: 'body',
key: 'qux',
},
],
},
],
description: 'flat arguments',
params: {
body: {
qux: 4,
},
headers: {
baz: 3,
},
path: {
foo: 1,
},
query: {
bar: 2,
},
},
},
{
args: [
1,
2,
{
baz: 3,
qux: 4,
},
],
config: [
{
in: 'path',
key: 'foo',
},
{
in: 'query',
key: 'bar',
},
{
args: [
{
in: 'headers',
key: 'baz',
},
{
in: 'body',
key: 'qux',
},
],
},
],
description: 'mixed arguments',
params: {
body: {
qux: 4,
},
headers: {
baz: 3,
},
path: {
foo: 1,
},
query: {
bar: 2,
},
},
},
{
args: [1, 2, 3, 4],
config: [
{
in: 'path',
key: 'foo',
map: 'f_o_o',
},
{
in: 'query',
key: 'bar',
map: 'b_a_r',
},
{
in: 'headers',
key: 'baz',
map: 'b_a_z',
},
{
in: 'body',
key: 'qux',
map: 'q_u_x',
},
],
description: 'positional mapped arguments',
params: {
body: {
q_u_x: 4,
},
headers: {
b_a_z: 3,
},
path: {
f_o_o: 1,
},
query: {
b_a_r: 2,
},
},
},
{
args: [
{
bar: 2,
baz: 3,
foo: 1,
qux: 4,
},
],
config: [
{
args: [
{
in: 'path',
key: 'foo',
map: 'f_o_o',
},
{
in: 'query',
key: 'bar',
map: 'b_a_r',
},
{
in: 'headers',
key: 'baz',
map: 'b_a_z',
},
{
in: 'body',
key: 'qux',
map: 'q_u_x',
},
],
},
],
description: 'flat mapped arguments',
params: {
body: {
q_u_x: 4,
},
headers: {
b_a_z: 3,
},
path: {
f_o_o: 1,
},
query: {
b_a_r: 2,
},
},
},
{
args: [1],
config: [
{
in: 'body',
},
],
description: 'positional primitive body',
params: {
body: 1,
},
},
{
args: [
{
$body_qux: 4,
$headers_baz: 3,
$path_foo: 1,
$query_bar: 2,
},
],
config: [
{
allowExtra: {},
},
],
description: 'namespace extra arguments',
params: {
body: {
qux: 4,
},
headers: {
baz: 3,
},
path: {
foo: 1,
},
query: {
bar: 2,
},
},
},
{
args: [
{
bar: 2,
baz: 3,
foo: 1,
qux: 4,
},
],
config: [
{
allowExtra: {
query: true,
},
},
],
description: 'slot extra arguments',
params: {
query: {
bar: 2,
baz: 3,
foo: 1,
qux: 4,
},
},
},
{
args: [],
config: [],
description: 'strip empty slots',
params: {},
},
];

it.each(scenarios)('$description', async ({ args, config, params }) => {
expect(buildClientParams(args, config)).toEqual(params);
});
});
1 change: 1 addition & 0 deletions packages/client-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export {
jsonBodySerializer,
urlSearchParamsBodySerializer,
} from './bodySerializer';
export { buildClientParams } from './params';
export type {
ArraySeparatorStyle,
ArrayStyle,
Expand Down
Loading
Loading