raml-org / webapi-parser

API Spec parser based on AMF. Currently supports RAML 0.8, RAML 1.0, OAS 2.0 and OAS 3.0(beta).
Other
68 stars 24 forks source link

Bug: Parser incorrectly translates `protocols` to invalid OAS property Schemas #80

Open xximjasonxx opened 4 years ago

xximjasonxx commented 4 years ago

Library version used E.g. "^0.4.0"

Language library used with JavaScript

Describe the bug When parsing RAML file specifying protocols property the corresponding OAS JSON file contains schemes which is not a valid property for the Specification.

Code that causes a bug

exports.convertRamlToJson = async function(ramlFilePath) {
    const inPath = path.join(__dirname, ramlFilePath);
    const model = await wap.raml10.parse(`file://${inPath}`);
    const resolved = await wap.raml10.resolve(model);

    return await wap.oas30.generateString(resolved);
}

Input RAML Input

#%RAML 1.0
title: File Message PAPI
baseUri: https://someuri
description: This is a prototype File Message Process API
mediaType:
  - application/json
version: 1.0.0
protocols:
  - HTTP

types:
  DocumentContainer: !include datatypes/DocumentContainer.raml

traits:
  errorResponses: !include traits/ErrorResponse.raml

/DocumentDataEvent:
  post:
    displayName: Document Data Event
    responses:
      "200":
        body:
          type: string
          example: "success"
      "400":
        body:
          type: object
    body:
      type: DocumentContainer

Actual behaviour/output/error JSON Output from above example

{
  "openapi": "3.0.0",
  "info": {
    "title": "File Message PAPI",
    "description": "This is a prototype File Message Process API",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://anypoint.mulesoft.com/mocking/api/v1/links/96097438-ef76-4a55-a9c3-5236724c2fe4/"
    }
  ],
  "schemes": [
    "HTTP"
  ],
  "paths": {
   }
}

Expected behaviour/output Expectation is the parser will not create properties in JSON that are not valid pieces of the OpenAPI Spec

postatum commented 4 years ago

Hi @xximjasonxx.

Thank a lot for reporting this issue!

It looks like a bug of our dependency library. I've reported the bug in the dependency lib repo: https://github.com/aml-org/amf/issues/597