Skip to content
This repository was archived by the owner on Jan 12, 2026. It is now read-only.
This repository was archived by the owner on Jan 12, 2026. It is now read-only.

Enhance Undocumented Body Error Message to Include Received Data for Consistency #2883

@yuki2006

Description

@yuki2006

Description:

When using Optic to validate API responses against an OpenAPI specification, the detail level in error messages for response body issues is inconsistent. This inconsistency makes debugging certain types of discrepancies more difficult than others.

Current Behavior:

  1. Type Mismatch: When a response body field doesn't match the type defined in the schema, the error message helpfully includes the received value.

    [200 response body] '<field_name>' does not match type <expected_type>. Received <actual_value>
    

    Example: [200 response body] 'attachment' does not match type object. Received null

  2. Undocumented Body: When a response body is received for a status code/content type combination that is not documented in the OpenAPI spec, the error message only states that it's undocumented, without showing what was actually received.

    [<status_code> response body] body is not documented
    

Expected Behavior:

For consistency and improved debugging, the "body is not documented" error message should also include a preview of the received data, similar to the type mismatch error.

Example of desired format:

[<status_code> response body] body is not documented. Received <actual_body_preview>

Example: [404 response body] body is not documented. Received {"error": "Not Found", "details": "Resource unavailable..."} (Preview might be truncated for large bodies).

Why this is important:

When an API returns an undocumented response (especially for error status codes like 4xx or 5xx), seeing the actual response body directly in the Optic output is crucial for quickly understanding what went wrong or what unexpected data was returned. Currently, developers need to manually inspect traffic logs or re-run requests to see the content of these undocumented responses, slowing down the debugging process. This even forces developers into cumbersome workarounds, such as intentionally defining incorrect schemas for undocumented responses in the YAML file just to trigger the more informative 'type mismatch' error that includes the Received... data. Including the received body preview in the "body is not documented" error would eliminate this need and significantly improve the developer experience, making Optic's validation feedback more actionable.

Thank you for considering this improvement!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions