Created
September 23, 2022 09:54
-
-
Save rjchow/2d0af535a0d098b1ae9461e131475ede to your computer and use it in GitHub Desktop.
snippet to output partial ts interface given openapi array of params
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function make (openapiArray) { | |
let stringOutput = "" | |
stringOutput += "interface { \n" | |
for (const a of openapiArray) { | |
stringOutput += `/** ${a.description} */\n` | |
stringOutput += `${a.name}${a.required ? "" : "?"}: ` | |
if (a.schema && a.schema.enum) { | |
stringOutput += a.schema.enum.map(e => `'${e}'`).join(" | ") | |
} | |
stringOutput += '\n'; | |
} | |
stringOutput += "}" | |
console.log(stringOutput) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment