Movatterモバイル変換


[0]ホーム

URL:


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

Added support to overwrite serializer methods in schema class#1098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
n2ygk merged 1 commit intodjango-json-api:mainfromsliverc:openapi_serializer
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes fromall 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
4 changes: 4 additions & 0 deletionsCHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,6 +14,10 @@ any parts of the framework not mentioned in the documentation should generally b

* Added support for Python 3.11.

### Changed

* Added support to overwrite serializer methods in customized schema class

## [6.0.0] - 2022-09-24

### Fixed
Expand Down
34 changes: 22 additions & 12 deletionsrest_framework_json_api/schemas/openapi.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -427,9 +427,9 @@ def get_operation(self, path, method):
# get request and response code schemas
if method == "GET":
if is_list_view(path, method, self.view):
self._add_get_collection_response(operation)
self._add_get_collection_response(operation, path)
else:
self._add_get_item_response(operation)
self._add_get_item_response(operation, path)
elif method == "POST":
self._add_post_item_response(operation, path)
elif method == "PATCH":
Expand DownExpand Up@@ -487,25 +487,29 @@ def _get_sort_parameters(self, path, method):
"""
return [{"$ref": "#/components/parameters/sort"}]

def _add_get_collection_response(self, operation):
def _add_get_collection_response(self, operation, path):
"""
Add GET 200 response for a collection to operation
"""
operation["responses"] = {
"200": self._get_toplevel_200_response(operation, collection=True)
"200": self._get_toplevel_200_response(
operation, path, "GET", collection=True
)
}
self._add_get_4xx_responses(operation)

def _add_get_item_response(self, operation):
def _add_get_item_response(self, operation, path):
"""
add GET 200 response for an item to operation
"""
operation["responses"] = {
"200": self._get_toplevel_200_response(operation, collection=False)
"200": self._get_toplevel_200_response(
operation, path, "GET", collection=False
)
}
self._add_get_4xx_responses(operation)

def _get_toplevel_200_response(self, operation, collection=True):
def _get_toplevel_200_response(self, operation,path, method,collection=True):
"""
return top-level JSON:API GET 200 response

Expand All@@ -516,10 +520,12 @@ def _get_toplevel_200_response(self, operation, collection=True):
if collection:
data = {
"type": "array",
"items": get_reference(self, self.view.get_serializer()),
"items": get_reference(
self, self.get_response_serializer(path, method)
),
}
else:
data = get_reference(self, self.view.get_serializer())
data = get_reference(self, self.get_response_serializer(path, method))

return {
"description": operation["operationId"],
Expand DownExpand Up@@ -555,7 +561,9 @@ def _add_post_item_response(self, operation, path):
"""
operation["requestBody"] = self.get_request_body(path, "POST")
operation["responses"] = {
"201": self._get_toplevel_200_response(operation, collection=False)
"201": self._get_toplevel_200_response(
operation, path, "POST", collection=False
)
}
operation["responses"]["201"]["description"] = (
"[Created](https://jsonapi.org/format/#crud-creating-responses-201). "
Expand All@@ -574,7 +582,9 @@ def _add_patch_item_response(self, operation, path):
"""
operation["requestBody"] = self.get_request_body(path, "PATCH")
operation["responses"] = {
"200": self._get_toplevel_200_response(operation, collection=False)
"200": self._get_toplevel_200_response(
operation, path, "PATCH", collection=False
)
}
self._add_patch_4xx_responses(operation)

Expand All@@ -591,7 +601,7 @@ def get_request_body(self, path, method):
"""
A request body is required by JSON:API for POST, PATCH, and DELETE methods.
"""
serializer = self.get_serializer(path, method)
serializer = self.get_request_serializer(path, method)
if not isinstance(serializer, (serializers.BaseSerializer,)):
return {}
is_relationship = isinstance(self.view, views.RelationshipView)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp