mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
Trying authorization in openapi
This commit is contained in:
parent
e48c9b3e09
commit
521b5bc7f4
4 changed files with 25 additions and 1 deletions
15
src/lib/server/api/common/openapi/create-cookie-schema.ts
Normal file
15
src/lib/server/api/common/openapi/create-cookie-schema.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { authCookieSchema } from '$lib/server/api/common/openapi/schemas';
|
||||
import { z } from '@hono/zod-openapi';
|
||||
|
||||
export type ZodSchema = z.ZodUnion<never> | z.AnyZodObject | z.ZodArray<z.AnyZodObject>;
|
||||
type ZodString = z.ZodString;
|
||||
|
||||
export function createAuthCookieSchema() {
|
||||
return createCookieSchema(authCookieSchema);
|
||||
}
|
||||
|
||||
export function createCookieSchema<T extends ZodSchema>(schema: ZodString) {
|
||||
return z.object({
|
||||
cookie: schema,
|
||||
});
|
||||
}
|
||||
3
src/lib/server/api/common/openapi/schemas.ts
Normal file
3
src/lib/server/api/common/openapi/schemas.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import { z } from '@hono/zod-openapi';
|
||||
|
||||
export const authCookieSchema = z.string().regex(/^session=\w+$/);
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
import { StatusCodes } from '$lib/constants/status-codes';
|
||||
import { unauthorizedSchema } from '$lib/server/api/common/exceptions';
|
||||
import { createAuthCookieSchema } from '$lib/server/api/common/openapi/create-cookie-schema';
|
||||
import { selectUserSchema } from '$lib/server/api/databases/tables/users.table';
|
||||
import { updateProfileDto } from '$lib/server/api/dtos/update-profile.dto';
|
||||
import { z } from '@hono/zod-openapi';
|
||||
import { defineOpenApiOperation } from 'hono-zod-openapi';
|
||||
import { createErrorSchema } from 'stoker/openapi/schemas';
|
||||
|
||||
|
|
@ -27,6 +29,10 @@ export const updateProfile = defineOpenApiOperation({
|
|||
tags,
|
||||
request: {
|
||||
json: updateProfileDto,
|
||||
cookies: createAuthCookieSchema(),
|
||||
headers: z.object({
|
||||
authorization: z.string(),
|
||||
}),
|
||||
},
|
||||
responses: {
|
||||
[StatusCodes.OK]: {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ const routes = app
|
|||
.route('/mfa', container.resolve(MfaController).routes())
|
||||
.get('/', (c) => c.json({ message: 'Server is healthy' }));
|
||||
|
||||
// @ts-ignore - this is a workaround for https://github.com/paolostyle/hono-zod-openapi/issues/2
|
||||
// @ts-expect-error - this is a workaround for https://github.com/paolostyle/hono-zod-openapi/issues/2
|
||||
configureOpenAPI(app);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
|
|
|||
Loading…
Reference in a new issue