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

Still wrong field names in schema #1047

jokiefer started this conversation in General
Discussion options

#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.

You must be logged in to vote

Replies: 1 comment 2 replies

Comment options

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.

You must be logged in to vote
2 replies
Comment options

Thanks for reporting. Those two spots were missed indeed in the fix of #967. A PR is very welcome.

Comment options

done #1048

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /