Skip to content

Commit f5128a3

Browse files
committed
fix: attributes with none type are excluded from Schema generation
1 parent b436dc2 commit f5128a3

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

doc/changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
=========
33

4+
[0.4.3] - Unreleased
5+
--------------------
6+
7+
Fixed
8+
^^^^^
9+
- Attributes with ``None`` type are excluded from Schema generation.
10+
411
[0.4.2] - 2025-08-05
512
--------------------
613

scim2_models/resources/resource.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ def _model_to_schema(model: type[BaseModel]) -> "Schema":
412412
_model_attribute_to_scim_attribute(model, attribute_name)
413413
for attribute_name in field_infos
414414
if attribute_name != "schemas"
415+
and model.get_field_root_type(attribute_name) is not type(None)
415416
]
416417
schema = Schema(
417418
name=model.__name__,

tests/test_schema.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
import pytest
24
from pydantic import ValidationError
35

@@ -6,6 +8,8 @@
68
from scim2_models import Returned
79
from scim2_models import Schema
810
from scim2_models import Uniqueness
11+
from scim2_models.resources.resource import Resource
12+
from scim2_models.resources.resource import _model_to_schema
913

1014

1115
def test_group_schema(load_sample):
@@ -123,3 +127,22 @@ def test_get_attribute_attribute(load_sample):
123127

124128
attribute["value"].mutability = Mutability.read_write
125129
assert attribute.sub_attributes[0].mutability == Mutability.read_write
130+
131+
132+
def test_model_to_schema_excludes_none_type_attributes():
133+
"""Test that _model_to_schema excludes attributes with None type from schema."""
134+
135+
class TestResource(Resource):
136+
schemas: list[str] = ["urn:test:schema"]
137+
valid_attr: Optional[str] = None
138+
none_attr: None = None
139+
140+
schema = _model_to_schema(TestResource)
141+
142+
assert schema.id == "urn:test:schema"
143+
assert schema.name == "TestResource"
144+
145+
attribute_names = [attr.name for attr in schema.attributes]
146+
147+
assert "validAttr" in attribute_names
148+
assert "noneAttr" not in attribute_names

0 commit comments

Comments
 (0)