@@ -20,7 +20,18 @@ import { FetchError } from 'ofetch'
2020
2121// export const useApiFetch = useApiData
2222
23- export type schemas = Components [ 'schemas' ]
23+ function parseQuery ( query : Record < string , any > , prefix : string = '' ) {
24+ let parsedQuery : any = { }
25+ for ( const q in query ) {
26+ const key = prefix ? `${ prefix } [${ q } ]` : q
27+ if ( typeof query [ q ] === 'object' ) {
28+ parsedQuery = { ...parsedQuery , ...parseQuery ( query [ q ] , key ) }
29+ } else {
30+ parsedQuery [ key ] = query [ q ]
31+ }
32+ }
33+ return parsedQuery
34+ }
2435
2536export function useApiFetch < P extends AllPaths < Paths > , M extends IgnoreCase < keyof Paths [ `/${P } `] & HttpMethod > > (
2637 path : MaybeRefOrGetter < P > ,
@@ -36,16 +47,19 @@ export function useApiFetch<P extends AllPaths<Paths>, M extends IgnoreCase<keyo
3647 /* @ts -ignore */
3748 body ?: Paths [ `/${P } `] [ Lowercase < M > ] [ 'requestBody' ] [ 'content' ] [ 'application/json' ] ,
3849) : /* @ts -ignore */
39- AsyncData < OpenApiResponse < Paths [ `/${P } `] [ Lowercase < M > ] > | undefined , FetchError < OpenApiError < Paths [ `/${P } `] [ Lowercase < M > ] > > > {
50+ AsyncData < OpenApiResponse < Paths [ `/${P } `] [ Lowercase < M > ] > | undefined , FetchError < OpenApiError < Paths [ `/${P } `] [ Lowercase < M > ] > > > {
51+ const query = parseQuery ( ( opts as any ) ?. query || { } )
4052 if ( ! body ) {
4153 return useApiData ( path , {
4254 ...opts ,
55+ query,
4356 cache : false ,
4457 client : true ,
4558 } as any )
4659 }
4760 return useApiData ( path , {
4861 ...opts ,
62+ query,
4963 cache : false ,
5064 client : true ,
5165 body : {
0 commit comments