chore: bump OpenAPI Specification from 3.0.0 to 3.1.0

This commit is contained in:
zyoshoka 2024-01-11 22:05:38 +09:00
parent 02225089e1
commit 3d58ca90ae
No known key found for this signature in database
GPG key ID: 0C2CB8FBA309A5B8
2 changed files with 14 additions and 14 deletions

View file

@ -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,

View file

@ -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<keyof OpenAPIV3.RequestBodyObject, unknown>;
const { content } = value as Record<keyof OpenAPIV3_1.RequestBodyObject, unknown>;
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<keyof OpenAPIV3.ResponseObject, unknown>;
const { description } = value as Record<keyof OpenAPIV3_1.ResponseObject, unknown>;
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);