ansible / django-ansible-base

Apache License 2.0
11 stars 43 forks source link

Use serializers for simple informational views like "metadata" views #283

Open AlanCoding opened 5 months ago

AlanCoding commented 5 months ago

Some background in https://github.com/ansible/django-ansible-base/pull/276

With the latest changes (speculative) I still have the schema outputting this:

        "/service-index/": {
            "get": {
                "operationId": "service_index_retrieve",
                "description": "Link other resource registry endpoints",
                "tags": [
                    "service-index"
                ],
                "security": [
                    {
                        "cookieAuth": []
                    },
                    {
                        "basicAuth": []
                    },
                    {
                        "jwtAuth": []
                    },
                    {
                        "EDAJWTAuthentication": []
                    }
                ],
                "responses": {
                    "200": {
                        "description": "No response body"
                    }
                }
            }
        },
        "/service-index/metadata/": {
            "get": {
                "operationId": "service_index_metadata_retrieve",
                "tags": [
                    "service-index"
                ],
                "security": [
                    {
                        "cookieAuth": []
                    },
                    {
                        "basicAuth": []
                    },
                    {
                        "jwtAuth": []
                    },
                    {
                        "EDAJWTAuthentication": []
                    }
                ],
                "responses": {
                    "200": {
                        "description": "No response body"
                    }
                }
            }
        },

This isn't correct / complete, and it can't be unless the view uses a serializer. In these cases, the serializer would just be filled with read-only fields. It would do the same thing it does not, but using the serializer would allow OPTIONS to show the expected keys, and would allow OpenAPI spec to provide information about the format of the response.

AlanCoding commented 1 month ago

I'm not saying this is my best work, but you can see

https://github.com/ansible/django-ansible-base/blob/devel/ansible_base/rbac/api/views.py#L48

but RoleMetadataView does the basics of what is asked for here.