Convert Swagger JSON to RAML/YAML
Asked Answered
R

6

51

How do I convert Swagger JSON to RAML/YAML and validate it? I am not looking for a programmatic way, just a one off conversion.

Rue answered 23/9, 2015 at 2:55 Comment(1)
this one too github.com/essuraj/swagger-toolbox - swagger-toolbox.firebaseapp.comHexachord
R
58

Here are the steps:

  1. Export Swagger JSON into a file on your drive. This JSON should be published on your server at the following URI: /swagger/docs/v1
  2. Go to http://editor.swagger.io/#/
  3. On the top left corner, select File-> Import File... Point to the local Swagger JSON file you exported in step #1 to open in the Swagger Editor
  4. Select Generate Client -> Swagger YAML option from the menu
  5. It will generate the YAML that you can validate at http://www.yamllint.com/ site
Rue answered 23/9, 2015 at 2:55 Comment(2)
I don't think that's what the question was about, this generates Swagger YAML, not RAML YAML.Casias
This does not answer the question but the actual solution can be found using almost the same way - Find my answer below.Molly
M
10

Its actually pretty simple

Web version of swagger editor gives the flexibility to import your existing swagger file(JSON/YAML) and download the configuration file that is currently being shown. So just combine these two.

Note: Converting JSON to YAML exists, but not JSON to RAML

  1. First import your swagger JSON at http://editor.swagger.io/#/ (File > Import File)
  2. Once you see your configurations, just download the corresponding YAML version (File > Download YAML).

The YAML version of the JSON you just uploaded will be downloaded.

Molly answered 23/10, 2017 at 11:42 Comment(0)
A
7

To convert API spec between various formats (e.g. Swagger/OpenAPI, RAML, Postman, etc), you can use the following free and open source tools:

Ashcan answered 6/12, 2016 at 14:53 Comment(0)
M
4

Conversion

If you are looking to convert from any version Swagger to RAML 0.8 then APITransformer.com can do it for you. We're almost done with RAML 1.0 export. Will release it in a week's time.

Validation

The converted description comes out of the same code-gen engine that APIMatic uses to validate an API description before generating SDKs/Client libraries. Therefore, the converted RAML will be validated by default.

API descriptions in a variety of formats can also be validated via APIMatic's CLI or APIMatic's API

Micro answered 23/10, 2016 at 1:40 Comment(0)
W
1

If you have the same OpenAPI spec (say for example same version 3.0.1) in a json format and you want to convert it to a YAML format, you only need to use yq the following way:

yq -p json -o yaml file.json > converted_file.yaml

And vice versa:

yq -p yaml -o json file.yaml > converted_file.json

-p: input format type

-o: output format type

Note that JSON is a subset of YAML

Wysocki answered 12/9, 2023 at 10:58 Comment(0)
C
0

While I wish there was a command line tool, this company has made a converter it seems:

https://apitransformer.com/

Casias answered 24/8, 2016 at 17:32 Comment(2)
There is a command line tool for conversions as well. Its located at github.com/apimatic/apimatic-cliHellenic
The link apimatic.io/transformer actually works and doing the same with their apimatic-cli seems to be tricky. Would you have an out-of-the-box guide?Selfexcited

© 2022 - 2024 — McMap. All rights reserved.