Skip to content

Add problem details JSON body with supported content type - #226

Open
arthurcro wants to merge 1 commit into
apple:mainfrom
arthurcro:arthurcro/problem-details
Open

arthurcro wants to merge 1 commit into
apple:mainfrom
arthurcro:arthurcro/problem-details

Conversation

@arthurcro

Copy link
Copy Markdown
Contributor

Motivation

Closes apple/swift-openapi-generator#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:

case .unexpectedAcceptHeader: .notAcceptable

Modifications

Adds the error returned as the http body of the error response structued as a product details https://www.rfc-editor.org/rfc/rfc9457.html.

Along with human readable informations, it adds two extra fields expected and received which contains machine readable information helping to figure out which accept header was received and which were expected.

Result

{
  "details":"Unexpected Accept header: text\/plain",
  "expected":"application\/json",
  "received":"text\/plain",
  "status":406,
  "title":"Unexpected Accept header",
  "type":"about:blank"
}

Test Plan

Added testRuntimeError_withUnexpectedAcceptHeader_returnsProblemDetails to Test_RuntimeError.

@czechboy0
czechboy0 self-requested a review October 10, 2026 20:07
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.

Include a JSON body with the supported content type when returning a 406

1 participant