Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [csharp-netcore] Parameter of type Enum will not use EnumMember attribute but rather serialise Enum.Tostring() #11447

Closed
5 tasks done
jafin opened this issue Jan 29, 2022 · 1 comment

Comments

@jafin
Copy link
Contributor

jafin commented Jan 29, 2022

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?
Description

A Get query that takes an enum string type as a parameter, is not serializing into the correct value. Instead, it is being serialized to the Enum name not the EnumMember value

In the below example, PetStatusFilter will return title case Available or Pending or Sold. whereas it should return available or pending or sold

/pet/findByStatusWithFilter:
    get:
      tags:
        - pet
      summary: Finds Pets by status
      description: Multiple status values can be provided with comma separated strings
      operationId: findPetsByStatusWithFilter
      parameters:
        - name: status
          in: query
          description: Status values that need to be considered for filter
          required: true
          schema:
            type: array
            items:
              $ref: '#/components/schemas/PetStatusFilter'
    PetStatusFilter:
      type: string
      enum:
        - available
        - pending
        - sold			  
openapi-generator version
  • 5.4
  • main
Generation Details

The method in ClientUtils , ParameterToString does not check if obj is an Enum, and will default return obj.ToString().
Instead, it should be looking at the Enum's EnumMember attribute fo the value to return.

Steps to reproduce

Run generator ./bin/generate-sample.sh ./bin/configs/csharp with a modified version of the petstore.yaml including the above changes.

Related issues/PRs

None found

Suggest a fix
@wing328
Copy link
Member

wing328 commented Oct 19, 2022

#11448 has been merged. Please give it a try with the latest master.

@wing328 wing328 closed this as completed Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants