denisorehovsky / django-rest-polymorphic

Polymorphic serializers for Django REST Framework
MIT License
179 stars 25 forks source link

Status of the library #22

Closed tfranzel closed 4 years ago

tfranzel commented 4 years ago

Hi, thank you for this awesome extension to DRF and django-polymorphic. we use it extensively!

Given that there has been no signal for quite some time, i'm wondering whether this repo is unmaintained. @apirobot would you mind telling us the current status?

is there a chance of merging #21 and resolving the other open issues?

Thanks

denisorehovsky commented 4 years ago

Hi @tfranzel. Sorry in advance. I have a lot of work at my job and on the side right now. That's the reason why I haven't reviewed and merged any PRs so far. To be honest, I didn't expect that people will use this library. In the near future, I'll try to allocate some time to merge and set up CI. Thanks.

tfranzel commented 4 years ago

Thank you for replying so quickly. Glad to hear that and i'm absolutely fine with that. Once released these things develop a life of their own :smile: i'm gonna leave the issue open for others who might be wondering.

FYI: django-rest-polymorphic is now supported by our DRF OpenAPI3 schema generation tool https://github.com/tfranzel/drf-spectacular

vaibhavhrt commented 2 years ago

@tfranzel , the autogenerated doc seems to be missing the resourcetype field.

tfranzel commented 2 years ago

@vaibhavhrt cannot confirm your statement. This is always added as propertyName. If you change the default resource_type_field_name, it is is naturally different.

https://github.com/tfranzel/drf-spectacular/blob/03276aac6f1eac93675becb55cd4873889337de7/drf_spectacular/contrib/rest_polymorphic.py#L31

vaibhavhrt commented 2 years ago

It's there in the schema, but not in request/response body. While creating objects we need to send the resourcetype field too in request body.

tfranzel commented 2 years ago

@vaibhavhrt it is part of the generated component. That component is referenced both in requests and response bodies. no need to have it there explicitly. This approach works without issue for both swagger-ui ad swagger-codegen.

https://github.com/tfranzel/drf-spectacular/blob/03276aac6f1eac93675becb55cd4873889337de7/tests/test_polymorphic.yml

vaibhavhrt commented 2 years ago

@tfranzel Right, if you look at the schema on Swagger UI, it shows only one field in request body, i.e. company_name, but to be able to create an object our request needs to be something like this:

{
  "company_name": "string",
  "resourcetype": "LegalPerson"  // or "NaturalPerson"
}
Screen Shot 2022-05-16 at 12 14 37 PM

We can figure out that we need to send resourcetype field by looking at the schema tab, but most of the time the person looking at the doc is someone who is working on the frontend, and they just look at the request/response body.

tfranzel commented 2 years ago

I see your point. It is a design choice by swagger-ui though. Looking at the schema, its clearly recognized as a polymorphic model. We have no simple way of influencing the choice of the example value there (except for providing explicit examples that can be selected via dropdown). I think they just use the first entry of the oneOf for that.

image