Repository navigation
Add problem details JSON body with supported content type - #226
Conversation
czechboy0
left a comment
There was a problem hiding this comment.
Thanks @arthurcro - a great start, let's make it even better with more type-safety and creating docs pages for each of our errors here.
czechboy0
left a comment
There was a problem hiding this comment.
A few more nits, mainly the missing docs page
c8ca1af to
a886963
Compare
- Added missing code documentation for new types and root folder for documenting supported problem details types. - Updated `ProblemDetails.ProblemType.type` to use updated documentation path - Updated `details` to `detail` to match RFC 9457 fields
a886963 to
6ac155d
Compare
- Updated `RuntimeError.unexpectedAcceptHeader` an expected header array and a received header array. - `receivedContentTypes` and `expectedContentTypes` attached to the problem type are now arrays. - Updated related docs to mention an array of string instead of a single string.
75c3e0d to
e8b9a07
Compare
czechboy0
left a comment
There was a problem hiding this comment.
Thanks, @arthurcro - I added a few more tweaks, ready to go now
Great, thanks for the help wrapping this up! 🙇 |
No problem - could you just update the PR description to reflect the new shape? That'll ensure the squashed commit reflects where we landed. |
I just updated the description! |
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:
swift-openapi-runtime/Sources/OpenAPIRuntime/Errors/RuntimeError.swift
Line 168 in 49689c7
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 apple/swift-openapi-generator#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 asapplication/jsonortext/*, listed in the request'sAcceptheader 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
typefield. https://www.rfc-editor.org/rfc/rfc9457.html#name-typeResult
Test Plan
testRuntimeError_withUnexpectedAcceptHeader_returnsProblemDetailstoTest_RuntimeError.testValidateAccept_notAcceptable_reportsContentTypestoTest_Converter+Server.