Skip to content

[Typescript/fetch] Can't use colon in query parameter name  #4284

@ChrisJamesC

Description

@ChrisJamesC
Description

If a query parameter contains a colon, the generated code is broken since they are interpreted as type information by the typescript compiler.

Swagger-codegen version

2.2.1 - This is not a regression

Swagger declaration file content or url
{
  "swaggerVersion": "1.2",
  "basePath": "http://localhost:8000/greetings",
  "apis": [
    {
      "path": "/hello/{subject:main}",
      "operations": [
        {
          "method": "GET",
          "type": "string",
          "parameters": [
            {
              "name": "subject:main",
              "type": "string",
              "paramType": "path"
            }
          ]
        }
      ]
    }
  ],
  "models": {}
}
Command line used for generation

swagger-codegen generate -i hello.json -l typescript-fetch -o generated

Steps to reproduce

Grep for subject:main in the generated code.

Suggest a Fix
  • escape all usage of the dot notation to refer to parameters in api.mustache. So replacing params.{{paramName}} by params["{{paramName}}"]
  • Also replace the param names when they are referred to as interface keys: {paramName: xxx} becomes {"paramName": xxx}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions