Skip to content

Creating Enum class from dictionary #13

@zero0nee

Description

@zero0nee

I want the user to be able to select parameter values from an enum list of values as a dropdown in the swagger documentation.

The only way, to my knowledge, to do that is to create a Enum pydantic class, and designate a parameter as a part of that class. Which is fine. But in my situation, I want the enum to be dynamically generated based on all unique document values of a property stored in a MongoDB collection. I think you can create a BaseModel class dynamically using the create_model() function, but as far as I know that's not possible with a Enum class.

So my question is: How can I create a parameter enumeration in Swagger from all values in a mongDb collection?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions