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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion openapi_python_client/parser/properties/model_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 11 additions & 1 deletion openapi_python_client/templates/endpoint_module.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 %}
Expand All @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down