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][PYTHON] Int Enum serialization is the enum name instead of value #18327

Closed
5 of 6 tasks
BaptisteSaves opened this issue Apr 8, 2024 · 0 comments · Fixed by #18328
Closed
5 of 6 tasks

[BUG][PYTHON] Int Enum serialization is the enum name instead of value #18327

BaptisteSaves opened this issue Apr 8, 2024 · 0 comments · Fixed by #18328

Comments

@BaptisteSaves
Copy link
Contributor

BaptisteSaves commented Apr 8, 2024

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

When using Enum as a parameter, the serialization is the enum name instead of the value. Enum.NUMBER_0 instead of 0

openapi-generator version

v7.4.0

OpenAPI declaration file content or url
openapi: 3.1.0
info:
  title: Sample API
  version: 1.0.0
paths:
  /path:
    get:
      parameters:
        - in: query
          name: param
          schema:
            type: array
            items:
              $ref: '#/components/schemas/AnEnum'
      responses:
        200:
          description: Ok
components:
  schemas:
    AnEnum:
      type: integer
      enum:
        - 0
        - 1
Generation Details

Simple generation in 7.4.0 with -g python

Steps to reproduce

This code currently fails

import unittest
from openapi_client import DefaultApi, AnEnum

class TestIssue(unittest.TestCase):

    def test_issue_enum(self):
        assert DefaultApi()._path_get_serialize([AnEnum.NUMBER_0], None,None,None, 0)[1] == '/api/issueX?param=0'
Suggest a fix

https://github.com/OpenAPITools/openapi-generator/blob/f323a3e788ec932ddc1e31f44f3bd0c8a88f7dbc/modules/openapi-generator/src/main/resources/python/api_client.mustache#L355C25-L355C28 Before testing for primitive types, test for Enum and return obj.value

In Python, the object is both primitive and enum

--> will push a PR with this fix

BaptisteSaves added a commit to BaptisteSaves/openapi-generator that referenced this issue Apr 8, 2024
BaptisteSaves added a commit to BaptisteSaves/openapi-generator that referenced this issue Apr 9, 2024
BaptisteSaves added a commit to BaptisteSaves/openapi-generator that referenced this issue Apr 9, 2024
BaptisteSaves added a commit to BaptisteSaves/openapi-generator that referenced this issue Apr 9, 2024
BaptisteSaves added a commit to BaptisteSaves/openapi-generator that referenced this issue Apr 9, 2024
BaptisteSaves added a commit to BaptisteSaves/openapi-generator that referenced this issue Apr 9, 2024
BaptisteSaves added a commit to BaptisteSaves/openapi-generator that referenced this issue Apr 9, 2024
BaptisteSaves added a commit to BaptisteSaves/openapi-generator that referenced this issue Apr 9, 2024
BaptisteSaves added a commit to BaptisteSaves/openapi-generator that referenced this issue Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant