Fastapi - response model exclude

Viewed 38

I have one response model which I use for two fast api end points. The second end point is very similar the first one, but I would like to remove one response parameter from it.

It looks like this:

endpoints:

app = FastAPI(title = settings.TITLE,
version=settings.VERSION,
description=settings.DESCRIPTION,
contact=settings.CONTACT
)

@app.get("/EP1", response_model=Model)
async def Func1():
    ...

@app.get("/EP2", response_model=Model)
async def Func2():
    ...

Model looks like this:

class ResourceInformation(BaseModel):
    resource_id:Optional[str]
    resource_pricing:Optional[list[PricingInformation]]
    has_backup:Optional[bool] = None

class InvoicingInformation(BaseModel):
    ...
    resource_information:Optional[list[ResourceInformation]] = None
    ...

class Model(BaseModel):
    data:Optional[list[InvoicingInformation]]

What I would like to achieve is hiding each occurence of "has_backup" in response of EP2.

0 Answers
Related