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
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.3.0
current_version = 2.4.0
commit = False
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)((\-rc)(?P<build>\d+))?
Expand Down
2 changes: 1 addition & 1 deletion pydantic_forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

"""Pydantic-forms engine."""

__version__ = "2.3.0"
__version__ = "2.4.0"
13 changes: 11 additions & 2 deletions pydantic_forms/validators/components/migration_summary.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2023 SURF.
# Copyright 2019-2026 SURF.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand All @@ -17,6 +17,7 @@
from pydantic import BaseModel, Field

from pydantic_forms.types import SummaryData
from pydantic_forms.validators import constants


class _MigrationSummary(BaseModel):
Expand All @@ -27,7 +28,15 @@ class _MigrationSummary(BaseModel):


def create_json_extra_schema(data: SummaryData, schema: dict[str, Any]) -> None:
Comment thread
Mark90 marked this conversation as resolved.
schema.update({"format": "summary", "type": "string", "uniforms": {"data": data}})
forms_schema = {"data": data}
schema.update(
{
"format": "summary",
"type": "string",
"uniforms": forms_schema, # Deprecated
constants.EXTRA_PROPERTIES: forms_schema,
}
)


def migration_summary(data: SummaryData) -> type[MigrationSummary]:
Expand Down
10 changes: 8 additions & 2 deletions pydantic_forms/validators/components/read_only.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2025 SURF, ESnet.
# Copyright 2019-2026 SURF, ESnet.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand All @@ -22,6 +22,7 @@

from pydantic_forms.types import strEnum
from pydantic_forms.utils.schema import merge_json_schema
from pydantic_forms.validators import constants

# from pydantic.json_schema
JSON_SCHEMA_TYPES = {
Expand Down Expand Up @@ -56,7 +57,12 @@ def _get_json_type(default: Any) -> str:

def _get_read_only_schema(default: Any) -> dict:
"""Get base schema dict object for uniforms."""
return {"uniforms": {"disabled": True, "value": default}, "type": _get_json_type(default)}
forms_schema = {"disabled": True, "value": default}
return {
"uniforms": forms_schema, # Deprecated
constants.EXTRA_PROPERTIES: forms_schema,
"type": _get_json_type(default),
}


def read_only_list(default: list[Any] | None = None) -> Any:
Expand Down
23 changes: 14 additions & 9 deletions pydantic_forms/validators/components/timestamp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2023 SURF.
# Copyright 2019-2026 SURF.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand All @@ -14,6 +14,9 @@

from annotated_types import Interval
from pydantic import Field
from pydantic.config import JsonDict

from pydantic_forms.validators import constants


def timestamp(
Expand All @@ -25,18 +28,20 @@ def timestamp(
date_format: Optional[str] = None,
time_format: Optional[str] = None,
) -> Any:
forms_schema: JsonDict = {
"showTimeSelect": show_time_select,
"locale": locale,
"min": min,
"max": max,
"dateFormat": date_format,
"timeFormat": time_format,
}
schema = Field(
json_schema_extra={
"format": "timestamp",
"type": "number",
"uniforms": {
"showTimeSelect": show_time_select,
"locale": locale,
"min": min,
"max": max,
"dateFormat": date_format,
"timeFormat": time_format,
},
"uniforms": forms_schema, # Deprecated
constants.EXTRA_PROPERTIES: forms_schema,
}
)

Expand Down
14 changes: 14 additions & 0 deletions pydantic_forms/validators/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2019-2026 SURF.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

EXTRA_PROPERTIES = "extraProperties"
1 change: 1 addition & 0 deletions tests/unit_tests/test_display_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Form(FormPage):
"format": "summary",
"type": "string",
"uniforms": {"data": {"headers": ["one"]}},
"extraProperties": {"data": {"headers": ["one"]}},
},
},
"title": "unknown",
Expand Down
5 changes: 2 additions & 3 deletions tests/unit_tests/test_migration_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ class Form(FormPage):
"default": None,
"format": "summary",
"type": "string",
"uniforms": {
"data": {"headers": ["one"]},
},
"uniforms": {"data": {"headers": ["one"]}},
"extraProperties": {"data": {"headers": ["one"]}},
},
},
"title": "unknown",
Expand Down
4 changes: 4 additions & 0 deletions tests/unit_tests/test_read_only_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Form(FormPage):
"default": schema_value,
"title": "Read Only",
"uniforms": {"disabled": True, "value": schema_value},
"extraProperties": {"disabled": True, "value": schema_value},
"type": schema_type,
}
},
Expand Down Expand Up @@ -89,6 +90,7 @@ class Form(FormPage):
"items": expected_item_type,
"title": "Read Only List",
"uniforms": {"disabled": True, "value": schema_value},
"extraProperties": {"disabled": True, "value": schema_value},
"type": "array",
}
},
Expand Down Expand Up @@ -175,6 +177,7 @@ class Form(FormPage):
"items": expected_item_type,
"title": "Read Only List",
"uniforms": {"disabled": True, "value": schema_value},
"extraProperties": {"disabled": True, "value": schema_value},
"type": "array",
}
},
Expand Down Expand Up @@ -223,6 +226,7 @@ class Form(FormPage):
read_only_schema = validated.model_json_schema()["properties"]["read_only"]
assert read_only_schema["format"] == expected_format
assert read_only_schema["uniforms"]["disabled"]
assert read_only_schema["extraProperties"]["disabled"]


def test_read_only_unsupported_type():
Expand Down
16 changes: 16 additions & 0 deletions tests/unit_tests/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ class Form(FormPage):
"showTimeSelect": True,
"timeFormat": None,
},
"extraProperties": {
"dateFormat": None,
"locale": None,
"max": None,
"min": None,
"showTimeSelect": True,
"timeFormat": None,
},
},
"t2": {
"format": "timestamp",
Expand All @@ -44,6 +52,14 @@ class Form(FormPage):
"showTimeSelect": True,
"timeFormat": "HH:mm",
},
"extraProperties": {
"dateFormat": "DD-MM-YYYY HH:mm",
"locale": "nl-nl",
"max": 1672751600,
"min": 1652751600,
"showTimeSelect": True,
"timeFormat": "HH:mm",
},
},
},
"required": ["t1", "t2"],
Expand Down