← Back to Pull requests

Add problem details JSON body with supported content type #226

Closed
unknown closed this pull request without merging on Nov 03, 2026 10:02 UTC
View on GitHub
unknown unknown commented on Oct 10, 2026 18:26 UTC
Author

Motivation

Closes https://github.com/apple/swift-openapi-generator/issues/963

When returning a 406, right now we only return the code. Figuring out what code (and thus content type) we were actually trying to return requires the user to dig into the OpenAPI doc/server codebase more: https://github.com/apple/swift-openapi-runtime/blob/49689c749c36542443e91c1bff4da2e2a5f28dc3/Sources/OpenAPIRuntime/Errors/RuntimeError.swift#L168

Modifications

Enables returning problem details error as the http body of the response when the server encountered a runtime error. https://www.rfc-editor.org/rfc/rfc9457.html.

For https://github.com/apple/swift-openapi-generator/issues/963, along with human readable informations specific to the problem type, it includes two machine-readable extension fields to help clients diagnose and correct the mismatch of the particular problem details instance:

  • responseContentType: A string with the content type of the response that the server tried to send.

  • acceptableContentTypes: An array of strings with the media ranges, such as application/json or text/*, listed in the request's Accept header field, without parameters such as quality values.
  • Further, we add a root documentation folder to document supported problem details types and refer to that documentation in the problem details type field. https://www.rfc-editor.org/rfc/rfc9457.html#name-type

    Result

    HTTP/1.1 406 Not Acceptable
    Content-Type: application/problem+json
    
    {
      "acceptableContentTypes": ["text/plain"],
      "detail": "Response content type not acceptable, content type: application/json, accepted: text/plain",
      "responseContentType": "application/json",
      "status": 406,
      "title": "Response content type not acceptable",
      "type": "https://swiftpackageindex.com/apple/swift-openapi-runtime/documentation/openapiruntime/response-content-type-not-acceptable"
    }
    

    Test Plan

  • Added testRuntimeError_withUnexpectedAcceptHeader_returnsProblemDetails to Test_RuntimeError.

  • Added testValidateAccept_notAcceptable_reportsContentTypes to Test_Converter+Server.
  • Diff: 269 lines (+201 / -68) across 3 files Reviewer: czechboy0 Review duration: 34056m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 269 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.335
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #226"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.4% (MEDIUM) · Higher = larger blast radius
    39.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.6% · Safe to merge
    15.6%