@@ -125,6 +125,46 @@ def test_schema_id_field():
125
125
assert "id" not in company_properties ["attributes" ]["properties" ]
126
126
127
127
128
+ def test_schema_subserializers ():
129
+ """Schema for child Serializers reflects the actual response structure."""
130
+ patterns = [
131
+ re_path (
132
+ "^questionnaires/?$" , views .QuestionnaireViewset .as_view ({"get" : "list" })
133
+ ),
134
+ ]
135
+ generator = SchemaGenerator (patterns = patterns )
136
+
137
+ request = create_request ("/" )
138
+ schema = generator .get_schema (request = request )
139
+
140
+ assert {
141
+ "type" : "object" ,
142
+ "properties" : {
143
+ "metadata" : {
144
+ "type" : "object" ,
145
+ "properties" : {
146
+ "author" : {"type" : "string" },
147
+ "producer" : {"type" : "string" },
148
+ },
149
+ "required" : ["author" ],
150
+ },
151
+ "questions" : {
152
+ "type" : "array" ,
153
+ "items" : {
154
+ "type" : "object" ,
155
+ "properties" : {
156
+ "text" : {"type" : "string" },
157
+ "required" : {"type" : "boolean" , "default" : False },
158
+ },
159
+ "required" : ["text" ],
160
+ },
161
+ },
162
+ "name" : {"type" : "string" , "maxLength" : 100 },
163
+ },
164
+ "required" : ["name" , "questions" , "metadata" ],
165
+ } == schema ["components" ]["schemas" ]["Questionnaire" ]["properties" ]["attributes" ]
166
+
167
+
128
168
def test_schema_parameters_include ():
129
169
"""Include paramater is only used when serializer defines included_serializers."""
130
170
patterns = [
0 commit comments