Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 126cd9f

Browse files
Add additionalProperties to includes' attributes and relationships (#1164)
Create new schema for objects in the included array This allows documenting the "attributes" and "relationships" objects to possibly have additional properties.
1 parent 39a9c92 commit 126cd9f

File tree

3 files changed

+59
-6
lines changed

3 files changed

+59
-6
lines changed

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ any parts of the framework not mentioned in the documentation should generally b
4343

4444
* `SerializerMethodResourceRelatedField(many=True)` relationship data now includes a meta section.
4545
* Required relationship fields are now marked as required in the OpenAPI schema.
46+
* Objects in the included array are documented in the OpenAPI schema to possibly have additional
47+
properties in their "attributes" and "relationships" objects.
4648

4749
### Fixed
4850

‎example/tests/__snapshots__/test_openapi.ambr‎

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185
},
186186
"included": {
187187
"items": {
188-
"$ref": "#/components/schemas/resource"
188+
"$ref": "#/components/schemas/include"
189189
},
190190
"type": "array",
191191
"uniqueItems": true
@@ -340,7 +340,7 @@
340340
},
341341
"included": {
342342
"items": {
343-
"$ref": "#/components/schemas/resource"
343+
"$ref": "#/components/schemas/include"
344344
},
345345
"type": "array",
346346
"uniqueItems": true
@@ -487,7 +487,7 @@
487487
},
488488
"included": {
489489
"items": {
490-
"$ref": "#/components/schemas/resource"
490+
"$ref": "#/components/schemas/include"
491491
},
492492
"type": "array",
493493
"uniqueItems": true
@@ -662,7 +662,7 @@
662662
},
663663
"included": {
664664
"items": {
665-
"$ref": "#/components/schemas/resource"
665+
"$ref": "#/components/schemas/include"
666666
},
667667
"type": "array",
668668
"uniqueItems": true
@@ -962,6 +962,36 @@
962962
"description": "Each resource object\u2019s type and id pair MUST [identify](https://jsonapi.org/format/#document-resource-object-identification) a single, unique resource.",
963963
"type": "string"
964964
},
965+
"include": {
966+
"additionalProperties": false,
967+
"properties": {
968+
"attributes": {
969+
"additionalProperties": true,
970+
"type": "object"
971+
},
972+
"id": {
973+
"$ref": "#/components/schemas/id"
974+
},
975+
"links": {
976+
"$ref": "#/components/schemas/links"
977+
},
978+
"meta": {
979+
"$ref": "#/components/schemas/meta"
980+
},
981+
"relationships": {
982+
"additionalProperties": true,
983+
"type": "object"
984+
},
985+
"type": {
986+
"$ref": "#/components/schemas/type"
987+
}
988+
},
989+
"required": [
990+
"type",
991+
"id"
992+
],
993+
"type": "object"
994+
},
965995
"jsonapi": {
966996
"additionalProperties": false,
967997
"description": "The server's implementation",
@@ -1252,7 +1282,7 @@
12521282
},
12531283
"included": {
12541284
"items": {
1255-
"$ref": "#/components/schemas/resource"
1285+
"$ref": "#/components/schemas/include"
12561286
},
12571287
"type": "array",
12581288
"uniqueItems": true

‎rest_framework_json_api/schemas/openapi.py‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@ class SchemaGenerator(drf_openapi.SchemaGenerator):
4949
"meta": {"$ref": "#/components/schemas/meta"},
5050
},
5151
},
52+
"include": {
53+
"type": "object",
54+
"required": ["type", "id"],
55+
"additionalProperties": False,
56+
"properties": {
57+
"type": {"$ref": "#/components/schemas/type"},
58+
"id": {"$ref": "#/components/schemas/id"},
59+
"attributes": {
60+
"type": "object",
61+
"additionalProperties": True,
62+
# ...
63+
},
64+
"relationships": {
65+
"type": "object",
66+
"additionalProperties": True,
67+
# ...
68+
},
69+
"links": {"$ref": "#/components/schemas/links"},
70+
"meta": {"$ref": "#/components/schemas/meta"},
71+
},
72+
},
5273
"link": {
5374
"oneOf": [
5475
{
@@ -531,7 +552,7 @@ def _get_toplevel_200_response(self, operation, path, method, collection=True):
531552
"included": {
532553
"type": "array",
533554
"uniqueItems": True,
534-
"items": {"$ref": "#/components/schemas/resource"},
555+
"items": {"$ref": "#/components/schemas/include"},
535556
},
536557
"links": {
537558
"description": "Link members related to primary data",

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /