diff --git a/openapi_python_client/parser/properties/model_property.py b/openapi_python_client/parser/properties/model_property.py index c7070494a..f08db52f9 100644 --- a/openapi_python_client/parser/properties/model_property.py +++ b/openapi_python_client/parser/properties/model_property.py @@ -66,7 +66,8 @@ def build( process_properties: Determines whether the new ModelProperty will be initialized with property data """ if not config.use_path_prefixes_for_title_model_names and data.title: - class_string = data.title + # biased towards name to avoid collisions with other models and align with the practice in datamodel-codegen + class_string = name else: title = data.title or name if parent_name: diff --git a/openapi_python_client/templates/endpoint_module.py.jinja b/openapi_python_client/templates/endpoint_module.py.jinja index 35090614c..579574732 100644 --- a/openapi_python_client/templates/endpoint_module.py.jinja +++ b/openapi_python_client/templates/endpoint_module.py.jinja @@ -3,12 +3,22 @@ from typing import Any, Optional, Union, cast import httpx +{% macro transform_import(original_string) -%} + {%- if original_string.startswith('from ...models') -%} + {%- set parts = original_string.split(' ') -%} + {%- set new_string = 'from ...models import ' + parts[3] -%} + {{ new_string }} + {%- else -%} + {{ original_string }} + {%- endif -%} +{%- endmacro %} + from ...client import AuthenticatedClient, Client from ...types import Response, UNSET from ... import errors {% for relative in endpoint.relative_imports | sort %} -{{ relative }} +{{ transform_import(relative) }} {% endfor %} {% from "endpoint_macros.py.jinja" import header_params, cookie_params, query_params, diff --git a/openapi_python_client/templates/property_templates/model_property.py.jinja b/openapi_python_client/templates/property_templates/model_property.py.jinja index 308b7478b..8d796c4c4 100644 --- a/openapi_python_client/templates/property_templates/model_property.py.jinja +++ b/openapi_python_client/templates/property_templates/model_property.py.jinja @@ -1,5 +1,5 @@ {% macro construct_function(property, source) %} -{{ property.class_info.name }}.from_dict({{ source }}) +{{ property.class_info.name }}.model_validate({{ source }}) {% endmacro %} {% from "property_templates/property_macros.py.jinja" import construct_template %} @@ -11,7 +11,7 @@ {% macro check_type_for_construct(property, source) %}isinstance({{ source }}, dict){% endmacro %} {% macro transform(property, source, destination, declare_type=True) %} -{% set transformed = source + ".to_dict()" %} +{% set transformed = source + ".model_dump(mode=\"json\", by_alias=True)" %} {% set type_string = property.get_type_string(json=True) %} {% if property.required %} {{ destination }} = {{ transformed }} diff --git a/pyproject.toml b/pyproject.toml index ac668fd78..f4d1a4835 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ dependencies = [ "typing-extensions>=4.8.0,<5.0.0", ] name = "openapi-python-client" -version = "0.24.3" +version = "0.24.3+fork" description = "Generate modern Python clients from OpenAPI" keywords = [ "OpenAPI",