feat(api-docs): add error responses to API documentation

This commit is contained in:
Daniel Hougaard
2024-09-27 20:02:43 +04:00
parent 2d51ed317f
commit 7ac4b0b79f
39 changed files with 297 additions and 14 deletions
@@ -7,7 +7,7 @@ import { daysToMillisecond } from "@app/lib/dates";
import { removeTrailingSlash } from "@app/lib/fn";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { SanitizedDynamicSecretSchema } from "@app/server/routes/sanitizedSchemas";
import { DefaultResponseErrorsSchema, SanitizedDynamicSecretSchema } from "@app/server/routes/sanitizedSchemas";
import { AuthMode } from "@app/services/auth/auth-type";
export const registerDynamicSecretLeaseRouter = async (server: FastifyZodProvider) => {
@@ -37,6 +37,7 @@ export const registerDynamicSecretLeaseRouter = async (server: FastifyZodProvide
environmentSlug: z.string().min(1).describe(DYNAMIC_SECRET_LEASES.CREATE.path)
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
lease: DynamicSecretLeasesSchema,
dynamicSecret: SanitizedDynamicSecretSchema,
@@ -81,6 +82,7 @@ export const registerDynamicSecretLeaseRouter = async (server: FastifyZodProvide
isForced: z.boolean().default(false).describe(DYNAMIC_SECRET_LEASES.DELETE.isForced)
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
lease: DynamicSecretLeasesSchema
})
@@ -134,6 +136,7 @@ export const registerDynamicSecretLeaseRouter = async (server: FastifyZodProvide
environmentSlug: z.string().min(1).describe(DYNAMIC_SECRET_LEASES.RENEW.environmentSlug)
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
lease: DynamicSecretLeasesSchema
})
@@ -174,6 +177,7 @@ export const registerDynamicSecretLeaseRouter = async (server: FastifyZodProvide
environmentSlug: z.string().min(1).describe(DYNAMIC_SECRET_LEASES.GET_BY_LEASEID.environmentSlug)
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
lease: DynamicSecretLeasesSchema.extend({
dynamicSecret: SanitizedDynamicSecretSchema
@@ -9,7 +9,7 @@ import { daysToMillisecond } from "@app/lib/dates";
import { removeTrailingSlash } from "@app/lib/fn";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { SanitizedDynamicSecretSchema } from "@app/server/routes/sanitizedSchemas";
import { DefaultResponseErrorsSchema, SanitizedDynamicSecretSchema } from "@app/server/routes/sanitizedSchemas";
import { AuthMode } from "@app/services/auth/auth-type";
export const registerDynamicSecretRouter = async (server: FastifyZodProvider) => {
@@ -59,6 +59,7 @@ export const registerDynamicSecretRouter = async (server: FastifyZodProvider) =>
})
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
dynamicSecret: SanitizedDynamicSecretSchema
})
@@ -90,6 +91,7 @@ export const registerDynamicSecretRouter = async (server: FastifyZodProvider) =>
clientSecret: z.string().min(1).describe("The client secret of the Azure Entra ID App Registration")
}),
response: {
...DefaultResponseErrorsSchema,
200: z
.object({
name: z.string().min(1).describe("The name of the user"),
@@ -155,6 +157,7 @@ export const registerDynamicSecretRouter = async (server: FastifyZodProvider) =>
})
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
dynamicSecret: SanitizedDynamicSecretSchema
})
@@ -194,6 +197,7 @@ export const registerDynamicSecretRouter = async (server: FastifyZodProvider) =>
isForced: z.boolean().default(false).describe(DYNAMIC_SECRETS.DELETE.isForced)
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
dynamicSecret: SanitizedDynamicSecretSchema
})
@@ -229,6 +233,7 @@ export const registerDynamicSecretRouter = async (server: FastifyZodProvider) =>
environmentSlug: z.string().min(1).describe(DYNAMIC_SECRETS.GET_BY_NAME.environmentSlug)
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
dynamicSecret: SanitizedDynamicSecretSchema.extend({
inputs: z.unknown()
@@ -263,6 +268,7 @@ export const registerDynamicSecretRouter = async (server: FastifyZodProvider) =>
environmentSlug: z.string().min(1).describe(DYNAMIC_SECRETS.LIST.environmentSlug)
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
dynamicSecrets: SanitizedDynamicSecretSchema.array()
})
@@ -302,6 +308,7 @@ export const registerDynamicSecretRouter = async (server: FastifyZodProvider) =>
environmentSlug: z.string().min(1).describe(DYNAMIC_SECRETS.LIST_LEAES_BY_NAME.environmentSlug)
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
leases: DynamicSecretLeasesSchema.array()
})
+9
View File
@@ -4,6 +4,7 @@ import { z } from "zod";
import { GroupsSchema, OrgMembershipRole, UsersSchema } from "@app/db/schemas";
import { GROUPS } from "@app/lib/api-docs";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { DefaultResponseErrorsSchema } from "@app/server/routes/sanitizedSchemas";
import { AuthMode } from "@app/services/auth/auth-type";
export const registerGroupRouter = async (server: FastifyZodProvider) => {
@@ -26,6 +27,7 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
role: z.string().trim().min(1).default(OrgMembershipRole.NoAccess).describe(GROUPS.CREATE.role)
}),
response: {
...DefaultResponseErrorsSchema,
200: GroupsSchema
}
},
@@ -51,6 +53,7 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
id: z.string().trim().describe(GROUPS.GET_BY_ID.id)
}),
response: {
...DefaultResponseErrorsSchema,
200: GroupsSchema
}
},
@@ -73,6 +76,7 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
schema: {
response: {
...DefaultResponseErrorsSchema,
200: GroupsSchema.array()
}
},
@@ -112,6 +116,7 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
})
.partial(),
response: {
...DefaultResponseErrorsSchema,
200: GroupsSchema
}
},
@@ -138,6 +143,7 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
id: z.string().trim().describe(GROUPS.DELETE.id)
}),
response: {
...DefaultResponseErrorsSchema,
200: GroupsSchema
}
},
@@ -168,6 +174,7 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
username: z.string().optional().describe(GROUPS.LIST_USERS.username)
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
users: UsersSchema.pick({
email: true,
@@ -210,6 +217,7 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
username: z.string().trim().describe(GROUPS.ADD_USER.username)
}),
response: {
...DefaultResponseErrorsSchema,
200: UsersSchema.pick({
email: true,
username: true,
@@ -243,6 +251,7 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
username: z.string().trim().describe(GROUPS.DELETE_USER.username)
}),
response: {
...DefaultResponseErrorsSchema,
200: UsersSchema.pick({
email: true,
username: true,
@@ -10,6 +10,7 @@ import { alphaNumericNanoId } from "@app/lib/nanoid";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import {
DefaultResponseErrorsSchema,
ProjectPermissionSchema,
ProjectSpecificPrivilegePermissionSchema,
SanitizedIdentityPrivilegeSchema
@@ -52,6 +53,7 @@ export const registerIdentityProjectAdditionalPrivilegeRouter = async (server: F
).optional()
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
privilege: SanitizedIdentityPrivilegeSchema
})
@@ -131,6 +133,7 @@ export const registerIdentityProjectAdditionalPrivilegeRouter = async (server: F
.describe(IDENTITY_ADDITIONAL_PRIVILEGE.CREATE.temporaryAccessStartTime)
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
privilege: SanitizedIdentityPrivilegeSchema
})
@@ -215,6 +218,7 @@ export const registerIdentityProjectAdditionalPrivilegeRouter = async (server: F
.partial()
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
privilege: SanitizedIdentityPrivilegeSchema
})
@@ -270,6 +274,7 @@ export const registerIdentityProjectAdditionalPrivilegeRouter = async (server: F
projectSlug: z.string().min(1).describe(IDENTITY_ADDITIONAL_PRIVILEGE.DELETE.projectSlug)
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
privilege: SanitizedIdentityPrivilegeSchema
})
@@ -311,6 +316,7 @@ export const registerIdentityProjectAdditionalPrivilegeRouter = async (server: F
projectSlug: z.string().min(1).describe(IDENTITY_ADDITIONAL_PRIVILEGE.GET_BY_SLUG.projectSlug)
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
privilege: SanitizedIdentityPrivilegeSchema
})
@@ -348,6 +354,7 @@ export const registerIdentityProjectAdditionalPrivilegeRouter = async (server: F
projectSlug: z.string().min(1).describe(IDENTITY_ADDITIONAL_PRIVILEGE.LIST.projectSlug)
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
privileges: SanitizedIdentityPrivilegeSchema.array()
})
@@ -6,7 +6,11 @@ import { ProjectMembershipRole, ProjectMembershipsSchema, ProjectRolesSchema } f
import { PROJECT_ROLE } from "@app/lib/api-docs";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { ProjectPermissionSchema, SanitizedRoleSchema } from "@app/server/routes/sanitizedSchemas";
import {
DefaultResponseErrorsSchema,
ProjectPermissionSchema,
SanitizedRoleSchema
} from "@app/server/routes/sanitizedSchemas";
import { AuthMode } from "@app/services/auth/auth-type";
export const registerProjectRoleRouter = async (server: FastifyZodProvider) => {
@@ -45,6 +49,7 @@ export const registerProjectRoleRouter = async (server: FastifyZodProvider) => {
permissions: ProjectPermissionSchema.array().describe(PROJECT_ROLE.CREATE.permissions)
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
role: SanitizedRoleSchema
})
@@ -105,6 +110,7 @@ export const registerProjectRoleRouter = async (server: FastifyZodProvider) => {
permissions: ProjectPermissionSchema.array().describe(PROJECT_ROLE.UPDATE.permissions).optional()
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
role: SanitizedRoleSchema
})
@@ -146,6 +152,7 @@ export const registerProjectRoleRouter = async (server: FastifyZodProvider) => {
roleId: z.string().trim().describe(PROJECT_ROLE.DELETE.roleId)
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
role: SanitizedRoleSchema
})
@@ -182,6 +189,7 @@ export const registerProjectRoleRouter = async (server: FastifyZodProvider) => {
projectSlug: z.string().trim().describe(PROJECT_ROLE.LIST.projectSlug)
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
roles: ProjectRolesSchema.omit({ permissions: true }).array()
})
@@ -212,6 +220,7 @@ export const registerProjectRoleRouter = async (server: FastifyZodProvider) => {
slug: z.string().trim().describe(PROJECT_ROLE.GET_ROLE_BY_SLUG.roleSlug)
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
role: SanitizedRoleSchema
})
@@ -242,6 +251,7 @@ export const registerProjectRoleRouter = async (server: FastifyZodProvider) => {
projectId: z.string().trim()
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
data: z.object({
membership: ProjectMembershipsSchema.extend({
@@ -6,6 +6,7 @@ import { AUDIT_LOGS, PROJECTS } from "@app/lib/api-docs";
import { getLastMidnightDateISO, removeTrailingSlash } from "@app/lib/fn";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { DefaultResponseErrorsSchema } from "@app/server/routes/sanitizedSchemas";
import { AuthMode } from "@app/services/auth/auth-type";
import { KmsType } from "@app/services/kms/kms-types";
@@ -33,6 +34,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
limit: z.coerce.number().default(20).describe(PROJECTS.GET_SNAPSHOTS.limit)
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
secretSnapshots: SecretSnapshotsSchema.array()
})
+2 -1
View File
@@ -4,7 +4,7 @@ import { SecretSnapshotsSchema, SecretTagsSchema } from "@app/db/schemas";
import { PROJECTS } from "@app/lib/api-docs";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { secretRawSchema } from "@app/server/routes/sanitizedSchemas";
import { DefaultResponseErrorsSchema, secretRawSchema } from "@app/server/routes/sanitizedSchemas";
import { AuthMode } from "@app/services/auth/auth-type";
export const registerSnapshotRouter = async (server: FastifyZodProvider) => {
@@ -77,6 +77,7 @@ export const registerSnapshotRouter = async (server: FastifyZodProvider) => {
secretSnapshotId: z.string().trim().describe(PROJECTS.ROLLBACK_TO_SNAPSHOT.secretSnapshotId)
}),
response: {
...DefaultResponseErrorsSchema,
200: z.object({
secretSnapshot: SecretSnapshotsSchema
})