httpie / http-prompt

An interactive command-line HTTP and API testing client built on top of HTTPie featuring autocomplete, syntax highlighting, and more. https://twitter.com/httpie
https://http-prompt.com
MIT License
8.96k stars 326 forks source link

OpenAPI: Failure when having a root("/") path #143

Closed steve-chavez closed 6 years ago

steve-chavez commented 6 years ago

Tried v0.11.2 on a spec generated by PostgREST(spec formated and validated with https://bigstickcarpet.com/swagger-parser/www/index.html), and http-prompt failed with:

Version: 0.11.2
Traceback (most recent call last):
  File "/nix/store/l9knvrkhb69qzny5bjhwdc095dm1yym9-http-prompt-0.11.2/bin/.http-prompt-wrapped", line 12, in <module>
    sys.exit(cli())
  File "/nix/store/pnfz195p4c3j10b46dr1kl1q24bcjvwz-python2.7-click-6.7/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/nix/store/pnfz195p4c3j10b46dr1kl1q24bcjvwz-python2.7-click-6.7/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/nix/store/pnfz195p4c3j10b46dr1kl1q24bcjvwz-python2.7-click-6.7/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/nix/store/pnfz195p4c3j10b46dr1kl1q24bcjvwz-python2.7-click-6.7/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/nix/store/l9knvrkhb69qzny5bjhwdc095dm1yym9-http-prompt-0.11.2/lib/python2.7/site-packages/http_prompt/cli.py", line 124, in cli
    context = Context(url, spec=spec)
  File "/nix/store/l9knvrkhb69qzny5bjhwdc095dm1yym9-http-prompt-0.11.2/lib/python2.7/site-packages/http_prompt/context/__init__.py", line 32, in __init__
    self.root.add_path(*path_tokens)
  File "/nix/store/l9knvrkhb69qzny5bjhwdc095dm1yym9-http-prompt-0.11.2/lib/python2.7/site-packages/http_prompt/tree.py", line 38, in add_path
    name = path[0]
IndexError: tuple index out of range

Here's a sample spec:

Spec
{
  "swagger": "2.0",
  "info": {
    "version": "0.5.0.0 (6229119)",
    "title": "PostgREST API",
    "description": "standard public schema"
  },
  "host": "0.0.0.0:3000",
  "basePath": "/",
  "schemes": [
    "http"
  ],
  "consumes": [
    "application/json",
    "application/vnd.pgrst.object+json",
    "text/csv"
  ],
  "produces": [
    "application/json",
    "application/vnd.pgrst.object+json",
    "text/csv"
  ],
  "paths": {
    "/": {
      "get": {
        "tags": [
          "Introspection"
        ],
        "summary": "OpenAPI description (this document)",
        "produces": [
          "application/openapi+json",
          "application/json"
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/items": {
      "get": {
        "tags": [
          "items"
        ],
        "parameters": [
          {
            "name": "id",
            "required": false,
            "format": "integer",
            "in": "query",
            "type": "string"
          },
          {
            "name": "select",
            "description": "Filtering Columns",
            "required": false,
            "in": "query",
            "type": "string"
          },
          {
            "name": "order",
            "description": "Ordering",
            "required": false,
            "in": "query",
            "type": "string"
          },
          {
            "name": "Range",
            "description": "Limiting and Pagination",
            "required": false,
            "in": "header",
            "type": "string"
          },
          {
            "name": "Range-Unit",
            "description": "Limiting and Pagination",
            "required": false,
            "default": "items",
            "in": "header",
            "type": "string"
          },
          {
            "name": "offset",
            "description": "Limiting and Pagination",
            "required": false,
            "in": "query",
            "type": "string"
          },
          {
            "name": "limit",
            "description": "Limiting and Pagination",
            "required": false,
            "in": "query",
            "type": "string"
          },
          {
            "name": "Prefer",
            "description": "Preference",
            "required": false,
            "in": "header",
            "type": "string",
            "enum": [
              "count=none"
            ]
          }
        ],
        "responses": {
          "200": {
            "schema": {
              "properties": {
                "id": {
                  "format": "integer",
                  "type": "integer",
                  "description": "Note:\nThis is a Primary Key."
                }
              },
              "type": "object"
            },
            "description": "OK"
          },
          "206": {
            "description": "Partial Content"
          }
        }
      },
      "post": {
        "tags": [
          "items"
        ],
        "parameters": [
          {
            "name": "items",
            "description": "items",
            "required": false,
            "schema": {
              "properties": {
                "id": {
                  "format": "integer",
                  "type": "integer",
                  "description": "Note:\nThis is a Primary Key."
                }
              },
              "type": "object"
            },
            "in": "body"
          },
          {
            "name": "Prefer",
            "description": "Preference",
            "required": false,
            "in": "header",
            "type": "string",
            "enum": [
              "return=representation",
              "return=minimal",
              "return=none"
            ]
          }
        ],
        "responses": {
          "201": {
            "description": "Created"
          }
        }
      },
      "delete": {
        "tags": [
          "items"
        ],
        "parameters": [
          {
            "name": "id",
            "required": false,
            "format": "integer",
            "in": "query",
            "type": "string"
          },
          {
            "name": "Prefer",
            "description": "Preference",
            "required": false,
            "in": "header",
            "type": "string",
            "enum": [
              "return=representation",
              "return=minimal",
              "return=none"
            ]
          }
        ],
        "responses": {
          "204": {
            "description": "No Content"
          }
        }
      },
      "patch": {
        "tags": [
          "items"
        ],
        "parameters": [
          {
            "name": "id",
            "required": false,
            "format": "integer",
            "in": "query",
            "type": "string"
          },
          {
            "name": "items",
            "description": "items",
            "required": false,
            "schema": {
              "properties": {
                "id": {
                  "format": "integer",
                  "type": "integer",
                  "description": "Note:\nThis is a Primary Key."
                }
              },
              "type": "object"
            },
            "in": "body"
          },
          {
            "name": "Prefer",
            "description": "Preference",
            "required": false,
            "in": "header",
            "type": "string",
            "enum": [
              "return=representation",
              "return=minimal",
              "return=none"
            ]
          }
        ],
        "responses": {
          "204": {
            "description": "No Content"
          }
        }
      }
    }
  },
  "definitions": {
    "items": {
      "properties": {
        "id": {
          "format": "integer",
          "type": "integer",
          "description": "Note:\nThis is a Primary Key."
        }
      },
      "type": "object"
    }
  },
  "parameters": {
    "preferParams": {
      "name": "Prefer",
      "description": "Preference",
      "required": false,
      "in": "header",
      "type": "string",
      "enum": [
        "params=single-object"
      ]
    },
    "preferReturn": {
      "name": "Prefer",
      "description": "Preference",
      "required": false,
      "in": "header",
      "type": "string",
      "enum": [
        "return=representation",
        "return=minimal",
        "return=none"
      ]
    },
    "preferCount": {
      "name": "Prefer",
      "description": "Preference",
      "required": false,
      "in": "header",
      "type": "string",
      "enum": [
        "count=none"
      ]
    },
    "select": {
      "name": "select",
      "description": "Filtering Columns",
      "required": false,
      "in": "query",
      "type": "string"
    },
    "order": {
      "name": "order",
      "description": "Ordering",
      "required": false,
      "in": "query",
      "type": "string"
    },
    "range": {
      "name": "Range",
      "description": "Limiting and Pagination",
      "required": false,
      "in": "header",
      "type": "string"
    },
    "rangeUnit": {
      "name": "Range-Unit",
      "description": "Limiting and Pagination",
      "required": false,
      "default": "items",
      "in": "header",
      "type": "string"
    },
    "offset": {
      "name": "offset",
      "description": "Limiting and Pagination",
      "required": false,
      "in": "query",
      "type": "string"
    },
    "limit": {
      "name": "limit",
      "description": "Limiting and Pagination",
      "required": false,
      "in": "query",
      "type": "string"
    },
    "body.items": {
      "name": "items",
      "description": "items",
      "required": false,
      "schema": {
        "properties": {
          "id": {
            "format": "integer",
            "type": "integer",
            "description": "Note:\nThis is a Primary Key."
          }
        },
        "type": "object"
      },
      "in": "body"
    },
    "rowFilter.items.id": {
      "name": "id",
      "required": false,
      "format": "integer",
      "in": "query",
      "type": "string"
    }
  },
  "externalDocs": {
    "url": "https://postgrest.org/en/v5.0/api.html",
    "description": "PostgREST Documentation"
  }
}
```


When removing the paths."/" object, http-prompt works normally.

eliangcs commented 6 years ago

Shipped fix #145 in v1.0.0.