jhthorsen / openapi-client

A client for talking to an Open API powered server
11 stars 17 forks source link

openapi /api command throws validation error with basic API #26

Closed lbjw closed 4 years ago

lbjw commented 4 years ago

Versions:

Issue:

OpenAPI command does not work with specified pet store. Issue #8 said probably fixed in 0.24 but it is not fixed.

Example:

REST server code actually works and can be called from a REST call:

$ ./app get /api/pets

[2020-03-08 13:14:54.65099] [28570] [debug] GET "/api/pets" (9245ecb7)
[2020-03-08 13:14:55.44719] [28570] [debug] Routing to controller "App::Controller::Pet" and action "list"
[2020-03-08 13:14:55.46035] [28570] [debug] 200 OK (0.809346s, 1.236/s)
{ ... JSON I returned from the test function "list" .. }

OpenAPI client command cannot be executed due to validation issue:

$ app openapi /api

[2020-03-08 13:14:01.41765] [28565] [debug] GET "/api" (3635cea4)
[2020-03-08 13:14:01.41832] [28565] [debug] Routing to a callback
[2020-03-08 13:14:01.41971] [28565] [debug] 200 OK (0.002047s, 488.520/s)
Invalid JSON specification HASH(0x5571d8363290):
- /: Properties not allowed: components, openapi, servers. at /usr/local/share/perl/5.28.1/JSON/Validator.pm line 159.
    JSON::Validator::load_and_validate_schema(JSON::Validator::OpenAPI::Mojolicious=HASH(0x5571d831bc98), "/api", HASH(0x5571d831bf08)) called at /usr/local/share/perl/5.28.1/JSON/Validator/OpenAPI/Mojolicious.pm line 63
    JSON::Validator::OpenAPI::Mojolicious::load_and_validate_schema(JSON::Validator::OpenAPI::Mojolicious=HASH(0x5571d831bc98), "/api", HASH(0x5571d831bf08)) called at /usr/local/share/perl/5.28.1/OpenAPI/Client.pm line 52
    OpenAPI::Client::new("OpenAPI::Client", "/api", "app",App=HASH(0x5571d5e201b0)) called at /usr/local/share/perl/5.28.1/Mojolicious/Command/openapi.pm line 57
    Mojolicious::Command::openapi::run(Mojolicious::Command::openapi=HASH(0x5571d82e0ff8), "/api") called at /usr/share/perl5/Mojolicious/Commands.pm line 55
    Mojolicious::Commands::run(Mojolicious::Commands=HASH(0x5571d83057f0), "openapi", "/api") called at /usr/share/perl5/Mojolicious.pm line 195
    Mojolicious::start(App=HASH(0x5571d5e201b0)) called at /usr/share/perl5/Mojolicious/Commands.pm line 72
    Mojolicious::Commands::start_app("Mojolicious::Commands", "App") called at ./app line 17

$ cat petstore.json

{
  "openapi": "3.0.2",
  "info": {
    "version": "1.0",
    "title": "Some awesome API"
  },
  "paths": {
    "/pets": {
      "get": {
        "operationId": "getPets",
        "x-mojo-name": "get_pets",
        "x-mojo-to": "pet#list",
        "summary": "Finds pets in the system",
        "parameters": [
          {
            "in": "query",
            "name": "age",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Pet response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "pets": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "servers": [
    {
      "url": "/api"
    }
  ]
}
jhthorsen commented 4 years ago

OpenAPI v3 is not supported. Please open a new issue if you want v3 to be supported.