Skip to content

Commit 950a450

Browse files
fix: headers field name and type for OpenAPI schema (#101)
* fix: fix headers field name and type for openapi schema Fixes #98 * refactor: prefer `Record` type --------- Co-authored-by: Johann Schopplich <mail@johannschopplich.com>
1 parent 6e8ddad commit 950a450

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

playground/pages/petStore.vue

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ const status = ref<typeof availableStatus[number] | undefined>()
1515
const { data: user, execute } = await usePetStoreData('/user/{username}', {
1616
path: { username: 'user1' },
1717
cache: true,
18+
headers: {
19+
'api_key': 'special',
20+
'x-test-header': 'test',
21+
},
1822
})
1923
2024
const { data, error } = await usePetStoreData('/pet/findByStatus', {
@@ -91,6 +95,22 @@ async function abandonGarfield() {
9195
console.error('Response body:', (error as NuxtError).data)
9296
}
9397
}
98+
99+
async function removePet(petId: number) {
100+
try {
101+
await $petStore('/pet/{petId}', {
102+
method: 'DELETE',
103+
path: { petId },
104+
headers: {
105+
'api_key': 'special-key',
106+
'x-test-header': 'test',
107+
},
108+
})
109+
}
110+
catch (error) {
111+
console.error(error)
112+
}
113+
}
94114
</script>
95115

96116
<template>

src/runtime/openapi.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ export type FetchResponseError<T extends Record<PropertyKey, any>> = NuxtError<E
1616
export type MethodOption<M, P> = 'get' extends keyof P ? { method?: M } : { method: M }
1717

1818
export type ParamsOption<T> = T extends { parameters?: any, query?: any }
19-
? T['parameters']
19+
? Omit<T['parameters'], 'cookie' | 'header'> & {
20+
headers?: T['parameters']['header'] | Record<string, unknown>
21+
}
2022
: Record<string, unknown>
2123

2224
export type RequestBodyOption<T> = OperationRequestBodyContent<T> extends never

0 commit comments

Comments
 (0)