goofmint / cURLtoSwagger

Convert from cURL command to YAML format. Compatible with Swagger.
MIT License
60 stars 14 forks source link

YAML to Swagger Editor Error- Missing required property: paths #1

Closed loretoparisi closed 8 years ago

loretoparisi commented 8 years ago

I have followed the tutorial, generating the YAML from a cURL command and its json response. When I try to import the resulting YAML in the Swagger Editor, I get several errors:

✖ Swagger Error
Missing required property: paths
Jump to line 1

✖ Swagger Error
Missing required property: info
Jump to line 1
Details
 Object
✖ Swagger Error
Missing required property: swagger
Jump to line 1

✖ Swagger Error
Additional properties not allowed: /v1/search
Jump to line 1
Details

etc.

I have tried the Spotify Web API here:

curl -X GET "https://api.spotify.com/v1/search?q=tania%20bowra&type=artist"

and json

{
  "artists": {
    "href": "https://api.spotify.com/v1/search?query=tania+bowra&offset=0&limit=20&type=artist",
    "items": [ {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/08td7MxkoHQkXnWAYD8d6Q"
      },
      "genres": [ ],
      "href": "https://api.spotify.com/v1/artists/08td7MxkoHQkXnWAYD8d6Q",
      "id": "08td7MxkoHQkXnWAYD8d6Q",
      "images": [ {
        "height": 640,
        "url": "https://i.scdn.co/image/f2798ddab0c7b76dc2d270b65c4f67ddef7f6718",
        "width": 640
      }, {
        "height": 300,
        "url": "https://i.scdn.co/image/b414091165ea0f4172089c2fc67bb35aa37cfc55",
        "width": 300
      }, {
        "height": 64,
        "url": "https://i.scdn.co/image/8522fc78be4bf4e83fea8e67bb742e7d3dfe21b4",
        "width": 64
      } ],
      "name": "Tania Bowra",
      "popularity": 0,
      "type": "artist",
      "uri": "spotify:artist:08td7MxkoHQkXnWAYD8d6Q"
    } ],
    "limit": 20,
    "next": null,
    "offset": 0,
    "previous": null,
    "total": 1
  }
}

The result from cURLToSwagger is


---
  /v1/search: 
    get: 
      summary: ""
      description: ""
      parameters: 
        - 
          name: "q"
          type: "string"
          in: "query"
          description: ""
          required: true
        - 
          name: "type"
          type: "string"
          in: "query"
          description: ""
          required: true
      responses: 
        200: 
          description: ""
          schema: 
            type: "object"
            properties: 
              artists: 
                type: "object"
                items: 
                  properties: 
                    href: 
                      type: "string"
                      description: ""
                    items: 
                      type: "array"
                      items: 
                        properties: 
                          0: 
                            type: "object"
                            items: 
                              properties: 
                                external_urls: 
                                  type: "object"
                                  items: 
                                    properties: 
                                      spotify: 
                                        type: "string"
                                        description: ""
                                genres: 
                                  type: "array"
                                  items: 
                                    type: "undefined"
                                    description: ""
                                href: 
                                  type: "string"
                                  description: ""
                                id: 
                                  type: "string"
                                  description: ""
                                images: 
                                  type: "array"
                                  items: 
                                    properties: 
                                      0: 
                                        type: "object"
                                        items: 
                                          properties: 
                                            height: 
                                              type: "number"
                                              description: ""
                                            url: 
                                              type: "string"
                                              description: ""
                                            width: 
                                              type: "number"
                                              description: ""
                                      1: 
                                        type: "object"
                                        items: 
                                          properties: 
                                            height: 
                                              type: "number"
                                              description: ""
                                            url: 
                                              type: "string"
                                              description: ""
                                            width: 
                                              type: "number"
                                              description: ""
                                      2: 
                                        type: "object"
                                        items: 
                                          properties: 
                                            height: 
                                              type: "number"
                                              description: ""
                                            url: 
                                              type: "string"
                                              description: ""
                                            width: 
                                              type: "number"
                                              description: ""
                                name: 
                                  type: "string"
                                  description: ""
                                popularity: 
                                  type: "number"
                                  description: ""
                                type: 
                                  type: "string"
                                  description: ""
                                uri: 
                                  type: "string"
                                  description: ""
                    limit: 
                      type: "number"
                      description: ""
                    next: 
                      type: "object"
                      items: 
                        properties: {}
                    offset: 
                      type: "number"
                      description: ""
                    previous: 
                      type: "object"
                      items: 
                        properties: {}
                    total: 
                      type: "number"
                      description: ""

I didn't use any custom options, and left all the checkmarks checked.

If I try the example YAML output in the Swagger editor, I can import/export the yaml format without errors. Any hint?

goofmint commented 8 years ago

Thank you for trying. This is a template.

# this is an example of the Uber API
# as a demonstration of an API spec in YAML
swagger: '2.0'
info:
  title: YOUR_API_TITLE
  description: YOUR_API_DESCRIPTION
  version: "1.0.0"
# the domain of the service
host: localhost
# array of all schemes that your API supports
schemes:
  - http
basePath: /
produces:
  - application/json
paths:
  ###########################
  # Paste from here
  ###########################

And I have some bugs currenty version in array.

So, I fix your json like below.

  /v1/search: 
    get: 
      summary: ""
      description: ""
      parameters: 
        - 
          name: "q"
          type: "string"
          in: "query"
          description: ""
          required: true
        - 
          name: "type"
          type: "string"
          in: "query"
          description: ""
          required: true
      responses: 
        200: 
          description: ""
          schema: 
            type: "object"
            properties: 
              artists: 
                type: "object"
                properties: 
                  href: 
                    type: "string"
                    description: ""
                  items: 
                    type: "array"
                    items: 
                      type: "object"
                      properties: 
                        external_urls: 
                          type: "object"
                          properties: 
                            spotify: 
                              type: "string"
                              description: ""
                        genres: 
                          type: "array"
                          items: 
                            type: "undefined"
                            description: ""
                        href: 
                          type: "string"
                          description: ""
                        id: 
                          type: "string"
                          description: ""
                        images: 
                          type: "array"
                          items: 
                            properties: 
                                type: "object"
                                properties: 
                                height: 
                                  type: "number"
                                  description: ""
                                url: 
                                  type: "string"
                                  description: ""
                                width: 
                                  type: "number"
                                  description: ""
                        name: 
                          type: "string"
                          description: ""
                        popularity: 
                          type: "number"
                          description: ""
                        type: 
                          type: "string"
                          description: ""
                        uri: 
                          type: "string"
                          description: ""
                  limit: 
                    type: "number"
                    description: ""
                  next: 
                    type: "object"
                    items: 
                      properties: {}
                  offset: 
                    type: "number"
                    description: ""
                  previous: 
                    type: "object"
                    items: 
                      properties: {}
                  total: 
                    type: "number"
                    description: ""

This is so good sample request, I'll use this for generating acutual format.

Thanks!

goofmint commented 8 years ago

@loretoparisi

I fixed some bugs. You can try newest version on demo

loretoparisi commented 8 years ago

@moongift great, happy to help this is a great project! I will wait the fix then.

loretoparisi commented 8 years ago

@moongift thank you now it works correctly.