jhthorsen / mojolicious-plugin-openapi

OpenAPI / Swagger plugin for Mojolicious
54 stars 44 forks source link

Parameter type problem with OpenAPI v3 #137

Closed jusdude closed 4 years ago

jusdude commented 5 years ago

When setting a parameter type as boolean with v3, I discovered that the value returned by validation->output() is not a JSON::PP::Boolean but a scalar. While debugging, I found out that the value was not going through the coerse function, and this was coming from the field type not being taken into account.

The type seems not to be retrieved correctly in lib/JSON/Validator/OpenAPI/Mojolicious.pm, line 69 : my ($in, $name, $type) = @$p{qw(in name type)};

This works with v2, but with v3 the type should be within the schema property ($p->{schema}{type}) or even within the content property (according to the specs).

This is the YAML I used for my tests

paths:
  /context/db_default_dsn:
    get:
      operationId: getContextDbDefaultDsn
      x-mojo-name: get_context_db_default_dsn
      x-mojo-to: 'context#get_db_default_dsn'
      summary: "Retourne la base de donnée par défaut pour l'environnement"
      parameters:
        - name: ano
          in: query
          description: Indique si l'on veut la base anonyme
          schema:
            type: boolean
jhthorsen commented 4 years ago

I'm quite busy these days, so I would love to see a PR for this. I think I would start by adding a new test to https://github.com/jhthorsen/mojolicious-plugin-openapi/blob/master/t/v3.t which also cares about boolean, and not just integer and strings.

jhthorsen commented 4 years ago

Closed by #147.