From 619907b1ec20487ec9abba493073d17d46d43922 Mon Sep 17 00:00:00 2001 From: Alex Seidmann Date: Tue, 16 Aug 2022 19:20:24 +0200 Subject: [PATCH 1/4] refactor: add separate parsing method --- rest_framework_json_api/parsers.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/rest_framework_json_api/parsers.py b/rest_framework_json_api/parsers.py index f77a6501..1cd65878 100644 --- a/rest_framework_json_api/parsers.py +++ b/rest_framework_json_api/parsers.py @@ -70,14 +70,11 @@ def parse_metadata(result): else: return {} - def parse(self, stream, media_type=None, parser_context=None): + def parse_data(self, result, parser_context): """ - Parses the incoming bytestream as JSON and returns the resulting data + Formats the output of calling JSONParser to match the JSON:API specification + and returns the result. """ - result = super().parse( - stream, media_type=media_type, parser_context=parser_context - ) - if not isinstance(result, dict) or "data" not in result: raise ParseError("Received document does not contain primary data") @@ -166,3 +163,13 @@ def parse(self, stream, media_type=None, parser_context=None): parsed_data.update(self.parse_relationships(data)) parsed_data.update(self.parse_metadata(result)) return parsed_data + + def parse(self, stream, media_type=None, parser_context=None): + """ + Parses the incoming bytestream as JSON and returns the resulting data + """ + result = super().parse( + stream, media_type=media_type, parser_context=parser_context + ) + + return self.parse_data(result, parser_context) From a6c5186b074627e13b2010567ce6494c84e3c64a Mon Sep 17 00:00:00 2001 From: Alex Seidmann Date: Tue, 16 Aug 2022 20:19:53 +0200 Subject: [PATCH 2/4] fix: formatting --- rest_framework_json_api/parsers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework_json_api/parsers.py b/rest_framework_json_api/parsers.py index 1cd65878..2aef1aa1 100644 --- a/rest_framework_json_api/parsers.py +++ b/rest_framework_json_api/parsers.py @@ -72,7 +72,7 @@ def parse_metadata(result): def parse_data(self, result, parser_context): """ - Formats the output of calling JSONParser to match the JSON:API specification + Formats the output of calling JSONParser to match the JSON:API specification and returns the result. """ if not isinstance(result, dict) or "data" not in result: From b8f9dc60c0d162df145da91535bded5e9fac8232 Mon Sep 17 00:00:00 2001 From: Alex Seidmann Date: Fri, 19 Aug 2022 15:19:19 +0200 Subject: [PATCH 3/4] feat: add myself to authors --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 419144b5..9a6c3fe4 100644 --- a/AUTHORS +++ b/AUTHORS @@ -47,3 +47,4 @@ Tim Selman Tom Glowka Ulrich Schuster Yaniv Peer +Alex Seidmann From c3c51c9f72501d657f2b04b7f7f6eebcd555ab9e Mon Sep 17 00:00:00 2001 From: Oliver Sauder Date: Sat, 20 Aug 2022 15:05:36 +0200 Subject: [PATCH 4/4] Added changelog --- AUTHORS | 2 +- CHANGELOG.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 9a6c3fe4..15a5393f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,6 +1,7 @@ Adam Wróbel Adam Ziolkowski Alan Crosswell +Alex Seidmann Anton Shutik Ashley Loewen Asif Saif Uddin @@ -47,4 +48,3 @@ Tim Selman Tom Glowka Ulrich Schuster Yaniv Peer -Alex Seidmann diff --git a/CHANGELOG.md b/CHANGELOG.md index 91551dca..41990d56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ any parts of the framework not mentioned in the documentation should generally b ### Added * Added support for Django 4.1. +* Expanded JSONParser API with `parse_data` method ### Removed