swagger-api / swagger-api/swagger-codegen

[Typescript Axios] Type annotations are escaping special characters

Open
#10,595 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I am using the typescript-axios preset to generate the API client. The generated code is using HTML escaping which is causing certain type annotations, particularly ones which use special characters, to not get recognized by Typescript in my client codebase.

Below is what the outputted client code looks like:

export interface ServerpbInvoice {
    /**
     * @inject_tag: validate:\"required\"
     * @type {Array<ServerpbInvoiceItems>}
     * @memberof ServerpbInvoice
     */
    items: any;
    ...
}
Swagger-codegen version

3.0.23

Swagger declaration file content or url
{
    ...
    "definitions": {
        "serverpb.Invoice": {
            "type": "object",
            "required": [
                ...
            ],
            "properties": {
                ...
                "items": {
                    "description": "@inject_tag: validate:\"required\"",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/serverpb.InvoiceItems"
                    }
                },
            }
        }
    }
    ...
}
Command line used for generation

swagger-codegen generate -i docs/swagger.json -l typescript-axios -o ./generated

Steps to reproduce
  1. Run the command described above to generate an API client
  2. Reference a property with escaped special characters in the type annotation
  3. Run the Typescript compiler
Related issues/PRs

I could not find any.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the stated swagger-codegen command with docs/swagger.json and inspect the typescript-axios output in generated. Trace where the items type annotation is rendered and verify that special characters remain usable by the TypeScript compiler; done means the generated client compiles without the escaping issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.