Skip to content

Fix OpenAPI v3.0 Schema Violation: Array value found, but an object is required - #125

Closed
thejamescollins wants to merge 2 commits into
cebe:masterfrom
tectalic:fix-array-value-found-but-an-object-is-required
Closed

Fix OpenAPI v3.0 Schema Violation: Array value found, but an object is required#125
thejamescollins wants to merge 2 commits into
cebe:masterfrom
tectalic:fix-array-value-found-but-an-object-is-required

Conversation

@thejamescollins

Copy link
Copy Markdown
Contributor

Hi there,

Thank you for your very useful tool, it's been really useful in our projects.

bin/php-openapi validate currently fails unexpectedly when validating a schema that specifies an empty value for a Map OpenAPI field.

For example, the minimal specification I've provided in c5ca523 currently fails:

bin/php-openapi validate tests/spec/data/empty-maps.json
OpenAPI v3.0 schema violations:
- [paths./products.get.responses[200].headers] Array value found, but an object is required
- [paths./products.get.responses[200].content] Array value found, but an object is required
- [paths./products.get.responses[200].links] Array value found, but an object is required

Whereas that specification passes in various other validation tools such as https://apitools.dev/swagger-parser/online/ or https://www.jsonschemavalidator.net/.

This PR changes to the Serialization process so that empty Map Fields are correctly validated.

The example in this PR uses the Response object, however, the fix should apply for any Map type fields.

@cebecebe added the bug Something isn't working label Oct 13, 2021
@cebecebe added this to the 1.5.3 milestone Oct 13, 2021
@cebe

cebe commented Feb 9, 2022

Copy link
Copy Markdown
Owner

Rebased onto master here: #152

Thank you!

@cebecebe closed this Feb 9, 2022
@cebecebe modified the milestones: 1.5.3, 1.6.0Feb 9, 2022
cebe added a commit that referenced this pull request Feb 9, 2022
* master: (22 commits)
Catch recursion when resolving inside included file
Improve Responses resolving references
Fixes default value for exclusiveMinimum and exclusiveMaximum
more specific deprecation
add hasPropertyValue() method
add comments, optimize tests for #125
During serialization convert empty Map fields to empty Objects
Add test to demonstrate OpenAPI v3.0 schema validation fails with empty Path properties
yarn upgrade
Added docker environment for local development
Add symfony 6 support (#151)
Bump node-fetch from 2.6.1 to 2.6.7 (#149)
Fix CI badge in Readme (#150)
Temporarily skip broken test (#145)
Run speccy through yarn
Add windows and macos cases
Temporarily skip broken test
Rework CI
Run all tests (#136)
Drop licence badge from readme (#137)
...
Conflicts:
README.md
composer.json
src/SpecBaseObject.php
tests/ReaderTest.php
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugSomething isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@thejamescollins@cebe