Skip to content

OpenAPI escaped strings are not escaped in Go #1529

Closed

Description

@TotallyGamerJet

I generated a Jellyfin client for the stable jellyfin spec with the following command:
oapi-codegen -package jellyfin -generate types,client jellyfin-openapi-stable.json > jellyfin_api.go

However, oapi-codegen stopped during formatting of the code with the message:

./jellyfin_api.go:105172:68: expected ':', found CamelCase (and 10 more errors)

The offending code looks like this:

case rsp.Header.Get("Content-Type") == "application/json; profile="CamelCase"" && rsp.StatusCode == 200:
  var dest BaseItemDtoQueryResult
  if err := json.Unmarshal(bodyBytes, &dest); err != nil {
	  return nil, err
  }
  response.ApplicationjsonProfileCamelCase200 = &dest

As you can see the content type string was not escaped.

Activity

  1. added
    bug
    on Apr 3, 2024
  2. deluan commented on Jan 7, 2025

    @deluan

    This error seems to also affect the strict-server generation for Jellyfin:

    jellyfin.go:26720:76: missing ',' in argument list (and 10 more errors)
    

    Offending code is the second line of this function:

    func (response GetInstantMixFromAlbum404ApplicationJSONProfileCamelCaseResponse) VisitGetInstantMixFromAlbumResponse(w http.ResponseWriter) error {
        w.Header().Set("Content-Type", "application/json; profile="CamelCase"")
        w.WriteHeader(404)
        return json.NewEncoder(w).Encode(response)
    }

    I'm using chi-server and strict-server. If I don't use strict-server it completes the code generation successfully.

    Tested with the latest from main: v2.4.2-0.20250102212541-8bbe226927c9

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