path operation decorator has an option called "response_model_include" which allows us
to select only certain sections of the complete response model.
this is extremely useful where i can just reuse the same model in different
APIs and return only the requested data.
But when the openAPI spec is rendered, i see the ENTIRE response_model in the spec response.
instead it should ONLY show the members included in response_model_include option.
Steps to reproduce the behavior with a minimum self-contained file.
Replace each part with your own scenario:
from fastapi import FastAPI
app = FastAPI()
@app.get("/status",
response_model=customerEvent,
response_model_include={"status"})
def get_customer_statuus():
return customerEvent(status="Available")
expected the spec to only show {"status": str}. which is the only included member of the
customerEvent class
python -c "import fastapi; print(fastapi.__version__)"
**0.54.1**
python --version
Python 3.7.7
Yeah, that's why you should have the specific model that should be returned in each specific path operation.
It's documented here: https://fastapi.tiangolo.com/tutorial/response-model/#response_model_include-and-response_model_exclude
But it is still recommended to use the ideas above, using multiple classes, instead of these parameters.
This is because the JSON Schema generated in your app's OpenAPI (and the docs) will still be the one for the complete model, even if you use response_model_include or response_model_exclude to omit some attributes.
Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.