jhthorsen / mojolicious-plugin-openapi

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

perl v5.40 core booleans not allowed in schema, when it's a nested perl data structre #252

Open akarelas opened 1 month ago

akarelas commented 1 month ago

e.g.:

package Example;

use v5.40;

# ...

  $self->plugin(OpenAPI => {
      coerce => 'booleans',
      spec => {
          swagger => '2.0',
          info    => {
              description => "This is the API specification",
              version     => '0.0.1',
              title       => 'abc.karelcom.net',
          },
          schemes => [ 'http' ],
          paths   => {
              '/api/foo' => {
                  get => {
                      description => 'foo',
                      summary     => 'foo',
                      'x-mojo-to' => 'API#foo',
                      operationId => 'foo',
                      tags        => [ 'Foo' ],
                      produces    => [ 'application/json' ],
                      responses   => {
                          200 => {
                              description => 'OK. Hi.',
                              schema      => {
                                  type                 => 'object',
                                  required             => [ qw/a b/ ],
                                  properties           => {
                                      a => { type => 'integer' },
                                      b => { type => 'integer' },
                                  },
                                  additionalProperties => false,
                              },
                          },
                      },
                  },
              },
          },
      },
  });

# ...

This is important, because you can't use Mojo::JSON 'true', 'false' to replace the meaning of true & false from core booleans, if you use v5.40.