Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ any parts of the framework not mentioned in the documentation should generally b

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

### Fixed

Expand Down
40 changes: 35 additions & 5 deletions example/tests/__snapshots__/test_openapi.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
},
"included": {
"items": {
"$ref": "#/components/schemas/resource"
"$ref": "#/components/schemas/include"
},
"type": "array",
"uniqueItems": true
Expand Down Expand Up @@ -340,7 +340,7 @@
},
"included": {
"items": {
"$ref": "#/components/schemas/resource"
"$ref": "#/components/schemas/include"
},
"type": "array",
"uniqueItems": true
Expand Down Expand Up @@ -487,7 +487,7 @@
},
"included": {
"items": {
"$ref": "#/components/schemas/resource"
"$ref": "#/components/schemas/include"
},
"type": "array",
"uniqueItems": true
Expand Down Expand Up @@ -662,7 +662,7 @@
},
"included": {
"items": {
"$ref": "#/components/schemas/resource"
"$ref": "#/components/schemas/include"
},
"type": "array",
"uniqueItems": true
Expand Down Expand Up @@ -962,6 +962,36 @@
"description": "Each resource object\u2019s type and id pair MUST [identify](https://jsonapi.org/format/#document-resource-object-identification) a single, unique resource.",
"type": "string"
},
"include": {
"additionalProperties": false,
"properties": {
"attributes": {
"additionalProperties": true,
"type": "object"
},
"id": {
"$ref": "#/components/schemas/id"
},
"links": {
"$ref": "#/components/schemas/links"
},
"meta": {
"$ref": "#/components/schemas/meta"
},
"relationships": {
"additionalProperties": true,
"type": "object"
},
"type": {
"$ref": "#/components/schemas/type"
}
},
"required": [
"type",
"id"
],
"type": "object"
},
"jsonapi": {
"additionalProperties": false,
"description": "The server's implementation",
Expand Down Expand Up @@ -1252,7 +1282,7 @@
},
"included": {
"items": {
"$ref": "#/components/schemas/resource"
"$ref": "#/components/schemas/include"
},
"type": "array",
"uniqueItems": true
Expand Down
23 changes: 22 additions & 1 deletion rest_framework_json_api/schemas/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ class SchemaGenerator(drf_openapi.SchemaGenerator):
"meta": {"$ref": "#/components/schemas/meta"},
},
},
"include": {
"type": "object",
"required": ["type", "id"],
"additionalProperties": False,
"properties": {
"type": {"$ref": "#/components/schemas/type"},
"id": {"$ref": "#/components/schemas/id"},
"attributes": {
"type": "object",
"additionalProperties": True,
# ...
},
"relationships": {
"type": "object",
"additionalProperties": True,
# ...
},
"links": {"$ref": "#/components/schemas/links"},
"meta": {"$ref": "#/components/schemas/meta"},
},
},
"link": {
"oneOf": [
{
Expand Down Expand Up @@ -531,7 +552,7 @@ def _get_toplevel_200_response(self, operation, path, method, collection=True):
"included": {
"type": "array",
"uniqueItems": True,
"items": {"$ref": "#/components/schemas/resource"},
"items": {"$ref": "#/components/schemas/include"},
},
"links": {
"description": "Link members related to primary data",
Expand Down