@@ -20,6 +20,19 @@ import { FetchError } from 'ofetch'
2020
2121// export const useApiFetch = useApiData
2222
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+ }
35+
2336export function useApiFetch < P extends AllPaths < Paths > , M extends IgnoreCase < keyof Paths [ `/${P } `] & HttpMethod > > (
2437 path : MaybeRefOrGetter < P > ,
2538 opts ?: Omit < UseOpenApiDataOptions < Paths [ `/${P } `] , M > , 'method' > & {
@@ -35,15 +48,18 @@ export function useApiFetch<P extends AllPaths<Paths>, M extends IgnoreCase<keyo
3548 body ?: Paths [ `/${P } `] [ Lowercase < M > ] [ 'requestBody' ] [ 'content' ] [ 'application/json' ] ,
3649) : /* @ts -ignore */
3750 AsyncData < OpenApiResponse < Paths [ `/${P } `] [ Lowercase < M > ] > | undefined , FetchError < OpenApiError < Paths [ `/${P } `] [ Lowercase < M > ] > > > {
51+ const query = parseQuery ( ( opts as any ) ?. query || { } )
3852 if ( ! body ) {
3953 return useApiData ( path , {
4054 ...opts ,
55+ query,
4156 cache : false ,
4257 client : true ,
4358 } as any )
4459 }
4560 return useApiData ( path , {
4661 ...opts ,
62+ query,
4763 cache : false ,
4864 client : true ,
4965 body : {
0 commit comments