Skip to content
Discussion options

You must be logged in to vote

@malsumis What I understand you want to achieve is to define that the keys of a JSON object (a dict) are one of the values in the enum, right?

That's not really supported by OpenAPI (nor JSON Schema, I think).

What I imagine you want to achieve could be done like:

from fastapi import FastAPI
from starlette.responses import JSONResponse, Response
from starlette.status import *
from typing import Set, Dict, List
from enum import Enum
from pydantic import BaseModel

class EnumBasedInfo(str, Enum):
    ENUM1: str = 'ENUM1'
    ENUM2: str = 'ENUM2'
    ENUM3: str = 'ENUM3'
    ENUM4: str = 'ENUM4'

class ProcessingRequest(BaseModel):
    request1: str
    request2: str
    enums: Set[EnumBased…

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by tiangolo
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
3 participants
Converted from issue

This discussion was converted from issue #509 on February 28, 2023 11:55.