Git Product home page Git Product logo

mulesoft / oas-raml-converter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stoplightio/api-spec-converter

72.0 245.0 47.0 32.08 MB

(DEPRECATED) Converts between OAS and RAML API specifications

Home Page: https://mulesoft.github.io/oas-raml-converter/

License: MIT License

JavaScript 99.51% HTML 0.16% CSS 0.22% RAML 0.10%
raml raml-tooling oas openapi-spec swagger raml-converter

oas-raml-converter's Introduction

OAS RAML Converter (DEPRECATED) npm version

Deprecation Notice

This project has been deprecated and is no longer maintained. Please use WebAPI Parser converter instead. https://github.com/raml-org/webapi-parser

Master Build Status Coverage Status

v0.2.x Build Status Coverage Status

This package helps to convert between different API specifications. It was originally forked from the stoplight.io converter.

Supported Conversions (beta)

Using

1. Online web page

For an online conversion, use: https://mulesoft.github.io/oas-raml-converter.

2. Command line tool

This command needs to be execute after cloning repository,

npm run build

This utility helps you converting local files from your command line.

./lib/bin/converter.js --from OAS20 --to RAML ./path/to/swagger.json
./lib/bin/converter.js --from OAS20 --to RAML ./path/to/swagger.json > output.raml

./lib/bin/converter.js --from RAML --to OAS20 ./path/to/source.raml > swagger.json

Or install globally and then:

oas-raml-converter --from OAS20 --to RAML ./path/to/swagger.json
oas-raml-converter --from OAS20 --to RAML ./path/to/swagger.json > output.raml

oas-raml-converter --from RAML --to OAS20 ./path/to/source.raml > swagger.json

3. As a service

For a REST API of the converter, you can start it in an express server, checkout the oas-raml-converter-service project.

4. As a dependency

Installation (NodeJS or Browser)

npm install --save oas-raml-converter

Initializing a converter

Raml 1.0 to OAS 2.0:

var converter = require('oas-raml-converter');
var raml10ToOas20 = new converter.Converter(converter.Formats.RAML, converter.Formats.OAS20);

OAS 2.0 to Raml 1.0:

var converter = require('oas-raml-converter');
var oas20ToRaml10 = new converter.Converter(converter.Formats.OAS20, converter.Formats.RAML);

The converter detects the input raml format automatically by passing RAML import format, so: Raml 0.8 to OAS 2.0:

var converter = require('oas-raml-converter');
var raml08ToOas20 = new converter.Converter(converter.Formats.RAML, converter.Formats.OAS20);

Raml 0.8 to Raml 1.0:

var converter = require('oas-raml-converter');
var raml08ToRaml10 = new converter.Converter(converter.Formats.RAML, converter.Formats.RAML);

Converting from a file or url

oas20ToRaml10.convertFile('/path/to/swagger.json').then(function(raml) {
  console.log(raml); // raml is raml yaml string
})
.catch(function(err) {
  console.error(err);
});

Converting from a string or json

var myOasString = '...';
oas20ToRaml10.convertData(myOasString).then(function(raml) {
  console.log(raml); // raml is raml yaml string
})
.catch(function(err) {
  console.error(err);
});

Passing options

var options = {
    validate: false, // Parse both input and output to check that its a valid document
    validateImport: false, // Only validate input
    validateExport: false, // Only validate output
    format: 'yaml', // Output format: json (default for OAS) or yaml (default for RAML)
    fs: { ... } // Use a custom file system solver (not yet available)
};

oas20ToRaml10.convertFile('/path/to/swagger.json', options).then(function(raml) {
  console.log(raml); // raml is raml yaml string
})
.catch(function(err) {
  console.error(err);
});

Contributing

Contributions are welcome! Please check the current issues to make sure what you are trying to do has not already been discussed.

Steps

  1. Fork.
  2. Make changes.
  3. Write tests.
  4. Send a pull request.

Develop

Install dependencies:

npm install

Run tests:

npm test

Run eslint to check linting errors:

npm run eslint

oas-raml-converter's People

Contributors

agustinlg avatar carowright avatar forsakenharmony avatar glodieu avatar jisoldi avatar joaquinbucca avatar jstoiko avatar lbauret avatar lottamus avatar mnbattaglia avatar postatum avatar pytlesk4 avatar rainum avatar ranacseruet avatar smulesoft avatar tomasmateus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oas-raml-converter's Issues

Oas to raml does not work well

Using npm library, if you convert oas to raml, some times the conversion is not right and this library does not detect it.
For example this oas file:

{
  "swagger": "2.0",
  "info": {
    "version": "1.0.0",
    "title": "Swagger Petstore"
  },
  "host": "petstore.swagger.io",
  "basePath": "/api",
  "schemes": [
    "http"
  ],
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "paths": {
    "/reviews": {
      "x-raml-resource-displayName": "reviews"
    },
    "/reviews/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "description": "ID of review",
          "required": true,
          "type": "string"
        }
      ],
      "post": {
        "operationId": "GET_reviews-id",
        "description": "Returns a review",
        "parameters": [
          {
            "name": "body",
            "in": "body",
            "description": "Review to add to the store",
            "schema": {
              "$ref": "#/definitions/NewReview"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "review response",
            "examples": {
              "application/json": {
                "$ref": "#/definitions/Review"
              }
            }
          }
        }
      },
      "x-raml-resource-displayName": "{id}"
    }
  },
  "definitions": {
    "Review": {
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32"
        },
        "message": {
          "type": "string"
        }
      },
      "type": "object"
    },
    "NewReview": {
      "properties": {
        "title": {
          "type": "string"
        }
      },
      "type": "object"
    }
  }
}

In OAS 20 to RAML 1 conversion, properties in RAML should be required: false when a required array is missing in OAS

When converting OAS 20 to RAML 1, the properties should be set required: false when no required array is present in the OAS as the default required value in OAS is true AND there are more than one property present.

If there is only one property, it's working fine.

OAS 20 (Source)

 Tag:
    type: object
    properties:
      id:
        type: integer
        format: int64
      name:
        type: string

RAML 1 (Expected)

  Tag:
    type: object
    properties:
      id:
        type: integer
        format: int64
        required: false
      name:
        type: string
        required: false

RAML 1 (Observed)

  Tag:
    type: object
    properties:
      id:
        type: integer
        format: int64
      name:
        type: string

OAS 2.0 to RAML 1.0 conversion generates invalid RAML when input OAS 2.0 file contains a non-top-level array type with inline items type definition

input OAS 2.0 file

swagger: '2.0'
info:
  description: Foo API
  version: 0.0.0
  title: Foo API
schemes:
  - http
  - https
paths:
  /foo:
    get:
      operationId: GetFoo
      produces:
        - application/json
      responses:
        '200':
          description: OK
          schema:
            $ref: '#/definitions/Foo'
definitions:
  Foo:
    type: object
    properties:
      barrs:
        type: array
        description: The Barrs for a single Foo
        items:
          type: object
          properties:
            name:
              type: string

