Accept validation: allow +json structured syntax types #165
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