Skip to content
This repository has been archived by the owner on Mar 15, 2019. It is now read-only.

Error converting swagger to raml to swagger #15

Open
glodieu opened this issue Aug 17, 2016 · 4 comments
Open

Error converting swagger to raml to swagger #15

glodieu opened this issue Aug 17, 2016 · 4 comments

Comments

@glodieu
Copy link
Contributor

glodieu commented Aug 17, 2016

I'm trying to run test that converts from swagger to raml to swagger using this file https://github.com/mulesoft/api-spec-converter/blob/master/example/source/swagger.json that is not working. Test results in a lot of differences.
Thanks.
Gaston

` 167 passing (2s)
46 pending
1 failing

  1. Converter convert should convert reversly from swagger to raml without loss:
  AssertionError: expected { Object (swagger, schemes, ...) } to deeply equal { Object (swagger, info, ...) }
  + expected - actual

   {
  -  "basePath": "//localhost:3000"
  +  "basePath": ""
     "consumes": [
       "application/json"
     ]
     "definitions": {
           "name"
         ]
       }
     }
  -  "host": "http"
  +  "host": "http://localhost:3000"
     "info": {
       "description": "A sample API"
       "title": "Swagger petstore"
       "version": "1.0.0"
     }
     "paths": {
       "/pets": {
         "delete": {
  +        "consumes": [
  +          "application/json"
  +        ]
           "description": "Deletes all pets, optionally filtered by one or more criteria"
           "operationId": "deletePets"
           "parameters": [
             {
  +            "description": "Filters pets by one or more tags"
  +            "in": "query"
  +            "items": {
  +              "type": "string"
  +            }
  +            "name": "tags"
  +            "type": "array"
  +          }
  +          {
               "description": "Filters pets by type (dog, cat, or bird)"
               "in": "query"
               "name": "type"
  -            "required": false
               "type": "string"
             }
             {
               "description": "Filters pets by age"
               "in": "query"
               "name": "age"
  -            "required": false
               "type": "integer"
             }
             {
               "description": "Filters pets by date of birth"
               "in": "query"
               "name": "dob"
  -            "required": false
               "type": "string"
             }
             {
               "description": "Filters pets by city"
               "in": "query"
               "name": "address.city"
  -            "required": false
               "type": "string"
             }
             {
               "description": "Filters pets by state"
               "in": "query"
               "name": "address.state"
  -            "required": false
               "type": "string"
             }
             {
               "description": "Filters pets by zip code"
               "in": "query"
               "name": "address.zipcode"
  -            "required": false
               "type": "integer"
             }
             {
               "description": "Filters pets by veterinarian name"
               "in": "query"
               "name": "vet.name"
  -            "required": false
               "type": "string"
             }
             {
               "description": "Filters pets by veterinarian city"
               "in": "query"
               "name": "vet.address.city"
  -            "required": false
               "type": "string"
             }
             {
               "description": "Filters pets by veterinarian state"
               "in": "query"
               "name": "vet.address.state"
  -            "required": false
               "type": "string"
             }
             {
               "description": "Filters pets by veterinarian zip code"
               "in": "query"
               "name": "vet.address.zipcode"
  -            "required": false
               "type": "integer"
             }
             {
               "description": ""
               "required": false
               "type": "string"
             }
           ]
  +        "produces": [
  +          "application/json"
  +        ]
           "responses": {
             "400": {
               "description": "Returns the pets that were deleted"
               "schema": {
           }
           "summary": ""
         }
         "get": {
  +        "consumes": [
  +          "application/json"
  +        ]
           "description": "Returns all pets, optionally filtered by one or more criteria"
           "operationId": "findPets"
           "parameters": [
             {
  +            "description": "Filters pets by one or more tags"
  +            "in": "query"
  +            "items": {
  +              "type": "string"
  +            }
  +            "name": "tags"
  +            "type": "array"
  +          }
  +          {
               "description": "Filters pets by type (dog, cat, or bird)"
               "in": "query"
               "name": "type"
  -            "required": false
               "type": "string"
             }
             {
               "description": "Filters pets by age"
               "in": "query"
               "name": "age"
  -            "required": false
               "type": "integer"
             }
             {
               "description": "Filters pets by date of birth"
               "in": "query"
               "name": "dob"
  -            "required": false
               "type": "string"
             }
             {
               "description": "Filters pets by city"
               "in": "query"
               "name": "address.city"
  -            "required": false
               "type": "string"
             }
             {
               "description": "Filters pets by state"
               "in": "query"
               "name": "address.state"
  -            "required": false
               "type": "string"
             }
             {
               "description": "Filters pets by zip code"
               "in": "query"
               "name": "address.zipcode"
  -            "required": false
               "type": "integer"
             }
             {
               "description": "Filters pets by veterinarian name"
               "in": "query"
               "name": "vet.name"
  -            "required": false
               "type": "string"
             }
             {
               "description": "Filters pets by veterinarian city"
               "in": "query"
               "name": "vet.address.city"
  -            "required": false
               "type": "string"
             }
             {
               "description": "Filters pets by veterinarian state"
               "in": "query"
               "name": "vet.address.state"
  -            "required": false
               "type": "string"
             }
             {
               "description": "Filters pets by veterinarian zip code"
               "in": "query"
               "name": "vet.address.zipcode"
  -            "required": false
               "type": "integer"
             }
             {
               "description": ""
               "required": false
               "type": "string"
             }
           ]
  +        "produces": [
  +          "application/json"
  +        ]
           "responses": {
             "400": {
               "description": "Returns the matching pets"
               "schema": {
             }
           }
           "security": [
             {
  -            "oauth2": true
  +            "petstore_auth": [
  +              "read:pets"
  +            ]
             }
           ]
           "summary": ""
         }
  +      "parameters": []
         "post": {
  +        "consumes": [
  +          "application/json"
  +        ]
           "description": "Creates a new pet in the store"
           "operationId": "addPet"
           "parameters": [
             {
  +            "description": "The pet to add to the store"
               "in": "body"
  -            "name": "body"
  +            "name": "pet"
  +            "required": false
               "schema": {
                 "$ref": "#/definitions/pet"
               }
  +            "type": "string"
             }
           ]
  +        "produces": [
  +          "application/json"
  +        ]
           "responses": {
             "201": {
               "description": "Returns the newly-added pet"
               "schema": {
         }
       }
       "/pets/{petName}": {
         "delete": {
  +        "consumes": [
  +          "application/json"
  +        ]
           "description": "Deletes a single pet based on the name supplied"
           "operationId": "deletePet"
  +        "parameters": []
  +        "produces": [
  +          "application/json"
  +        ]
           "responses": {
             "400": {
               "description": "Returns the pet that was deleted"
               "schema": {
           }
           "summary": ""
         }
         "get": {
  +        "consumes": [
  +          "application/json"
  +        ]
           "description": "Returns a pet by name"
           "operationId": "findPetByName"
  +        "parameters": []
  +        "produces": [
  +          "application/json"
  +        ]
           "responses": {
             "400": {
               "description": "Returns the pet data"
               "schema": {
             }
           }
           "summary": ""
         }
  -      "parameters": [
  -        {
  -          "description": "petName"
  -          "in": "path"
  -          "name": "petName"
  -          "required": true
  -          "type": "string"
  -        }
  -      ]
  +      "parameters": []
         "patch": {
  +        "consumes": [
  +          "application/json"
  +        ]
           "description": "Updates a pet by name"
  -        "operationId": "PATCH_pets-petName"
  +        "operationId": ""
           "parameters": [
             {
  +            "description": "The updated pet info"
               "in": "body"
  -            "name": "body"
  +            "name": "pet"
  +            "required": false
               "schema": {
                 "$ref": "#/definitions/pet"
               }
  +            "type": "string"
             }
           ]
  +        "produces": [
  +          "application/json"
  +        ]
           "responses": {
             "400": {
               "description": "Returns the updated pet data"
               "schema": {
         }
       }
       "/pets/{petName}/photos": {
         "get": {
  +        "consumes": [
  +          "application/json"
  +        ]
           "description": "Get a list of the photos for a pet"
  -        "operationId": "GET_pets-petName-photos"
  +        "operationId": ""
  +        "parameters": []
  +        "produces": [
  +          "application/json"
  +        ]
           "responses": {
             "200": {
               "description": "Returns the list of photos"
               "schema": {
             }
           }
           "summary": ""
         }
  -      "parameters": [
  -        {
  -          "description": "petName"
  -          "in": "path"
  -          "name": "petName"
  -          "required": true
  -          "type": "string"
  -        }
  -      ]
  +      "parameters": []
         "post": {
           "consumes": [
             "multipart/form-data"
           ]
             {
               "description": "The photo ID (generated automatically)"
               "in": "formData"
               "name": "id"
  +            "required": false
               "type": "string"
             }
             {
               "description": "A label for the photo"
               "in": "formData"
               "name": "label"
  +            "required": false
               "type": "string"
             }
             {
               "description": "An optional description of the photo"
               "in": "formData"
               "name": "description"
  +            "required": false
               "type": "string"
             }
             {
               "description": "The pet photo"
               "required": true
               "type": "string"
             }
           ]
  +        "produces": [
  +          "application/json"
  +        ]
           "responses": {
             "400": {
               "description": "Returns the photo information"
               "schema": {
         }
       }
       "/pets/{petName}/photos/{id}": {
         "delete": {
  +        "consumes": [
  +          "application/json"
  +        ]
           "description": "Deletes a pet photo"
           "operationId": "deletePetPhoto"
  +        "parameters": []
  +        "produces": [
  +          "application/json"
  +        ]
           "responses": {
             "400": {
               "description": "The photo was deleted successfully"
             }
           }
           "summary": ""
         }
         "get": {
  +        "consumes": [
  +          "application/json"
  +        ]
           "description": "Gets a pet photo"
           "operationId": "getPetPhoto"
  +        "parameters": []
           "produces": [
             "image/jpeg"
           ]
           "responses": {
           "summary": ""
         }
         "parameters": [
           {
  -          "description": "petName"
  -          "in": "path"
  -          "name": "petName"
  -          "required": true
  -          "type": "string"
  -        }
  -        {
             "description": "The ID of the photo"
             "in": "path"
             "name": "id"
             "required": true
     ]
     "schemes": [
       "http"
       "https"
  +    "ws"
     ]
     "securityDefinitions": {
  +    "api_key": {
  +      "in": "header"
  +      "name": "api_key"
  +      "type": "apiKey"
  +    }
       "basic_auth": {
         "description": "basic authentication support"
  +      "name": "basic_auth"
         "type": "basic"
       }
  -    "oauth2": {
  +    "petstore_auth": {
         "authorizationUrl": "http://swagger.io/api/oauth/dialog"
         "flow": "implicit"
  -      "scopes": {}
  +      "scopes": {
  +        "read:pets": "read your pets"
  +        "write:pets": "modify pets in your account"
  +      }
         "type": "oauth2"
       }
     }
     "swagger": "2.0"

  at Assertion.assertEqual (node_modules/chai/lib/chai/core/assertions.js:485:19)
  at Assertion.ctx.(anonymous function) [as equal] (node_modules/chai/lib/chai/utils/addMethod.js:41:25)
  at test/lib/converter.js:121:49
  at lib/converter.js:9:2241

Writing coverage object [/Users/gaston/stoplightio/api-spec-converter/coverage/coverage.json]

Writing coverage reports at [/Users/gaston/stoplightio/api-spec-converter/coverage]

=============================== Coverage summary ===============================
Statements : 87.54% ( 1743/1991 )
Branches : 73.48% ( 690/939 )
Functions : 91.38% ( 350/383 )
Lines : 87.57% ( 1740/1987 )
================================================================================`

@marbemac
Copy link
Contributor

Interesting, could you provide the before and after swagger's separately, perhaps in a couple of linked gists?

One thing I noticed right off the bat is that the original swagger is not valid - the "host" property should have the actual host, not the protocol. And the "basePath" property should not have the host, it should have a relative path or nothing.

@glodieu
Copy link
Contributor Author

glodieu commented Aug 17, 2016

Hi Marc, I'm attaching before.json and after.json.
Regarding host and baseHost... such file is hosted in mulesoft/api-spec-converter repo (https://github.com/mulesoft/api-spec-converter/blob/master/example/source/swagger.json) I'll talk with Christian Vogel about this.
Thanks a lot for you help!
Gaston

before.json.txt
after.json.txt

@glodieu
Copy link
Contributor Author

glodieu commented Aug 17, 2016

Hi Marc,
File that we're mentioned is hosted in this repository https://github.com/stoplightio/api-spec-converter/blob/master/example/source/swagger.json
Thanks.
Gaston

@marbemac
Copy link
Contributor

OH I read that as a diff of the input swagger to output swagger, not as a test result, whoops! We will take a look, thanks for pointing this out.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants