File: util.py

package info (click to toggle)
django-ninja 1.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,280 kB
  • sloc: python: 16,041; javascript: 1,689; makefile: 40; sh: 25
file content (13 lines) | stat: -rw-r--r-- 395 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
import pydantic


def pydantic_ref_fix(data: dict):
    "In pydantic 1.7 $ref was changed to allOf: [{'$ref': ...}] but in 2.9 it was changed back"
    v = tuple(map(int, pydantic.version.version_short().split(".")))
    if v < (1, 7) or v >= (2, 9):
        return data

    result = data.copy()
    if "$ref" in data:
        result["allOf"] = [{"$ref": result.pop("$ref")}]
    return result