-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
2,107 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{ | ||
"openapi": "3.0.0", | ||
"info": { "version": "1.0.6", "title": "My API" }, | ||
"components": { | ||
"schemas": { | ||
"Todo": { | ||
"type": "object", | ||
"properties": { | ||
"id": { "type": "string", "example": "123" }, | ||
"text": { "type": "string", "example": "Clean my room" }, | ||
"isDone": { "type": "boolean", "example": false } | ||
}, | ||
"required": ["id", "text", "isDone"] | ||
} | ||
}, | ||
"parameters": {} | ||
}, | ||
"paths": { | ||
"/todo/{id}": { | ||
"put": { | ||
"parameters": [ | ||
{ | ||
"schema": { "type": "string", "minLength": 1, "example": "1212121" }, | ||
"required": true, | ||
"name": "id", | ||
"in": "path" | ||
}, | ||
{ | ||
"schema": { "type": "string", "minLength": 1, "example": "Clean my room" }, | ||
"required": true, | ||
"name": "text", | ||
"in": "query" | ||
}, | ||
{ | ||
"schema": { "type": "boolean", "example": false }, | ||
"required": true, | ||
"name": "isDone", | ||
"in": "query" | ||
} | ||
], | ||
"responses": { "200": { "description": "Create or update a todo item" } } | ||
}, | ||
"delete": { | ||
"parameters": [ | ||
{ | ||
"schema": { "type": "string", "minLength": 1, "example": "1212121" }, | ||
"required": true, | ||
"name": "id", | ||
"in": "path" | ||
} | ||
], | ||
"responses": { "200": { "description": "Deleted a todo item" } } | ||
} | ||
}, | ||
"/todos": { | ||
"get": { | ||
"responses": { | ||
"200": { | ||
"description": "Get all user's todo", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"type": "array", | ||
"items": { "$ref": "#/components/schemas/Todo" } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { defineConfig } from "orval"; | ||
|
||
export default defineConfig({ | ||
openapi: { | ||
input: "./openApi.json", | ||
output: { | ||
mode: "tags", | ||
target: "src/api/", | ||
schemas: "src/model/api", | ||
client: "react-query", | ||
override: { | ||
mutator: { | ||
path: "./src/api/axiosInstance.ts", | ||
name: "axiosInstance" | ||
} | ||
} | ||
}, | ||
hooks: { | ||
afterAllFilesWrite: "yarn format" | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
/** | ||
* Generated by orval v6.29.1 🍺 | ||
* Do not edit manually. | ||
* My API | ||
* OpenAPI spec version: 1.0.6 | ||
*/ | ||
import { useMutation, useQuery } from "@tanstack/react-query"; | ||
import type { | ||
MutationFunction, | ||
QueryFunction, | ||
QueryKey, | ||
UseMutationOptions, | ||
UseMutationResult, | ||
UseQueryOptions, | ||
UseQueryResult | ||
} from "@tanstack/react-query"; | ||
import type { PutTodoIdParams, Todo } from "../model/api"; | ||
import { axiosInstance } from "./axiosInstance"; | ||
|
||
type SecondParameter<T extends (...args: any) => any> = Parameters<T>[1]; | ||
|
||
export const putTodoId = ( | ||
id: string, | ||
params: PutTodoIdParams, | ||
options?: SecondParameter<typeof axiosInstance> | ||
) => { | ||
return axiosInstance<void>({ url: `/todo/${id}`, method: "PUT", params }, options); | ||
}; | ||
|
||
export const getPutTodoIdMutationOptions = <TError = unknown, TContext = unknown>(options?: { | ||
mutation?: UseMutationOptions< | ||
Awaited<ReturnType<typeof putTodoId>>, | ||
TError, | ||
{ id: string; params: PutTodoIdParams }, | ||
TContext | ||
>; | ||
request?: SecondParameter<typeof axiosInstance>; | ||
}): UseMutationOptions< | ||
Awaited<ReturnType<typeof putTodoId>>, | ||
TError, | ||
{ id: string; params: PutTodoIdParams }, | ||
TContext | ||
> => { | ||
const { mutation: mutationOptions, request: requestOptions } = options ?? {}; | ||
|
||
const mutationFn: MutationFunction< | ||
Awaited<ReturnType<typeof putTodoId>>, | ||
{ id: string; params: PutTodoIdParams } | ||
> = props => { | ||
const { id, params } = props ?? {}; | ||
|
||
return putTodoId(id, params, requestOptions); | ||
}; | ||
|
||
return { mutationFn, ...mutationOptions }; | ||
}; | ||
|
||
export type PutTodoIdMutationResult = NonNullable<Awaited<ReturnType<typeof putTodoId>>>; | ||
|
||
export type PutTodoIdMutationError = unknown; | ||
|
||
export const usePutTodoId = <TError = unknown, TContext = unknown>(options?: { | ||
mutation?: UseMutationOptions< | ||
Awaited<ReturnType<typeof putTodoId>>, | ||
TError, | ||
{ id: string; params: PutTodoIdParams }, | ||
TContext | ||
>; | ||
request?: SecondParameter<typeof axiosInstance>; | ||
}): UseMutationResult< | ||
Awaited<ReturnType<typeof putTodoId>>, | ||
TError, | ||
{ id: string; params: PutTodoIdParams }, | ||
TContext | ||
> => { | ||
const mutationOptions = getPutTodoIdMutationOptions(options); | ||
|
||
return useMutation(mutationOptions); | ||
}; | ||
export const deleteTodoId = (id: string, options?: SecondParameter<typeof axiosInstance>) => { | ||
return axiosInstance<void>({ url: `/todo/${id}`, method: "DELETE" }, options); | ||
}; | ||
|
||
export const getDeleteTodoIdMutationOptions = <TError = unknown, TContext = unknown>(options?: { | ||
mutation?: UseMutationOptions< | ||
Awaited<ReturnType<typeof deleteTodoId>>, | ||
TError, | ||
{ id: string }, | ||
TContext | ||
>; | ||
request?: SecondParameter<typeof axiosInstance>; | ||
}): UseMutationOptions<Awaited<ReturnType<typeof deleteTodoId>>, TError, { id: string }, TContext> => { | ||
const { mutation: mutationOptions, request: requestOptions } = options ?? {}; | ||
|
||
const mutationFn: MutationFunction< | ||
Awaited<ReturnType<typeof deleteTodoId>>, | ||
{ id: string } | ||
> = props => { | ||
const { id } = props ?? {}; | ||
|
||
return deleteTodoId(id, requestOptions); | ||
}; | ||
|
||
return { mutationFn, ...mutationOptions }; | ||
}; | ||
|
||
export type DeleteTodoIdMutationResult = NonNullable<Awaited<ReturnType<typeof deleteTodoId>>>; | ||
|
||
export type DeleteTodoIdMutationError = unknown; | ||
|
||
export const useDeleteTodoId = <TError = unknown, TContext = unknown>(options?: { | ||
mutation?: UseMutationOptions< | ||
Awaited<ReturnType<typeof deleteTodoId>>, | ||
TError, | ||
{ id: string }, | ||
TContext | ||
>; | ||
request?: SecondParameter<typeof axiosInstance>; | ||
}): UseMutationResult<Awaited<ReturnType<typeof deleteTodoId>>, TError, { id: string }, TContext> => { | ||
const mutationOptions = getDeleteTodoIdMutationOptions(options); | ||
|
||
return useMutation(mutationOptions); | ||
}; | ||
export const getTodos = (options?: SecondParameter<typeof axiosInstance>, signal?: AbortSignal) => { | ||
return axiosInstance<Todo[]>({ url: `/todos`, method: "GET", signal }, options); | ||
}; | ||
|
||
export const getGetTodosQueryKey = () => { | ||
return [`/todos`] as const; | ||
}; | ||
|
||
export const getGetTodosQueryOptions = < | ||
TData = Awaited<ReturnType<typeof getTodos>>, | ||
TError = unknown | ||
>(options?: { | ||
query?: Partial<UseQueryOptions<Awaited<ReturnType<typeof getTodos>>, TError, TData>>; | ||
request?: SecondParameter<typeof axiosInstance>; | ||
}) => { | ||
const { query: queryOptions, request: requestOptions } = options ?? {}; | ||
|
||
const queryKey = queryOptions?.queryKey ?? getGetTodosQueryKey(); | ||
|
||
const queryFn: QueryFunction<Awaited<ReturnType<typeof getTodos>>> = ({ signal }) => | ||
getTodos(requestOptions, signal); | ||
|
||
return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< | ||
Awaited<ReturnType<typeof getTodos>>, | ||
TError, | ||
TData | ||
> & { queryKey: QueryKey }; | ||
}; | ||
|
||
export type GetTodosQueryResult = NonNullable<Awaited<ReturnType<typeof getTodos>>>; | ||
export type GetTodosQueryError = unknown; | ||
|
||
export const useGetTodos = <TData = Awaited<ReturnType<typeof getTodos>>, TError = unknown>(options?: { | ||
query?: Partial<UseQueryOptions<Awaited<ReturnType<typeof getTodos>>, TError, TData>>; | ||
request?: SecondParameter<typeof axiosInstance>; | ||
}): UseQueryResult<TData, TError> & { queryKey: QueryKey } => { | ||
const queryOptions = getGetTodosQueryOptions(options); | ||
|
||
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey }; | ||
|
||
query.queryKey = queryOptions.queryKey; | ||
|
||
return query; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Generated by orval v6.29.1 🍺 | ||
* Do not edit manually. | ||
* My API | ||
* OpenAPI spec version: 1.0.6 | ||
*/ | ||
|
||
export * from "./putTodoIdParams"; | ||
export * from "./todo"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Generated by orval v6.29.1 🍺 | ||
* Do not edit manually. | ||
* My API | ||
* OpenAPI spec version: 1.0.6 | ||
*/ | ||
|
||
export type PutTodoIdParams = { | ||
text: string; | ||
isDone: boolean; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Generated by orval v6.29.1 🍺 | ||
* Do not edit manually. | ||
* My API | ||
* OpenAPI spec version: 1.0.6 | ||
*/ | ||
|
||
export interface Todo { | ||
id: string; | ||
isDone: boolean; | ||
text: string; | ||
} |
Oops, something went wrong.