File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed
Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 11Changelog
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
Original file line number Diff line number Diff 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__ ,
Original file line number Diff line number Diff line change 1+ from typing import Optional
2+
13import pytest
24from pydantic import ValidationError
35
68from scim2_models import Returned
79from scim2_models import Schema
810from scim2_models import Uniqueness
11+ from scim2_models .resources .resource import Resource
12+ from scim2_models .resources .resource import _model_to_schema
913
1014
1115def 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
You can’t perform that action at this time.
0 commit comments