Skip to content

Commit 26d6a49

Browse files
committed
Revert "fix: attributes with none type are excluded from Schema generation"
This reverts commit f5128a3.
1 parent 1103415 commit 26d6a49

File tree

4 files changed

+0
-65
lines changed

4 files changed

+0
-65
lines changed

doc/changelog.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Changelog
66

77
Fixed
88
^^^^^
9-
- Attributes with ``None`` type are excluded from Schema generation.
109
- Allow PATCH operations on resources and extensions root path.
1110
- Multiple ComplexAttribute do not inherit from MultiValuedComplexAttribute by default. :issue:`72` :issue:`73`
1211
- Forbid :class:`~scim2_models.PatchOp` with zero ``operations``.

doc/tutorial.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,6 @@ This is useful for server implementations, so custom models or models provided b
357357
... ],
358358
... }
359359
360-
To disable an attribute in a custom resource subclass, annotate it with type ``None``:
361-
362-
.. code-block:: python
363-
:caption: Disabling a field inherited from a parent resource
364-
365-
>>> class CustomUser(User):
366-
... # This attribute will be excluded from schema generation
367-
... display_name: None = None
368-
369360
Dynamic models from schemas
370361
===========================
371362

scim2_models/resources/resource.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,6 @@ def _model_to_schema(model: type[BaseModel]) -> "Schema":
411411
_model_attribute_to_scim_attribute(model, attribute_name)
412412
for attribute_name in field_infos
413413
if attribute_name != "schemas"
414-
and model.get_field_root_type(attribute_name) is not type(None)
415414
]
416415
schema = Schema(
417416
name=model.__name__,

tests/test_schema.py

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
1-
from typing import Annotated
2-
from typing import Optional
3-
41
import pytest
52
from pydantic import ValidationError
63

74
from scim2_models import Attribute
8-
from scim2_models import CaseExact
95
from scim2_models import Mutability
10-
from scim2_models import Required
116
from scim2_models import Returned
127
from scim2_models import Schema
138
from scim2_models import Uniqueness
14-
from scim2_models.resources.resource import Resource
15-
from scim2_models.resources.resource import _model_to_schema
169

1710

1811
def test_group_schema(load_sample):
@@ -130,50 +123,3 @@ def test_get_attribute_attribute(load_sample):
130123

131124
attribute["value"].mutability = Mutability.read_write
132125
assert attribute.sub_attributes[0].mutability == Mutability.read_write
133-
134-
135-
def test_model_to_schema_excludes_none_type_attributes():
136-
"""Test that _model_to_schema excludes attributes with None type from schema."""
137-
138-
class TestResource(Resource):
139-
schemas: list[str] = ["urn:test:schema"]
140-
valid_attr: Optional[str] = None
141-
none_attr: None = None
142-
143-
schema = TestResource.to_schema()
144-
145-
assert schema.id == "urn:test:schema"
146-
assert schema.name == "TestResource"
147-
148-
attribute_names = [attr.name for attr in schema.attributes]
149-
150-
assert "validAttr" in attribute_names
151-
assert "noneAttr" not in attribute_names
152-
153-
154-
def test_external_id_redefined_in_subclass_is_exported():
155-
class CustomResource(Resource):
156-
schemas: list[str] = ["urn:custom:schema"]
157-
158-
external_id: Annotated[
159-
Optional[str],
160-
Mutability.immutable,
161-
Returned.always,
162-
Required.true,
163-
CaseExact.false,
164-
] = None
165-
166-
schema = CustomResource.to_schema()
167-
168-
attribute_names = [attr.name for attr in schema.attributes]
169-
assert "externalId" in attribute_names
170-
171-
172-
def test_external_id_not_exported_when_not_redefined():
173-
class SimpleResource(Resource):
174-
schemas: list[str] = ["urn:simple:schema"]
175-
176-
schema = _model_to_schema(SimpleResource)
177-
178-
attribute_names = [attr.name for attr in schema.attributes]
179-
assert "externalId" not in attribute_names

0 commit comments

Comments
 (0)