add openapi registers

This commit is contained in:
miloschwartz
2025-04-06 22:44:14 -04:00
parent a76e3e00f7
commit d260450a84
50 changed files with 852 additions and 60 deletions

View File

@@ -9,6 +9,7 @@ import logger from "@server/logger";
import { fromError } from "zod-validation-error";
import { ActionsEnum } from "@server/auth/actions";
import { eq, and } from "drizzle-orm";
import { OpenAPITags, registry } from "@server/openApi";
const createRoleParamsSchema = z
.object({
@@ -33,6 +34,24 @@ export type CreateRoleBody = z.infer<typeof createRoleSchema>;
export type CreateRoleResponse = Role;
registry.registerPath({
method: "put",
path: "/org/{orgId}/role",
description: "Create a role.",
tags: [OpenAPITags.Org, OpenAPITags.Role],
request: {
params: createRoleParamsSchema,
body: {
content: {
"application/json": {
schema: createRoleSchema
}
}
}
},
responses: {}
});
export async function createRole(
req: Request,
res: Response,

View File

@@ -8,6 +8,7 @@ import HttpCode from "@server/types/HttpCode";
import createHttpError from "http-errors";
import logger from "@server/logger";
import { fromError } from "zod-validation-error";
import { OpenAPITags, registry } from "@server/openApi";
const deleteRoleSchema = z
.object({
@@ -21,6 +22,24 @@ const deelteRoleBodySchema = z
})
.strict();
registry.registerPath({
method: "delete",
path: "/role/{roleId}",
description: "Delete a role.",
tags: [OpenAPITags.Role],
request: {
params: deleteRoleSchema,
body: {
content: {
"application/json": {
schema: deelteRoleBodySchema
}
}
}
},
responses: {}
});
export async function deleteRole(
req: Request,
res: Response,

View File

@@ -9,6 +9,7 @@ import { sql, eq } from "drizzle-orm";
import logger from "@server/logger";
import { fromError } from "zod-validation-error";
import stoi from "@server/lib/stoi";
import { OpenAPITags, registry } from "@server/openApi";
const listRolesParamsSchema = z
.object({
@@ -57,6 +58,18 @@ export type ListRolesResponse = {
};
};
registry.registerPath({
method: "get",
path: "/orgs/{orgId}/roles",
description: "List roles.",
tags: [OpenAPITags.Org, OpenAPITags.Role],
request: {
params: listRolesParamsSchema,
query: listRolesSchema
},
responses: {}
});
export async function listRoles(
req: Request,
res: Response,