Skip to content

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

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 \").

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions