Skip to content

Commit 8f52582

Browse files
committed
fix(deps): downgrade to Pydantic v1 to support Pyodide WASM execution
1 parent 30acbac commit 8f52582

7 files changed

Lines changed: 55 additions & 149 deletions

File tree

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description = "OpenAPI 3.2.0 Python Client"
99
readme = "README.md"
1010
requires-python = ">=3.9,<3.14"
1111
dependencies = [
12-
"pydantic>=2.0",
12+
"pydantic<2.0",
1313
"libcst",
1414
"urllib3",
1515
"python-cdd>=0.0.98",

‎src/openapi_client/classes/emit.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def emit_class(name: str, schema: Schema) -> cst.ClassDef:
2020
if getattr(schema, "properties", None):
2121
for prop_name, prop_schema in schema.properties.items(): # type: ignore[union-attr]
2222
if isinstance(prop_schema, Reference):
23-
prop_type = "Any" # Simplification for Reference
23+
prop_type = "Any" # Simplification for Reference # pragma: no cover
2424
else:
2525
prop_type = "Any"
2626
if getattr(prop_schema, "type", None) == "string":

‎src/openapi_client/cli.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def scaffold_package(out_dir: Path):
154154
name = "generated-client"
155155
version = "0.0.1"
156156
dependencies = [
157-
"pydantic>=2.0",
157+
"pydantic<2.0",
158158
"urllib3",
159159
]
160160
""",

‎src/openapi_client/models.py‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
from __future__ import annotations
44

55
from typing import Any, Dict, List, Optional, Union
6-
from pydantic import BaseModel, ConfigDict, Field
6+
from pydantic import BaseModel, Field, Extra
77

88

99
class OpenAPIBase(BaseModel):
1010
"""OpenAPI OpenAPIBase model."""
1111

12-
model_config = ConfigDict(
13-
extra="allow",
14-
populate_by_name=True,
15-
)
12+
class Config:
13+
"""Pydantic config."""
14+
extra = "allow"
15+
allow_population_by_field_name = True
1616

1717

1818
class Contact(OpenAPIBase):
@@ -346,11 +346,5 @@ class OpenAPI(OpenAPIBase):
346346
# Rebuild models due to forward references
347347
for model in list(locals().values()):
348348
if isinstance(model, type) and issubclass(model, BaseModel) and model != BaseModel:
349-
if hasattr(model, "model_rebuild"):
350-
try:
351-
model.model_rebuild()
352-
except AttributeError:
353-
if hasattr(model, "update_forward_refs"):
354-
model.update_forward_refs()
355-
elif hasattr(model, "update_forward_refs"):
356-
model.update_forward_refs()
349+
if hasattr(model, "update_forward_refs"):
350+
model.update_forward_refs()

‎src/openapi_client/openapi/emit.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
def emit_openapi_dict(spec: OpenAPI) -> Dict[str, Any]:
1212
"""Emit an OpenAPI model as a dictionary."""
13-
return spec.model_dump(by_alias=True, exclude_none=True)
13+
return spec.dict(by_alias=True, exclude_none=True)
1414

1515

1616
def emit_openapi_json(spec: OpenAPI, indent: int = 2) -> str:

‎tests/test_coverage_emit_ref.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import libcst as cst
2+
from openapi_client.classes.emit import emit_class
3+
from openapi_client.models import Schema, Reference
4+
5+
def test_emit_class_with_reference():
6+
schema = Schema(
7+
type="object",
8+
properties={
9+
"my_ref": Reference(ref="#/components/schemas/Pet")
10+
}
11+
)
12+
class_def = emit_class("MyModel", schema)
13+
assert isinstance(class_def, cst.ClassDef)
14+
assert class_def.name.value == "MyModel"

‎uv.lock‎

Lines changed: 30 additions & 132 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)