Skip to content

fix: properly handle quotes in content-type when generating server code#1929

Merged
mromaszewicz merged 7 commits into
oapi-codegen:mainfrom
viktorasm:fix/1799-content-type-with-quotes
May 4, 2026
Merged

fix: properly handle quotes in content-type when generating server code#1929
mromaszewicz merged 7 commits into
oapi-codegen:mainfrom
viktorasm:fix/1799-content-type-with-quotes

Conversation

@viktorasm

@viktorasm viktorasm commented Mar 15, 2025

Copy link
Copy Markdown
Contributor

fixes #1799

OpenAPI media types may contain characters that require escaping in Go string literals, for example, application/ld+json; profile="https://..." which the templates were emitting verbatim, producing invalid Go.

PR #2217 had a partial fix for this, and this PR fixes the other cases.

Adds a regression test under internal/test/issues/issue1799/ covering chi, client, echo, fiber, gin, gorilla, iris, and std-http generation modes with a spec containing a quoted media-type parameter.

@viktorasm
viktorasm requested a review from a team as a code owner March 15, 2025 14:13
@viktorasm
viktorasm marked this pull request as draft March 15, 2025 14:45
@viktorasm
viktorasm marked this pull request as ready for review March 15, 2025 14:54
@FenTiger

Copy link
Copy Markdown

I gave this a quick try. It's now able to generate code for my original API definition, so this looks good to me.

@mromaszewicz

Copy link
Copy Markdown
Member

I'm going to rebase and fix up this commit then merge it. It does address a few bugs, thanks.

@mromaszewicz mromaszewicz added the bug Something isn't working label May 4, 2026
# Conflicts:
#	pkg/codegen/template_helpers.go
#	pkg/codegen/templates/strict/strict-fiber-interface.tmpl
#	pkg/codegen/templates/strict/strict-interface.tmpl
#	pkg/codegen/templates/strict/strict-iris-interface.tmpl
@mromaszewicz
mromaszewicz merged commit c346d12 into oapi-codegen:main May 4, 2026
14 checks passed
lwc pushed a commit to lwc/oapi-codegen that referenced this pull request Jun 23, 2026
…de (oapi-codegen#1929)

fixes oapi-codegen#1799

OpenAPI media types may contain characters that require escaping in Go string literals, for example, application/ld+json; profile="https://..." which the templates were emitting verbatim, producing invalid Go.

PR oapi-codegen#2217 had a partial fix for this, and this PR fixes the other cases.

Adds a regression test under internal/test/issues/issue1799/ covering chi, client, echo, fiber, gin, gorilla, iris, and std-http generation modes with a spec containing a quoted media-type parameter.
Co-authored-by: Marcin Romaszewicz <marcinr@gmail.com>
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.

Quotes in Content-Type cause "error generating code: error formatting Go code"

3 participants