From b043aaa97ca4293a1519fa81c2ae8f02cbae3b7d Mon Sep 17 00:00:00 2001 From: osamu <46447427+sam-osamu@users.noreply.github.com> Date: Wed, 22 Nov 2023 13:57:29 +0900 Subject: [PATCH] =?UTF-8?q?securitySchemes=E3=81=AE=E5=AE=9A=E7=BE=A9?= =?UTF-8?q?=E3=82=92=E5=BE=A9=E6=B4=BB=EF=BC=86ApiCallService=E3=81=AE?= =?UTF-8?q?=E5=AE=9F=E8=A3=85=E7=9A=84=E3=81=AB=E3=83=99=E3=82=A2=E3=83=A9?= =?UTF-8?q?=E3=83=88=E3=83=BC=E3=82=AF=E3=83=B3=E3=81=AA=E3=81=AE=E3=81=A7?= =?UTF-8?q?=E3=81=9D=E3=81=AE=E5=BD=A2=E3=81=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/server/api/openapi/gen-spec.ts | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/packages/backend/src/server/api/openapi/gen-spec.ts b/packages/backend/src/server/api/openapi/gen-spec.ts index 3546802440..ffad61b611 100644 --- a/packages/backend/src/server/api/openapi/gen-spec.ts +++ b/packages/backend/src/server/api/openapi/gen-spec.ts @@ -31,6 +31,13 @@ export function genOpenapiSpec(config: Config) { components: { schemas: schemas, + + securitySchemes: { + bearerAuth: { + type: 'http', + scheme: 'bearer', + }, + }, }, }; @@ -61,21 +68,6 @@ export function genOpenapiSpec(config: Config) { const requestType = endpoint.meta.requireFile ? 'multipart/form-data' : 'application/json'; const schema = { ...endpoint.params }; - if (endpoint.meta.requireCredential) { - // https://swagger.io/docs/specification/authentication/api-keys/ - // ↑曰く、「can be "header", "query" or "cookie"」とのこと。 - // Misskeyはbodyに埋め込む形にしているので、各エンドポイントのパラメータに直接APIキー用のフィールドを追加する必要がある - schema.properties = { - 'i': { - type: 'string', - nullable: false, - description: 'API Key', - }, - ...schema.properties, - }; - schema.required = ['i', ...schema.required ?? []]; - } - if (endpoint.meta.requireFile) { schema.properties = { ...schema.properties, @@ -104,6 +96,11 @@ export function genOpenapiSpec(config: Config) { ...(endpoint.meta.tags ? { tags: [endpoint.meta.tags[0]], } : {}), + ...(endpoint.meta.requireCredential ? { + security: [{ + bearerAuth: [], + }], + } : {}), requestBody: { required: true, content: {