Repository navigation
feat(generator): RFC 9457 problem details are read as such, so errors show their detail instead of a JSON body - #133
Merged
Conversation
… show their detail instead of a JSON body
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A generated client reads an
application/problem+jsonerror as RFC 9457 problem details, whatever the operation's error schema declares.APIErrorrecords the response'sContentType.APIError.Problem()returns a*ProblemDetails(Type,Title,Status,Detail,Instance, and every other member inExtensionsas raw JSON) for a problem body, and nil for any other media type or a body that doesn't parse as one.APIError.Error()renders the problem'sdetail, or itstitlewhen it has none, instead of the raw body.APIError.Error()rather than JSON.ProblemDetailsis a reserved identifier, so a schema with that name is renamed. README documents it.Behavior for servers that don't send
application/problem+jsonis unchanged.Why
An API that answers with problem details, but whose spec still declares an older error schema for its operations, made generated clients print
API error 422 ...: {"type":...}: the typed wrapper's parse failed on the problem'serrorsobjects, andAPIErroronly knew how to print the body. Code that wanted the problem's code had to re-parseBodyitself.Test
go test ./...(the new e2e test generates a client and checks detail and title rendering, members and extensions, thatapplication/jsonbodies aren't parsed, malformed problems keep the body, both wrapper fallbacks, and a real round trip recordingContent-Typewitherrors.Is(err, ErrNotFound)still true),go vet,gofmt, golangci-lint 0 issues.