Skip to content

Commit 01eff13

Browse files
fix: remove redundant response_model from generated FastAPI stubs
Co-Authored-By: thomas@buildwithfern.com <tjb9dcshop@gmail.com>
1 parent 5d7ebbe commit 01eff13

File tree

99 files changed

+8
-352
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+8
-352
lines changed

generators/python/src/fern_python/generators/fastapi/service_generator/endpoint_generator.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,16 @@ def _write_init_body(writer: AST.NodeWriter) -> None:
188188
with writer.indent():
189189
writer.write_line(f'path="{self._get_endpoint_path()}",')
190190

191-
# Void responses make more sense as response_class, but keeping as response_model to not modify existing users
191+
# Only specify response_class for non-pydantic models (file downloads, bytes)
192+
# For pydantic models, FastAPI infers response_model from the return type annotation
193+
# See: https://docs.astral.sh/ruff/rules/fast-api-redundant-response-model/
192194
if not self._get_is_return_type_pydantic_model():
193195
writer.write("response_class=")
194-
else:
195-
writer.write("response_model=")
196-
197-
if self._endpoint.response is not None:
198-
writer.write_node(self._get_return_type())
199-
else:
200-
writer.write("None")
201-
writer.write_line(",")
196+
if self._endpoint.response is not None:
197+
writer.write_node(self._get_return_type())
198+
else:
199+
writer.write("None")
200+
writer.write_line(",")
202201

203202
if self._endpoint.response is None or self._endpoint.response.body is None:
204203
writer.write("status_code=")

seed/fastapi/exhaustive/frozen_utils/resources/endpoints/resources/container/service/service.py

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seed/fastapi/exhaustive/frozen_utils/resources/endpoints/resources/content_type/service/service.py

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seed/fastapi/exhaustive/frozen_utils/resources/endpoints/resources/enum/service/service.py

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seed/fastapi/exhaustive/frozen_utils/resources/endpoints/resources/http_methods/service/service.py

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seed/fastapi/exhaustive/frozen_utils/resources/endpoints/resources/object/service/service.py

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seed/fastapi/exhaustive/frozen_utils/resources/endpoints/resources/params/service/service.py

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seed/fastapi/exhaustive/frozen_utils/resources/endpoints/resources/primitive/service/service.py

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seed/fastapi/exhaustive/frozen_utils/resources/endpoints/resources/put/service/service.py

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seed/fastapi/exhaustive/frozen_utils/resources/endpoints/resources/union/service/service.py

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)