jhthorsen / openapi-client

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

Fix OpenAPI::Client so it will use the port from the specification file #12

Closed nfg closed 6 years ago

nfg commented 6 years ago

Hello! There's something weird going on with ports. According to the Swagger2 spec, I should be able to include a port as part of my host as such:

---
swagger: 2.0
host: api.example.com:3300
basePath: /
paths:
  /foo:
    get:
      operationId: listPets
      responses:
        200:
          description: "TEST"
info:
  title: "TEST"
  version: "foo"

But when I try to hit that endpoint with the client, it's somehow adding ":80" to the host. IE:

➜  ~ cat bug.pl 
#!/usr/bin/env perl
use strict;
use warnings;

use OpenAPI::Client;

my $client = OpenAPI::Client->new('min.swagger');
print $client->listPets({})->result->to_string() . "\n";

➜  ~ MOJO_CLIENT_DEBUG=1 perl bug.pl
-- Blocking request (http://api.example.com:3300/foo)
-- Connect 602f9810529364379e04496e1971cc08 (http://api.example.com:3300:80)
Can't resolve: Name or service not known at bug.pl line 8.

I tried digging into it, but I can't seem to figure out where :80 is being added. Do you have any idea what's going on?

nfg commented 6 years ago

This is with the latest versions of OpenAPI::Client, Mojolicious, and JSON::Validator.

(Also, I'm new to Swagger / OpenAPI, and I could be doing something wrong.)

jhthorsen commented 6 years ago

Thanks! This was indeed a bug. A new version is soon available on cpan, but you can install it now if you like:

cpanm https://github.com/jhthorsen/openapi-client/archive/master.zip 
nfg commented 6 years ago

It works, thank you. :smile: