jhthorsen / openapi-client

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

basePath and schemes missing from spec #1

Closed jdalberg closed 6 years ago

jdalberg commented 6 years ago

Hi there.

I was trying to use OpenAPI::Client in a project of mine, where I generate the swagger using a plugin for phoenix (the go-to elixir web framework if you are not familiar). It generates swagger like many other plugins i guess, but comes up with swagger thats not quite what OpenAPI::Client expects. More specifically "schemes" and "basePath" is missing from the specification.

When that happens the base_url attribute of OpenAPI::Client gets into trouble with references to undef'ed objects aso.

I found that this version of base_url handled better defaults, to make it survive.

has base_url => sub {
  my $self   = shift;
  my $schema = $self->validator->schema;

  my $scheme = $schema->get('/schemes') || ['http'];

  return Mojo::URL->new->host($schema->get('/host'))->path($schema->get('/basePath') || '/')
    ->scheme($scheme->[0]);
};

I know that you can just brush it of and say: That looks like a generator problem, and you might be right. But no one ever died for having better defaults ;)

jhthorsen commented 6 years ago

Is "http" a good default? I would rather default to "https" or even die if "schemes" is not set. I do agree about the "basePath" part though.

jhthorsen commented 6 years ago

I see that I already default to "http", so I answered my own question.

A new version soon available on CPAN.

Thanks 👍