I got many serializers named 'InputSerializer' and 'OutputSerializer' which translates to 'Input' and 'Output' schema name in drf-spectacular. This ends up referring the api endpoints to the same schema. Is there a way to override the autogenerated schema names of these serializers without changing the name of the class?
Is there a way to change the autogenerated shema name of a serializer in drf-spectacular
2k views Asked by Gofven At
2
There are 2 answers
0
Insa
On
Understandable, but a unique name has to come from somewhere and spectacular cannot know what is a good name for you other than the classname itself. Andrew provides the native solution but there is also syntactic sugar for that (compatibility feature with drf-yasg).
class InputSerializer(serializer.Serializer):
class Meta:
ref_name = 'SomeNiceReallyLongId'
https://drf-spectacular.readthedocs.io/en/latest/drf_yasg.html?highlight=ref_name#compatibility
Otherwise I would recommend subclassing AutoSchema and overriding _get_serializer_name and make it work for you.
Related Questions in DJANGO
- Display images on Django Template Site
- Protractor did not run properly when using browser.wait, msg: "Wait timed out after XXXms"
- Django invalid literal for int() with base 10:
- Removing URL features from tokens in NLTK
- Django Noob URL to from Root Page to sub Page
- Django Admin tables not displaying correctly
- Django with chartkick
- Django urls.py not rendering correct template
- django form errors before submit
- django admin: custom app_index with context
- Display multiple models in one view in Django
- Unexpected NoReverseMatch error when using include() in urls patterns
- Search for a key in django.core.cache
- Django webapp (on an Apache2 server) hangs indefintely when importing nltk in views.py
- Django flush won't load fixtures
Related Questions in DJANGO-REST-FRAMEWORK
- CORS in ionic app and django
- DjangoRestFramework Class Serializers missing "Meta" attribute?
- django rest framework - token authentication logout
- Django Rest Framework + React + Reflux: Can't GET new objects
- Is it possible to restrict url access from application only in Django REST
- Using QHttpMultiPart with QHttpPart Binary and Form Data
- django rest framework search filter all fields
- How to install python django rest framework on fedora 21 with yum?
- Django REST : Making a custom serializer return proper error message
- Why `create()` method of django rest framework serializer return a value?
- Automatically add all model fields to django rest serializer
- django rest framework - adding to views.obtain_auth_token
- How to deserialize nested objects with Django Rest Framework
- Django REST Framework - Update object with FK to a model with unique field
- Django user login through api
Related Questions in OPENAPI
- Swagger: How do you add ApiModelProperty for 3rd party code?
- Why `additionalProperties` is the way to represent Dictionary/Map in Swagger/OpenAPI 2.0
- Allow swagger query param to be array of strings or integers
- How to refer to an external JSON file containing response examples in Swagger?
- How to generate JSON examples from OpenAPI/Swagger model definition?
- Swagger/OpenAPI - use $ref to pass a reusable defined parameter
- Provide alternate (international) spelling for defined Swagger route
- Unable to use tags in swagger documentation
- Hello,I am using swagger 3.0.0.The operation oneOf is not working here too?Where is the mistaken?
- How to document a response comprised of a list of resources using OpenAPI
- Error generating OpenAPI doc using endpoints-framework-tools
- Swagger/OpenAPI spec for arrays of objects in URL query parameter
- Custom Security Definition for Google Cloud Endpoints OpenAPI Key Mismatch
- xml to swagger 2.0 spec conversion using golang
- In swagger, is it possible import multiple yaml files in one single file?
Related Questions in DRF-SPECTACULAR
- How to get a prefilled authorization key in swagger with drf-specatular
- Change the parent lookup kwarg in nested routes using Django REST Framework
- Override type name in the drf-spectacular - generated OpenAPI schema
- How to fix vertical naming of endpoints in swagger
- Marking endpoints in a viewset that require authentication for drf-spectacular (cookiecutter-django)
- Difficulty Sending List of Working Hours as Multipart Data Using Swagger in Django DRF
- Pass Swagger-UI url in drf-spectacular settings
- Using FileField/ImageField with Swagger UI and drf-spectacular
- drf-spectacular: how to show the primary key in examples section of Swagger
- DRF spectacular not discovering custom auth extension classes
- drf-spectacular: Specify empty payload using @extend_schema
- Different descriptions for methods in custom @action for routing
- drf-spectacular: Automatic rendering of schema fields
- Field with default value appears as optional in schema
- How to generate a schema for a custom pagination in django rfw with drf-spectacular?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
I've run into this a bunch, but never tried to solve it. Looking at the docs I found
extended_schema_serializer, which might do what you need. Here is the full api, and the relevant point:component_name– override default class name extractionIts kinda long and ugly, but that can be fixed by a decorator on the decorator :D
Edit:
I ended up implementing this. Here is the small wrapper I wrote. It just makes things shorter and consistent between serializers and fields.
You can use
extended_schema_serializermore than once on a serializer, so this won't break anything.