Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class DataModelField(DataModelFieldV1):
"min_length",
"max_length",
"union_mode",
"deprecated",
Comment thread
koxudaxi marked this conversation as resolved.
}
constraints: Optional[Constraints] = None # pyright: ignore[reportIncompatibleVariableOverride] # noqa: UP045
_PARSE_METHOD: ClassVar[str] = "model_validate"
Expand Down
1 change: 1 addition & 0 deletions src/datamodel_code_generator/parser/jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ def _get_type(type_: str, format__: str | None = None) -> Types:
"title",
"const",
"default_factory",
"deprecated",
}

EXCLUDE_FIELD_KEYS_IN_JSON_SCHEMA: set[str] = {
Expand Down
15 changes: 15 additions & 0 deletions tests/data/expected/main/openapi/deprecated_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# generated by datamodel-codegen:
# filename: deprecated_field.yaml
# timestamp: 2019-07-26T00:00:00+00:00

from __future__ import annotations

from pydantic import BaseModel, Field


class Service(BaseModel):
name: str = Field(..., description='Name of the service')
location: str | None = Field(
None, deprecated=True, description='Location of the service (deprecated)'
)
old_id: int | None = Field(None, deprecated=True)
22 changes: 22 additions & 0 deletions tests/data/openapi/deprecated_field.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: Deprecated Field Test
paths: {}
components:
schemas:
Service:
type: object
properties:
name:
type: string
description: Name of the service
location:
type: string
description: Location of the service (deprecated)
deprecated: true
old_id:
type: integer
deprecated: true
required:
- name
13 changes: 13 additions & 0 deletions tests/main/openapi/test_main_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4856,3 +4856,16 @@ def test_main_openapi_include_paths_warning_without_paths_scope() -> None:
assert any(
"--openapi-include-paths has no effect without --openapi-scopes paths" in msg for msg in warning_messages
)


@SKIP_PYDANTIC_V1
def test_main_openapi_deprecated_field(output_file: Path) -> None:
"""Test OpenAPI generation with deprecated field property."""
run_main_and_assert(
input_path=OPEN_API_DATA_PATH / "deprecated_field.yaml",
output_path=output_file,
input_file_type="openapi",
assert_func=assert_file_content,
expected_file="deprecated_field.py",
extra_args=["--output-model-type", "pydantic_v2.BaseModel"],
)
Loading