Skip to content

Commit

Permalink
breakpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ddecrulle committed May 29, 2024
1 parent 58378d1 commit 557ed86
Show file tree
Hide file tree
Showing 14 changed files with 345 additions and 148 deletions.
74 changes: 60 additions & 14 deletions openApi.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"openapi": "3.0.0",
"info": { "version": "1.0.8", "title": "My API" },
"info": { "version": "2.0.1", "title": "My API" },
"components": {
"schemas": {
"Todo": {
Expand All @@ -24,21 +24,26 @@
"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" } }
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"text": {
"type": "string",
"minLength": 1,
"example": "Clean my room"
},
"isDone": { "type": "boolean", "example": false }
}
}
}
}
},
"responses": { "200": { "description": "Update an existing todo item" } }
},
"delete": {
"parameters": [
Expand All @@ -52,6 +57,47 @@
"responses": { "200": { "description": "Deleted a todo item" } }
}
},
"/todo": {
"put": {
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"text": {
"type": "string",
"minLength": 1,
"example": "Clean my room"
}
},
"required": ["text"]
}
}
}
},
"responses": {
"200": {
"description": "Create a new todo item returns the newly created todo item's id",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "The id of the newly created todo item",
"example": "123"
}
},
"required": ["id"]
}
}
}
}
}
}
},
"/todos": {
"get": {
"responses": {
Expand Down
84 changes: 72 additions & 12 deletions src/api/endpoints/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Generated by orval v6.29.1 🍺
* Do not edit manually.
* My API
* OpenAPI spec version: 1.0.6
* OpenAPI spec version: 2.0.1
*/
import { useMutation, useQuery } from "@tanstack/react-query";
import type {
Expand All @@ -14,63 +14,71 @@ import type {
UseQueryOptions,
UseQueryResult
} from "@tanstack/react-query";
import type { PutTodoIdParams, Todo } from "../model";
import type { PutTodo200, PutTodoBody, PutTodoIdBody, Todo } from "../model";
import { customInstance } from "../mutator/customInstance";

type SecondParameter<T extends (...args: any) => any> = Parameters<T>[1];

export const putTodoId = (
id: string,
params: PutTodoIdParams,
putTodoIdBody: PutTodoIdBody,
options?: SecondParameter<typeof customInstance>
) => {
return customInstance<void>({ url: `/todo/${id}`, method: "PUT", params }, options);
return customInstance<void>(
{
url: `/todo/${id}`,
method: "PUT",
headers: { "Content-Type": "application/json" },
data: putTodoIdBody
},
options
);
};

export const getPutTodoIdMutationOptions = <TError = unknown, TContext = unknown>(options?: {
mutation?: UseMutationOptions<
Awaited<ReturnType<typeof putTodoId>>,
TError,
{ id: string; params: PutTodoIdParams },
{ id: string; data: PutTodoIdBody },
TContext
>;
request?: SecondParameter<typeof customInstance>;
}): UseMutationOptions<
Awaited<ReturnType<typeof putTodoId>>,
TError,
{ id: string; params: PutTodoIdParams },
{ id: string; data: PutTodoIdBody },
TContext
> => {
const { mutation: mutationOptions, request: requestOptions } = options ?? {};

const mutationFn: MutationFunction<
Awaited<ReturnType<typeof putTodoId>>,
{ id: string; params: PutTodoIdParams }
{ id: string; data: PutTodoIdBody }
> = props => {
const { id, params } = props ?? {};
const { id, data } = props ?? {};

return putTodoId(id, params, requestOptions);
return putTodoId(id, data, requestOptions);
};

return { mutationFn, ...mutationOptions };
};

export type PutTodoIdMutationResult = NonNullable<Awaited<ReturnType<typeof putTodoId>>>;

export type PutTodoIdMutationBody = PutTodoIdBody;
export type PutTodoIdMutationError = unknown;

export const usePutTodoId = <TError = unknown, TContext = unknown>(options?: {
mutation?: UseMutationOptions<
Awaited<ReturnType<typeof putTodoId>>,
TError,
{ id: string; params: PutTodoIdParams },
{ id: string; data: PutTodoIdBody },
TContext
>;
request?: SecondParameter<typeof customInstance>;
}): UseMutationResult<
Awaited<ReturnType<typeof putTodoId>>,
TError,
{ id: string; params: PutTodoIdParams },
{ id: string; data: PutTodoIdBody },
TContext
> => {
const mutationOptions = getPutTodoIdMutationOptions(options);
Expand Down Expand Up @@ -121,6 +129,58 @@ export const useDeleteTodoId = <TError = unknown, TContext = unknown>(options?:

return useMutation(mutationOptions);
};
export const putTodo = (putTodoBody: PutTodoBody, options?: SecondParameter<typeof customInstance>) => {
return customInstance<PutTodo200>(
{
url: `/todo`,
method: "PUT",
headers: { "Content-Type": "application/json" },
data: putTodoBody
},
options
);
};

export const getPutTodoMutationOptions = <TError = unknown, TContext = unknown>(options?: {
mutation?: UseMutationOptions<
Awaited<ReturnType<typeof putTodo>>,
TError,
{ data: PutTodoBody },
TContext
>;
request?: SecondParameter<typeof customInstance>;
}): UseMutationOptions<Awaited<ReturnType<typeof putTodo>>, TError, { data: PutTodoBody }, TContext> => {
const { mutation: mutationOptions, request: requestOptions } = options ?? {};

const mutationFn: MutationFunction<
Awaited<ReturnType<typeof putTodo>>,
{ data: PutTodoBody }
> = props => {
const { data } = props ?? {};

return putTodo(data, requestOptions);
};

return { mutationFn, ...mutationOptions };
};

export type PutTodoMutationResult = NonNullable<Awaited<ReturnType<typeof putTodo>>>;
export type PutTodoMutationBody = PutTodoBody;
export type PutTodoMutationError = unknown;

export const usePutTodo = <TError = unknown, TContext = unknown>(options?: {
mutation?: UseMutationOptions<
Awaited<ReturnType<typeof putTodo>>,
TError,
{ data: PutTodoBody },
TContext
>;
request?: SecondParameter<typeof customInstance>;
}): UseMutationResult<Awaited<ReturnType<typeof putTodo>>, TError, { data: PutTodoBody }, TContext> => {
const mutationOptions = getPutTodoMutationOptions(options);

return useMutation(mutationOptions);
};
export const getTodos = (options?: SecondParameter<typeof customInstance>, signal?: AbortSignal) => {
return customInstance<Todo[]>({ url: `/todos`, method: "GET", signal }, options);
};
Expand Down
5 changes: 4 additions & 1 deletion src/api/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
* Generated by orval v6.29.1 🍺
* Do not edit manually.
* My API
* OpenAPI spec version: 1.0.6
* OpenAPI spec version: 2.0.1
*/

export * from "./putTodo200";
export * from "./putTodoIdParams";
export * from "./todo";
export * from "./putTodoBody";
export * from "./putTodoIdBody";
11 changes: 11 additions & 0 deletions src/api/model/putTodo200.ts
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: 2.0.1
*/

export type PutTodo200 = {
/** The id of the newly created todo item */
id: string;
};
11 changes: 11 additions & 0 deletions src/api/model/putTodoBody.ts
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: 2.0.1
*/

export type PutTodoBody = {
/** @minLength 1 */
text: string;
};
12 changes: 12 additions & 0 deletions src/api/model/putTodoIdBody.ts
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: 2.0.1
*/

export type PutTodoIdBody = {
isDone?: boolean;
/** @minLength 1 */
text?: string;
};
2 changes: 1 addition & 1 deletion src/api/model/putTodoIdParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Generated by orval v6.29.1 🍺
* Do not edit manually.
* My API
* OpenAPI spec version: 1.0.6
* OpenAPI spec version: 1.0.8
*/

export type PutTodoIdParams = {
Expand Down
2 changes: 1 addition & 1 deletion src/api/model/todo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Generated by orval v6.29.1 🍺
* Do not edit manually.
* My API
* OpenAPI spec version: 1.0.6
* OpenAPI spec version: 2.0.1
*/

export interface Todo {
Expand Down
20 changes: 15 additions & 5 deletions src/oidc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@ import { createReactOidc } from "oidc-spa/react";
import { createMockReactOidc } from "oidc-spa/mock/react";
import { z } from "zod";

const decodedIdTokenSchema = z.object({
sub: z.string(),
preferred_username: z.string()
});

export const { OidcProvider, useOidc, prOidc } = import.meta.env.VITE_OIDC_ISSUER
? createReactOidc({
issuerUri: import.meta.env.VITE_OIDC_ISSUER,
clientId: import.meta.env.VITE_OIDC_CLIENT_ID,
publicUrl: import.meta.env.BASE_URL,
decodedIdTokenSchema: z.object({
sub: z.string(),
preferred_username: z.string()
})
decodedIdTokenSchema: decodedIdTokenSchema
})
: createMockReactOidc({ isUserInitiallyLoggedIn: false });
: createMockReactOidc({
isUserInitiallyLoggedIn: false,
mockedTokens: {
decodedIdToken: {
sub: "123",
preferred_username: "john doe"
} satisfies z.infer<typeof decodedIdTokenSchema>
}
});

export const protectedLoader = async () => {
const oidc = await prOidc;
Expand Down
Loading

0 comments on commit 557ed86

Please sign in to comment.