Skip to content

Commit

Permalink
fix: table in docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
zumuta committed Nov 19, 2024
1 parent c3e740d commit cb5ad4a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## [0.1.3](https://github.com/fbraem/griffe-fastapi/releases/tag/0.1.2) - 2024-11-19

- Fix generated table in docstring.

## [0.1.2](https://github.com/fbraem/griffe-fastapi/releases/tag/0.1.2) - 2024-11-19

- Add generate_table option to add a table with responses in the docstring.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "griffe-fastapi"
version = "0.1.2"
version = "0.1.3"
description = "Griffe extension for FastAPI."
authors = ["fbraem <[email protected]>"]
readme = "README.md"
Expand Down
3 changes: 2 additions & 1 deletion src/griffe_fastapi/_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ def on_function_instance(
if not func.docstring:
func.docstring = Docstring("", parent=func)
sections = func.docstring.parsed
table_str = "\n".join(table)
sections.append(
DocstringSectionText(
f"This api can return the following HTTP codes:\n\n{table}",
f"This api can return the following HTTP codes:\n\n{table_str}",
title="HTTP Responses",
)
)
2 changes: 1 addition & 1 deletion tests/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,5 +232,5 @@ def get_teams() -> list[str]:
assert extra["responses"]["200"]["description"] == "Ok"
assert (
package.functions["get_teams"].docstring.parsed[1].value
== "This api can return the following HTTP codes:\n\n['| Status | Description |', '|--------|-------------|', '| 200 | Ok |']"
== "This api can return the following HTTP codes:\n\n| Status | Description |\n|--------|-------------|\n| 200 | Ok |"
)

0 comments on commit cb5ad4a

Please sign in to comment.