jhthorsen / mojolicious-plugin-openapi

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

Additional properties and inheritance with OpenAPI spec 3.0.3 #180

Closed waterkip closed 4 years ago

waterkip commented 4 years ago

Hello, first of all, thank you for writing this software! I'm a happy consumer of OpenAPI::Client for one of my work related projects and now in a personal project I'm running into an unexpected issue with Mojolicous::Plugin::OpenAPI.

While I was testing an OpenAPI specification with Swagger-UI and Mojo I came across a weird issue when using additionalProperties: false in combination with multiple allOf's. I've simplified the scenario in the attached testfile + spec.

In the test I'm expecting /max to succeed, and /min to fail, yet they both fail for different reasons, which cannot be solved unless you set additionalProperties: true.

[2020-04-30 00:11:10.55251] [261476] [debug] [0ca5e3de] GET "/max"
[2020-04-30 00:11:10.55281] [261476] [debug] [0ca5e3de] Routing to a callback
[2020-04-30 00:11:10.55295] [261476] [debug] Your secret passphrase needs to be changed
[2020-04-30 00:11:10.55332] [261476] [warn] OpenAPI >>> GET /max [{"message":"Properties not allowed: id.","path":"\/"}]
[2020-04-30 00:11:10.55344] [261476] [debug] [0ca5e3de] 500 Internal Server Error (0.000924s, 1082.251/s)

#   Failed test '200 OK'
#   at t/v3-additional_properties.t line 43.
#          got: '500'
#     expected: '200'
[2020-04-30 00:11:10.55500] [261476] [debug] [51019c05] GET "/min"
[2020-04-30 00:11:10.55514] [261476] [debug] [51019c05] Routing to a callback
[2020-04-30 00:11:10.55552] [261476] [warn] OpenAPI >>> GET /min [{"message":"\/allOf\/0\/allOf\/0 Missing property.","path":"\/data"},{"message":"\/allOf\/0\/allOf\/0 Missing property.","path":"\/id"}]
[2020-04-30 00:11:10.55561] [261476] [debug] [51019c05] 500 Internal Server Error (0.00061s, 1639.344/s)
# Looks like you failed 1 test of 4.
t/v3-additional_properties.t .. 
ok 1 - GET /max
not ok 2 - 200 OK
ok 3 - GET /min
ok 4 - 500 Internal Server Error
1..4
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/4 subtests 

Test Summary Report
-------------------
t/v3-additional_properties.t (Wstat: 256 Tests: 4 Failed: 1)
  Failed test:  2
  Non-zero exit status: 1
Files=1, Tests=4,  0 wallclock secs ( 0.01 usr  0.01 sys +  0.27 cusr  0.02 csys =  0.31 CPU)
Result: FAIL

v3-additional_properties.zip

waterkip commented 4 years ago

I found out why: https://stackoverflow.com/questions/22689900/json-schema-allof-with-additionalproperties

I'll close the bug and solve it by repeating the properties in the sibling.