discourse/spec/requests/api
Blake Erickson 7434116933
DEV: Add schema checking to api doc testing (#11721)
* DEV: Add schema checking to api doc testing

This commit improves upon rswag which lacks schema checking. rswag
really only checks that the https status matches, but this change adds
in the json-schema_builder gem which also has schema validation.

Now we can define schemas for each of our requests/responses in the
`spec/requests/api/schemas` directory which will make our documentation
specs a lot cleaner.

If we update a serializer by either adding or removing an attribute the
tests will now fail (this is a good thing!). Also if you change the type
of an attribute say from an array to a string the tests will now fail.
This will help significantly with keeping the docs in sync with actual
code changes! Now if you change how an endpoint will respond you will
have to update the docs too in order for the tests to pass. :D

This PR is inspired by:

 https://www.tealhq.com/post/how-teal-keeps-their-api-tests-and-documentation-in-sync

* Swap out json schema validator gem

Swapped out the outdated json-schema_builder gem with the json_schemer
gem.

* Add validation fields to schema

In order to have "strict" validation we need to add
`additionalProperties: false` to the schema, and we need to specify
which attributes are required.

Updated the debugging test output to print out the error details if
there are any.
2021-01-21 16:28:08 -07:00
..
schemas DEV: Add schema checking to api doc testing (#11721) 2021-01-21 16:28:08 -07:00
shared DEV: Add schema checking to api doc testing (#11721) 2021-01-21 16:28:08 -07:00
categories_spec.rb FIX: Redirect user to the URL with the correct category slug (#10167) 2020-07-07 15:25:36 +03:00
groups_spec.rb DEV: Add api docs for invite and group update endpoint (#11019) 2020-10-26 08:55:22 -06:00
invites_spec.rb DEV: Add api docs for invite and group update endpoint (#11019) 2020-10-26 08:55:22 -06:00
notifications_spec.rb DEV: Document notifications and tags api endpoints 2020-08-07 14:30:54 -06:00
posts_spec.rb FEATURE: Implement edit functionality for post notices (#11140) 2020-11-11 14:49:53 +02:00
private_messages_spec.rb DEV: Document private message api endpoints 2020-07-31 18:27:08 -06:00
tags_spec.rb DEV: Add schema checking to api doc testing (#11721) 2021-01-21 16:28:08 -07:00
topics_spec.rb FIX: Actually error when topic timer time is in the past (#11434) 2020-12-08 11:13:45 -06:00
users_spec.rb DEV: Document get user by external_id api endpoint (#11717) 2021-01-14 16:59:58 -07:00