Skip to content

Instantly share code, notes, and snippets.

@rjchow
Created September 23, 2022 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjchow/2d0af535a0d098b1ae9461e131475ede to your computer and use it in GitHub Desktop.
Save rjchow/2d0af535a0d098b1ae9461e131475ede to your computer and use it in GitHub Desktop.
snippet to output partial ts interface given openapi array of params
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