Skip to content

Commit fef1f75

Browse files
authored
Merge pull request #1649 from hey-api/fix/client-nuxt-body
fix: handle reactive refs in Nuxt client body
2 parents b767e10 + 603541e commit fef1f75

File tree

20 files changed

+1576
-2326
lines changed

20 files changed

+1576
-2326
lines changed

.changeset/light-fans-vanish.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/client-nuxt': patch
3+
---
4+
5+
fix: do not run validator and transformer when response is not ok

.changeset/metal-flowers-fix.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@hey-api/client-axios': patch
3+
'@hey-api/client-fetch': patch
4+
'@hey-api/client-nuxt': patch
5+
---
6+
7+
fix: handle BigInt in JSON body serializer

.changeset/tough-islands-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/client-nuxt': patch
3+
---
4+
5+
fix: handle reactive refs in Nuxt client body

examples/openapi-ts-axios/src/client/sdk.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import type {
4242
UploadFileResponse,
4343
} from './types.gen';
4444

45-
type Options<
45+
export type Options<
4646
TData extends TDataShape = TDataShape,
4747
ThrowOnError extends boolean = boolean,
4848
> = ClientOptions<TData, ThrowOnError> & {

examples/openapi-ts-fastify/src/client/sdk.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type {
1818
ShowPetByIdResponse,
1919
} from './types.gen';
2020

21-
type Options<
21+
export type Options<
2222
TData extends TDataShape = TDataShape,
2323
ThrowOnError extends boolean = boolean,
2424
> = ClientOptions<TData, ThrowOnError> & {

examples/openapi-ts-fetch/src/client/sdk.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import type {
4242
UploadFileResponse,
4343
} from './types.gen';
4444

45-
type Options<
45+
export type Options<
4646
TData extends TDataShape = TDataShape,
4747
ThrowOnError extends boolean = boolean,
4848
> = ClientOptions<TData, ThrowOnError> & {

examples/openapi-ts-next/src/client/sdk.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import type {
4242
UploadFileResponse,
4343
} from './types.gen';
4444

45-
type Options<
45+
export type Options<
4646
TData extends TDataShape = TDataShape,
4747
ThrowOnError extends boolean = boolean,
4848
> = ClientOptions<TData, ThrowOnError> & {

examples/openapi-ts-nuxt/client/sdk.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import {
6969
zUploadFileResponse,
7070
} from './zod.gen';
7171

72-
type Options<
72+
export type Options<
7373
TComposable extends Composable,
7474
TData extends TDataShape = TDataShape,
7575
> = ClientOptions<TComposable, TData> & {

examples/openapi-ts-nuxt/components/home.vue

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<script setup lang="ts">
22
import {
3+
addPet,
34
findPetsByStatus,
45
getPetById,
56
type FindPetsByStatusData,
67
} from '~/client';
78
9+
const name = ref('foo');
810
const petId = ref(BigInt(8));
911
const status =
1012
ref<NonNullable<FindPetsByStatusData['query']>['status']>('available');
@@ -13,6 +15,10 @@ function incrementPetId() {
1315
petId.value++;
1416
}
1517
18+
function addNewPet() {
19+
name.value = name.value === 'foo' ? 'bar' : 'foo';
20+
}
21+
1622
function changeStatus() {
1723
status.value = status.value === 'available' ? 'pending' : 'available';
1824
}
@@ -79,6 +85,30 @@ const fetch = await getPetById({
7985
},
8086
});
8187
88+
await addPet({
89+
asyncDataOptions: {
90+
watch: [name],
91+
},
92+
body: {
93+
category: {
94+
id: BigInt(0),
95+
name: 'Cats',
96+
},
97+
id: BigInt(0),
98+
name,
99+
photoUrls: ['string'],
100+
status: 'available',
101+
tags: [
102+
{
103+
id: BigInt(0),
104+
name: 'pet',
105+
},
106+
],
107+
},
108+
composable: 'useAsyncData',
109+
key: 'addPet',
110+
});
111+
82112
/**
83113
* useLazyAsyncData
84114
*
@@ -121,23 +151,27 @@ watch(lazyFetch.data, (newPet) => {
121151
});
122152
123153
async function handleFetch() {
124-
const result = await getPetById({
125-
composable: '$fetch',
126-
onRequest: [
127-
() => {
128-
console.log('onRequest: local');
129-
},
130-
],
131-
onResponse: [
132-
() => {
133-
console.log('onResponse: local');
154+
try {
155+
const result = await getPetById({
156+
composable: '$fetch',
157+
onRequest: [
158+
() => {
159+
console.log('onRequest: local');
160+
},
161+
],
162+
onResponse: [
163+
() => {
164+
console.log('onResponse: local');
165+
},
166+
],
167+
path: {
168+
petId,
134169
},
135-
],
136-
path: {
137-
petId,
138-
},
139-
});
140-
console.log(result);
170+
});
171+
console.log(result);
172+
} catch (error) {
173+
console.log(error);
174+
}
141175
}
142176
</script>
143177

@@ -147,5 +181,11 @@ async function handleFetch() {
147181
<button @click="handleFetch" type="button">$fetch</button>
148182
<button @click="incrementPetId" type="button">increment petId</button>
149183
<button @click="changeStatus" type="button">change status</button>
184+
<button @click="addNewPet" type="button">add pet</button>
185+
<div>
186+
<p>id: {{ petId }}</p>
187+
<p>name: {{ name }}</p>
188+
<p>status: {{ status }}</p>
189+
</div>
150190
</div>
151191
</template>

examples/openapi-ts-nuxt/nuxt.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@ export default defineNuxtConfig({
44
devtools: {
55
enabled: true,
66
},
7+
imports: {
8+
transform: {
9+
// Build was throwing an error.
10+
// see https://github.com/nuxt/nuxt/issues/18823#issuecomment-1419704343
11+
exclude: [/\bclient-nuxt\b/],
12+
},
13+
},
714
});

0 commit comments

Comments
 (0)