Giter Site home page Giter Site logo

Comments (6)

Augustinio avatar Augustinio commented on May 5, 2024 3

I gotta say I don't quite understand the logic.
If a Schema instance can be substituted with a Serializer instance in a Response, then why not in a Schema property?

from drf-yasg.

axnsan12 avatar axnsan12 commented on May 5, 2024 2

Hello,

Sadly, no, there is currently no such mechanism implemented for recursively converting Serializers inside a Schema object.

Unless you have a good reason not to, it's probably better to use a single serializer for your view result (drf-yasg limitations or not):

class FooBarSerializer(Serializer):
    foo = FooSerializer(many=True)
    bar = BarSerializer(many=True)
out = FooBarSerializer({'foo': foo, 'bar': bar}).data
@swagger_auto_schema(responses={
    200: openapi.Response('OK', FooBarSerializer),
})

from drf-yasg.

sevetseh28 avatar sevetseh28 commented on May 5, 2024 1

@axnsan12 would it be possible to inspect a serializer class that is not used by any view to include it manually in the Model definitions ? if so, how? I've been looking at the code but still having a hard time trying to do so.

Thanks!

from drf-yasg.

vvarp avatar vvarp commented on May 5, 2024

Yes, this is where I am headed right now 😉

But what about using SchemaRef? Is there a way to "pre-register" schemas based on Serializers?

from drf-yasg.

axnsan12 avatar axnsan12 commented on May 5, 2024

Unfortunately not, since some aspects of Serializer to Schema conversion can depend on runtime parameters (i.e. the user who is requesting the swagger definition).

Also do note that there is no global ReferenceResolver, and your last example is wrong in any situation because it always tries to get a definition from an empty ReferenceResolver. The instance that is actually used is created for every new run of get_schema, here.

from drf-yasg.

vvarp avatar vvarp commented on May 5, 2024

Okay, now I get it - I saw docstring for Schema mentioning SchemaRef and tried to just use it w/o fully understanding the context!

from drf-yasg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.