Generated RAML file from oas-raml-converter:

#%RAML 1.0
title: Foo API
description: Foo API
version: 0.0.0
protocols:
  - HTTP
  - HTTPS
types:
  Foo:
    type: object
    properties:
      barrs:
        description: The Barrs for a single Foo
        type: array
        items:
          type: object
          properties:
            name:
              type: string
/foo:
  get:
    displayName: GetFoo
    responses:
      '200':
        description: OK
        body:
          application/json:
            type: Foo

I believe this generated file is not a valid RAML 1.0 file.

Note that the value for barrs: is an inline type declaration for an array type. Regarding array types, the RAML 1.0 spec states:

If you are defining a top-level array type, such as the Emails in the examples below, you can declare the following facets in addition to those previously described to further restrict the behavior of the array type.

Facet Description
items? Indicates the type all items in the array are inherited from. Can be a reference to an existing type or an inline type declaration.

(ref: https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md#array-type )

My understanding is that since we are inside an inline type declaration, we are not defining a top-level array type, hence we cannot use the items facet.

In OAS30, inheriting schemas miss their required fields

oas-raml-coverter version 1.1.35

When inheriting from Foo, FooFromBar schema should have a required array with its field names in it.

I believe it is related to #43 since the schemas afflicted with the bug are also wrongly typed string.

Full reproduction

Raml definition

types:
  Foo:
    type: object
    properties:
      foo1:
        type: number
        required: true
  BarFromFoo:
    type: Foo
    properties:
      bar1:
        type: string
        required: true

Expected output (oas3+json)

{
  "components": {
    "schemas": {
      "Foo": {
        "type": "object",
        "properties": {
          "foo1": {
            "type": "number"
          }
        },
        "required": [
          "foo1"
        ]
      },
      "BarFromFoo": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Foo"
          },
          {
            "properties": {
              "bar1": {
                "type": "string"
              },
              "bar2": {
                "type": "string"
              }
            },
            "type": "object"
          }
        ],
        "required": [
          "bar1",
          "bar2"
        ]
      }
    }
  }
}

Observed output (oas3+json)

{
  "components": {
    "schemas": {
      "Foo": {
        "type": "object",
        "properties": {
          "foo1": {
            "type": "number"
          }
        },
        "required": [
          "foo1"
        ]
      },
      "BarFromFoo": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Foo"
          },
          {
            "properties": {
              "bar1": {
                "type": "string"
              },
              "bar2": {
                "type": "string"
              }
            },
            "type": "object"
          }
        ],
        "type": "string"
      }
    }
  }
}

raml1 to oas2 converts ok, but raml1 to oas3 fails


#%RAML 1.0
title: oas-raml-converter does not process this correctly
baseUri: http://api.samplehost.com/
mediaType: application/json
protocols: [HTTP]

types:
  geoCoordinates:
    properties:
      latitude:
        description:
          Latitude (degree range -90 to +90) with positive values for N latitude and
          negative for S latitude.
        type: number
        format: double
        minimum: -90
        maximum: 90
      longitude:
        description:
          Longitude (degree range -180 to +180) positive values for E of the prime
          meridian, and negative values W longitude.
        type: number
        format: double
        minimum: -180
        maximum: 180

/geoCoordinates:
  get:
    responses:
      200:
        body:
          type: geoCoordinates

Conversion to OAS3 shows this:

Model {
  openapi: '3.0.0',
  info:
   Info {
     title: 'oas-raml-converter does not process this correctly',
     version: 'undefined',
     description: undefined,
     termsOfService: undefined },
  servers: [ Server { url: 'http://api.samplehost.com/' } ],
  paths: { '/geoCoordinates': { get: [Operation] } },
  components:
   Components {
     schemas: { geoCoordinates: [Object] },
     responses: {},
     parameters: {},
     examples: {},
     requestBodies: {},
     headers: {},
     securitySchemes: {},
     links: {},
     callbacks: {} } }

What's up with this geoCoordinates: [Object]? Why isn't the type expanded?

Running oas-raml-converter throws an error

oas-raml-converter is installed globally. However, when I run it, it immediately raises an error:

> oas-raml-converter
module.js:471
    throw err;
    ^

Error: Cannot find module 'serializer.ts/Decorators'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/wgreen/.nvm/versions/node/v6.10.3/lib/node_modules/oas-raml-converter/node_modules/oas-raml-converter-model/lib/model/index.js:12:20)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at require (internal/module.js:20:19)

Node version is 6.10.3
NPM version is 3.10.10

OAS 2.0 โ†’ RAML 1.0: [object Object] is not a valid Swagger API definition

An error is thrown:

SyntaxError: [object Object] is not a valid Swagger API definition

