Treat "+json" structured-syntax-suffix media types as JSON - #1415
Open
fpcousins wants to merge 1 commit into
Open
Treat "+json" structured-syntax-suffix media types as JSON#1415fpcousins wants to merge 1 commit into
fpcousins wants to merge 1 commit into
Conversation
Classify any "+json" media type as JSON for both request bodies and responses. Requests send the media type the spec declares rather than application/json. Adds a json-suffix.json sample spec covering a "+json" request, a "+json" 2XX response, and a problem+json default error. RFC 6839 §3.1: https://www.rfc-editor.org/rfc/rfc6839#section-3.1
fpcousins
marked this pull request as ready for review
August 27, 2026 23:00
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.
Firstly, thank you for progenitor! It's doing great work for us.
Would you consider accepting
+jsonstructured-syntax-suffix media types? I appreciate Dropshot never emits them, but they're standardised (RFC 6839 §3.1) and our in-house specs useapplication/problem+jsonfor errors which means that our generated clients get untyped errors, so this would be a lovely addition! Happy to rework the implementation if you'd prefer a different shape.Currently progenitor only recognises
application/jsonexactly, so:application/problem+json(RFC 9457) generatesError<ByteStream>instead of a typed error;+jsontype is rejected withUnexpectedFormat.This change classifies any
+jsonmedia type as JSON for both request bodies and responses. Only the exactapplication/jsonor a+jsonsuffix qualifies,text/jsonand friends are deliberately still rejected.Request bodies keep the declared media type:
BodyContentType::Jsonnow carries it (asText(String)does), and for a+jsontype the generated call setsContent-Typebefore.json(&body). reqwest'sjson()only addsapplication/jsonwhen noContent-Typeis already present, so the declared type is what's sent, and because it's still.json()serialization errors are deferred as before. This matters where the media type itself carries semantics (e.g.application/merge-patch+jsonvsapplication/json-patch+jsonon the same JSON body) and other generators (oapi-codegen, hey-api) do the same. Plainapplication/jsonbodies generate exactly as before so no existing fixture changes.One new fixture:
sample_openapi/json-suffix.json: one operation with a+jsonrequest, a+json2XXresponse and aproblem+jsondefaulterror, in the style ofparam-collision.json. It generates (positional variant):sending
Content-Type: application/vnd.example.annotation+json.Not touched: the request
Acceptheader and the httpmocksuccess/createdhelpers still hard-codeapplication/jsonfor a+jsonresponse. Left alone as this is pre-existing behaviour.Related: #1239 (open, no review yet) takes the same approach for responses only, without a fixture. This PR also covers request bodies and adds output tests, so I'd suggest it supersedes #1239 but I can rebase onto it if preferred.