Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
/* eslint-disable no-param-reassign */
import fp from "fastify-plugin";
import { getConfig } from "@app/lib/config/env";
import { DefaultResponseErrorsSchema } from "../routes/sanitizedSchemas";
const isScimRoutes = (pathname: string) =>
pathname.startsWith("/api/v1/scim/Users") || pathname.startsWith("/api/v1/scim/Groups");
const isAcmeRoutes = (pathname: string) => pathname.startsWith("/api/v1/cert-manager/acme/");
const isOauthTokenRoute = (pathname: string) => pathname === "/api/v1/oauth/token";
export const registerResponseSchemaHooks = fp(async (server) => {
const appCfg = getConfig();
server.addHook("onRoute", (routeOptions) => {
if (appCfg.isDevelopmentMode && routeOptions.schema) {
routeOptions.schema.hide = false;
}
if (
routeOptions.schema &&
routeOptions.schema.response &&
!isScimRoutes(routeOptions.path) &&
!isAcmeRoutes(routeOptions.path) &&
!isOauthTokenRoute(routeOptions.path)
) {
routeOptions.schema.response = {
...DefaultResponseErrorsSchema,
...routeOptions.schema.response
};
}
});
});