Skip to content
Discussion options

You must be logged in to vote

AFAIK, openapi doesn't support such thing.

Consider this approach:

from typing import Literal

from fastapi.applications import FastAPI
from pydantic import BaseModel


class LessonWithExtra(BaseModel):
    id: int
    name: str
    extra_field: str


app = FastAPI()


@app.post("/path")
async def demo_post(value: str, value_type: Literal["this", "that"]):
    return {"message": f"{value_type} == {value}"}

Instead of two optional this and that parameters define two required parameters. First of them is to pass the value and second defines type of value (this or that)

Replies: 4 comments 2 replies

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
2 replies
@OlegZv
Comment options

@saltaverde
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
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
5 participants
Converted from issue

This discussion was converted from issue #5731 on February 28, 2023 15:44.