mulesoft / oas-raml-converter

(DEPRECATED) Converts between OAS and RAML API specifications
https://mulesoft.github.io/oas-raml-converter/
MIT License
73 stars 48 forks source link

raml1 to oas2 converts ok, but raml1 to oas3 fails #35

Closed amammes closed 6 years ago

amammes commented 6 years ago

#%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?

ForsakenHarmony commented 6 years ago

it isn't expanded?

I'm not sure what you're showing

amammes commented 6 years ago

shouldn't

schemas: { geoCoordinates: [Object] },

detail the properties of geoCoordinates (latitude, longitude)?

ForsakenHarmony commented 6 years ago

Where do you get that output?

It might just not display it and says [Object] because it's an object

amammes commented 6 years ago

I get that output on the windows cmd when I run the following script:

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

var options = {
    validate: true, // Parse both input and output to check that its a valid document
    validateImport: true, // Only validate input
    validateExport: true, // Only validate output
    format: 'yaml' // Output format: json (default for OAS) or yaml (default for RAML)
};

ramlToOas.convertFile('broken4.raml', options).then(function(raml) {
  console.log(raml); // raml is raml yaml string
})
.catch(function(err) {
  console.error(err);
});

I realize it's an object. The issue is that the object properties do not appear anywhere. This happens to all my types, they are just converted to Object without any detail.

Just FYI, OS is Windows 10 Pro 64 bit, Nodejs version 9.7.0. oas-raml-converter version oas-raml-converter@1.1.28. Is my node version too new?

ForsakenHarmony commented 6 years ago

can you put JSON.stringify(raml, void 0, 2) in the console.log statement?

amammes commented 6 years ago

That seemed to have done it. I took that js from the examples. Thanks

{
  "openapi": "3.0.0",
  "info": {
    "title": "oas-raml-converter does not process this correctly",
    "version": "undefined"
  },
  "servers": [
    {
      "url": "http://api.samplehost.com/"
    }
  ],
  "paths": {
    "/geoCoordinates": {
      "get": {
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/geoCoordinates"
                }
              }
            }
          }
        },
        "operationId": "GET_geoCoordinates"
      }
    }
  },
  "components": {
    "schemas": {
      "geoCoordinates": {
        "properties": {
          "latitude": {
            "minimum": -90,
            "maximum": 90,
            "format": "double",
            "description": "Latitude (degree range -90 to +90) with positive values for N latitude and negative for S latitude.",
            "type": "number"
          },
          "longitude": {
            "minimum": -180,
            "maximum": 180,
            "format": "double",
            "description": "Longitude (degree range -180 to +180) positive values for E of the prime meridian, and negative values W longitude.",
            "type": "number"
          }
        },
        "required": [
          "latitude",
          "longitude"
        ],
        "type": "object"
      }
    },
    "responses": {},
    "parameters": {},
    "examples": {},
    "requestBodies": {},
    "headers": {},
    "securitySchemes": {},
    "links": {},
    "callbacks": {}
  }
}