Project

Profile

Help

Issue #3966

closed

Repository Version OpenAPI response schema is wrong

Added by dkliban@redhat.com over 5 years ago. Updated over 4 years ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Assignee:
-
Category:
-
Sprint/Milestone:
Start date:
Due date:
Estimated time:
Severity:
2. Medium
Version:
Platform Release:
OS:
Triaged:
No
Groomed:
No
Sprint Candidate:
No
Tags:
Sprint:
Quarter:

Description

The OpenAPI schema for the response of Repository Version contains 2 required fields: 'add_content_units' and 'remove_content_units'. The live docs are wrong and the generated bindings produce the following traceback:

repo_version = api.repositories_versions_read(repository.latest_version_href)

Traceback (most recent call last):
  File "devel/pulp3_python_client_example/test_bindings.py", line 46, in <module>
    repo_version = api.repositories_versions_read(repository.latest_version_href)
  File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/my_pulp3_client/api/pulp_api.py", line 6760, in repositories_versions_read
    (data) = self.repositories_versions_read_with_http_info(repository_version_href, **kwargs)  # noqa: E501
  File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/my_pulp3_client/api/pulp_api.py", line 6838, in repositories_versions_read_with_http_info
    collection_formats=collection_formats)
  File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/my_pulp3_client/api_client.py", line 322, in call_api
    _preload_content, _request_timeout)
  File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/my_pulp3_client/api_client.py", line 161, in __call_api
    return_data = self.deserialize(response_data, response_type)
  File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/my_pulp3_client/api_client.py", line 233, in deserialize
    return self.__deserialize(data, response_type)
  File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/my_pulp3_client/api_client.py", line 272, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/my_pulp3_client/api_client.py", line 615, in __deserialize_model
    instance = klass(**kwargs)
  File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/my_pulp3_client/models/repository_version.py", line 93, in __init__
    self.add_content_units = add_content_units
  File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/my_pulp3_client/models/repository_version.py", line 291, in add_content_units
    raise ValueError("Invalid value for `add_content_units`, must not be `None`")  # noqa: E501
ValueError: Invalid value for `add_content_units`, must not be `None`
Actions #1

Updated by dkliban@redhat.com over 5 years ago

The problem is that we have 2 fields that have a 'write_only' property set to True. Unlike DRF, drf_yasg does not make a distinction between the fields.

There is an open feature request[0] for a feature like this in drf_yasg. We may need to fix this in Pulp first and and then submit a patch upstream. I'll investigate.

[0] https://github.com/axnsan12/drf-yasg/issues/70

Actions #2

Updated by dkliban@redhat.com over 5 years ago

  • Status changed from NEW to ASSIGNED
Actions #3

Updated by dkliban@redhat.com over 5 years ago

  • Status changed from ASSIGNED to POST

Added by dkliban@redhat.com over 5 years ago

Revision 402a2920 | View on GitHub

Problem: OpenAPI schema for RepositoryVersion 'retrieve' is wrong

Solution: Create separate serializers for 'create' operation

The problem was that we had a single serializer for both GET and POST. DRF was able to distinguish which fields were to be used for accepting POST body params and which fields to use when serializing for a GET response. DRF knows this because some fields are 'write_only'. However, the drf_yasg library we use for generating OpenAPI schema does not take into account the 'write_only' attribute of a field. As a result when it was using the serializer to generate a schema for the GET response it was including the 'write_only' fields.

This patch introduces a new serializer that is only used for the 'create' operation of the RepositoryVersion ViewSet. This serializer is only used to inspect the inbound data in the POST body. It is not used for the response. The response is generated using the OperationPostponed serializer.

closes: #3966 https://pulp.plan.io/issues/3966

Added by dkliban@redhat.com over 5 years ago

Revision 402a2920 | View on GitHub

Problem: OpenAPI schema for RepositoryVersion 'retrieve' is wrong

Solution: Create separate serializers for 'create' operation

The problem was that we had a single serializer for both GET and POST. DRF was able to distinguish which fields were to be used for accepting POST body params and which fields to use when serializing for a GET response. DRF knows this because some fields are 'write_only'. However, the drf_yasg library we use for generating OpenAPI schema does not take into account the 'write_only' attribute of a field. As a result when it was using the serializer to generate a schema for the GET response it was including the 'write_only' fields.

This patch introduces a new serializer that is only used for the 'create' operation of the RepositoryVersion ViewSet. This serializer is only used to inspect the inbound data in the POST body. It is not used for the response. The response is generated using the OperationPostponed serializer.

closes: #3966 https://pulp.plan.io/issues/3966

Actions #4

Updated by dkliban@redhat.com over 5 years ago

  • Status changed from POST to MODIFIED
Actions #5

Updated by daviddavis almost 5 years ago

  • Sprint/Milestone set to 3.0.0
Actions #6

Updated by bmbouter almost 5 years ago

  • Tags deleted (Pulp 3, Pulp 3 MVP)
Actions #7

Updated by bmbouter over 4 years ago

  • Status changed from MODIFIED to CLOSED - CURRENTRELEASE

Also available in: Atom PDF