Skip to content

Commit 50fcf27

Browse files
hsunnercommonism
authored andcommitted
test: add regression test for additionalProperties nullable+allOf+ref
1 parent 2987c95 commit 50fcf27

3 files changed

Lines changed: 68 additions & 0 deletions

File tree

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,11 @@ def with_schema_additionalProperties_and_named_properties():
449449
yield _get_parsed_yaml("schema-additionalProperties-and-named-properties.yaml")
450450

451451

452+
@pytest.fixture
453+
def with_schema_additionalProperties_nullable_allof():
454+
yield _get_parsed_yaml("schema-additionalProperties-nullable-allof.yaml")
455+
456+
452457
@pytest.fixture
453458
def with_schema_date_types():
454459
yield _get_parsed_yaml("schema-date-types.yaml")
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
openapi: "3.0.3"
2+
info:
3+
version: 1.0.0
4+
title: additionalProperties nullable allOf
5+
6+
components:
7+
schemas:
8+
LinkOccasion:
9+
type: object
10+
properties:
11+
unitTestId:
12+
type: integer
13+
14+
RelationsModel:
15+
type: object
16+
properties:
17+
unitPartNumber:
18+
type: string
19+
linkOccasions:
20+
type: array
21+
items:
22+
$ref: "#/components/schemas/LinkOccasion"
23+
24+
paths:
25+
/relations:
26+
get:
27+
operationId: getRelations
28+
responses:
29+
"200":
30+
description: ok
31+
content:
32+
application/json:
33+
schema:
34+
type: object
35+
additionalProperties:
36+
nullable: true
37+
allOf:
38+
- $ref: "#/components/schemas/RelationsModel"

tests/schema_test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,31 @@ def test_schema_with_additionalProperties_and_named_properties(with_schema_addit
332332
assert b.aio3_additionalProperties["foo"] == "bar"
333333

334334

335+
def test_schema_additionalProperties_nullable_allof(with_schema_additionalProperties_nullable_allof):
336+
"""
337+
Inline additionalProperties schema with nullable+allOf+$ref must produce a fully
338+
resolved Pydantic model (regression test for _get_combined_attributes omitting
339+
additionalProperties from schema traversal).
340+
"""
341+
api = OpenAPI("/", with_schema_additionalProperties_nullable_allof)
342+
343+
schema = api.paths["/relations"].get.responses["200"].content["application/json"].schema_
344+
value_type = schema.additionalProperties.get_type()
345+
346+
assert value_type.__pydantic_complete__ is True
347+
348+
# non-null value
349+
obj = value_type.model_validate({"unitPartNumber": "ABC", "linkOccasions": [{"unitTestId": 1}]})
350+
assert obj.unitPartNumber == "ABC"
351+
assert obj.linkOccasions[0].unitTestId == 1
352+
353+
# map model accepts null values for the map entries
354+
map_type = schema.get_type()
355+
result = map_type.model_validate({"key1": {"unitPartNumber": "ABC", "linkOccasions": []}, "key2": None})
356+
assert result.root["key2"] is None
357+
assert result.root["key1"].unitPartNumber == "ABC"
358+
359+
335360
def test_schema_with_patternProperties(with_schema_patternProperties):
336361
api = OpenAPI("/", with_schema_patternProperties)
337362
A = api.components.schemas["A"].get_type()

0 commit comments

Comments
 (0)