Comments (6)
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.
Hello,
Sadly, no, there is currently no such mechanism implemented for recursively converting Serializer
s 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.
@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.
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.
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.
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)
- 1.21.6 - Missing redoc.min.map HOT 13
- get_schema_fields breaks when using django-filters after last update HOT 2
- Redirect URL is not being processed in Django 4.2 when using oauth2 implicit flow HOT 1
- coreschema does not get installed with 1.21.6 HOT 4
- Can I use swagger_auto_schema in generic views?
- Vulnerability Issue
- `SerializerMethodField` return type is always 'STRING' when a file uses `from __future__ import annotations` due to PEP 563 HOT 2
- Animation not working on brave browser
- swagger_serializer_method does not work with partialmethod
- Headers Not Getting Sent Along with Request!
- Wrong Base URL: localhost HOT 2
- Add Python 3.12 Support HOT 1
- from pkg_resources import DistributionNotFound, get_distribution `ModuleNotFoundError: No module named 'pkg_resources`
- Export enums with drf-yasg to Swagger: Works in responses serializers but not in query_serializer
- Showing the read_only fields in the serializer in the post /swagger template in (ForignKeyFields)
- Django5 not supported? HOT 1
- tags hierarchy (sub-tags grouping)
- How can i remove default urls generated by base_url of router from swagger ui ??
- django_filters is not compatible
- Login with JWT
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drf-yasg.