Repository navigation
Bug: RestAPI event resolver: OpenAPI generation with content-type header generated wrong spec #8347
Description
Activity
- addedbugSomething isn't workingSomething isn't workingtriagePending triage from maintainersPending triage from maintainers
on Jul 14, 2026 Thanks for the detailed reproduction. I checked the current
developimplementation, and the request-body media type is intentionally derived fromBody.media_typeinopenapi/schema_generator.py;Header(...)creates a separatein: headerparameter.The resolver already supports the expected request-body entry by declaring the body parameter as:
approved_consumers: Annotated[ list[ApprovedConsumersPatchOperation], Body(media_type=application/json-patch+json), ]
That produces
requestBody.content[application/json-patch+json]directly. Keeping theContent-Typeheader annotation is separate from selecting the OpenAPI request-body representation.Could you confirm whether moving the media-type declaration to
Body(...)addresses the generated schema for your route? If it does, this appears to be a supported usage path rather than a generator defect.Reacted by Ryno MarreeYes you are right, adding the media type to the body correctly generates the schema. However adding this alone does not actually prevent other media types being rejected, I guess by design? Im wondering what the design philosophy should be then for a use-case like this. We might keep the header validation separate then?
Thanks, that separates two concerns cleanly.
With request validation enabled, retaining the Header(alias=Content-Type) parameter with a Literal[...] is what enforces the accepted value at runtime; Body(media_type=application/json-patch+json) supplies the correct requestBody.content entry. The resolver therefore needs both declarations for this use case.
The remaining OpenAPI-generation defect is narrower: it serializes that runtime-only Content-Type validation as an in: header parameter. OpenAPI does not allow Content-Type header parameters; the request body content media type is its representation instead. A focused fix could keep the header field in the runtime dependant/validation path, but omit a header parameter named content-type from the generated schema. A functional test would assert that the media type remains under requestBody.content and that no Content-Type parameter is emitted.
Would maintainers consider that the intended behavior? If so, I can prepare the small schema-generator patch and regression test.
Hey @RynoM and @DebadityaHait, thanks a lot for working through this together. The back and forth here made the actual problem much clearer than the original report, and I appreciate it.
I think two separate things were mixed up:
The request body media type was a usage thing, not a bug.
Body(media_type="application/json-patch+json")generates the rightrequestBody.contententry, as you confirmed.The real bug is narrower: we emit
Content-Typeas anin: headerparameter. The spec says a header parameter namedAccept,Content-TypeorAuthorization"SHALL be ignored", so what we generate is not invalid, but it is noise that every tool throws away, and it pollutes the docs. The request body content key is the correct representation.I checked and the runtime validation is doing real work here: with
Literal[...]on that header, a wrong media type gets a 422 and the right one passes. So the fix has to keep the field in the dependant and validation path, and only skip it when generating the schema. Removing it outright would silently kill that validation.On scope, I'd like to keep this to
Content-Typeonly for now. I looked at our test suite and we have existing tests assertingauthorizationshows up as a parameter, so filtering all three names at once changes behaviour people may be relying on in their generated docs.Authorizationreally belongs in a Security Scheme, but that is a bigger conversation and I don't want to sneak it into a bug fix. Happy to open a separate issue for it if you think it's worth it.@DebadityaHait if you're still up for it, please go ahead with the PR. Scope it to
Content-Type(case insensitive, since we normalise header names to lowercase), and for tests it would be great to cover: the media type stays underrequestBody.content, nocontent-typeparameter is emitted, and the runtime still returns 422 for a wrong media type. That last one matters most to me.Thanks again to both of you.
- moved this from Triage to Coming soon in Powertools for AWS Lambda (Python)
on Aug 10, 2026 powertools-for-aws-oss-automation commented
on Aug 10, 2026 More actionsWarning
This issue is now closed. Please be mindful that future comments are hard for our team to see.
If you need more assistance, please either reopen the issue, or open a new issue referencing this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.- addedpending-releaseFix or implementation already in dev waiting to be releasedFix or implementation already in dev waiting to be releasedand removedtriagePending triage from maintainersPending triage from maintainers
on Aug 10, 2026 github-actions commented
on Aug 10, 2026 on Aug 10, 2026 – with GitHub ActionsContributorMore actionsThis is now released under 3.34.0 version!
- removedpending-releaseFix or implementation already in dev waiting to be releasedFix or implementation already in dev waiting to be released
on Aug 10, 2026
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsComing soon
Expected Behaviour
Given the following route in our application:
We would expect the following snippet in our OpenAPI spec:
Current Behaviour
However currently this generates:
Code snippet
Possible Solution
Couple headers should be treated as special cases:
https://swagger.io/docs/specification/v3_0/describing-parameters/#header-parameters
Steps to Reproduce
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.13
Packaging format used
PyPi
Debugging logs