the api parser creates it's output directory if it does not exist (#399)

This commit is contained in:
Pascal Fischer
2025-07-30 12:12:17 +02:00
committed by GitHub
parent 8c057cf72f
commit 36e21f688a

View File

@@ -3,28 +3,12 @@ import { slugify, toArrayWithKey, toTitle, writeToDisk } from './helpers'
import {OpenAPIV3, OpenAPIV3_1} from 'openapi-types' import {OpenAPIV3, OpenAPIV3_1} from 'openapi-types'
import * as fs from 'fs' import * as fs from 'fs'
import * as ejs from 'ejs' import * as ejs from 'ejs'
import { spawn } from 'child_process';
import * as yaml from 'js-yaml'; import * as yaml from 'js-yaml';
import { merge } from 'allof-merge' import { merge } from 'allof-merge'
import RequestBodyObject = OpenAPIV3_1.RequestBodyObject; import RequestBodyObject = OpenAPIV3_1.RequestBodyObject;
const goExecutable = './generator/expandOpenAPIRef'
export default async function gen(inputFileName: string, outputDir: string) { export default async function gen(inputFileName: string, outputDir: string) {
// const args = [inputFileName];
// const process = spawn(goExecutable, args);
// process.stdout.on('data', (data) => {
// console.log(`Output: ${data}`);
// });
// process.stderr.on('data', (data) => {
// console.error(`Error: ${data}`);
// });
// process.on('close', (code) => {
// console.log(`Process exited with code ${code}`);
// });
// const specRaw = fs.readFileSync("generator/openapi/expanded.yml", 'utf8')
const specRaw = fs.readFileSync(inputFileName, 'utf8') const specRaw = fs.readFileSync(inputFileName, 'utf8')
// const spec = JSON.parse(specRaw) as any
const specYaml = yaml.load(specRaw); const specYaml = yaml.load(specRaw);
const onMergeError = (msg) => { const onMergeError = (msg) => {
throw new Error(msg) throw new Error(msg)
@@ -33,6 +17,8 @@ export default async function gen(inputFileName: string, outputDir: string) {
const spec = merged as OpenAPIV3.Document const spec = merged as OpenAPIV3.Document
await fs.promises.mkdir(outputDir, { recursive: true });
switch (spec.openapi) { switch (spec.openapi) {
case '3.0.0': case '3.0.0':
case '3.0.1': case '3.0.1':