RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.69k stars 1.24k forks source link

TypeScript: Enum array treated as ObjectArray and produces a wrong URL #1733

Open Kordonme opened 5 years ago

Kordonme commented 5 years ago

I have an enum like this:

export enum UserRole {
    Role1 = "Role1", 
    Role2 = "Role2", 
    Role3 = "Role3"
}

When generating a TypeScript client, the parameters in the method is generated as includedUserRoles: any[] and therefore the it's being treated as an ObjectArray. See the template on these lines.

This results in a wrong URL:

IncludedUserRoles[0].0=R&IncludedUserRoles[0].1=o&IncludedUserRoles[0].2=l&IncludedUserRoles[0].3=e&IncludedUserRoles[0].4=1

Expected output is simply IncludedUserRoles=Role1.

Is this related to Swagger generation or array handling in NSwag?

RicoSuter commented 5 years ago

Can you also post the produced swagger spec?

Kordonme commented 5 years ago

Here's a swagger.json.

RicoSuter commented 5 years ago

I'd say the output is as expected... you need to change the parameter type to array of this enum not array of any

Kordonme commented 5 years ago

The swagger is generated from C#

public List<UserRole> IncludedUserRoles { get; set; }
RicoSuter commented 5 years ago

With what do you generate the spec?

It should be:

            "type": "array",
            "items": {
                "$ref": "#/definitions/UserRole"
            },

Can you do that? Maybe with an operation filter/processor?