question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OpenAPI support for flex fields

See original GitHub issue

I am using drf-spectacular for schema generation; using the @extend_schema decorator to add docs to my views.

Say I have a serializer named PersonSerializer that inherits from FlexFieldsModelSerializer. If I pass it the fields argument, I expect it to show only those fields in the schema. Example code:

@extend_schema(
    responses={201: PersonSerializer(fields=["id", "username"])},
)
@api_view(["POST"])
def my_view(request):

But the schema picks up all the default fields from the PersonSerializer class.

I do not know if this is something that needs to be solved in this project or drf-spectacular but any help is greatly appreciated.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
soroush-tabeshcommented, Sep 13, 2021

@mzanki So glad I could help!

Sure, but I was hoping for feedback from the owner before opening a PR on the repo. I guess I should open one.

2reactions
soroush-tabeshcommented, Aug 30, 2021

@rsinger86 I’m wondering why didn’t you use get_fields instead of to_representation in FlexFieldsSerializerMixin? by taking advantage of overriding fields, drf-spectacular could also generate a proper schema. Actually, I forked your code and changed it so and is working pretty fine in my project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · rsinger86/drf-flex-fields - GitHub
Dynamically set fields and expand nested resources in Django REST Framework ... Issues · rsinger86/drf-flex-fields. ... OpenAPI support for query parameters.
Read more >
OpenAPI extensions | Cloud Endpoints with OpenAPI
Cloud Endpoints accepts a set of Google-specific extensions to the OpenAPI specification that configure the behaviors of the Extensible Service Proxy (ESP) ...
Read more >
REST API for Oracle Fusion Cloud SCM - Create flexfields
Last Updated November 2022 You can use Oracle REST APIs to view and manage data stored in Oracle Supply Chain Management Cloud.
Read more >
How OpenAPI Data Types Enable Robust APIs - Stoplight Blog
OpenAPI Provides Context to Your Schemas. The JSON data format simply declares what data types can be described. JSON Schema defines fields, ...
Read more >
Describing Request Body - Swagger
If you used OpenAPI 2.0 before, here is a summary of changes to help you get ... The requestBody is more flexible in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found