0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-11 02:59:07 +08:00
discourse/spec/requests/api
Martin Brennan cd98d818dc
DEV: Improve JSON schema failure output in API specs (#41182)
The shared JSON endpoint examples used to validate schemas with a
boolean
assertion and print one ad hoc hint to stdout. A failure was hard to act
on:

```
  VALUE AT "/access_control": {"mandatory_acl" => {}}
  POSSIBLE ISSUE W/: /access_control

  expected: true
       got: false
```

That output hid the real validator error, only showed the first failure,
and did not explain whether the response or schema needed to change.

Build a proper RSpec failure message from all JSONSchemer validation
results
instead. Each error now includes the issue, validator error, data path,
schema path, offending value, optional parent/details context, and a
concrete
suggested fix.

For unexpected properties:

```
  JSON schema validation failed with 1 error:

  1. Unexpected property at /access_control
     Error: object property at `/access_control` is a disallowed additional property
     Data path: /access_control
     Schema path: /additionalProperties
     Value:
       {
         "mandatory_acl": {}
       }
     Suggested fix: If this response/request field is intentional, add this entry
     to the parent schema's `properties` object:
       {
         "access_control": {
           "type": "object",
           "additionalProperties": false,
           "properties": {
             "mandatory_acl": {
               "type": "object",
               "additionalProperties": true
             }
           },
           "required": [
             "mandatory_acl"
           ]
         }
       }
       If the field is always present, also add "access_control" to the parent
       schema's `required` array.
```

For missing required properties, the message now groups missing keys and
shows
the response root plus validator details:

```
  Missing required properties default_archetype, notification_types at root
  Error: object at root is missing required properties: ...
  Details:
    {
      "missing_keys": [
        "default_archetype",
        "notification_types"
      ]
    }
  Suggested fix: Add default_archetype, notification_types to the
  response/request, or remove them from `required` at root schema.
```

For type mismatches, the message now points at the mismatched schema
node and
suggests an inferred replacement shape:

```
  Error: value at `/access_control` is not an array
  Data path: /access_control
  Schema path: /properties/access_control
  Value:
    {
      "mandatory_acl": {}
    }
  Suggested fix: Update the payload to match the documented `type`, or replace
  the schema at /properties/access_control with:
    {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "mandatory_acl": {
          "type": "object",
          "additionalProperties": true
        }
      },
      "required": [
        "mandatory_acl"
      ]
    }
```
2026-06-25 15:55:40 +10:00
..
schemas DEV: Make upcoming change CSS classes opt-in (#40669) 2026-06-10 12:12:58 +10:00
shared DEV: Improve JSON schema failure output in API specs (#41182) 2026-06-25 15:55:40 +10:00
backups_spec.rb DEV: Restore and update request/api specs (#39483) 2026-04-23 20:13:52 +02:00
badges_spec.rb
categories_spec.rb
groups_spec.rb DEV: Fix api docs openapi spec validation errors (#35361) 2025-10-14 07:32:58 -06:00
invites_spec.rb DEV: Update api docs spec for invite enpoint (#34843) 2025-09-17 14:50:53 -05:00
multiple_invites_spec.rb
notifications_spec.rb
posts_spec.rb DEV: Update api-docs for posts locked endpoint (#35453) 2025-10-16 12:56:34 -06:00
private_messages_spec.rb
rate_limits_spec.rb DEV: API to register custom request rate limiting conditions (#30239) 2024-12-23 09:57:18 +08:00
search_spec.rb DEV: Replace JS build system with Rolldown (#35963) 2026-05-29 11:11:55 +01:00
site_spec.rb DEV: Enable Style/RedundantBegin rubocop rule (#40096) 2026-05-19 18:44:54 +02:00
tags_spec.rb DEV: Use tag_name/tag.name instead of tag_id/tag.id where the name is actually used (#36226) 2025-12-29 13:20:06 +08:00
topics_spec.rb DEV: Fix api docs openapi spec validation errors (#35361) 2025-10-14 07:32:58 -06:00
uploads_spec.rb DEV: Restore and update request/api specs (#39483) 2026-04-23 20:13:52 +02:00
user_badges_spec.rb
users_spec.rb FIX: Reject DiscourseConnect SSO payloads when secret is blank (#40830) 2026-06-12 15:17:16 +03:00