update openapi spec generator

This commit is contained in:
Johann150 2022-07-18 18:37:41 +02:00
parent edac21e8f7
commit 660f6dba30
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -15,7 +15,7 @@ export function genOpenapiSpec() {
externalDocs: { externalDocs: {
description: 'Repository', description: 'Repository',
url: 'https://github.com/misskey-dev/misskey', url: 'https://akkoma.dev/FoundKeyGang/FoundKey',
}, },
servers: [{ servers: [{
@ -33,6 +33,11 @@ export function genOpenapiSpec() {
in: 'body', in: 'body',
name: 'i', name: 'i',
}, },
// TODO: change this to oauth2 when the remaining oauth stuff is set up
Bearer: {
type: 'http',
scheme: 'bearer',
}
}, },
}, },
}; };
@ -71,22 +76,29 @@ export function genOpenapiSpec() {
schema.required.push('file'); schema.required.push('file');
} }
const security = [
{
ApiKeyAuth: [],
},
{
Bearer: [],
},
];
if (!endpoint.meta.requireCredential) {
// add this to make authentication optional
security.push({});
}
const info = { const info = {
operationId: endpoint.name, operationId: endpoint.name,
summary: endpoint.name, summary: endpoint.name,
description: desc, description: desc,
externalDocs: { externalDocs: {
description: 'Source code', description: 'Source code',
url: `https://github.com/misskey-dev/misskey/blob/develop/packages/backend/src/server/api/endpoints/${endpoint.name}.ts`, url: `https://akkoma.dev/FoundKeyGang/FoundKey/src/branch/main/packages/backend/src/server/api/endpoints/${endpoint.name}.ts`,
}, },
...(endpoint.meta.tags ? { tags: endpoint.meta.tags || undefined,
tags: [endpoint.meta.tags[0]], security,
} : {}),
...(endpoint.meta.requireCredential ? {
security: [{
ApiKeyAuth: [],
}],
} : {}),
requestBody: { requestBody: {
required: true, required: true,
content: { content: {
@ -181,9 +193,16 @@ export function genOpenapiSpec() {
}, },
}; };
spec.paths['/' + endpoint.name] = { const path = {
post: info, post: info,
}; };
if (endpoint.meta.allowGet) {
path.get = { ...info };
// API Key authentication is not permitted for GET requests
path.get.security = path.get.security.filter(elem => !Object.prototype.hasOwnProperty.call(elem, 'ApiKeyAuth'));
}
spec.paths['/' + endpoint.name] = path;
} }
return spec; return spec;