jhthorsen / json-validator

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

fix defaults for arrays with collectionFormat #263

Closed elcamlost closed 2 years ago

elcamlost commented 2 years ago

Summary

Fixing defaults for arrays in query and path

Motivation

Current implementation has a bug:

- name: elvishRingsOwners
  type: array
  items:
    type: string
  minItems: 1
  default: ["Gandalf", "Galadriel", "Cirdan"]

This schema cannot be validated if parameter is omitted.

References

https://swagger.io/docs/specification/2-0/describing-parameters/#array-and-multi-value-parameters there is an example of describing default value for array parameter

elcamlost commented 2 years ago

This PR looks incomplete. Did you forget to push some changes in that unit test?

I can’t accept the PR without a new test case.

I changed t/openapiv2-collection-format.t test. Without changes in lib/JSON/Validator/Schema/OpenAPIv2.pm this test now fails. I can extract this changes into new test file, if it is what you're asking for. But the new test is here ))

jhthorsen commented 2 years ago

I tested the changes locally now and I see what you mean 👍 Thanks for the PR!