| 1 | import pydantic |
| 2 | |
| 3 | |
| 4 | def pydantic_ref_fix(data: dict): |
| 5 | "In pydantic 1.7 $ref was changed to allOf: [{'$ref': ...}] but in 2.9 it was changed back" |
| 6 | v = tuple(map(int, pydantic.version.version_short().split("."))) |
| 7 | if v < (1, 7) or v >= (2, 9): |
| 8 | return data |
| 9 | |
| 10 | result = data.copy() |
| 11 | if "$ref" in data: |
| 12 | result["allOf"] = [{"$ref": result.pop("$ref")}] |
| 13 | return result |