autorest icon indicating copy to clipboard operation
autorest copied to clipboard

Is there a way to transfer swagger from json to yaml in AutoRest?

Open hellosnow opened this issue 9 years ago • 7 comments

Hi AutoRest team,

In AutoRest, is there any way to transfer swagger from json to yaml? We can deserialize from json and serialize to yaml, but just wonder whether AutoRest has the ability, our tool depends on AutoRest already. Thanks!!

hellosnow avatar Sep 05 '17 03:09 hellosnow

Hi @hellosnow, try --output-artifact=swagger-document.yaml. However, this will emit a fully resolved (if your Swagger contains external references) and merged (if you have multiple input-files) Swagger. Hopefully this is helpful, now that I think about it, we should probably also add an "ouput-artfact" that will spit out the original files individually (but transcoded to YAML/JSON)

olydis avatar Sep 05 '17 15:09 olydis

Wow great! Fully resolved swagger contains external references is expected by us.

Does output-artifact option only available in new CLI? I tried autorest -FANCY -g SwaggerResolver -i advisor.json --output-artifact=advisor.yaml and it hint me to use new CLI. Or please help to correct the syntax if I'm wrong, thanks!

hellosnow avatar Sep 06 '17 02:09 hellosnow

yes, this is only available in the new CLI, i.e. in your case:

autorest --input-file=advisor.json --output-artifact=swagger-document.yaml

olydis avatar Sep 06 '17 03:09 olydis

@olydis wow cool I can generate the yaml files from swagger now, thanks!

hellosnow avatar Sep 06 '17 07:09 hellosnow

@hellosnow Nice! Note that I had a typo in my command: output-artifact must be swagger-document.yaml and not advisor.yaml, this is about the type of thing to be emitted and advisor.yaml is nothing AutoRest recognizes as a type of thing to emit.

I'll close this issue but feel free to post further questions in here or reopen if it doesn't work for you!

olydis avatar Sep 06 '17 15:09 olydis

@olydis interesting that I can generate the advisor.yaml via autorest --input-file=D:\Code\azure-rest-api-specs\specification\advisor\resource-manager\Microsoft.Advisor\2017-04-19\advisor.json --output-artifact=advisor.yaml, where the output-artifact could be any name?

hellosnow avatar Sep 07 '17 03:09 hellosnow

@hellosnow Are you saying you can generate the resolved YAML with autorest --input-file=D:\Code\azure-rest-api-specs\specification\advisor\resource-manager\Microsoft.Advisor\2017-04-19\advisor.json --output-artifact=advisor.yaml, even if output-artifact is any name? Not sure if this is a question or a statement.

olydis avatar Sep 07 '17 15:09 olydis