jhthorsen / openapi-client

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

OpenAPI::Client - how to pass additionalProperties in OpenAPI GET query request? #34

Open nige123 opened 2 years ago

nige123 commented 2 years ago

I'm trying to pass filter variables in a GET request to an OpenAPI route with this specification:

 - in: query
    name: params
    schema:
      type: object
      additionalProperties:
        type: string
    style: form
    explode: true       

I've tried various different ways of passing the data at request time:


my $client = OpenAPI::Client->new(...);

my $tx = $client->findApps({
    params => { 'id' =>  '1' }
});

my $tx = $client->findApps({ 'id' =>  '1' });

What is the correct way to do this?

I'm currently getting this warning/error:

Use of uninitialized value $name in exists at /usr/local/share/perl/5.26.1/OpenAPI/Client.pm line 204

jhthorsen commented 2 years ago

This is currently not supported I'm afraid. (Currently working on https://github.com/jhthorsen/mojolicious-plugin-openapi/pull/223) I don't know when I will get around to it, but if someone wants to hack on it, this is (probably) the place that needs to be changed: https://github.com/jhthorsen/openapi-client/blob/master/lib/OpenAPI/Client.pm#L164-L169

PR is more than welcome!

XSven commented 2 years ago

It is not easy to implement a PR without knowing the design ideas of the current development. From my perspective the starting point is the JSON::Validator::Schema::OpenAPIv3 implementation

https://github.com/jhthorsen/json-validator/blob/fc9d7826e4f46b8bc828f7be4be97602b9951647/lib/JSON/Validator/Schema/OpenAPIv3.pm#L258-L261

The above OpenAPI spec extracts from nige123 leads to an undefined $name. The original name (params) is still a key of the $param hashref. Both $name (undef) and $params are passed to the query-type coderef. Is this part ok and stable?