-
Notifications
You must be signed in to change notification settings - Fork 60
Accept validation: allow +json structured syntax types #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,6 +103,8 @@ final class Test_OpenAPIMIMEType: Test_Runtime { | |
| let jsonWith2Params = OpenAPIMIMEType("application/json; charset=utf-8; version=1")! | ||
| let jsonWith1Param = OpenAPIMIMEType("application/json; charset=utf-8")! | ||
| let json = OpenAPIMIMEType("application/json")! | ||
| let problemJSON = OpenAPIMIMEType("application/problem+json")! | ||
| let anyJsonStructuredSyntax = OpenAPIMIMEType("application/*+json")! | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also add
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I only covered the structured-suffix -> base-JSON direction here. I’ll add explicit |
||
| let fullWildcard = OpenAPIMIMEType("*/*")! | ||
| let subtypeWildcard = OpenAPIMIMEType("application/*")! | ||
|
|
||
|
|
@@ -130,5 +132,48 @@ final class Test_OpenAPIMIMEType: Test_Runtime { | |
| testJSONWith2Params(against: json, expected: .typeAndSubtype(matchedParameterCount: 0)) | ||
| testJSONWith2Params(against: subtypeWildcard, expected: .subtypeWildcard) | ||
| testJSONWith2Params(against: fullWildcard, expected: .wildcard) | ||
|
|
||
| testCase( | ||
| receivedType: "application", | ||
| receivedSubtype: "problem+json", | ||
| receivedParameters: [:], | ||
| against: json, | ||
| expected: .typeAndSubtype(matchedParameterCount: 0) | ||
| ) | ||
| testCase( | ||
| receivedType: "application", | ||
| receivedSubtype: "json", | ||
| receivedParameters: [:], | ||
| against: problemJSON, | ||
| expected: .typeAndSubtype(matchedParameterCount: 0) | ||
| ) | ||
| testCase( | ||
| receivedType: "application", | ||
| receivedSubtype: "json", | ||
| receivedParameters: [:], | ||
| against: anyJsonStructuredSyntax, | ||
| expected: .typeAndSubtype(matchedParameterCount: 0) | ||
| ) | ||
| testCase( | ||
| receivedType: "application", | ||
| receivedSubtype: "problem+json", | ||
| receivedParameters: [:], | ||
| against: anyJsonStructuredSyntax, | ||
| expected: .typeAndSubtype(matchedParameterCount: 0) | ||
| ) | ||
| testCase( | ||
| receivedType: "application", | ||
| receivedSubtype: "problem+xml", | ||
| receivedParameters: [:], | ||
| against: json, | ||
| expected: .incompatible(.subtype) | ||
| ) | ||
| testCase( | ||
| receivedType: "text", | ||
| receivedSubtype: "foo+json", | ||
| receivedParameters: [:], | ||
| against: json, | ||
| expected: .incompatible(.type) | ||
| ) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this right? Should
text/foo+jsonnot matchapplication/json?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that was intentional. I kept top-level type matching exact and only relaxed subtype matching via the structured suffix. My read of RFC 6839 is that
+jsonenables generic JSON processing, but not necessarily treating different top-level media types as equivalent for negotiation. Since OpenAPI content types are still full media types, I scoped this to same-type cases likeapplication/problem+jsonandapplication/json. If you think cross-type+jsonmatching is desirable, I can expand it, but that felt like a larger behavior change than this fix.