From b599fa0c160a5a6caa29a373d378ad8ab314f008 Mon Sep 17 00:00:00 2001 From: flakey5 <73616808+flakey5@users.noreply.github.com> Date: Tue, 14 May 2024 10:47:11 -0700 Subject: [PATCH] Add Authorization header to OpenAPI docs Closes #43 Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com> --- index.ts | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index ab02bd1..4cdab3e 100644 --- a/index.ts +++ b/index.ts @@ -22,7 +22,34 @@ const stackable: Stackable<AiWarpConfig> = async function (fastify, opts) { }) } - await fastify.register(platformaticService, opts) + if (config.service === undefined) { + config.service = {} + } + + const currentOpenApiConfig = typeof config.service.openapi === 'object' ? config.service.openapi : {} + config.service.openapi = { + ...currentOpenApiConfig, + components: { + ...currentOpenApiConfig.components, + securitySchemes: { + ...currentOpenApiConfig.components?.securitySchemes, + aiWarpJwtToken: { + type: 'apiKey', + in: 'header', + name: 'Authorization' + } + } + } + } + + if (config.auth?.jwt !== undefined) { + await fastify.register(platformaticService, { + ...opts, + + } as any) + } else { + await fastify.register(platformaticService, opts) + } await fastify.register(warpPlugin, opts) // needs to be registered here for fastify.ai to be decorated