-
Notifications
You must be signed in to change notification settings - Fork 300
-
#967 fixes field names in schema based on the JSON_API_FORMAT_FIELD_NAMES setting.
But there are still 'wrong' field names which causes in mismatching field references:
Filter fields are still snake case:
filter[bbox_lat_lon.icontains]
Required post/patch data fields are still snake case:
"post": { "operationId": "create/api/v1/registry/wms/", ... "requestBody": { "content": { "application/vnd.api+json": { "schema": { "required": [ "data" ], "properties": { "data": { ... "attributes": { "type": "object", "properties": { "getCapabilitiesUrl": { "type": "string", "format": "uri", "pattern": "^(?:[a-z0-9.+-]*)://(?:[^\\s:@/]+(?::[^\\s:@/]*)?@)?(?:(?:0|25[0-5]|2[0-4]\\d|1\\d?\\d?|[1-9]\\d?)(?:\\.(?:0|25[0-5]|2[0-4]\\d|1\\d?\\d?|[1-9]\\d?)){3}|\\[[0-9a-f:.]+\\]|([a-z\u00a1-\uffff0-9](?:[a-z\u00a1-\uffff0-9-]{0,61}[a-z\u00a1-\uffff0-9])?(?:\\.(?!-)[a-z\u00a1-\uffff0-9-]{1,63}(?<!-))*\\.(?!-)(?:[a-z\u00a1-\uffff-]{2,63}|xn--[a-z0-9]{1,59})(?<!-)\\.?|localhost))(?::\\d{2,5})?(?:[/?#][^\\s]*)?\\z" }, ... "required": [ "get_capabilities_url" ] } }
It's not really possible to match the required fields with the properties of the object... I think this should be fixed.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 2 replies
-
Fix:
class DjangoFilterBackend(DjangoFilterBackend): def get_schema_operation_parameters(self, view): """ Convert backend filter `name` to JSON:API-style `filter[name]`. For filters that are relationship paths, rewrite ORM-style `__` to our preferred `.`. For example: `blog__name__contains` becomes `filter[blog.name.contains]`. This is basically the reverse of `get_filterset_kwargs` above. """ result = super().get_schema_operation_parameters(view) for res in result: if "name" in res: name = format_field_name(res["name"].replace("__", ".")) res["name"] = "filter[{}]".format(name) return result
class AutoSchema(drf_openapi.AutoSchema): """ Extend DRF's openapi.AutoSchema for JSON:API serialization. """ ... def map_serializer(self, serializer): ... if field.required: required.append(format_field_name(field.field_name))
would fix it.
Beta Was this translation helpful? Give feedback.
All reactions
2 replies
-
Thanks for reporting. Those two spots were missed indeed in the fix of #967. A PR is very welcome.
Beta Was this translation helpful? Give feedback.
All reactions
-
done #1048
Beta Was this translation helpful? Give feedback.
All reactions
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment