Gi60s / openapi-enforcer

Apache License 2.0
94 stars 23 forks source link

fix case when deserialize screw up example with oneOf/anyOf #117

Closed imsamurai closed 3 years ago

imsamurai commented 3 years ago

Hi, maybe you know better solution?) Without fix i got something like:

EnforcerException: One or more warnings exist in the Schema definition
    at: example
      Invalid value
        at: f > 0
          Did not validate against exactly one schema
            at: 0
              Invalid value
                at: n1
                  Expected a string. Received: undefined
                at: v
                  at: 0
                    Expected a string. Received: undefined
                  at: 1
                    Expected a string. Received: undefined

What happends: in schema utils lib try to get score of all possible variants value differs by type when lib deserialize with schema that have other type for field it screws up actual value with undefined (because deserialize return undefined on error) after scoring lib try to validate screwed value against correct schema and it fails because value contains undefined

Gi60s commented 3 years ago

Thanks for the PR. Can you include an example of the schema or OpenAPI document that you're using to produce the error that is being fixed by this PR?

imsamurai commented 3 years ago

Already included in test) https://github.com/byu-oit/openapi-enforcer/pull/117/commits/382d8ccc0e6e26fb328c17cd29ae3f512c3fead6#diff-fc9c5c013c64338b66aadb694a9093eea50df5ba4b97817805852c9302e805d6R1659

Gi60s commented 3 years ago

The solution ended up being wrong (it was hiding the problem) but your test made it possible for me to track down the underlying issue. Thanks for the PR.

Changes have been merged to master and this has been published to NPM as version 1.14.2.