jhthorsen / mojolicious-plugin-openapi

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

Support defaults in requestBody properties #176

Closed mschout closed 4 years ago

mschout commented 4 years ago

In requestBody, it is possible to specify a default for each property per OpenAPI 3.0 like this:

requestBody:
  required: true
  content:
    application/json:
      schema:
        type: object
        properties:
          foo:
            type: string
            default: bar

See https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v3.0/schema.yaml#L311 for where this is in the spec.

Currently this is not handled by the plugin, fix coming in PR shortly.

jhthorsen commented 4 years ago

I don't want this code in mojolicious-plugin-openapi, since it involves looping through the body twice, making validation twice as slow. Please help fixing jhthorsen/json-validator#155 instead.

To make failing cases, try loading the plugin like this:

$app->plugin(OpenAPI => {..., coerce => 'booleans,numbers,strings,defaults'});
mschout commented 4 years ago

Sure, I'll look there. thanks!