securitySchemesの定義を復活&ApiCallServiceの実装的にベアラトークンなのでその形で

This commit is contained in:
osamu 2023-11-22 13:57:29 +09:00
parent 2fd053058d
commit b043aaa97c
1 changed files with 12 additions and 15 deletions

View File

@ -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: {