Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 2 commits into from
Closed

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

wants to merge 2 commits into from

Conversation

thejamescollins
Copy link
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.

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

cebe commented Feb 9, 2022

Rebased onto master here: #152

Thank you!

@cebe cebe closed this Feb 9, 2022
@cebe cebe modified the milestones: 1.5.3, 1.6.0 Feb 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 free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants