swagger-api / swagger-api/swagger-codegen

[Python] Add function to get list of allowed enum vars

Open
#9,745 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

We have a lot of enums defined in our backend. We have a small UI that shows these enums as a dropdown. The problem we face is whenever we update the enums on our backend. We have to update the frontend code. If swagger codegen can provide the enum values as a list we can return that in an API for frontend to populate these values or use this function to render it in django forms.

For example:

Consider this class

https://github.com/swagger-api/swagger-codegen/blob/b7ba9623a6fa8d9d352f4d8f9adea68119d71721/samples/client/petstore/python/petstore_api/models/outer_enum.py#L29-L31

It has enums placed, approved, delivered. But there is no way for me to get these values as a list at the moment.

Swagger-codegen version

2.4.8

Suggest a fix/enhancement

Add a function that returns the list of enum vars.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated Python model shown in samples/client/petstore/python/petstore_api/models/outer_enum.py around lines 29–31, then trace the template or generator input that produces its enum definitions. Confirm how the allowed values should be exposed for generated models and add coverage for the outer_enum example. Done means callers can retrieve placed, approved, and delivered as a list.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.