โ€ฆwhen calling oas20ToRaml10.convertData() with this data (please forgive the denormalized style here, it's part of a ๐Ÿšง work in progress ๐Ÿšง):

{
  "type": "object",
  "definitions": {
    "generateUuids": {
      "$schema": "http://json-schema.org/draft-04/hyper-schema",
      "title": "Generate UUIDs",
      "description": "Create UUID v4, random identifiers.",
      "stability": "prototype",
      "strictProperties": true,
      "type": [
        "object"
      ],
      "definitions": {
        "identity": {
          "anyOf": [
            {
              "description": "Universally unique identifier",
              "readOnly": true,
              "format": "uuid",
              "type": [
                "string"
              ]
            }
          ]
        },
        "id": {
          "description": "Universally unique identifier",
          "readOnly": true,
          "format": "uuid",
          "type": [
            "string"
          ]
        },
        "contextId": {
          "description": "Pass-through identifier",
          "type": [
            "string"
          ]
        }
      },
      "links": [
        {
          "description": "Create a new UUID",
          "href": "/generateUuids",
          "method": "POST",
          "rel": "create",
          "schema": {
            "properties": {
              "contextId": {
                "description": "Pass-through identifier",
                "type": [
                  "string"
                ]
              }
            },
            "required": [
              "contextId"
            ],
            "type": [
              "object"
            ]
          },
          "targetSchema": {
            "properties": {
              "id": {
                "description": "Universally unique identifier",
                "readOnly": true,
                "format": "uuid",
                "type": [
                  "string"
                ]
              },
              "contextId": {
                "description": "Pass-through identifier",
                "type": [
                  "string"
                ]
              }
            },
            "required": [
              "id",
              "contextId"
            ],
            "type": [
              "object"
            ]
          },
          "title": "Create"
        }
      ],
      "properties": {
        "id": {
          "description": "Universally unique identifier",
          "readOnly": true,
          "format": "uuid",
          "type": [
            "string"
          ]
        }
      }
    }
  },
  "properties": {
    "generateUuids": {
      "title": "Generate UUIDs",
      "description": "Create UUID v4, random identifiers.",
      "stability": "prototype",
      "strictProperties": true,
      "type": "object",
      "definitions": {
        "identity": {
          "anyOf": [
            {
              "description": "Universally unique identifier",
              "readOnly": true,
              "format": "uuid",
              "type": [
                "string"
              ]
            }
          ]
        },
        "id": {
          "description": "Universally unique identifier",
          "readOnly": true,
          "format": "uuid",
          "type": [
            "string"
          ]
        },
        "contextId": {
          "description": "Pass-through identifier",
          "type": [
            "string"
          ]
        }
      },
      "links": [
        {
          "description": "Create a new UUID",
          "href": "/generateUuids",
          "method": "POST",
          "rel": "create",
          "schema": {
            "properties": {
              "contextId": {
                "description": "Pass-through identifier",
                "type": [
                  "string"
                ]
              }
            },
            "required": [
              "contextId"
            ],
            "type": [
              "object"
            ]
          },
          "targetSchema": {
            "properties": {
              "id": {
                "description": "Universally unique identifier",
                "readOnly": true,
                "format": "uuid",
                "type": "string"
              },
              "contextId": {
                "description": "Pass-through identifier",
                "type": "string"
              }
            },
            "required": [
              "id",
              "contextId"
            ],
            "type": "object"
          },
          "title": "Create"
        }
      ],
      "properties": {
        "id": {
          "description": "Universally unique identifier",
          "readOnly": true,
          "format": "uuid",
          "type": "string"
        }
      }
    }
  },
  "description": "An example microservice to generate UUIDs.",
  "links": [
    {
      "href": "https://heroku-microservice-api.herokuapp.com",
      "rel": "self"
    }
  ],
  "title": "Generate UUIDs API"
}

It seems like the nested objects are being toString()'d somewhere along the way.

Invalid conversion result when converting RAML 1.0 with multiple examples to OAS 2

I have a RAML 1.0 file with multiple examples. The functional specification says that only one example will be kept because OpenApi Specification only supports one example.

This is my RAML fragment:

/{shippingZoneId}/shipping-methods/{shippingMethodId}:
  get:
    description: null
    responses:
      200:
        body:
          application/hal+json:
            type: !include 'shipping-zones-shipping-method-get-schema-response-merged.json'
            examples:
              shipping-zones-shipping-method-get-with-weight-based-price: !include 'shipping-zones-shipping-method-get-with-weight-based-price-response.json'
              shipping-zones-shipping-method-get: !include 'shipping-zones-shipping-method-get-response.json'

This is the output - it is having the example name and also carries all the examples:

 "/shipping-zones/{shippingZoneId}/shipping-methods/{shippingMethodId}": {
      "get": {
        "operationId": "GET_shipping-zones-shippingZoneId-shipping-methods-shippingMethodId",
        "produces": [
          "application/hal+json"
        ],
        "responses": {
          "200": {
            "description": "",
            "schema": {
              "example": {
                "shipping-zones-shipping-method-get-with-weight-based-price": {
                  "name": "Standard Shipping 1",
                  "description": "Standard Shipping",
                  "taxClass": "REGULAR",
                  "position": 0,
                  "freeShippingValue": null,
                  "fixedPrice": {
                    "taxModel": "GROSS",
                    "currency": "EUR",
                    "amount": 16.95
                  },
                  "weightBasedPrice": null,
                  "_id": "8ed01c04-6fc2-47f7-985b-f6855ca6f17b",
                  "_links": {
                    "self": {
                      "href": "https://yourshop.api.urn/shipping-zones/b24b7049-79f0-4758-aa90-49bb78a95cb6/shipping-methods/8ed01c04-6fc2-47f7-985b-f6855ca6f17b"
                    }
                  }
                },
                "shipping-zones-shipping-method-get": {
                  "name": "Standard Shipping 2",
                  "description": "Standard Shipping",
                  "taxClass": "REGULAR",
                  "position": 0,
                  "freeShippingValue": {
                    "currency": "EUR",
                    "amount": 400
                  },
                  "fixedPrice": {
                    "taxModel": "GROSS",
                    "currency": "EUR",
                    "amount": 19.99
                  },
                  "weightBasedPrice": null,
                  "_id": "b7b58df1-c493-4ec6-8fe4-783877a0f14c",
                  "_links": {
                    "self": {
                      "href": "https://yourshop.api.urn/shipping-zones/390a3013-ca74-4f0b-8c29-9b0a34facfd7/shipping-methods/b7b58df1-c493-4ec6-8fe4-783877a0f14c"
                    }
                  }
                }
              },
              "type": "object"
            }
          }

env: can't execute 'node --harmony': No such file or directory

env: can't execute 'node --harmony': No such file or directory

Getting this in Alpine Linux running in a Docker container. Seems that passing the --harmony flag won't work on some Linux distributions, as described for example here:
lambtron/emojipacks#94

Seeing that the --harmony flag was there at Dec 12 2016.

#!/usr/bin/env node --harmony

Could the flag be dropped now to support more linux distributions?

In RAML 1 to OAS3 conversion, resource description should not be a lost semantic

From OAS3 specifications:

Paths may have an optional short summary and a longer description for documentation purposes. This information is supposed to be relevant to all operations in this path. description can be multi-line and supports Markdown (CommonMark) for rich text representation.

Example

paths:
  /users/{id}:
    summary: Represents a user
    description: >
      This resource represents an individual user in the system.
      Each user is identified by a numeric `id`.
    get:
      ...
    patch:
      ...
    delete:
      ...

ERROR ./node_modules/raml-1-parser/dist/parser/ast.core/expanderLL.js at compilation.

Currently, I am trying to use the library in an Angular application but I got an error at

ng serve

Can you please tell me if there is any walk around or solution for this?
Running under NPM 6.4.1, Node v10.15.3

ERROR in ./node_modules/raml-1-parser/dist/parser/ast.core/expanderLL.js Module not found: Error: Can't resolve '../../../resources/errorMessages' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser\ast.core' ERROR in ./node_modules/raml-1-parser/dist/parser/ast.core/LowLevelASTProxy.js Module not found: Error: Can't resolve '../../../resources/errorMessages' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser\ast.core' ERROR in ./node_modules/raml-1-parser/dist/parser/ast.core/overloadingValidator.js Module not found: Error: Can't resolve '../../../resources/errorMessages' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser\ast.core' ERROR in ./node_modules/raml-1-parser/dist/parser/ast.core/builder.js Module not found: Error: Can't resolve '../../../resources/errorMessages' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser\ast.core' ERROR in ./node_modules/raml-1-parser/dist/parser/ast.core/mutators.js Module not found: Error: Can't resolve '../../../resources/errorMessages' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser\ast.core' ERROR in ./node_modules/raml-1-parser/dist/parser/ast.core/linter.js Module not found: Error: Can't resolve '../../../resources/errorMessages' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser\ast.core' ERROR in ./node_modules/raml-1-parser/dist/parser/jsyaml/json2lowLevel.js Module not found: Error: Can't resolve '../../../resources/errorMessages' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser\jsyaml' ERROR in ./node_modules/raml-1-parser/dist/parser/jsyaml/jsyaml2lowLevel.js Module not found: Error: Can't resolve '../../../resources/errorMessages' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser\jsyaml' ERROR in ./node_modules/raml-1-parser/dist/parser/tools/schemaModelGen.js Module not found: Error: Can't resolve '../../../resources/errorMessages' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser\tools' ERROR in ./node_modules/raml-1-parser/dist/parser/wrapped-ast/wrapperHelper08.js Module not found: Error: Can't resolve '../../../resources/errorMessages' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser\wrapped-ast' ERROR in ./node_modules/raml-1-parser/dist/parser/wrapped-ast/wrapperHelper.js Module not found: Error: Can't resolve '../../../resources/errorMessages' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser\wrapped-ast' ERROR in ./node_modules/raml-1-parser/dist/parser/highLevelImpl.js Module not found: Error: Can't resolve '../../resources/errorMessages' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser' ERROR in ./node_modules/raml-1-parser/dist/parser/apiLoader.js Module not found: Error: Can't resolve '../../resources/errorMessages' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser' ERROR in ./node_modules/raml-1-parser/dist/parser/lowLevelAST.js Module not found: Error: Can't resolve '../../resources/errorMessages' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser' ERROR in ./node_modules/raml-typesystem/dist/src/nominal-types.js Module not found: Error: Can't resolve '../../resources/errorMessages' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-typesystem\dist\src' ERROR in ./node_modules/raml-typesystem/dist/src/index.js Module not found: Error: Can't resolve '../../resources/errorMessages' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-typesystem\dist\src' ERROR in ./node_modules/raml-typesystem/dist/src/xmlio.js Module not found: Error: Can't resolve '../../resources/errorMessages' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-typesystem\dist\src' ERROR in ./node_modules/raml-typesystem/dist/src/jsonSchemaValidation.js Module not found: Error: Can't resolve '../../resources/errorMessages' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-typesystem\dist\src' ERROR in ./node_modules/raml-typesystem/dist/src/typesystem.js Module not found: Error: Can't resolve '../../resources/errorMessages' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-typesystem\dist\src' ERROR in ./node_modules/raml-definition-system/dist/index.js Module not found: Error: Can't resolve './RAML08' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-definition-system\dist' ERROR in ./node_modules/raml-definition-system/dist/index.js Module not found: Error: Can't resolve './RAML10' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-definition-system\dist' ERROR in ./node_modules/oas-raml-converter/lib/helpers/ramlErrorModel.js Module not found: Error: Can't resolve 'fs' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\oas-raml-converter\lib\helpers' ERROR in ./node_modules/oas-raml-converter/lib/raml/ramlConverter.js Module not found: Error: Can't resolve 'fs' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\oas-raml-converter\lib\raml' ERROR in ./node_modules/json-schema-ref-parser/lib/resolvers/http.js Module not found: Error: Can't resolve 'http' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\json-schema-ref-parser\lib\resolvers' ERROR in ./node_modules/json-schema-ref-parser/lib/resolvers/http.js Module not found: Error: Can't resolve 'https' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\json-schema-ref-parser\lib\resolvers' ERROR in ./node_modules/oas-raml-converter/lib/helpers/ramlErrorModel.js Module not found: Error: Can't resolve 'os' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\oas-raml-converter\lib\helpers' ERROR in ./node_modules/oas-raml-converter/lib/raml/ramlConverter.js Module not found: Error: Can't resolve 'path' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\oas-raml-converter\lib\raml' ERROR in ./node_modules/raml-1-parser/dist/schema.js Module not found: Error: Can't resolve 'path' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist' ERROR in ./node_modules/raml-1-parser/dist/parser/apiLoader.js Module not found: Error: Can't resolve 'path' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser' ERROR in ./node_modules/raml-1-parser/dist/parser/highLevelImpl.js Module not found: Error: Can't resolve 'path' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser' ERROR in ./node_modules/raml-1-parser/dist/parser/lowLevelAST.js Module not found: Error: Can't resolve 'path' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser' ERROR in ./node_modules/raml-1-parser/dist/parser/ast.core/linter.js Module not found: Error: Can't resolve 'path' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser\ast.core' ERROR in ./node_modules/raml-1-parser/dist/parser/ast.core/namespaceResolver.js Module not found: Error: Can't resolve 'path' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser\ast.core' ERROR in ./node_modules/raml-1-parser/dist/parser/jsyaml/jsyaml2lowLevel.js Module not found: Error: Can't resolve 'path' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser\jsyaml' ERROR in ./node_modules/raml-1-parser/dist/parser/wrapped-ast/wrapperHelper.js Module not found: Error: Can't resolve 'path' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser\wrapped-ast' ERROR in ./node_modules/raml-1-parser/dist/parser/wrapped-ast/wrapperHelper08.js Module not found: Error: Can't resolve 'path' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\parser\wrapped-ast' ERROR in ./node_modules/raml-1-parser/dist/util/jsonSerializerHL.js Module not found: Error: Can't resolve 'path' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\util' ERROR in ./node_modules/raml-1-parser/dist/util/jsonSerializer.js Module not found: Error: Can't resolve 'path' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\util' ERROR in ./node_modules/raml-1-parser/dist/util/contentprovider.js Module not found: Error: Can't resolve 'path' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\raml-1-parser\dist\util' ERROR in ./node_modules/oas-raml-converter/lib/utils/url.js Module not found: Error: Can't resolve 'request' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\oas-raml-converter\lib\utils' ERROR in ./node_modules/xml2js/lib/parser.js Module not found: Error: Can't resolve 'timers' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\xml2js\lib' ERROR in ./node_modules/loophole/lib/loophole.js Module not found: Error: Can't resolve 'vm' in 'C:\develop\api-governance-tool\GovernanceAPIDashboard\node_modules\loophole\lib'

how to run ?

oas-raml-converter --from OAS --to RAML10 api_doc.yml > raml.yml
/usr/bin/env: โ€˜node --harmonyโ€™: No such file or directory

RAML json schema REFs are not resolved recursively

Hi,

Thanks for this converter!
I'm trying to convert some RAML1.0 to OAS2.

I use this RAML file:

#%RAML 1.0

title: Webhooks
version: 0
baseUri: https://example.com/v0/d/payments
mediaType: application/json
protocols: [ HTTPS ]
documentation:
  - title: Payment Provider Webhooks
    content: Allows integration of a payment provider.

/instruments:
  displayName: Instruments webhooks
  description: |
    Instrument webhooks description
  post:
    displayName: Create financial instrument
    body:
      application/json:
        type: !include hook/create_instrument.json
    description: |
      Description here
    responses:
      200:
        description: |
          The operation was successful.
        body:
         application/json:
           type: !include hook/operation_success.json

This last line import this hook/operation_success.json file:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "array",
    "items": {
        "items": {
            "$ref": "./financial_instrument_transaction.json"
        }
    }
}

The $ref field points to a file that lives in the same folder. When I build my html output from RAML, everything is fine.

But when I convert my file to OAS2, i get an incorrect $ref value, notice "$ref": "./financial_instrument_transaction.json":

{
  "swagger": "2.0",
  "info": {
    "title": "Webhooks",
    "version": "0"
  },
  "host": "example.com",
  "basePath": "/v0/d/payments",
  "schemes": [
    "https"
  ],
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "paths": {
    "/instruments": {
      "post": {
        "description": "Description here\n",
        "operationId": "Create financial instrument",
        "responses": {
          "200": {
            "description": "The operation was successful.\n",
            "schema": {
              "title": "Schema of a successful financial operation.",
              "description": "A list of transactions that resulted from a successful operation. If the operation is asynchronous, this list is empty. To complete the request, use the Payment Provider Asynchronous API to notify NewStore of the outcome of the request.",
              "type": "array",
              "items": {
                "type": "string",
                "items": {
                  "$ref": "./financial_instrument_transaction.json"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "schema": {
              "title": "Create instrument operation schema",
              "required": [
                "account_id"
              ],
              "type": "object",
              "properties": {
                "account_id": {
                  "type": "string"
                }
              }
            },
            "in": "body",
            "name": "body",
            "required": true
          }
        ]
      }
    }
  }
}

So it seems that the converter does not resolve refs recursively. The correct conversion should be "$ref": "hook/financial_instrument_transaction.json" or the whole referenced file should be pulled in (which would make more sense).

Could this be fixed, somehow?

Thanks ๐Ÿ™‚

OAS 2 to RAML 1 conversion generates invalid '0' media type when input OAS 2 file contains single string "examples" value

observed behaviour

When an input OAS 2 file includes something of the form examples: <string> when defining a response, the resulting generated RAML 1 output file contains an invalid / fictitious media type '0' .

note, this input OAS 2 file in this scenario appears to be invalid, as the spec states that the examples value should be an object keyed by mime types. in this case, the input has a single string instead of an example object. https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#exampleObject

desired behaviour

it'd be preferable if the input was rejected for being an invalid OAS 2 file, or if the invalid examples value was ignored and otherwise output was generated normally.

version of oas-raml-converter where behaviour is observed

whatever is running currently in https://mulesoft.github.io/oas-raml-converter/ at time of writing
presumably current tip of master?: cadc93e

detail

input format: OAS 2
input content:

swagger: '2.0'
info:
  description: McGuffin API
  version: 0.0.0
  title: McGuffin API
schemes:
  - http
paths:
  /mcguffin:
    get:
      operationId: GetMcGuffin
      produces:
        - application/json
      responses:
        '200':
          description: OK
          schema:
            $ref: '#/definitions/McGuffinResponse'
          examples: blah
definitions:
  McGuffinResponse:
    type: object
    properties:
      status:
        type: string
    required:
      - status

output format: RAML 1.0
output content:

#%RAML 1.0
title: McGuffin API
description: McGuffin API
version: 0.0.0
protocols:
  - HTTP
types:
  McGuffinResponse:
    type: object
    properties:
      status:
        type: string
annotationTypes:
  oas-responses-example:
    type: string
    allowedTargets: TypeDeclaration
/mcguffin:
  get:
    displayName: GetMcGuffin
    responses:
      '200':
        description: OK
        body:
          '0':
            type: McGuffinResponse
            (oas-responses-example): h

In OAS30, nullables are faultily converted to generic "object" type

oas-raml-coverter version 1.1.35

Similar to #42.

bar2 field of FooFromBar schema should be of schema Foo with nullable option set, but is instead set to "type": "object"

OAS30 reference on nullable

Full reproduction

RAML Source

types:
  Foo:
    properties:
      bar1: number
  FooFromBar:
    properties:
      bar2: Foo?

Expected (oas3+json)

{
  "components": {
    "schemas": {
      "Foo": {
        "properties": {
          "bar1": {
            "type": "number"
          }
        },
        "required": [
          "bar1"
        ],
        "type": "object"
      },
      "FooFromBar": {
        "properties": {
          "bar2": {
            "nullable": true,
            "allOf": {
              "$ref": "#/components/schemas/Foo"
            }
          }
        },
        "required": [
          "bar2"
        ],
        "type": "object"
      }
    }
  }
}

Observed (oas3+json)

{
  "components": {
    "schemas": {
      "Foo": {
        "properties": {
          "bar1": {
            "type": "number"
          }
        },
        "required": [
          "bar1"
        ],
        "type": "object"
      },
      "FooFromBar": {
        "properties": {
          "bar2": {
            "type": "object"
          }
        },
        "required": [
          "bar2"
        ],
        "type": "object"
      }
    }
  }
}

all required property in response object set to false

When converting from OAS2.0 to RAML all the required field in properties of the response objects are set to false regardless of the actual boolean value in OAS2.0.

Assumed removing the property from the OAS2.0 would at least use the default as per https://github.com/mulesoft/oas-raml-converter/blob/master/docs/OAS20-to-RAML10.md
"In RAML, required is true by default. Mapped to required=false when necessary."
but still is always set to false.

Occurs with both json and yaml input.
Confirmed issue with multiple specification examples including the classic "Swagger Petstore" - see attached.

I applaud the commitment to interoperability (https://blogs.mulesoft.com/dev/api-dev/open-api-raml-better-together/). Given this, hoping this bug can be addressed quickly.

Surely other users have hit this issue?
petstoreINPUT.yaml.txt
petstoreOUTPUT.raml.txt

When run different scripts that convert the same oas to raml, return differents results.

For example:
OasFile:

{
  "swagger": "2.0",
  "info": {
    "version": "1.0.0",
    "title": "Swagger Petstore"
  },
  "host": "petstore.swagger.io",
  "basePath": "/api",
  "schemes": [
    "http"
  ],
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "paths": {
    "/reviews": {
      "x-raml-resource-displayName": "reviews"
    },
    "/reviews/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "description": "ID of review",
          "required": true,
          "type": "string"
        }
      ],
      "post": {
        "operationId": "GET_reviews-id",
        "description": "Returns a review",
        "parameters": [
          {
            "name": "body",
            "in": "body",
            "description": "Review to add to the store",
            "schema": {
              "$ref": "#/definitions/NewReview"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "review response",
            "examples": {
              "application/json": {
                "$ref": "#/definitions/Review"
              }
            }
          }
        }
      },
      "x-raml-resource-displayName": "{id}"
    }
  },
  "definitions": {
    "Review": {
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32"
        },
        "message": {
          "type": "string"
        }
      },
      "type": "object"
    },
    "NewReview": {
      "properties": {
        "title": {
          "type": "string"
        }
      },
      "type": "object"
    }
  }
}

Script 1:

#!/usr/local/bin/nano

const fs = require('fs');

const path = './oasFile.json';
const conv = require('oas-raml-converter');
const sw = new conv.Converter(conv.Formats.SWAGGER, conv.Formats.RAML10);

sw.convertFile(path).then((a) => console.log(a));

Script 2:

#!/usr/local/bin/nano

const fs = require('fs');

const path = './oasFile.json';
const conv = require('oas-raml-converter');
const sw = new conv.Converter(conv.Formats.SWAGGER, conv.Formats.RAML10);

sw.convertFile(path).then((a) => a);
sw.convertFile(path).then((a) => console.log(a));

Wrong OAS30 object type definition which faultily inherits from string

oas-raml-coverter version 1.1.35

The OAS parser used by ReDoc project complains about a forbidden definition:

Error: Incompatible types in allOf at "#/components/schemas/BarFromFoo"

BarFromFoo should not be of "type": "string"

Full reproduction

Raml definition

types:
  Foo:
    type: object
  BarFromFoo:
    type: Foo
    properties:
      foo: string

Expected output

{
  "components": {
    "schemas": {
      "Foo": {
        "type": "object"
      },
      "BarFromFoo": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Foo"
          },
          {
            "properties": {
              "foo": {
                "type": "string"
              }
            },
            "type": "object"
          }
        ]
      }
    }
  }
}

