From 8ab71401b1bc82a29ef55ecf7b7e5c14d4b58c6c Mon Sep 17 00:00:00 2001 From: Victor de Jager Date: Fri, 24 Nov 2017 14:32:17 +0100 Subject: [PATCH 1/2] compare Field.method to the Link method in AutoSchema manual fields --- rest_framework/schemas/inspectors.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/rest_framework/schemas/inspectors.py b/rest_framework/schemas/inspectors.py index 80dc492684..7f3f27458b 100644 --- a/rest_framework/schemas/inspectors.py +++ b/rest_framework/schemas/inspectors.py @@ -171,6 +171,7 @@ def __init__(self, manual_fields=None): * `manual_fields`: list of `coreapi.Field` instances that will be added to auto-generated fields, overwriting on `Field.name` + if the link method matches the manual field method. """ self._manual_fields = manual_fields @@ -184,7 +185,14 @@ def get_link(self, path, method, base_url): if self._manual_fields is not None: by_name = {f.name: f for f in fields} for f in self._manual_fields: - by_name[f.name] = f + + try: + if f.method in method: + by_name[f.name] = f + except AttributeError: + by_name[f.name] = f + warnings.warn('coreapi.Field has no attribute "method", please update coreapi') + fields = list(by_name.values()) if fields and any([field.location in ('form', 'body') for field in fields]): From d468a6ec76c0a3ddbb2427e26ea5de1c453b76cb Mon Sep 17 00:00:00 2001 From: Victor de Jager Date: Fri, 24 Nov 2017 14:55:17 +0100 Subject: [PATCH 2/2] switched thed comparisson logic --- rest_framework/schemas/inspectors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/schemas/inspectors.py b/rest_framework/schemas/inspectors.py index 7f3f27458b..c139db9108 100644 --- a/rest_framework/schemas/inspectors.py +++ b/rest_framework/schemas/inspectors.py @@ -187,7 +187,7 @@ def get_link(self, path, method, base_url): for f in self._manual_fields: try: - if f.method in method: + if method in f.method: by_name[f.name] = f except AttributeError: by_name[f.name] = f