Skip to content

FastAPI shows no attributes for models. #151

Answered by vincentsarago
TNick asked this question in Q&A
Discussion options

You must be logged in to vote

confirmed this is not a geojson-pydantic issue. It's more a FastAPI (or a pydantic) one!

from typing import Any, Dict
from fastapi import FastAPI
from pydantic import BaseModel, Field, SerializationInfo, model_serializer


class SomeModel(BaseModel):
    lorem: str = Field(..., description="describe me")
    ipsum: int

    @model_serializer(when_used="always", mode="wrap")
    def clean_model(self, serializer: Any, info: SerializationInfo) -> Dict[str, Any]:
        data: Dict[str, Any] = serializer(self)
        return data

app = FastAPI()

@app.get("/another/{dataset}", response_model=SomeModel)
def get_another_dataset(dataset: str):
    raise NotImplementedError

Replies: 11 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
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
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 TNick
Comment options

You must be logged in to vote
0 replies
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
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #150 on November 16, 2023 10:21.