Observed output

{
  "components": {
    "schemas": {
      "Foo": {
        "type": "object"
      },
      "BarFromFoo": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Foo"
          },
          {
            "properties": {
              "foo": {
                "type": "string"
              }
            },
            "type": "object"
          }
        ],
        "type": "string"
      }
    }
  }
}

Error messages should include more detail

I would like to add a reference to the line and column number in the source file where the error was encountered, to the error messages. The current error messages are too terse to provide useful feedback.

Library references cannot be chained

I'm not sure if this is a bug, but I'm trying to convert from Swagger (OAS 2.0) to RAML and get error(s):

image

The error is:

Invalid type expression syntax: "My.Custom.Type". Caused by : Library references cannot be chained: My.Custom.Type at character : ...

The best thing I could find is this QA which suggests to have My.Custom.Type defined as Library.


Is there a way to have OAS RAML Converter create a RAML file + libraries for types, instead of a single giant RAML file?

Build problems

MacOS Mojave.
Got problems with package nan and fsevents.
Helped running following commands:

npm install fsevents
npm install nan

Fix this please.

In RAML1 to OAS3 conversion, header examples should be preserved

Currently, header examples are lost while they are supported in OAS3. They are not designated as a lost semantic, so they should be included in header schema.

RAML 1 source

#%RAML 1.0
title: headers example
version: 1
/last-article:
 get:
   description: Get latest article
   responses:
     200:
       headers:
         Last-Modified-By:
           description: Author of latest modification.
           example: UTF-8'fr'Jean-Pierre%20Dupont

