openapi-to-md
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -74,4 +74,11 @@ #!/usr/bin/env node | ||
}; | ||
const getRefName = (refObjecgt) => { | ||
if (typeof refObjecgt === "object" && refObjecgt && "$ref" in refObjecgt) { | ||
return refObjecgt["$ref"]; | ||
} | ||
return undefined; | ||
}; | ||
const getApiObject = ({ references }, object, refs) => { | ||
if (typeof object === "object" && object && "$ref" in object) { | ||
const refName = getRefName(object); | ||
if (refName) { | ||
const ref = object["$ref"]; | ||
@@ -115,2 +122,3 @@ if (refs) { | ||
if (apiObject.type === "object") { | ||
output += outputComment(apiObject, 0); | ||
output += outputObject(apiDocument, undefined, apiObject); | ||
@@ -127,2 +135,14 @@ } | ||
const SP = (size) => "".padEnd(size); | ||
const outputRefComment = (apiObject, level) => { | ||
const refName = getRefName(apiObject); | ||
return refName ? SP(level) + `// ${refName}\n` : ""; | ||
}; | ||
const outputComment = (apiObject, level) => { | ||
return apiObject.description | ||
? SP(level * 2) + | ||
apiObject.description | ||
.split("\n") | ||
.reduce((a, b) => a + SP(level) + `// ${b}\n`, "") | ||
: ""; | ||
}; | ||
const outputObject = (apiDocument, name, schemas, required, refs, level) => { | ||
@@ -139,2 +159,4 @@ const nowLevel = level || 0; | ||
else if (apiObject.type === "object") { | ||
output += outputRefComment(schemas, nowLevel); | ||
output += outputComment(apiObject, nowLevel); | ||
output += name ? SP(nowLevel * 2) + `${name}: {\n` : "{\n"; | ||
@@ -155,2 +177,3 @@ apiObject.properties && | ||
else { | ||
output += outputComment(apiObject, nowLevel); | ||
const type = Array.isArray(apiObject.type) | ||
@@ -157,0 +180,0 @@ ? apiObject.type |
{ | ||
"name": "openapi-to-md", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"main": "dist/index.js", | ||
@@ -9,3 +9,3 @@ "bin": { | ||
"scripts": { | ||
"test": "ts-node dist/index.js test/test.yaml test/readme.md", | ||
"test": "ts-node src/index.ts test/test.yaml test/readme.md", | ||
"build": "tsc -b", | ||
@@ -12,0 +12,0 @@ "lint": "eslint src", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12571
3
308