Skip to content

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

Closed

Description

@FenTiger

Sample api.yml:

openapi: "3.0.0"

info:
  version: 0.0.1
  title: example

paths:
  /object:
    get:
      responses:
        '200':
          content:
            "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"":
              schema:
                type: string

Sample config.yml:

package: main
generate:
  gorilla-server: true
  strict-server: true
output: test.go

The result I get is

error generating code: error formatting Go code 
[ ... dump of the code it is trying to generate ... ]
: main.go:221:79: missing ',' in argument list (and 10 more errors)

The dumped code has some invalid syntax:

func (response GetObject200ApplicationLdPlusJSONProfilehttpswwwW3OrgnsactivitystreamsResponse) VisitGetObjectResponse(w http.ResponseWriter) error {
    w.Header().Set("Content-Type", "application/ld+json; profile="https://www.w3.org/ns/activitystreams"")
    w.WriteHeader(200)

This can be worked around by double-escaping the quotes in the input (ie using \\\" instead of \").

Activity

  1. jamietanna commented on Nov 3, 2024

    @jamietanna
    Member

    Ooh very interesting catch thanks! Yep that's a bug we should address

  2. added
    bug
    on Nov 3, 2024
  3. viktorasm commented on Mar 15, 2025

    @viktorasm
    Contributor

    @jamietanna posted a proposed fix.

  4. mromaszewicz commented on May 1, 2026

    @mromaszewicz
    Member

    PR #2217 (merged Feb 13 2026, commit 01d4fc0) fixed this exact bug by introducing StringToGoString() in pkg/codegen/utils.go and updating both buildUnmarshalCase/buildUnmarshalCaseStrict in template_helpers.go and the strict-interface templates to use this function. The fix officially targets issue #1529 which is the same underlying bug. The generated test file internal/test/issues/issue-1529/strict-echo/issue1529.gen.go shows correctly escaped output (e.g. "application/json; profile="Foo""), confirming the fix covers the exact case from issue #1799 (gorilla + strict-server with quoted profile parameter in Content-Type).

    Closing as fixed. If you can still reproduce on a recent release, please reopen with the exact spec and version used.

  5. added a commit that references this issue on May 4, 2026
    c346d12
  6. added a commit that references this issue on Jun 23, 2026
    a72ae89
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions