File tree 3 files changed +20
-0
lines changed
rest_framework_json_api/schemas
3 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ any parts of the framework not mentioned in the documentation should generally b
27
27
28
28
* Refactored handling of the ` sort ` query parameter to fix duplicate declaration in the generated schema definition
29
29
* Non-field serializer errors are given a source.pointer value of "/data".
30
+ * Fixed "id" field being added to /data/attributes in the OpenAPI schema when it is not rendered there.
30
31
31
32
## [ 6.0.0] - 2022-09-24
32
33
Original file line number Diff line number Diff line change @@ -110,6 +110,21 @@ def test_schema_construction(snapshot):
110
110
assert snapshot == json .dumps (schema , indent = 2 , sort_keys = True )
111
111
112
112
113
+ def test_schema_id_field ():
114
+ """ID field is only included in the root, not the attributes."""
115
+ patterns = [
116
+ re_path ("^companies/?$" , views .CompanyViewset .as_view ({"get" : "list" })),
117
+ ]
118
+ generator = SchemaGenerator (patterns = patterns )
119
+
120
+ request = create_request ("/" )
121
+ schema = generator .get_schema (request = request )
122
+
123
+ company_properties = schema ["components" ]["schemas" ]["Company" ]["properties" ]
124
+ assert company_properties ["id" ] == {"$ref" : "#/components/schemas/id" }
125
+ assert "id" not in company_properties ["attributes" ]["properties" ]
126
+
127
+
113
128
def test_schema_parameters_include ():
114
129
"""Include paramater is only used when serializer defines included_serializers."""
115
130
patterns = [
Original file line number Diff line number Diff line change @@ -670,6 +670,10 @@ def map_serializer(self, serializer):
670
670
"$ref" : "#/components/schemas/reltomany"
671
671
}
672
672
continue
673
+ if field .field_name == "id" :
674
+ # ID is always provided in the root of JSON:API and removed from the
675
+ # attributes in JSONRenderer.
676
+ continue
673
677
674
678
if field .required :
675
679
required .append (format_field_name (field .field_name ))
You can’t perform that action at this time.
0 commit comments