[BUG][csharp-netcore] Ignoring EnumMember.Value when converting an list of enums query parameter to string
Created by: JonasSchubert
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
If a query parameter is of type ICollection the underlying type will be ignored and it will be cast to an object and then joined using string.Join. It might be similar to https://github.com/OpenAPITools/openapi-generator/issues/10107, but now EnumMember.Value is considered if standalone - not in a collection.
openapi-generator version
6.3.0
OpenAPI declaration file content or url
UserType:
type: string
enum:
- I
- X
- T
minLength: 1
maxLength: 1
description: |
Contains the user type.
- `I` - internal
- `X` - external
- `T` - team / functional
example: I
[JsonConverter(typeof(StringEnumConverter))]
public enum UserType
{
[EnumMember(Value = "I")]
Internal = 1,
[EnumMember(Value = "X")]
External = 2,
[EnumMember(Value = "T")]
TeamOrFunctional = 3
}
Generation Details
- Docker container openapitools/openapi-generator-cli:latest
- for csharp-netcore
docker run --rm -v ${PWD}/:/local openapitools/openapi-generator-cli generate -i /local/openapi.yaml -g csharp-netcore -o /local/out --additional-properties=aspnetCoreVersion=6.0,buildTarget=program,operationIsAsync=true,packageName=My.Package.Name,swashbuckleVersion=6.5.0 --skip-validate-spec
Steps to reproduce
- Generate a client from above examples and perform a query with an enum as a query parameter.
- The list/collection query parameter will not have the Value from EnumMember but rather their name
- instead of
"X,T"it will be"External,TeamOrFunctional"
- instead of
Related issues/PRs
Suggest a fix
Change ln 115 in ClientUtils to iterate over every item in a collection and convert them one by one:
if (obj is ICollection collection)
{
var stringParameterList = new List<string>();
foreach (var item in collection)
{
stringParameterList.Add(ParameterToString(item, configuration));
}
return string.Join(",", stringParameterList);
}
using System.Collections.Generic; has to be added additionally.