Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Need to update Path and Body parameters DOC default values examples #4911

@akash-vns

Description

@akash-vns

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google "How to X in FastAPI" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from typing import Union

from fastapi import Body, FastAPI, Path
from pydantic import BaseModel, Field

app = FastAPI()


class Item(BaseModel):
    name: str
    description: Union[str, None] = Field(
        default=None, title="The description of the item", max_length=300
    )
    price: float = Field(gt=0, description="The price must be greater than zero")
    tax: Union[float, None] = None


@app.post("/{data_id:str}")
async def index(data_id: int = Path(title="The ID of the item to get", ge=0, le=1000),
                data: Item = Body(embed=True)):
    if data:
        print(data)
    return data

Description

Hello Team,

When i try to follow the same steps that are described into the (Body-Fields Doc , and Path-params Doc )
and its give us default values are required error .

(when i try to run above code and that code gave me a default value is required error )

Document is not have update that default values is required into the Path and Body like Query

happy to raise PR for the Doc update.

Operating System

Linux

Operating System Details

No response

FastAPI Version

0.77.1

Python Version

3.8

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions