FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix: Model generation using `oneOf`, `anyOf` & `type` lists by egormanga · Pull Request #1424 · openapi-generators/openapi-python-client · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .lock  (1) .py  (2) .toml  (1) All 3 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
14 changes: 13 additions & 1 deletion openapi_python_client/parser/properties/union.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Any, ClassVar, cast

from attr import define, evolve
from deepmerge import always_merger

from ... import Config
from ... import schema as oai
Expand Down Expand Up @@ -74,6 +75,17 @@ def build(
else:
subscript = f"type_{i}"

if isinstance(sub_prop_data, oai.Schema):
merged_data = oai.Schema.model_validate(always_merger.merge(
data.model_dump(exclude_unset=True),
sub_prop_data.model_dump(exclude_unset=True),
))
merged_data.oneOf = sub_prop_data.oneOf
merged_data.anyOf = sub_prop_data.anyOf
if getattr(sub_prop_data, 'type', None) is not None:
merged_data.type = sub_prop_data.type
sub_prop_data = merged_data

sub_prop, schemas = property_from_data(
name=f"{name}_{subscript}",
required=True,
Expand Down Expand Up @@ -144,7 +156,7 @@ def _get_inner_type_strings(self, json: bool) -> set[str]:
@staticmethod
def _get_type_string_from_inner_type_strings(inner_types: set[str]) -> str:
if len(inner_types) == 1:
return inner_types.pop()
return next(iter(inner_types))
return " | ".join(sorted(inner_types, key=lambda x: x.lower()))

def get_base_type_string(self) -> str:
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Reference(BaseModel):
model_config = ConfigDict(
extra="allow",
populate_by_name=True,
serialize_by_alias=True,
json_schema_extra={
"examples": [{"$ref": "#/components/schemas/Pet"}, {"$ref": "Pet.json"}, {"$ref": "definitions.json#/Pet"}]
},
Expand Down
16 changes: 15 additions & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies = [
"httpx>=0.23.0,<0.29.0",
"ruamel.yaml>=0.18.6,<0.20.0",
"ruff>=0.2",
"deepmerge>=2.0",
]
name = "openapi-python-client"
version = "0.28.3"
Expand Down

Back | FazBrowse Home | New Git URL