Accept validation: allow +json structured syntax types#165
Open
brandonbloom wants to merge 1 commit intoapple:mainfrom
Open
Accept validation: allow +json structured syntax types#165brandonbloom wants to merge 1 commit intoapple:mainfrom
brandonbloom wants to merge 1 commit intoapple:mainfrom
Conversation
Contributor
|
I didn't realize the suffix behavior is defined in an RFC, thanks for sharing! I agree we should improve this and handle Now, I think we also need to adjust the client response content type checking logic here: We'll need to be careful when multiple JSON-ish content types are specified, the method linked above does create a specific priority based on parameters, and so on. So we should integrate the suffix handling there. |
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.
Motivation
Converter.validateAcceptIfPresentvalidates the requestAcceptheader against the server’s chosen responseContent-Type. Today this is strict (exacttype/subtypematch,type/*, or*/*), which means a common real-world pairing fails:Accept: application/jsonContent-Type: application/problem+jsonHTTP content negotiation does not standardize suffix-aware matching for structured syntax suffixes, so treating
application/jsonas compatible withapplication/*+jsonis a server policy choice. However, it is widely expected in practice (especially around Problem Details), and the strict behavior forces downstream servers to add middleware workarounds (e.g. mutateAcceptor avoid emittingapplication/problem+json) just to prevent a runtime error.Modifications
OpenAPIMIMEType.satisfies(acceptValue:)to add an additional compatibility rule for structured syntax suffixes:Accept: application/jsonas compatible withContent-Type: application/problem+json(and otherapplication/*+jsontypes with+json).Accept: application/*+jsonas compatible withapplication/problem+json(and alsoapplication/json).Tests/OpenAPIRuntimeTests/Conversion/Test_Converter+Server.swiftundertestValidateAccept.Result
The runtime’s
Acceptvalidation no longer throws for common JSON-based structured media types likeapplication/problem+jsonwhen clients sendAccept: application/json, reducing downstream middleware/workarounds while keeping existing exact and wildcard matching behavior.Test Plan
swift test --filter Test_ServerConverterExtensions.testValidateAccept