Expected output (yaml+json)

{
  "openapi": "3.0.0",
  "info": {
    "title": "headers example",
    "version": "1"
  },
  "servers": [],
  "paths": {
    "/last-article": {
      "get": {
        "responses": {
          "200": {
            "description": "",
            "headers": {
              "Last-Modified-By": {
                "description": "Author of latest modification.",
                "schema": {
                  "type": "string",
                  "example": "UTF-8'fr'Jean-Pierre%20Dupont"
                }
              }
            }
          }
        },
        "description": "Get latest article",
        "operationId": "GET_last-article"
      }
    }
  },
  "components": {
    "schemas": {},
    "responses": {},
    "parameters": {},
    "examples": {},
    "requestBodies": {},
    "headers": {},
    "securitySchemes": {},
    "links": {},
    "callbacks": {}
  }
}

Observed output (yaml+json)

{
  "openapi": "3.0.0",
  "info": {
    "title": "headers example",
    "version": "1"
  },
  "servers": [],
  "paths": {
    "/last-article": {
      "get": {
        "responses": {
          "200": {
            "description": "",
            "headers": {
              "Last-Modified-By": {
                "description": "Author of latest modification.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "description": "Get latest article",
        "operationId": "GET_last-article"
      }
    }
  },
  "components": {
    "schemas": {},
    "responses": {},
    "parameters": {},
    "examples": {},
    "requestBodies": {},
    "headers": {},
    "securitySchemes": {},
    "links": {},
    "callbacks": {}
  }
}

Preserve !include, preserve "schemas"

https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md#applying-security-schemes

securitySchemes should still have their schema locations preserved.

I think schemas, since deprecated in raml 1.0, can be replaced by types, followed by the !include statements, but without reference to a type, see below, looks like string is applied...

#%RAML 0.8
title: Flickr API
baseUri: https://api.flickr.com/services
version: test-version
securitySchemes:
  - oauth_2_0: !include securitySchemes/raml08_oauth_2_0.raml
  - tokenSchema: !include securitySchemes/tokenSchema.raml
schemas:
  - photoPost-xml: !include /schemas/photoPost-xml-schema.xsd
  - okResponse-xml: !include /schemas/okResponse-xml-schema.xsd
#%RAML 1.0
title: Flickr API
version: test-version
protocols:
  - HTTPS
baseUri: 'https://api.flickr.com/services'
securitySchemes:
  oauth_2_0: {}
  tokenSchema: {}
types:
  photoPost-xml:
    type: string
  okResponse-xml:
    type: string

In OAS3, converter should never use `$ref` at schema root since it prevents overriding metadata fields

oas-raml-coverter version 1.1.35

In the provided example, Foo description field is lost when converted to OAS3 because of the use of $ref which should be replaced by allOf.

The reason is explained in the OAS3 specification document:

Any sibling elements of a $ref are ignored. This is because $ref works by replacing itself and everything on its level with the definition it is pointing at.

Full reproduction

Raml definition

#%RAML 1.0
title: Bug report
types:
  FooCore:
    description: This is FooCore
    properties:
      name: string
  Foo:
    description: This is Foo, not FooCore
    type: FooCore

Expected output (oas3+json, irrelevant fields removed)

{
  "openapi": "3.0.0",
  "info": {
    "title": "Bug report",
    "version": "undefined"
  },
  "components": {
    "schemas": {
      "FooCore": {
        "description": "This is FooCore",
        "properties": {
          "name": {
            "type": "string"
          }
        },
        "required": [
          "name"
        ],
        "type": "object"
      },
      "Foo": {
        "description": "This is Foo, not FooCore",
        "allOf": [
          {
            "$ref": "#/components/schemas/FooCore"
          }
        ]
      }
    }
  }
}

Observed output (oas3+json, irrelevant fields removed)

{
  "openapi": "3.0.0",
  "info": {
    "title": "Bug report",
    "version": "undefined"
  },
  "components": {
    "schemas": {
      "FooCore": {
        "description": "This is FooCore",
        "properties": {
          "name": {
            "type": "string"
          }
        },
        "required": [
          "name"
        ],
        "type": "object"
      },
      "Foo": {
        "description": "This is Foo, not FooCore",
        "$ref": "#/components/schemas/FooCore"
      }
    }
  }
}

Union Type ignored when converting to OAS3

Example 15 of 'Export from Raml 1.0 to OAS 3.0' seems not behaving as documented:

expected:

Device:
anyOf:
- "$ref": "#/components/schemas/Phone"
- "$ref": "#/components/schemas/Notebook"

but the output is (both in online converter and builded project):

"Device": {
"type": "object"
}

raml array of objects in query parameters converts to array of string

In my raml definition I have an endpoint with query parameters described as follows:

queryParameters:
      financial_documents:
        description: list of financial document to get information in the format ["type,series,doc,statusflag","type2,series2,doc2,statusflag2"]
        type: array
        items: ATDFinancialDocumentKey
        minItems: 1
        maxItems: 15
        example: | 
         [{"type":"REC","series":"REC2017","number":"1","statusFlag":"C"}]

when converting to oas20 I get the following:

"parameters": [
          {
            "minItems": 1,
            "maxItems": 15,
            "description": "list of financial document to get information in the format [\"type,series,doc,statusflag\",\"type2,series2,doc2,statusflag2\"]",
            "type": "array",
            "items": {
              "type": "string"
            },
            "in": "query",
            "name": "financial_documents",
            "required": true
          }
        ]

Is this the default behaviour? I would expect the financial_documents query parameter to be converted with a reference to a definition. Something like:

"parameters": [
          {
            "minItems": 1,
            "maxItems": 15,
            "description": "list of financial document to get information in the format [\"type,series,doc,statusflag\",\"type2,series2,doc2,statusflag2\"]",
            "type": "array",
            "items": {
              "$ref": "#/definitions/ATDFinancialDocumentKey"
            },
            "in": "query",
            "name": "financial_documents",
            "required": true
          }
        ]

RAML 1.0 > OAS 3.0 not conforming to the spec when merging traits and resourceTypes

My RAML has something along these lines:

#%RAML 1.0
title: My API
version: v1
baseUri: https://{tenant}.test.com/api/{version}/organization/{organizationId}
baseUriParameters:
  tenant:
    type: string
    displayName: Tenant Identifier
    default: yourSubDomain
  organizationId:
    type: UUID
    displayName: ID of the Organization to interact with
    default: 00000000-0000-4000-0000-000000000000

traits:
  # Using Default trait to specify support for application/json, as using global mediaType for this would be overridden by Printable trait
  Default:
    headers:
      Accept:
        type: string
        enum: [application/json]
        default: application/json
  Printable:
    headers:
      Accept:
        type: string
        enum: [application/pdf] #does this add to the enum, or does it overwrite
    responses:
      200:
        body:
          application/pdf:

resourceTypes: #Add error types, more response codes
  Collection:
    get:
      is: [ Default ]
      responses:
        200:
          body:
            application/json:
              type: <<item>>[]
  Member:
    get:
      is: [ Default ]
      responses:
        200:
          body:
            application/json:
              type: <<item>>

types:
  Company:
    properties:
      id: string

/companies:
  type: { Collection: {item: Company} }

  /{id}:
    type: { Member: {item: Company} }

    get:
      is: [ Printable ]

What this basically does is say: a GET on companies/{id} can either Accept application/json or application/pdf.

When you run this through the converter to generate OAS 3.0, only the application/pdf is properly included:

openapi: 3.0.0
info:
  title: My API
  version: v1
servers:
  - url: 'https://{tenant}.test.com/api/{version}/organization/{organizationId}'
    variables:
      tenant:
        default: tenant
      version:
        default: version
      organizationId:
        default: organizationId
paths:
  /companies:
    get:
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Company'
      operationId: GET_companies
      parameters:
        - $ref: '#/components/parameters/trait_Default_Accept'
  '/companies/{id}':
    get:
      responses:
        '200':
          $ref: '#/components/responses/trait_Printable_200'
      operationId: GET_companies-id
      parameters:
        - $ref: '#/components/parameters/trait_Printable_Accept'
    parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
components:
  schemas:
    Company:
      properties:
        id:
          type: string
      required:
        - id
      type: object
  responses:
    trait_Printable_200:
      description: ''
  parameters:
    trait_Default_Accept:
      name: Accept
      in: header
      required: true
      schema:
        default: application/json
        enum:
          - application/json
        type: string
    trait_Printable_Accept:
      name: Accept
      in: header
      required: true
      schema:
        enum:
          - application/pdf
        type: string
  examples: {}
  requestBodies: {}
  headers: {}
  securitySchemes: {}
  links: {}
  callbacks: {}

I've also tested with the same RAML file and generating HTML data from it using https://www.npmjs.com/package/raml2html and that library does parse stuff as expected, so I think my RAML is ok.

I've also Looked at the RAML specs to see how stuff in the RAML file should merge, see https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md/#resource-types-and-traits-effect-on-collections. I've also put the sample RAML code from the spec through the converter and the outcome is not correct:

#%RAML 1.0
title: Example API
version: v1
traits:
  withQueryParameters:
    queryParameters:
      platform:
        enum:
          - win
          - mac
/installer:
  get:
    is: [ withQueryParameters ]
    queryParameters:
      platform: #the actual enum is [ mac, unix, win ]
        enum:
          - mac
          - unix

becomes

{
  "openapi": "3.0.0",
  "info": {
    "title": "Example API",
    "version": "v1"
  },
  "servers": [],
  "paths": {
    "/installer": {
      "get": {
        "responses": {
          "default": {
            "description": ""
          }
        },
        "operationId": "GET_installer",
        "parameters": [
          {
            "$ref": "#/components/parameters/trait_withQueryParameters_platform"
          }
        ]
      }
    }
  },
  "components": {
    "schemas": {},
    "responses": {},
    "parameters": {
      "trait_withQueryParameters_platform": {
        "name": "platform",
        "in": "query",
        "required": true,
        "schema": {
          "enum": [
            "win",
            "mac"
          ],
          "type": "string"
        }
      }
    },
    "examples": {},
    "requestBodies": {},
    "headers": {},
    "securitySchemes": {},
    "links": {},
    "callbacks": {}
  }
}

As you can see in the above example, the merging of the enum is not done according to the RAML spec

RAML Extension Chain doesn't go far enough

So I have these files:

user_short.raml

#% RAML 1.0 DataType

properties:
  user_id: string

user_standard.raml

#% RAML 1.0 DataType

type: !include user_short.raml
properties:
  birthday: string
  gender:
    type: string
    enum: ['Male', 'Female', 'Non-Binary']

user_full.raml

#% RAML 1.0 DataType

type: !include user_standard.raml
properties:
  country_code: string

When I convert to HTML with raml2html, it shows the user_full object as having the user_id property, but when I use this tool to convert to swagger, the definitions are:

  "definitions": {
    "user_short": {
      "properties": {
        "user_id": {
          "type": "string"
        }
      },
      "required": [
        "user_id"
      ],
      "type": "object"
    },
    "user_standard": {
      "properties": {
        "birthday": {
          "type": "string"
        },
        "gender": {
          "enum": [
            "Male",
            "Female",
            "Non-Binary"
          ],
          "type": "string"
        },
        "user_id": {
          "type": "string"
        }
      },
      "required": [
        "birthday",
        "gender",
        "user_id"
      ],
      "type": "object"
    },
    "user_full": {
      "properties": {
        "country_code": {
          "type": "string"
        },
        "birthday": {
          "type": "string"
        },
        "gender": {
          "enum": [
            "Male",
            "Female",
            "Non-Binary"
          ],
          "type": "string"
        }
      },
      "required": [
        "country_code",
        "birthday",
        "gender"
      ],
      "type": "object"
    }

You can see that user_standard has user_id, and user_full has items from user_standard, but doesn't have user_id from user_short

RAML 1.0 to OAS 3.0 doesn't convert baseUriParameters default value

The variable default value in OAS is being set to the variable name, not the variable's default value.

Given

#%RAML 1.0
title: MyServer
protocols: [ HTTP, HTTPS ]
baseUri: http://{myServerURI}/{version}
baseUriParameters:
  myServerURI:
    description: The server URL
    default: localhost
version: v1
oas-raml-converter -f RAML -t OAS30 myserver.raml

Expected

{
  "openapi": "3.0.0",
  "info": {
    "title": "MyServer",
    "version": "v1"
  },
  "servers": [
    {
      "url": "http://{myServerURI}/{version}",
      "variables": {
        "myServerURI": {
          "default": "localhost"
        },
        "version": {
          "default": "v1"
        }
      }
    },
    {
      "url": "https://{myServerURI}/{version}",
      "variables": {

        "myServerURI": {
          "default": "localhost"
        },
        "version": {
          "default": "v1"
        }
      }
    }
  ],
  "paths": {},
  "components": {
    "schemas": {},
    "responses": {},
    "parameters": {},
    "examples": {},
    "requestBodies": {},
    "headers": {},
    "securitySchemes": {},
    "links": {},
    "callbacks": {}
  }
}

Actual

{
  "openapi": "3.0.0",
  "info": {
    "title": "MyServer",
    "version": "v1"
  },
  "servers": [
    {
      "url": "http://{myServerURI}/{version}",
      "variables": {
        "myServerURI": {
          "default": "myServerURI"
        },
        "version": {
          "default": "version"
        }
      }
    },
    {
      "url": "https://{myServerURI}/{version}",
      "variables": {

        "myServerURI": {
          "default": "myServerURI"
        },
        "version": {
          "default": "version"
        }
      }
    }
  ],
  "paths": {},
  "components": {
    "schemas": {},
    "responses": {},
    "parameters": {},
    "examples": {},
    "requestBodies": {},
    "headers": {},
    "securitySchemes": {},
    "links": {},
    "callbacks": {}
  }
}

Thanks

Invalid enum translation

I have a yaml that is translated to an invalid raml. The issue is with enum with true and false values.

Yaml:

  /temperature/{zoneId}/heater/{state}:
    post:
      tags:
      - Environment
      description: turns the heater on or off
      operationId: setHeaterState
      parameters:
      - name: zoneId
        in: path
        required: true
        type: string
      - name: state
        in: path
        required: true
        type: string
        enum:
        - false
        - true
      responses:
        200:
          description: Status of the operation
          schema:
            $ref: '#/definitions/ApiResponse'
      x-swagger-router-controller: Environment

Translated:

  '/{zoneId}':
    /heater:
      '/{state}':
        uriParameters:
          state:
            required: true
            type: string
            enum:
              - false # error: string is expected
              - true  # error: string is expected
        post:
          (oas-x-swagger-router-controller): Environment
          displayName: setHeaterState
          description: turns the heater on or off
          responses:
            '200':
              body:
                application/json:
                  type: ApiResponse
              description: Status of the operation
          (oas-tags):
            - Environment

It seems that it would be enough to replace

enum:
  - false
  - true

With

enum:
  - "false"
  - "true"

I attach example files:

  • enum-issue.zip
    • input.yaml
    • output.raml
    • valid-example.raml

enum-issue.zip

In OAS30, converter should output all content types for one peculiar path

oas-raml-coverter version 1.1.35

/foo route with GET method serves two representations of the same resource, one simple and one more complex, but all with the same format (json). Both content types application/vnd.representation1+json and application/vnd.representation2+json should be defined in OAS path /foo, but only one gets picked.

Full reproduction

RAML Source

/foo:
  get:
    responses:
      200:
        body:
          'application/vnd.representation1+json':
            type:
              properties:
                foo1: string
          'application/vnd.representation2+json':
            type:
              properties:
                foo1: number

expected (oas3+json)

{
  "paths": {
    "/foo": {
      "get": {
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/vnd.representation1+json": {
                "schema": {
                  "properties": {
                    "foo1": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "foo1"
                  ]
                }
              },
              "application/vnd.representation2+json": {
                "schema": {
                  "properties": {
                    "foo1": {
                      "type": "number"
                    }
                  },
                  "required": [
                    "foo1"
                  ]
                }
              }
            }
          }
        },
        "operationId": "GET_foo"
      }
    }
  }
}

observed (oas3+json)

Only the last content type is picked.

{
  "paths": {
    "/foo": {
      "get": {
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/vnd.representation2+json": {
                "schema": {
                  "properties": {
                    "foo1": {
                      "type": "number"
                    }
                  },
                  "required": [
                    "foo1"
                  ]
                }
              }
            }
          }
        },
        "operationId": "GET_foo"
      }
    }
  }
}

