openapi-to-md
Advanced tools
Comparing version 1.0.22 to 1.0.23
@@ -12,2 +12,3 @@ #!/usr/bin/env node | ||
const swagger2openapi_1 = __importDefault(require("swagger2openapi")); | ||
const getData_1 = require("./libs/getData"); | ||
const readDocument = (src) => { | ||
@@ -24,3 +25,12 @@ try { | ||
}; | ||
/** | ||
* Replaces newlines with two spaces and a newline character, as required by | ||
* Markdown for a line break. | ||
*/ | ||
const markdownText = (text) => text.replace(/\n/g, " \n"); | ||
/** | ||
* Creates an API document from an OpenAPI document. | ||
* @param document The OpenAPI document. | ||
* @returns The API document. | ||
*/ | ||
const createApiDocument = (document) => { | ||
@@ -52,2 +62,9 @@ const pathMethods = []; | ||
}; | ||
/** | ||
* Converts a path to a format that can be used in a URL, such as replacing | ||
* spaces. | ||
* | ||
* @param path Path to convert | ||
* @returns The converted path | ||
*/ | ||
const convertPath = (path) => path | ||
@@ -69,2 +86,7 @@ .replace(/[!@#$%^&*()+|~=`[\]{};':",./<>?]/g, "") | ||
}; | ||
/** | ||
* outputReferenceTable outputs a Markdown table of all API references. | ||
* | ||
* @param apiDocument The API document to output. | ||
*/ | ||
const outputReferenceTable = (apiDocument) => { | ||
@@ -83,2 +105,6 @@ const { references } = apiDocument; | ||
}; | ||
/** | ||
* Return the name of a reference object. | ||
* @param refObject | ||
*/ | ||
const getRefName = (refObject) => { | ||
@@ -341,6 +367,6 @@ if (typeof refObject === "object" && refObject && "$ref" in refObject) { | ||
: "") + | ||
("requestBody" in operation | ||
(operation.requestBody | ||
? outputRequestBody(apiDocument, operation.requestBody) | ||
: "") + | ||
("responses" in operation | ||
(operation.responses | ||
? outputResponses(apiDocument, operation.responses) | ||
@@ -351,5 +377,3 @@ : ""), ""); | ||
const convertMarkdown = async (srcFile, destFile, sort = false) => { | ||
const src = await fs_1.promises | ||
.readFile(srcFile, { encoding: "utf8" }) | ||
.catch(() => null); | ||
const src = await (0, getData_1.getData)(srcFile); | ||
if (!src) { | ||
@@ -395,5 +419,5 @@ console.error(`'${srcFile}' not found`); | ||
.action((src, dest, options) => { | ||
(0, exports.convertMarkdown)(src, dest, options["sort"]); | ||
(0, exports.convertMarkdown)(src, dest, options.sort); | ||
}); | ||
commander_1.program.parse(process.argv); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "openapi-to-md", | ||
"version": "1.0.22", | ||
"version": "1.0.23", | ||
"main": "dist/index.js", | ||
@@ -9,4 +9,5 @@ "bin": { | ||
"scripts": { | ||
"test": "ts-node src/index.ts test/test.yaml test/readme.md", | ||
"test:sort": "ts-node src/index.ts -s test/test.yaml test/readme.md", | ||
"test": "ts-node src/index.ts test/api.github.com.yaml test/README.md", | ||
"test:sort": "ts-node src/index.ts -s test/api.github.com.yaml test/README.md", | ||
"test:url": "ts-node src/index.ts -s https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.yaml test/README.md", | ||
"build": "tsc -b", | ||
@@ -13,0 +14,0 @@ "lint": "eslint src", |
@@ -27,2 +27,3 @@ # openapi-to-md | ||
openapi-to-md openapi.json > README.md | ||
openapi-to-md https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.yaml README.md | ||
``` |
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
54669
9
452
29
3
1