From 3d58ca90ae303c40a6c95f7926b507a26361d1bb Mon Sep 17 00:00:00 2001 From: zyoshoka Date: Thu, 11 Jan 2024 22:05:38 +0900 Subject: [PATCH] chore: bump OpenAPI Specification from 3.0.0 to 3.1.0 --- .../src/server/api/openapi/gen-spec.ts | 2 +- .../misskey-js/generator/src/generator.ts | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/backend/src/server/api/openapi/gen-spec.ts b/packages/backend/src/server/api/openapi/gen-spec.ts index 0e71510b48..8958be8c0b 100644 --- a/packages/backend/src/server/api/openapi/gen-spec.ts +++ b/packages/backend/src/server/api/openapi/gen-spec.ts @@ -10,7 +10,7 @@ import { schemas, convertSchemaToOpenApiSchema } from './schemas.js'; export function genOpenapiSpec(config: Config) { const spec = { - openapi: '3.0.0', + openapi: '3.1.0', info: { version: config.version, diff --git a/packages/misskey-js/generator/src/generator.ts b/packages/misskey-js/generator/src/generator.ts index f12ed94513..6a7b509f5e 100644 --- a/packages/misskey-js/generator/src/generator.ts +++ b/packages/misskey-js/generator/src/generator.ts @@ -1,10 +1,10 @@ import { mkdir, writeFile } from 'fs/promises'; -import { OpenAPIV3 } from 'openapi-types'; +import { OpenAPIV3_1 } from 'openapi-types'; import { toPascal } from 'ts-case-convert'; import SwaggerParser from '@apidevtools/swagger-parser'; import openapiTS from 'openapi-typescript'; -function generateVersionHeaderComment(openApiDocs: OpenAPIV3.Document): string { +function generateVersionHeaderComment(openApiDocs: OpenAPIV3_1.Document): string { const contents = { version: openApiDocs.info.version, generatedAt: new Date().toISOString(), @@ -21,7 +21,7 @@ function generateVersionHeaderComment(openApiDocs: OpenAPIV3.Document): string { } async function generateBaseTypes( - openApiDocs: OpenAPIV3.Document, + openApiDocs: OpenAPIV3_1.Document, openApiJsonPath: string, typeFileName: string, ) { @@ -47,7 +47,7 @@ async function generateBaseTypes( } async function generateSchemaEntities( - openApiDocs: OpenAPIV3.Document, + openApiDocs: OpenAPIV3_1.Document, typeFileName: string, outputPath: string, ) { @@ -71,7 +71,7 @@ async function generateSchemaEntities( } async function generateEndpoints( - openApiDocs: OpenAPIV3.Document, + openApiDocs: OpenAPIV3_1.Document, typeFileName: string, entitiesOutputPath: string, endpointOutputPath: string, @@ -79,7 +79,7 @@ async function generateEndpoints( const endpoints: Endpoint[] = []; // misskey-jsはPOST固定で送っているので、こちらも決め打ちする。別メソッドに対応することがあればこちらも直す必要あり - const paths = openApiDocs.paths; + const paths = openApiDocs.paths ?? {}; const postPathItems = Object.keys(paths) .map(it => paths[it]?.post) .filter(filterUndefined); @@ -160,7 +160,7 @@ async function generateEndpoints( } async function generateApiClientJSDoc( - openApiDocs: OpenAPIV3.Document, + openApiDocs: OpenAPIV3_1.Document, apiClientFileName: string, endpointsFileName: string, warningsOutputPath: string, @@ -168,7 +168,7 @@ async function generateApiClientJSDoc( const endpoints: { operationId: string; description: string; }[] = []; // misskey-jsはPOST固定で送っているので、こちらも決め打ちする。別メソッドに対応することがあればこちらも直す必要あり - const paths = openApiDocs.paths; + const paths = openApiDocs.paths ?? {}; const postPathItems = Object.keys(paths) .map(it => paths[it]?.post) .filter(filterUndefined); @@ -221,21 +221,21 @@ async function generateApiClientJSDoc( await writeFile(warningsOutputPath, endpointOutputLine.join('\n')); } -function isRequestBodyObject(value: unknown): value is OpenAPIV3.RequestBodyObject { +function isRequestBodyObject(value: unknown): value is OpenAPIV3_1.RequestBodyObject { if (!value) { return false; } - const { content } = value as Record; + const { content } = value as Record; return content !== undefined; } -function isResponseObject(value: unknown): value is OpenAPIV3.ResponseObject { +function isResponseObject(value: unknown): value is OpenAPIV3_1.ResponseObject { if (!value) { return false; } - const { description } = value as Record; + const { description } = value as Record; return description !== undefined; } @@ -330,7 +330,7 @@ async function main() { await mkdir(generatePath, { recursive: true }); const openApiJsonPath = './api.json'; - const openApiDocs = await SwaggerParser.validate(openApiJsonPath) as OpenAPIV3.Document; + const openApiDocs = await SwaggerParser.validate(openApiJsonPath) as OpenAPIV3_1.Document; const typeFileName = './built/autogen/types.ts'; await generateBaseTypes(openApiDocs, openApiJsonPath, typeFileName);