summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/openapi
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2022-09-18 03:27:08 +0900
committerGitHub <noreply@github.com>2022-09-18 03:27:08 +0900
commitb75184ec8e3436200bacdcd832e3324702553d20 (patch)
tree8b7e316f29e95df921db57289c8b8da476d18f07 /packages/backend/src/server/api/openapi
parentUpdate ROADMAP.md (diff)
downloadsharkey-b75184ec8e3436200bacdcd832e3324702553d20.tar.gz
sharkey-b75184ec8e3436200bacdcd832e3324702553d20.tar.bz2
sharkey-b75184ec8e3436200bacdcd832e3324702553d20.zip
なんかもうめっちゃ変えた
Diffstat (limited to 'packages/backend/src/server/api/openapi')
-rw-r--r--packages/backend/src/server/api/openapi/gen-spec.ts190
1 files changed, 0 insertions, 190 deletions
diff --git a/packages/backend/src/server/api/openapi/gen-spec.ts b/packages/backend/src/server/api/openapi/gen-spec.ts
deleted file mode 100644
index 68fa814041..0000000000
--- a/packages/backend/src/server/api/openapi/gen-spec.ts
+++ /dev/null
@@ -1,190 +0,0 @@
-import endpoints from '../endpoints.js';
-import config from '@/config/index.js';
-import { errors as basicErrors } from './errors.js';
-import { schemas, convertSchemaToOpenApiSchema } from './schemas.js';
-
-export function genOpenapiSpec() {
- const spec = {
- openapi: '3.0.0',
-
- info: {
- version: 'v1',
- title: 'Misskey API',
- 'x-logo': { url: '/static-assets/api-doc.png' },
- },
-
- externalDocs: {
- description: 'Repository',
- url: 'https://github.com/misskey-dev/misskey',
- },
-
- servers: [{
- url: config.apiUrl,
- }],
-
- paths: {} as any,
-
- components: {
- schemas: schemas,
-
- securitySchemes: {
- ApiKeyAuth: {
- type: 'apiKey',
- in: 'body',
- name: 'i',
- },
- },
- },
- };
-
- for (const endpoint of endpoints.filter(ep => !ep.meta.secure)) {
- const errors = {} as any;
-
- if (endpoint.meta.errors) {
- for (const e of Object.values(endpoint.meta.errors)) {
- errors[e.code] = {
- value: {
- error: e,
- },
- };
- }
- }
-
- const resSchema = endpoint.meta.res ? convertSchemaToOpenApiSchema(endpoint.meta.res) : {};
-
- let desc = (endpoint.meta.description ? endpoint.meta.description : 'No description provided.') + '\n\n';
- desc += `**Credential required**: *${endpoint.meta.requireCredential ? 'Yes' : 'No'}*`;
- if (endpoint.meta.kind) {
- const kind = endpoint.meta.kind;
- desc += ` / **Permission**: *${kind}*`;
- }
-
- const requestType = endpoint.meta.requireFile ? 'multipart/form-data' : 'application/json';
- const schema = endpoint.params;
-
- if (endpoint.meta.requireFile) {
- schema.properties.file = {
- type: 'string',
- format: 'binary',
- description: 'The file contents.',
- };
- schema.required.push('file');
- }
-
- const info = {
- operationId: endpoint.name,
- summary: endpoint.name,
- description: desc,
- externalDocs: {
- description: 'Source code',
- url: `https://github.com/misskey-dev/misskey/blob/develop/packages/backend/src/server/api/endpoints/${endpoint.name}.ts`,
- },
- ...(endpoint.meta.tags ? {
- tags: [endpoint.meta.tags[0]],
- } : {}),
- ...(endpoint.meta.requireCredential ? {
- security: [{
- ApiKeyAuth: [],
- }],
- } : {}),
- requestBody: {
- required: true,
- content: {
- [requestType]: {
- schema,
- },
- },
- },
- responses: {
- ...(endpoint.meta.res ? {
- '200': {
- description: 'OK (with results)',
- content: {
- 'application/json': {
- schema: resSchema,
- },
- },
- },
- } : {
- '204': {
- description: 'OK (without any results)',
- },
- }),
- '400': {
- description: 'Client error',
- content: {
- 'application/json': {
- schema: {
- $ref: '#/components/schemas/Error',
- },
- examples: { ...errors, ...basicErrors['400'] },
- },
- },
- },
- '401': {
- description: 'Authentication error',
- content: {
- 'application/json': {
- schema: {
- $ref: '#/components/schemas/Error',
- },
- examples: basicErrors['401'],
- },
- },
- },
- '403': {
- description: 'Forbidden error',
- content: {
- 'application/json': {
- schema: {
- $ref: '#/components/schemas/Error',
- },
- examples: basicErrors['403'],
- },
- },
- },
- '418': {
- description: 'I\'m Ai',
- content: {
- 'application/json': {
- schema: {
- $ref: '#/components/schemas/Error',
- },
- examples: basicErrors['418'],
- },
- },
- },
- ...(endpoint.meta.limit ? {
- '429': {
- description: 'To many requests',
- content: {
- 'application/json': {
- schema: {
- $ref: '#/components/schemas/Error',
- },
- examples: basicErrors['429'],
- },
- },
- },
- } : {}),
- '500': {
- description: 'Internal server error',
- content: {
- 'application/json': {
- schema: {
- $ref: '#/components/schemas/Error',
- },
- examples: basicErrors['500'],
- },
- },
- },
- },
- };
-
- spec.paths['/' + endpoint.name] = {
- post: info,
- };
- }
-
- return spec;
-}