Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #14643
Closed
Open
Issue created Feb 08, 2023 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[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"
Related issues/PRs
  • https://github.com/OpenAPITools/openapi-generator/issues/10107
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.

Assignee
Assign to
Time tracking