Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reusable responses not validated properly #276

Open
potatogim opened this issue Oct 12, 2024 · 1 comment
Open

Reusable responses not validated properly #276

potatogim opened this issue Oct 12, 2024 · 1 comment

Comments

@potatogim
Copy link

  • JSON::Validator version: 5.14
  • Perl version: 5.16, 5.40
  • Operating system: CentOS 7, ArchLinux

Steps to reproduce the behavior

use Mojolicious::Lite;

post "/echo" => sub {
    my $c = shift->openapi->valid_input or return;

    my $data = { body => $c->req->json };

    $c->stash( openapi => $data->{body} );
  },
  "echo";

plugin OpenAPI => { url => "data:///swagger.yaml", plugins => [qw(+Security)] };

app->start;

__DATA__
@@ swagger.yaml
openapi: "3.1.0"
info: { version: "0.8", title: "Echo Service" }

servers:
  - url: "/api"

components:
  schemas:
    Potato:
      type: object
      properties:
        name:
          type: string

  responses:
    Potato:
      description: 'test'
      content:
        application/json:
          schema:
            allOf:
              - $ref: '#/components/schemas/Potato'
              - type: object
                properties:
                  id:
                    type: object

  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: default auth by JWT

paths:
  /echo:
    post:
      x-mojo-name: "echo"
      requestBody:
        content:
          application/json:
            schema:
              type: "object"
      responses:
        200:
          $ref: '#/components/responses/Potato'

security:
 - bearerAuth: []

Expected behavior

[potatogim@Potato-Arch]$ curl -XPOST -H 'Content-Type: application/json' -d '{"name": "test", "id": "test"}' http://localhost:3001/api/echo
{"errors":[{"message":"\/allOf\/1 Expected object - got string.","path":"\/body\/id"}],"status":500}

Actual behavior

AFAIK, OpenAPI supports the reusing responses defined under the components section but this response not validated properly.

[potatogim@Potato-Arch ~]$ curl -XPOST -H 'Content-Type: application/json' -d '{"name": "test", "id": "test"}' http://localhost:3001/api/echo
{"id":"test","name":"test"}
@potatogim potatogim changed the title Reusable responses not validated properly. Reusable responses not validated properly Oct 12, 2024
@potatogim
Copy link
Author

potatogim commented Nov 26, 2024

@jhthorsen Hello! 😄

First of all, sorry to bother you 😅

If there is anything wrong or strange, could you please give me some advice?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant