Skip to content

매개변수의 추가 정보

Nexify를 사용하면 다양한 매개변수에 대한 추가 정보를 기입할 수 있습니다.

제목 (title)과 설명 (description)

만약 특정 경로 매개변수나 쿼리 매개변수에 대해서 제목 또한 설명을 추가하고 싶다면, titledescription을 사용하면 됩니다.

from typing import Annotated

from nexify import Nexify, Path

app = Nexify()


@app.get("/items/{item_id}")
def read_item(
    item_id: Annotated[
        str,
        Path(
            title="Item ID",
            description="This is Item ID",
        ),
    ],
) -> dict:
    return {"item_id": item_id}

item_id에 대한 설명이 있는 것을 볼 수 있습니다.

Swagger UI Title and Description

Info

제목은 ReDoc에서만 표시됩니다.

예시 (openapi_examples)

from typing import Annotated

from nexify import Nexify, Path

app = Nexify()


@app.get("/items/{item_id}")
def read_item(
    item_id: Annotated[
        str,
        Path(
            openapi_examples={
                "Test item: Foo": {
                    "summary": "Item ID of a test item (Foo)",
                    "value": "2341",
                },
                "Test item: Bar": {
                    "summary": "Item ID of a test item (Bar)",
                    "value": "2342",
                },
            }
        ),
    ],
) -> dict:
    return {"item_id": item_id}

OpenAPI 예시가 Swagger 문서에서 볼 수 있는 것을 확인할 수 있습니다.

Swagger UI Example

지원 중단 기능 (deprecated)

만약 특정 경로 매개변수나 쿼리 매개변수를 삭제하지 않고, 지원 중단을 해야한다면, deprecated를 사용하면 됩니다.

from typing import Annotated

from nexify import Nexify, Path, Query

app = Nexify()


@app.get("/items/{item_id}")
def read_item(
    item_id: Annotated[str | None, Path()] = None,
    itemId: Annotated[
        str | None,
        Query(deprecated=True, description="This parameter is deprecated"),
    ] = None,
) -> dict:
    if itemId:
        return {"item_id": itemId}
    return {"item_id": item_id}

해당 itemId가 빨간색 deprecated 표시를 통해 지원 중단된 쿼리 매개변수인 것을 확인 할 수 있습니다.

Swagger UI Deprecated