Skip to content

Conversation

@maks-oleksyuk
Copy link
Contributor

Overview

This PR enhances OpenAPI response generation by adding support for custom Content-Types.
Now responses can correctly specify and document schemas for:

  • application/problem+json (RFC 7807 error format)
  • application/vnd.api+json (JSON:API)
  • application/octet-stream (binary data)
  • text/plain (plain text)
  • Defaulting to application/json when no content-type is provided

Example

return new JsonResponse([
    'type' => 'https://example.com/probs/invalid-user-id',
    'title' => 'Invalid user ID',
    'status' => 404,
    'detail' => 'User with given ID not found',
], 404, ['Content-Type' => 'application/problem+json']);

Generated OpenAPI

404:
  description: Invalid user ID
  content:
    application/problem+json:
      schema:
        type: object
        properties:
          type: { type: string, example: https://example.com/probs/invalid-user-id }
          title: { type: string, example: Invalid user ID }
          status: { type: integer, example: 404 }
          detail: { type: string, example: User with given ID not found }

Tests

Added unit tests for JSON, problem+json, text/plain, binary, nullable, and arrays.

@shalvah shalvah merged commit 3278e9e into knuckleswtf:v5 Oct 20, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants