Skip to content

Commit

Permalink
add docstring for _construct_ref_object
Browse files Browse the repository at this point in the history
  • Loading branch information
jfschneider committed Dec 3, 2024
1 parent 49bbb4d commit 143d088
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions openapi_pydantic/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ def _traverse(obj: Any) -> None:


def _construct_ref_obj(pydantic_schema: PydanticSchema[PydanticType]) -> Reference:
"""
Construct a reference object from the Pydantic schema name
characters in the schema name that are invalid/problematic
for JSONschema $ref names will get replaced with underscores.
Especially needed for Pydantic generic Models with brackets "[]"
see: https://github.com/pydantic/pydantic/blob/aee6057378ccfec02126bf9c984a9b6d6b411777/pydantic/json_schema.py#L2031
"""
ref_name = re.sub(
r"[^a-zA-Z0-9.\-_]", "_", pydantic_schema.schema_class.__name__
).replace(".", "__")
Expand Down
9 changes: 9 additions & 0 deletions openapi_pydantic/v3/v3_0/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,15 @@ def _traverse(obj: Any) -> None:


def _construct_ref_obj(pydantic_schema: PydanticSchema[PydanticType]) -> Reference:
"""
Construct a reference object from the Pydantic schema name
characters in the schema name that are invalid/problematic
for JSONschema $ref names will get replaced with underscores.
Especially needed for Pydantic generic Models with brackets "[]"
see: https://github.com/pydantic/pydantic/blob/aee6057378ccfec02126bf9c984a9b6d6b411777/pydantic/json_schema.py#L2031
"""
ref_name = re.sub(
r"[^a-zA-Z0-9.\-_]", "_", pydantic_schema.schema_class.__name__
).replace(".", "__")
Expand Down

0 comments on commit 143d088

Please sign in to comment.