Skip to content

Commit 143d088

Browse files
committed
add docstring for _construct_ref_object
1 parent 49bbb4d commit 143d088

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

openapi_pydantic/util.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ def _traverse(obj: Any) -> None:
171171

172172

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

openapi_pydantic/v3/v3_0/util.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,15 @@ def _traverse(obj: Any) -> None:
243243

244244

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

0 commit comments

Comments
 (0)