1
0

merge upstream

This commit is contained in:
Hazelnoot
2025-03-25 16:14:53 -04:00
1065 changed files with 32953 additions and 20092 deletions
@@ -14,4 +14,10 @@ export default [
},
},
},
{
files: ['built/autogen/**.ts'],
rules: {
'@stylistic/indent': 'off',
},
},
];
+7 -7
View File
@@ -7,16 +7,16 @@
"generate": "tsx src/generator.ts && eslint ./built/**/*.ts --fix --cache"
},
"devDependencies": {
"@readme/openapi-parser": "2.6.0",
"@types/node": "22.9.0",
"@typescript-eslint/eslint-plugin": "7.17.0",
"@typescript-eslint/parser": "7.17.0",
"@readme/openapi-parser": "2.7.0",
"@types/node": "22.13.9",
"@typescript-eslint/eslint-plugin": "8.26.0",
"@typescript-eslint/parser": "8.26.0",
"eslint": "9.14.0",
"openapi-types": "12.1.3",
"openapi-typescript": "6.7.3",
"openapi-typescript": "6.7.6",
"ts-case-convert": "2.1.0",
"tsx": "4.4.0",
"typescript": "5.6.3"
"tsx": "4.19.3",
"typescript": "5.8.2"
},
"files": [
"built"
+29 -6
View File
@@ -1,8 +1,9 @@
import { mkdir, writeFile } from 'fs/promises';
import assert from 'assert';
import { mkdir, readFile, writeFile } from 'fs/promises';
import { OpenAPIV3_1 } from 'openapi-types';
import { toPascal } from 'ts-case-convert';
import OpenAPIParser from '@readme/openapi-parser';
import openapiTS from 'openapi-typescript';
import openapiTS, { OpenAPI3, OperationObject, PathItemObject } from 'openapi-typescript';
async function generateBaseTypes(
openApiDocs: OpenAPIV3_1.Document,
@@ -20,7 +21,29 @@ async function generateBaseTypes(
}
lines.push('');
const generatedTypes = await openapiTS(openApiJsonPath, {
// NOTE: Align `operationId` of GET and POST to avoid duplication of type definitions
const openApi = JSON.parse(await readFile(openApiJsonPath, 'utf8')) as OpenAPI3;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
for (const [key, item] of Object.entries(openApi.paths!)) {
assert('post' in item);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
openApi.paths![key] = {
...('get' in item ? {
get: {
...item.get,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
operationId: ((item as PathItemObject).get as OperationObject).operationId!.replaceAll('get___', ''),
},
} : {}),
post: {
...item.post,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
operationId: ((item as PathItemObject).post as OperationObject).operationId!.replaceAll('post___', ''),
},
};
}
const generatedTypes = await openapiTS(openApi, {
exportType: true,
transform(schemaObject) {
if ('format' in schemaObject && schemaObject.format === 'binary') {
@@ -78,7 +101,7 @@ async function generateEndpoints(
for (const operation of postPathItems) {
const path = operation._path_;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const operationId = operation.operationId!;
const operationId = operation.operationId!.replaceAll('get___', '').replaceAll('post___', '');
const endpoint = new Endpoint(path);
endpoints.push(endpoint);
@@ -150,7 +173,7 @@ async function generateEndpoints(
endpointOutputLine.push(
...endpoints.map(it => '\t' + it.toLine()),
);
endpointOutputLine.push('}');
endpointOutputLine.push('};');
endpointOutputLine.push('');
function generateEndpointReqMediaTypesType() {
@@ -195,7 +218,7 @@ async function generateApiClientJSDoc(
for (const operation of postPathItems) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const operationId = operation.operationId!;
const operationId = operation.operationId!.replaceAll('get___', '').replaceAll('post___', '');
if (operation.description) {
endpoints.push({
+1 -1
View File
@@ -3,7 +3,7 @@
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "nodenext",
"moduleResolution": "node16",
"strict": true,
"strictFunctionTypes": true,
"strictNullChecks": true,