Skip to content

Invalid code generated for paths starting with number #5226

@etriebe

Description

@etriebe

Have one of the methods in your open api be the following, which is one of the default identity api names provided by Microsoft and sadly trying to change this also creates issues on Microsoft's end. I've logged an issue for that (dotnet/aspnetcore#62934).

    "/manage/2fa": {
      "post": {
        "tags": [
          "Pickem.API"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TwoFactorRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TwoFactorResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/HttpValidationProblemDetails"
                }
              }
            }
          },
          "404": {
            "description": "Not Found"
          }
        }
      }
    },

Then run a TypeScriptClientGenerator that looks like this.

// See https://aka.ms/new-console-template for more information
using NSwag;
using NSwag.CodeGeneration.TypeScript;

Console.WriteLine("Hello, World!");
var document = await OpenApiDocument.FromFileAsync("D:\\Repos\\pickem\\GenerateTypescriptClients\\v1.json");

var settings = new TypeScriptClientGeneratorSettings
{
    ClassName = "{controller}Client",
};

var generator = new TypeScriptClientGenerator(document, settings);
var code = generator.GenerateFile();
File.WriteAllText("MyApiClient.ts", code);
Console.WriteLine("TypeScript client code generated and saved to MyApiClient.ts");

The resulting typescript file will have invalid typescript because a method starts with a number.

This may be converted to an async function.ts(80006)
Member '2' implicitly has an 'any' type.ts(7008)
An identifier or keyword cannot immediately follow a numeric literal.ts(1351)

Expected:

Either give me an option to rename a particular API with some sort of lambda or be smart enough to recognize that this will create invalid typescript and do something like add an underscore at the start.

Attached v1.json and the generated typescript file.

v1.json
MyApiClient.ts.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions