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

Add assertions for testing response against JSON Schema from API resource #3003

Merged

Conversation

meyerbaptiste
Copy link
Member

@meyerbaptiste meyerbaptiste commented Aug 20, 2019

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR api-platform/docs#875

@teohhanhui teohhanhui self-assigned this Aug 23, 2019
@teohhanhui teohhanhui force-pushed the resource_json_schema_assertion branch from 2c94ac4 to 450627e Compare August 24, 2019 11:59
@teohhanhui teohhanhui changed the title WIP: Add a resource json schema assertion Add assertions for testing response against JSON Schema from API resource Aug 24, 2019
@teohhanhui teohhanhui marked this pull request as ready for review August 24, 2019 12:00
@teohhanhui teohhanhui force-pushed the resource_json_schema_assertion branch 2 times, most recently from 3a2a0bd to 4b3afaf Compare August 24, 2019 12:26
@teohhanhui teohhanhui force-pushed the resource_json_schema_assertion branch 4 times, most recently from 87c6b02 to 750959a Compare August 24, 2019 13:18
@teohhanhui teohhanhui force-pushed the resource_json_schema_assertion branch 2 times, most recently from bba5ffa to 3ba1589 Compare August 26, 2019 14:44
@teohhanhui
Copy link
Contributor

The Travis failures for Elasticsearch are... weird. The same Behat tests pass on CircleCI.

src/Bridge/Symfony/Bundle/Test/ApiTestAssertionsTrait.php Outdated Show resolved Hide resolved
src/Bridge/Symfony/Bundle/Test/ApiTestAssertionsTrait.php Outdated Show resolved Hide resolved
'type' => 'integer',
'minimum' => 1,
'type' => 'string',
'format' => 'iri-reference',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware of the existence of iri-reference! We should use it everywhere we know that an IRI will be generated!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dunglas Do you have any in mind? (We could do it in another PR.)

Copy link
Member

@soyuka soyuka Sep 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

he means in the rest of the core I guess (tests?), so def another pr!

@teohhanhui teohhanhui force-pushed the resource_json_schema_assertion branch 2 times, most recently from f9f9dd4 to 62fa278 Compare August 29, 2019 13:54
@teohhanhui teohhanhui force-pushed the resource_json_schema_assertion branch 2 times, most recently from ac5fec5 to ddebb8b Compare September 6, 2019 16:27
@teohhanhui teohhanhui force-pushed the resource_json_schema_assertion branch 2 times, most recently from 4bdb552 to c4da141 Compare September 19, 2019 09:26
*
* Specifically, we need to ensure that a JSON object is represented as a PHP object, not as an associative array.
*/
private function normalizeJson($document)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We support validating any JSON document against a JSON Schema now. 🎉

…urce

Co-authored-by: Teoh Han Hui <teohhanhui@gmail.com>
@@ -43,7 +43,7 @@
"friendsofsymfony/user-bundle": "^2.2@dev",
"guzzlehttp/guzzle": "^6.0",
"jangregor/phpstan-prophecy": "^0.4.2",
"justinrainbow/json-schema": "^5.0",
"justinrainbow/json-schema": "^5.2.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@teohhanhui
Copy link
Contributor

Simplified the implementation a little.

Copy link
Member

@soyuka soyuka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 as is

@soyuka soyuka merged commit 1088a5d into api-platform:master Sep 19, 2019
@soyuka
Copy link
Member

soyuka commented Sep 19, 2019

thanks @meyerbaptiste @teohhanhui !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants