UNPKG

fluid-oas

Version:

Build declarative OpenApiv3.* specifications.

36 lines (35 loc) 1.37 kB
import { withExternalDocs, withTags, withSecurityArray, withWebhooks, withPaths, withServersArray, withJSONSchemaDialect, withInfo, withOpenApi, withComponents, } from "./common"; import { Base } from "./lib/base"; import * as fs from "fs"; const OpenApiBase = withComponents(withExternalDocs(withTags(withSecurityArray(withWebhooks(withPaths(withServersArray(withJSONSchemaDialect(withInfo(withOpenApi(Base))))())))())())); class _OpenApiV3 extends OpenApiBase { async writeOASImpl(fileWriteFn, filePath) { let json = JSON.stringify(this); if (!filePath) { console.log(json); return; } await fileWriteFn(filePath, json); } async writeOASASync(filePath) { const fn = async (filePath, json) => await fs.writeFile(filePath, json, { encoding: "utf-8" }, err => { if (err) { console.error("Error writing file.", err.message); } }); this.writeOASImpl(fn, filePath); } writeOASSync(filePath) { const fn = (filePath, json) => fs.writeFileSync(filePath, json); this.writeOASImpl(fn, filePath); } } export const OpenApiV3 = { addOpenApiVersion(version) { return { addInfo(info) { return new _OpenApiV3().addOpenApiVersion(version).addInfo(info); }, }; }, };