./util import issue

just running the tool from an cloned repo gives the following error:

converting ... ../../swagger2.0/swagger.json
module.js:472
throw err;
^

Error: Cannot find module './util'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object. (C:\Users\wovander\Documents\Wouter\API\ivp-vDCM\scrip
ts\oas-raml-converter\lib\bin\converter.js:5:12)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)

this happens when running from:
lib/bin/converter.js
when running from
src/bin/converter.js
the next error occurs:

$ sh convert_swagger.sh
converting ... ../../swagger2.0/swagger.json
C:\Users\wovander\Documents\Wouter\API\ivp-vDCM\scripts\oas-raml-converter\src\r
aml10\raml10Converter.js:39
_loadFile(filePath:string, options:any) {
^
SyntaxError: Unexpected token :
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object. (C:\Users\wovander\Documents\Wouter\API\ivp-vDCM\scrip
ts\oas-raml-converter\src\converters\index.js:2:8)

OAS3.0 doesn't support YAML

var raml08ToOas30 = new converter.Converter(converter.Formats.RAML, converter.Formats.OAS30);

raml08ToOas30.convertFile('../client_reference/api_definition/workspace/raml/api.raml', {format: 'yaml'}).then(function(oas) {
  console.log(oas);
})

returns a json insted of raml

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.