developmentseed / titiler

Build your own Raster dynamic map tile services
https://developmentseed.org/titiler/
MIT License
765 stars 157 forks source link

OpenAPI do not render Dependencies #723

Closed vincentsarago closed 10 months ago

vincentsarago commented 10 months ago

Just seeing this right now but it seems it's been quite some time now.

In ☝️ we should see examples and also have abilities to enter multiple entries for List parameters like

https://github.com/developmentseed/titiler/blob/75c94de2227059f13762dcf2d91c6c5fb5f708fc/src/titiler/core/titiler/core/dependencies.py#L78-L91

ref: https://github.com/tiangolo/fastapi/discussions/8420

vincentsarago commented 10 months ago

🤔 well it's not directly the same as https://github.com/tiangolo/fastapi/discussions/8420 because this simple example

from fastapi import Depends, FastAPI, Query
from dataclasses import dataclass
from typing import List, Optional
from typing_extensions import Annotated

app = FastAPI()

@dataclass
class CommonQueryParams:
    stuff: Annotated[
        Optional[List[str]],
        Query(
            title="stuff",
            description="some stuff.",
            examples={
                "example1": {
                    "description": "example for stuff 1.",
                    "value": ["stuffffff"],
                },
                "example2": {
                    "description": "example for stuff 2.",
                    "value": ["stuffffff", "stuffffff"],
                },
            },
        ),
    ] = None

@app.get('/using-model')
async def using_model(
        query: CommonQueryParams = Depends()
):
    pass

@app.get('/using-func')
async def using_func(
        stuff: Annotated[
            Optional[List[str]],
            Query(
                title="stuff",
                description="some stuff.",
                examples={
                    "example1": {
                        "description": "example for stuff 1.",
                        "value": ["stuffffff"],
                    },
                    "example2": {
                        "description": "example for stuff 2.",
                        "value": ["stuffffff", "stuffffff"],
                    },
                },
            ),
        ] = None,
):
    pass

returns the same things for both methods, so using a class or a direct reference do not change the output

vincentsarago commented 10 months ago

ref: https://github.com/tiangolo/fastapi/discussions/10537

vincentsarago commented 10 months ago

solution is to rename examples -> openapi_examples