File tree Expand file tree Collapse file tree 3 files changed +20
-0
lines changed
rest_framework_json_api/schemas Expand file tree Collapse file tree 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
2727
2828* Refactored handling of the ` sort ` query parameter to fix duplicate declaration in the generated schema definition
2929* 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.
3031
3132## [ 6.0.0] - 2022-09-24
3233
Original file line number Diff line number Diff line change @@ -110,6 +110,21 @@ def test_schema_construction(snapshot):
110110 assert snapshot == json .dumps (schema , indent = 2 , sort_keys = True )
111111
112112
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+
113128def test_schema_parameters_include ():
114129 """Include paramater is only used when serializer defines included_serializers."""
115130 patterns = [
Original file line number Diff line number Diff line change @@ -670,6 +670,10 @@ def map_serializer(self, serializer):
670670 "$ref" : "#/components/schemas/reltomany"
671671 }
672672 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
673677
674678 if field .required :
675679 required .append (format_field_name (field .field_name ))
You can’t perform that action at this time.
0 commit comments