jhthorsen / json-validator

:cop: Validate data against a JSON schema
https://metacpan.org/release/JSON-Validator
56 stars 57 forks source link

Validator does not follow Reference in patterned fields in Responses Object in OpenAPI v2 & v3 #269

Open AnotherOneAckap opened 1 year ago

AnotherOneAckap commented 1 year ago

First things first: thank you for your great job!

Steps to reproduce the behavior

I have an openapi v3 spec and I would like to test responses got from server against it.

Here is the test sample https://github.com/AnotherOneAckap/json-validator-issue-example

Expected behavior

In the given example output with both specifications should be identical.

Actual behavior

Validator ignores futher schema if it meets Reference in patterned filed in Responses Object

How to fix it

According to openapi spec v3.0 2019-04-02 Responses Object contains patterned fields which could be either a Response Object or a Reference see https://spec.openapis.org/oas/v3.0.3#patterned-fields-0 also https://github.com/OAI/OpenAPI-Specification/blob/3.0.3/schemas/v3.0/schema.json#L211

But if I use Reference instead of Response Object, validator ignores it.

This happens because here validator first make get (which resolves any refs) to reach responses node and then it just go down by hash with status code. But node after status code also could be a Reference. So I suppose to use another get there. Same problem exists in JSON::Validator::Schema::OpenAPIv2