Skip to content

fix (#49): restore body on clone - #61

Merged
mromaszewicz merged 4 commits into
oapi-codegen:mainfrom
karlpip:restoreBody
Oct 23, 2026
Merged

mromaszewicz merged 4 commits into
oapi-codegen:mainfrom
karlpip:restoreBody

Conversation

@karlpip

@karlpip karlpip commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

fixes: #49

@karlpip
karlpip requested a review from a team as a code owner July 24, 2026 15:36
@karlpip karlpip changed the title #49 restore body on clone fix (#49): restore body on clone Jul 24, 2026
@mromaszewicz mromaszewicz added the bug Something isn't working label Oct 23, 2026
mromaszewicz and others added 2 commits October 22, 2026 18:06
Bring the branch up to date with kin-openapi v0.152.0 and echo v4.16.0.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Validating a req.Clone() meant openapi3filter put the re-readable body,
the KeepValidatedValue wrapper and any defaults-rewritten ContentLength
back on the clone only. Copying Body/GetBody back still missed
ContentLength, and only URL.Path was trimmed, so percent-encoded path
parameters under a prefix mis-routed.

Follow the approach of oapi-codegen/echo-v5-middleware#17 by blacksud0
so both repos share one fix: trim URL.Path and URL.RawPath on the live
request and restore them in a defer that runs before the next handler.
Everything kin writes to the body now lands on the request the handler
sees. An AuthenticationFunc reading GetEchoContext(ctx).Request().URL.Path
now sees the trimmed path during validation.

Keep the POST case added to TestOapiRequestValidatorWithPrefix and add
tests for the issue oapi-codegen#49 security + AuthenticationFunc + body scenario
(exact body, ContentLength, original path), a defaults-rewritten body,
KeepValidatedValue, and a percent-encoded path parameter under a prefix.

Closes oapi-codegen#49

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@mromaszewicz

Copy link
Copy Markdown
Member

Thanks for the fix and the test, @karlpip. A maintainer has pushed two commits on top of your branch: a merge of main (kin-openapi v0.152.0, echo v4.16.0) and a change of approach to match oapi-codegen/echo-v5-middleware#17, trimming the prefix in place on the live request instead of validating a clone. That also carries over ContentLength and the new kin-openapi KeepValidatedValue wrapper, and fixes RawPath for percent-encoded path params under a prefix. Your POST test is kept, with more tests added alongside it.

@mromaszewicz
mromaszewicz enabled auto-merge (squash) October 23, 2026 01:13
@mromaszewicz
mromaszewicz merged commit d033a0b into oapi-codegen:main Oct 23, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Prefix option causes http: invalid Read on closed Body in downstream handlers

2 participants