swagger-typescript-codegen icon indicating copy to clipboard operation
swagger-typescript-codegen copied to clipboard

YAML-Support

Open DenisSabo opened this issue 5 years ago • 5 comments

Hey there, for libraries like https://www.npmjs.com/package/swagger-typescript-codegen it would be nice, if your tool could generate a Typescript file, out of a YAML file.

DenisSabo avatar Mar 10 '19 21:03 DenisSabo

Hey @DenisSabo!

Do you mean using YAML files for specifying the Swagger spec (similar to the current Swagger JSON file)?

Thanks for the input!

mtennoe avatar Mar 11 '19 07:03 mtennoe

Hey @mtennoe,

yes that's what I meant. The reason for the suggestion is that for me it would mean one less step in my toolchain.

Thank you for the fast response! 👍

DenisSabo avatar Mar 11 '19 16:03 DenisSabo

It would add some complexity to the whole pipeline, but if we do it correctly we can hide a lot of the complexity. I guess there are some nice tools out there for parsing and reading the YAML and convert it to the internal format in the codegen tool as well. Don't really have the time to look into that in the nearest future myself though. But you are free to give it a go if you want to :)

mtennoe avatar Mar 12 '19 07:03 mtennoe

Out of scope IMHO.

@DenisSabo you could convert from YAML to JSON as a preprocessing step, e.g. https://stackoverflow.com/questions/34733253/converting-a-swagger-yaml-file-to-json-from-the-command-line

sbusch avatar Mar 26 '19 08:03 sbusch

with npm install --save js-yaml you can change the line in the example usage:

var swagger = JSON.parse(fs.readFileSync(file, "UTF-8"));

by

var yaml = require('js-yaml');
var swagger = yaml.safeLoad(fs.readFileSync(file, 'utf8'));

IMHO, there is no need for adding the yaml dependency... mh, maybe for the CLI tool...

Kosta-Github avatar Jun 19 '19 15:06 Kosta-Github