{"id":405506,"date":"2024-06-29T18:21:48","date_gmt":"2024-06-29T18:21:48","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=405506"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=405506","title":{"rendered":"<span>\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0438 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u044f OpenAPI \u0432 Django\/Django Rest Framework<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h3>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0421\u0442\u0430\u0442\u044c\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0431\u043e\u0440\u043d\u0438\u043a \u0441\u0441\u044b\u043b\u043e\u043a \u0438 \u0440\u0435\u0446\u0435\u043f\u0442\u043e\u0432, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0445 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c API \u0431\u043e\u043b\u0435\u0435 \u0433\u0438\u0431\u043a\u043e, \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f frontend \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 <a href=\"https:\/\/www.openapis.org\/\" rel=\"noopener noreferrer nofollow\">OpenAPI<\/a> \u0432 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0443 Django\/DRF.<\/p>\n<p>\u041a\u043e\u0440\u0435\u043d\u043d\u0430\u044f \u043c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 OpenAPI \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 &#8212; \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 API \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 API \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u043d\u0430 \u0431\u0430\u0437\u0435 \u0441\u0445\u0435\u043c\u044b OpenAPI. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0445 \u0442\u0438\u043f\u043e\u0432\/\u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0434\u043b\u044f JS\/TS, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"https:\/\/github.com\/ferdikoomen\/openapi-typescript-codegen\" rel=\"noopener noreferrer nofollow\">openapi-typescript-codegen<\/a>, <a href=\"https:\/\/github.com\/drwpow\/openapi-typescript\" rel=\"noopener noreferrer nofollow\">openapi-typescript<\/a>, \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 <a href=\"https:\/\/openapi-generator.tech\/\" rel=\"noopener noreferrer nofollow\">\u043e\u0431\u0449\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0448\u0438\u0440\u043e\u043a\u043e\u0433\u043e \u0441\u043f\u0435\u043a\u0442\u0440\u0430 \u044f\u0437\u044b\u043a\u043e\u0432<\/a>.<br \/> \u0418\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 Django\/DRF \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u0431\u043e\u0433\u0430\u0442\u0443\u044e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u0441\u0445\u0435\u043c\u044b API, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u043c \u0434\u0430\u043b\u0435\u0435 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f, \u043a\u0430\u043a \u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0447\u0435\u0433\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<h3>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c OpenAPI<\/h3>\n<p>\u0414\u043b\u044f Django\/DRF \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043e\u0434\u043d\u0438 \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 &#8212; <a href=\"https:\/\/github.com\/axnsan12\/drf-yasg\/tree\/1795ed15031dc742a09b95c3ee55ac52d66fa796\" rel=\"noopener noreferrer nofollow\">drf-yasg<\/a> \u0438 <a href=\"https:\/\/github.com\/tfranzel\/drf-spectacular\" rel=\"noopener noreferrer nofollow\">drf-spectacular<\/a>. drf-yasg \u0432 \u0446\u0435\u043b\u043e\u043c \u043e\u0442\u043b\u0438\u0447\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043e\u0434\u043d\u0430\u043a\u043e \u043e\u043d\u043e \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 OpenAPI 3.0. \u0411\u0443\u0434\u0435\u043c \u0438\u0434\u0442\u0438 \u0432 \u043d\u043e\u0433\u0443 \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0432\u0437\u044f\u0442 <code>drf-spectacular<\/code>. \u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043e\u0442\u043b\u0438\u0447\u043d\u0430\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0435\u0451 <a href=\"https:\/\/drf-spectacular.readthedocs.io\/en\/latest\/readme.html#installation\" rel=\"noopener noreferrer nofollow\">\u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u043c \u0432 \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442<\/a>, \u0437\u0430\u0442\u0435\u043c <a href=\"https:\/\/drf-spectacular.readthedocs.io\/en\/latest\/readme.html#take-it-for-a-spin\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 urls.py<\/a> redoc\/swagger, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437 UI. <code>drf-spectacular<\/code> \u043d\u0435\u043f\u043b\u043e\u0445\u043e \u0441\u0442\u0440\u043e\u0438\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043f\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c API \u043c\u0435\u0442\u043e\u0434\u043e\u0432 &#8212; action&#8217;\u043e\u0432 \u0438\u0437 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 View \u0438\u0437 DRF, \u043e\u0434\u043d\u0430\u043a\u043e, \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043d\u0430\u0448\u0438\u0445 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0435\u0439 \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043a\u0440\u044b\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430 <a href=\"https:\/\/drf-spectacular.readthedocs.io\/en\/latest\/readme.html#take-it-for-a-spin\" rel=\"noopener noreferrer nofollow\">@extend_view<\/a>. \u0415\u0441\u043b\u0438 \u0432\u043a\u0440\u0430\u0442\u0446\u0435, \u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0433\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (request), \u0444\u043e\u0440\u043c\u0430\u0442 \u043e\u0442\u0432\u0435\u0442\u0430 \u0438 \u043a\u043e\u0434 \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u043e\u0442\u0432\u0435\u0442\u0430 (responses), \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435, \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0434\u0440. \u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e API \u043c\u0435\u0442\u043e\u0434\u0430. \u041e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432 \u043e\u0442\u0432\u0435\u0442\u0430\/\u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u041e\u0434\u043d\u0430\u043a\u043e, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\/\u043e\u0442\u0432\u0435\u0442\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043e\u0434\u043d\u0438\u043c \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u0443\u0436\u0435 \u043d\u0435 \u043e\u0431\u043e\u0439\u0434\u0451\u043c\u0441\u044f \u0438 \u0437\u0430 \u0441\u0445\u0435\u043c\u043e\u0439 OpenAPI \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0435\u0434\u0438\u0442\u044c. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0430\u043b\u0435\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0438 \u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 <code>drf-spectacular<\/code>.<\/p>\n<h3>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0445\u0435\u043c\u044b<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0432\u043e\u043e\u0440\u0443\u0436\u0435\u043d\u044b \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c \u0441\u0445\u0435\u043c\u044b API, \u043e\u0434\u043d\u0430\u043a\u043e, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u043c\u0438 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0430\u0448\u0430 \u0441\u0445\u0435\u043c\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 API. \u0414\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0441\u0445\u0435\u043c\u044b \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0435\u0451 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 API \u043c\u043e\u0436\u0435\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 <a href=\"https:\/\/github.com\/snok\/drf-openapi-tester\" rel=\"noopener noreferrer nofollow\">drf-openapi-tester<\/a>. \u041f\u043e \u0441\u0443\u0442\u0438, \u0432\u0441\u0451 \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e &#8212; \u043f\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 API \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u044b\u0437\u043e\u0432<\/p>\n<pre><code class=\"python\">schema_tester.validate_response(response=response) <\/code><\/pre>\n<p>\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0430\u0441\u0442 \u043d\u0430\u043c \u0437\u043d\u0430\u0442\u044c, \u0432\u0441\u0451 \u043b\u0438 \u0443 \u043d\u0430\u0441 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0441 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0435\u0439 OpenAPI \u0441\u0445\u0435\u043c\u044b.<\/p>\n<h3>\u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u043e\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432<\/h3>\n<p>\u041d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432 \u0440\u0430\u0434\u0438 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442 \u043e\u0442\u0434\u0430\u0432\u0430\u043b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043b\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u043e\u043b\u0435\u0439 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0436\u0435 \u0438\u043c\u0435\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u0430. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432: \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>fields<\/code> \u0441 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043f\u043e\u043b\u0435\u0439, \u0438\u043b\u0438 \u0436\u0435 \u0441\u0430\u043c\u0438\u043c, \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 backend&#8217;\u0430 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u043e\u0442\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u041d\u0435\u0434\u043e\u043b\u0433\u043e \u0434\u0443\u043c\u0430\u044f, \u0434\u0435\u043b\u0430\u0435\u043c \u0432\u044b\u0431\u043e\u0440 \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430, \u0442.\u043a. \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430: 1) OpenAPI \u0431\u0443\u0434\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f \u043e\u0442\u0432\u0435\u0442\u0430 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438, \u0447\u0442\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e, 2) \u0414\u043b\u044f \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d \u0440\u0430\u0437\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u0430, \u0430 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043a \u0434\u0430\u043d\u043d\u044b\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d \u0432\u0438\u0434\u0435\u0442\u044c \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d. \u0412 \u0446\u0435\u043b\u043e\u043c, \u0434\u043b\u044f \u043e\u0431\u043e\u0438\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0435\u0441\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 \u0432\u0438\u0434\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <a href=\"https:\/\/github.com\/rsinger86\/drf-flex-fields\" rel=\"noopener noreferrer nofollow\">drf-flex-fields<\/a>. \u041c\u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0440\u043e\u0448\u043e <code>drf-flex-fields<\/code> \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441 <code>drf-spectacular\/drf-yasg<\/code>, \u0442.\u043a. \u044f \u043d\u0435 \u0441\u0442\u0430\u043b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u044d\u0442\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043b\u0441\u044f <a href=\"https:\/\/www.django-rest-framework.org\/api-guide\/serializers\/#dynamically-modifying-fields\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c<\/a> \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 DRF:<\/p>\n<pre><code class=\"python\">class DynamicFieldsModelSerializer(serializers.ModelSerializer):     def __init__(self, *args, **kwargs):         fields = kwargs.pop('fields', None)         self.ref_name = kwargs.pop('ref_name', None)          super().__init__(*args, **kwargs)          if fields is not None:             allowed = set(fields)             existing = set(self.fields)             for field_name in existing - allowed:                 self.fields.pop(field_name)      def get_fields(self):         return super().get_fields() <\/code><\/pre>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u043e\u043b\u0435\u0439 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u0445\u0435\u043c\u044b, \u0442.\u043a. \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0438\u043c\u0435\u044e\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438 \u0438\u043c\u0435\u043d\u0430\u043c\u0438 \u0438 \u043f\u043e \u0438\u0442\u043e\u0433\u0443 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0432\u0430\u043b\u0438\u0434\u043d\u0443\u044e \u0441\u0445\u0435\u043c\u0443. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0443 <code>self.ref_name = kwargs.pop('ref_name', None)<\/code>, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0443\u044e \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0439 OpenAPI \u0441\u0445\u0435\u043c\u044b. \u041e\u0434\u043d\u0430\u043a\u043e, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 drf-spectacular \u044d\u0442\u043e\u0433\u043e \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043c\u0430\u043b\u043e \u0438 \u0432 \u043a\u043e\u0434 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 <code>OpenApiSerializerExtension<\/code> (\u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u043b\u043e\u0433\u0438\u0438 drf-spectacular):<\/p>\n<pre><code class=\"python\">from drf_spectacular.extensions import OpenApiSerializerExtension  class DynamicFieldsModelSerializerExtension(OpenApiSerializerExtension):     target_class = DynamicFieldsModelSerializer     match_subclasses = True      def map_serializer(self, auto_schema, direction):         return auto_schema._map_serializer(self.target, direction, bypass_extensions=True)      def get_name(self, auto_schema, direction):         return self.target.ref_name <\/code><\/pre>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u0439 \u043c\u0430\u0433\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/github.com\/tfranzel\/drf-spectacular\/issues\/375\" rel=\"noopener noreferrer nofollow\">\u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c issue<\/a>.\u0412\u0441\u0451 \u0433\u043e\u0442\u043e\u0432\u043e, \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u043f\u043e\u043b\u044f \u0438 \u0431\u044b\u0442\u044c \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u044b\u043c \u0437\u0430 OpenAPI \u0441\u0445\u0435\u043c\u0443, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"python\">CustomSerializer(fields=('id', 'title', 'description'), ref_name='UniqueCustomSerializer') <\/code><\/pre>\n<h3>\u041a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 (DRF Response)<\/h3>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e DRF \u043e\u0442\u0434\u0430\u0451\u0442 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0432\u0438\u0434\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u043b\u0435\u0439. \u0418\u043d\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u043d\u0435 \u043f\u043e\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435\u0445 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439 \u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u043e\u0442\u0432\u0435\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 <code>body: {}<\/code>, \u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 <code>errors: []<\/code>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>render()<\/code> \u0443 \u043a\u043b\u0430\u0441\u0441\u0430<code>rest_framework.renderers.JsonRenderer<\/code>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">from rest_framework.renderers import JSONRenderer from rest_framework.utils import json   class JSONResponseRenderer(JSONRenderer):     charset = 'utf-8'      def render(self, data, accepted_media_type=None, renderer_context=None):         errors = []         if isinstance(data, dict) and (error := data.get('errors')):             errors.extend(error)             del data['errors']         response_dict = {             'body': data if data else {},             'errors': errors,         }         return json.dumps(response_dict) <\/code><\/pre>\n<p>\u0438 \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <code>JSONResponseRenderer<\/code> \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e <code>REST_FRAMEWORK<\/code> \u0432 <code>settings.py<\/code>:<\/p>\n<pre><code class=\"python\">...'DEFAULT_RENDERER_CLASSES': ('path_to_module.JSONResponseRenderer', ),... <\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441 OpenAPI \u0441\u0445\u0435\u043c\u043e\u0439, \u0442.\u043a. <code>drf-spectacular<\/code> \u0431\u0443\u0434\u0435\u0442 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u0438\u0437 <code>responses<\/code> \u0432 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0435 <code>@extend_schema<\/code>, \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/drf-spectacular.readthedocs.io\/en\/latest\/faq.html#how-do-i-wrap-my-responses-my-endpoints-are-wrapped-in-a-generic-envelope\" rel=\"noopener noreferrer nofollow\">FAQ drf-spectacular<\/a>, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u0435\u0439 \u043f\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u043e\u043b\u0435\u0439 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"python\">def enveloper(serializer_class=None, many=False, fields=None, ref_name=None):     if serializer_class:         if issubclass(serializer_class, DynamicFieldsModelSerializer):             inner_serializer = serializer_class(many=many, fields=fields, ref_name=ref_name)         else:             inner_serializer = serializer_class(many=many)          component_name = 'Enveloped{}{}{}'.format(             serializer_class.__name__.replace('Serializer', ''),             'List' if many else '',             ref_name if ref_name else ''         )     else:         inner_serializer = serializers.JSONField()         component_name = 'Enveloped{}{}'.format(             ref_name if ref_name else '',             'List' if many else ''         )      @extend_schema_serializer(many=False, component_name=component_name)     class EnvelopeSerializer(serializers.Serializer):         body = inner_serializer         errors = ApiErrorSerializer(many=True)      return EnvelopeSerializer <\/code><\/pre>\n<h3>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u043e\u0448\u0438\u0431\u043e\u043a<\/h3>\n<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043a\u043e\u0434\u0430 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043d \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 <code>ApiErrorSerializer<\/code> \u0434\u043b\u044f, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043e\u0442\u0434\u0430\u0447\u0438 \u043e\u0448\u0438\u0431\u043e\u043a API \u0432 \u0442\u0435\u043b\u0435 \u043e\u0442\u0432\u0435\u0442\u0430. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u043d \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<pre><code class=\"python\">class ApiErrorSerializer(serializers.Serializer):     code = serializers.CharField(allow_null=True)     message = serializers.CharField()     field = serializers.CharField(allow_null=True) <\/code><\/pre>\n<p>\u041d\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u043a\u043e\u0434 \u0432\u044b\u0448\u0435 \u0431\u044b\u043b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u0445\u0435\u043c\u044b, \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0436\u0435 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c <a href=\"https:\/\/www.django-rest-framework.org\/api-guide\/exceptions\/#custom-exception-handling\" rel=\"noopener noreferrer nofollow\">\u0441\u0432\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439<\/a>, \u0438\u043b\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 <a href=\"https:\/\/github.com\/ghazi-git\/drf-standardized-errors\" rel=\"noopener noreferrer nofollow\">drf-standardized-errors<\/a>. \u0421 \u043d\u0435\u0439 \u043d\u0430\u0448\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"json\">{   \"type\": \"client_error\",   \"errors\": [     {       \"code\": \"authentication_failed\",       \"detail\": \"Incorrect authentication credentials.\",       \"attr\": null     }   ] } <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u0435\u0439 \u0438\u043b\u0438 \u0443\u0431\u0440\u0430\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442 type, \u0442\u043e \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c<code> ExceptionFormatter<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"python\">from drf_standardized_errors.formatter import ExceptionFormatter from drf_standardized_errors.types import ErrorResponse   class DRFExceptionFormatter(ExceptionFormatter):     def format_error_response(self, error_response: ErrorResponse):         errors_lst = [             {                 'code': err.code,                 'message': err.detail,                 'field': err.attr             }             for err in error_response.errors         ]         return {'errors': errors_lst, 'type': error_response.type}  <\/code><\/pre>\n<p>\u0418 \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0432 <code>settings.py<\/code>:<\/p>\n<pre><code class=\"python\">DRF_STANDARDIZED_ERRORS = {'EXCEPTION_FORMATTER_CLASS': 'path_to_module.DRFExceptionFormatter'} <\/code><\/pre>\n<h3>\u0421amelCase\/lowerCamelCase<\/h3>\n<p>\u041d\u0435 \u0431\u0443\u0434\u0435\u043c \u0432\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0434\u0435\u0442\u0430\u043b\u0438 \u043d\u0430 \u043a\u0430\u043a\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043b\u0443\u0447\u0448\u0435 \u043c\u0435\u043d\u044f\u0442\u044c \u0441\u0442\u0438\u043b\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043c \u0437\u0430 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f DRF \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u0432\u0438\u0434\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <a href=\"https:\/\/github.com\/vbabiy\/djangorestframework-camel-case\" rel=\"noopener noreferrer nofollow\">djangorestframework-camel-case<\/a>. \u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0432\u0441\u0451 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>REST_FRAMEWORK<\/code> \u0432 <code>settings.py<\/code>. \u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/github.com\/vbabiy\/djangorestframework-camel-case#installation\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u0414\u043b\u044f drf-spectacular \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0430\u0440\u0443 \u043f\u043e\u043b\u0435\u0439 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 <code>SPECTACULAR_SETTINGS<\/code> \u0432 <code>settings.py<\/code>:<\/p>\n<pre><code class=\"python\">SPECTACULAR_SETTINGS = {     ...     'POSTPROCESSING_HOOKS': [         'drf_spectacular.contrib.djangorestframework_camel_case.camelize_serializer_fields'],     'CAMELIZE_NAMES': True,      ... }  <\/code><\/pre>\n<p>\u0410 \u0442\u0430\u043a\u0436\u0435, \u0440\u0430\u0437 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 <code>renderer<\/code>, \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0438 \u0435\u0433\u043e \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0443 \u043d\u0430 <code>CamelCase<\/code>:<\/p>\n<pre><code class=\"python\">from djangorestframework_camel_case.settings import api_settings from djangorestframework_camel_case.util import camelize from rest_framework.renderers import JSONRenderer from rest_framework.utils import json   class JSONResponseRenderer(JSONRenderer):     charset = 'utf-8'     json_underscoreize = api_settings.JSON_UNDERSCOREIZE      def render(self, data, accepted_media_type=None, renderer_context=None):         data = camelize(data, **self.json_underscoreize)         errors = []         if isinstance(data, dict) and (error := data.get('errors')):             errors.extend(error)             del data['errors']         response_dict = {             'body': data if data else {},             'errors': errors,         }         return json.dumps(response_dict) <\/code><\/pre>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0425\u043e\u0440\u043e\u0448\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u0432\u0430\u0448\u0435\u0433\u043e API, \u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0435\u0439\/\u0442\u0438\u043f\u043e\u0432 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 OpenAPI \u0441\u0445\u0435\u043c\u044b \u043c\u043e\u0436\u0435\u0442 \u0435\u0449\u0451 \u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043a\u043e\u043b\u043b\u0435\u0433\u0430\u043c.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/727936\/\"> https:\/\/habr.com\/ru\/articles\/727936\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h3>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0421\u0442\u0430\u0442\u044c\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0431\u043e\u0440\u043d\u0438\u043a \u0441\u0441\u044b\u043b\u043e\u043a \u0438 \u0440\u0435\u0446\u0435\u043f\u0442\u043e\u0432, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0445 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c API \u0431\u043e\u043b\u0435\u0435 \u0433\u0438\u0431\u043a\u043e, \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f frontend \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 <a href=\"https:\/\/www.openapis.org\/\" rel=\"noopener noreferrer nofollow\">OpenAPI<\/a> \u0432 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0443 Django\/DRF.<\/p>\n<p>\u041a\u043e\u0440\u0435\u043d\u043d\u0430\u044f \u043c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 OpenAPI \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 &#8212; \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 API \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 API \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u043d\u0430 \u0431\u0430\u0437\u0435 \u0441\u0445\u0435\u043c\u044b OpenAPI. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0445 \u0442\u0438\u043f\u043e\u0432\/\u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0434\u043b\u044f JS\/TS, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"https:\/\/github.com\/ferdikoomen\/openapi-typescript-codegen\" rel=\"noopener noreferrer nofollow\">openapi-typescript-codegen<\/a>, <a href=\"https:\/\/github.com\/drwpow\/openapi-typescript\" rel=\"noopener noreferrer nofollow\">openapi-typescript<\/a>, \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 <a href=\"https:\/\/openapi-generator.tech\/\" rel=\"noopener noreferrer nofollow\">\u043e\u0431\u0449\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0448\u0438\u0440\u043e\u043a\u043e\u0433\u043e \u0441\u043f\u0435\u043a\u0442\u0440\u0430 \u044f\u0437\u044b\u043a\u043e\u0432<\/a>.<br \/> \u0418\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 Django\/DRF \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u0431\u043e\u0433\u0430\u0442\u0443\u044e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u0441\u0445\u0435\u043c\u044b API, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u043c \u0434\u0430\u043b\u0435\u0435 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f, \u043a\u0430\u043a \u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0447\u0435\u0433\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<h3>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c OpenAPI<\/h3>\n<p>\u0414\u043b\u044f Django\/DRF \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043e\u0434\u043d\u0438 \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 &#8212; <a href=\"https:\/\/github.com\/axnsan12\/drf-yasg\/tree\/1795ed15031dc742a09b95c3ee55ac52d66fa796\" rel=\"noopener noreferrer nofollow\">drf-yasg<\/a> \u0438 <a href=\"https:\/\/github.com\/tfranzel\/drf-spectacular\" rel=\"noopener noreferrer nofollow\">drf-spectacular<\/a>. drf-yasg \u0432 \u0446\u0435\u043b\u043e\u043c \u043e\u0442\u043b\u0438\u0447\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043e\u0434\u043d\u0430\u043a\u043e \u043e\u043d\u043e \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 OpenAPI 3.0. \u0411\u0443\u0434\u0435\u043c \u0438\u0434\u0442\u0438 \u0432 \u043d\u043e\u0433\u0443 \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0432\u0437\u044f\u0442 <code>drf-spectacular<\/code>. \u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043e\u0442\u043b\u0438\u0447\u043d\u0430\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0435\u0451 <a href=\"https:\/\/drf-spectacular.readthedocs.io\/en\/latest\/readme.html#installation\" rel=\"noopener noreferrer nofollow\">\u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u043c \u0432 \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442<\/a>, \u0437\u0430\u0442\u0435\u043c <a href=\"https:\/\/drf-spectacular.readthedocs.io\/en\/latest\/readme.html#take-it-for-a-spin\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 urls.py<\/a> redoc\/swagger, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437 UI. <code>drf-spectacular<\/code> \u043d\u0435\u043f\u043b\u043e\u0445\u043e \u0441\u0442\u0440\u043e\u0438\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043f\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c API \u043c\u0435\u0442\u043e\u0434\u043e\u0432 &#8212; action&#8217;\u043e\u0432 \u0438\u0437 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 View \u0438\u0437 DRF, \u043e\u0434\u043d\u0430\u043a\u043e, \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043d\u0430\u0448\u0438\u0445 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0435\u0439 \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043a\u0440\u044b\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430 <a href=\"https:\/\/drf-spectacular.readthedocs.io\/en\/latest\/readme.html#take-it-for-a-spin\" rel=\"noopener noreferrer nofollow\">@extend_view<\/a>. \u0415\u0441\u043b\u0438 \u0432\u043a\u0440\u0430\u0442\u0446\u0435, \u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0433\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (request), \u0444\u043e\u0440\u043c\u0430\u0442 \u043e\u0442\u0432\u0435\u0442\u0430 \u0438 \u043a\u043e\u0434 \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u043e\u0442\u0432\u0435\u0442\u0430 (responses), \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435, \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0434\u0440. \u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e API \u043c\u0435\u0442\u043e\u0434\u0430. \u041e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432 \u043e\u0442\u0432\u0435\u0442\u0430\/\u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u041e\u0434\u043d\u0430\u043a\u043e, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\/\u043e\u0442\u0432\u0435\u0442\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043e\u0434\u043d\u0438\u043c \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u0443\u0436\u0435 \u043d\u0435 \u043e\u0431\u043e\u0439\u0434\u0451\u043c\u0441\u044f \u0438 \u0437\u0430 \u0441\u0445\u0435\u043c\u043e\u0439 OpenAPI \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0435\u0434\u0438\u0442\u044c. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0430\u043b\u0435\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0438 \u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 <code>drf-spectacular<\/code>.<\/p>\n<h3>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0445\u0435\u043c\u044b<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0432\u043e\u043e\u0440\u0443\u0436\u0435\u043d\u044b \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c \u0441\u0445\u0435\u043c\u044b API, \u043e\u0434\u043d\u0430\u043a\u043e, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u043c\u0438 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0430\u0448\u0430 \u0441\u0445\u0435\u043c\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 API. \u0414\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0441\u0445\u0435\u043c\u044b \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0435\u0451 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 API \u043c\u043e\u0436\u0435\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 <a href=\"https:\/\/github.com\/snok\/drf-openapi-tester\" rel=\"noopener noreferrer nofollow\">drf-openapi-tester<\/a>. \u041f\u043e \u0441\u0443\u0442\u0438, \u0432\u0441\u0451 \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e &#8212; \u043f\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 API \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u044b\u0437\u043e\u0432<\/p>\n<pre><code class=\"python\">schema_tester.validate_response(response=response) <\/code><\/pre>\n<p>\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0430\u0441\u0442 \u043d\u0430\u043c \u0437\u043d\u0430\u0442\u044c, \u0432\u0441\u0451 \u043b\u0438 \u0443 \u043d\u0430\u0441 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0441 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0435\u0439 OpenAPI \u0441\u0445\u0435\u043c\u044b.<\/p>\n<h3>\u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u043e\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432<\/h3>\n<p>\u041d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432 \u0440\u0430\u0434\u0438 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442 \u043e\u0442\u0434\u0430\u0432\u0430\u043b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043b\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u043e\u043b\u0435\u0439 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0436\u0435 \u0438\u043c\u0435\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u0430. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432: \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>fields<\/code> \u0441 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043f\u043e\u043b\u0435\u0439, \u0438\u043b\u0438 \u0436\u0435 \u0441\u0430\u043c\u0438\u043c, \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 backend&#8217;\u0430 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u043e\u0442\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u041d\u0435\u0434\u043e\u043b\u0433\u043e \u0434\u0443\u043c\u0430\u044f, \u0434\u0435\u043b\u0430\u0435\u043c \u0432\u044b\u0431\u043e\u0440 \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430, \u0442.\u043a. \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430: 1) OpenAPI \u0431\u0443\u0434\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f \u043e\u0442\u0432\u0435\u0442\u0430 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438, \u0447\u0442\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e, 2) \u0414\u043b\u044f \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d \u0440\u0430\u0437\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u0430, \u0430 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043a \u0434\u0430\u043d\u043d\u044b\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d \u0432\u0438\u0434\u0435\u0442\u044c \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d. \u0412 \u0446\u0435\u043b\u043e\u043c, \u0434\u043b\u044f \u043e\u0431\u043e\u0438\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0435\u0441\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 \u0432\u0438\u0434\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <a href=\"https:\/\/github.com\/rsinger86\/drf-flex-fields\" rel=\"noopener noreferrer nofollow\">drf-flex-fields<\/a>. \u041c\u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0440\u043e\u0448\u043e <code>drf-flex-fields<\/code> \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441 <code>drf-spectacular\/drf-yasg<\/code>, \u0442.\u043a. \u044f \u043d\u0435 \u0441\u0442\u0430\u043b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u044d\u0442\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043b\u0441\u044f <a href=\"https:\/\/www.django-rest-framework.org\/api-guide\/serializers\/#dynamically-modifying-fields\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c<\/a> \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 DRF:<\/p>\n<pre><code class=\"python\">class DynamicFieldsModelSerializer(serializers.ModelSerializer):     def __init__(self, *args, **kwargs):         fields = kwargs.pop('fields', None)         self.ref_name = kwargs.pop('ref_name', None)          super().__init__(*args, **kwargs)          if fields is not None:             allowed = set(fields)             existing = set(self.fields)             for field_name in existing - allowed:                 self.fields.pop(field_name)      def get_fields(self):         return super().get_fields() <\/code><\/pre>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u043e\u043b\u0435\u0439 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u0445\u0435\u043c\u044b, \u0442.\u043a. \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0438\u043c\u0435\u044e\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438 \u0438\u043c\u0435\u043d\u0430\u043c\u0438 \u0438 \u043f\u043e \u0438\u0442\u043e\u0433\u0443 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0432\u0430\u043b\u0438\u0434\u043d\u0443\u044e \u0441\u0445\u0435\u043c\u0443. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0443 <code>self.ref_name = kwargs.pop('ref_name', None)<\/code>, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0443\u044e \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0439 OpenAPI \u0441\u0445\u0435\u043c\u044b. \u041e\u0434\u043d\u0430\u043a\u043e, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 drf-spectacular \u044d\u0442\u043e\u0433\u043e \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043c\u0430\u043b\u043e \u0438 \u0432 \u043a\u043e\u0434 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 <code>OpenApiSerializerExtension<\/code> (\u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u043b\u043e\u0433\u0438\u0438 drf-spectacular):<\/p>\n<pre><code class=\"python\">from drf_spectacular.extensions import OpenApiSerializerExtension  class DynamicFieldsModelSerializerExtension(OpenApiSerializerExtension):     target_class = DynamicFieldsModelSerializer     match_subclasses = True      def map_serializer(self, auto_schema, direction):         return auto_schema._map_serializer(self.target, direction, bypass_extensions=True)      def get_name(self, auto_schema, direction):         return self.target.ref_name <\/code><\/pre>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u0439 \u043c\u0430\u0433\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/github.com\/tfranzel\/drf-spectacular\/issues\/375\" rel=\"noopener noreferrer nofollow\">\u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c issue<\/a>.\u0412\u0441\u0451 \u0433\u043e\u0442\u043e\u0432\u043e, \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u043f\u043e\u043b\u044f \u0438 \u0431\u044b\u0442\u044c \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u044b\u043c \u0437\u0430 OpenAPI \u0441\u0445\u0435\u043c\u0443, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"python\">CustomSerializer(fields=('id', 'title', 'description'), ref_name='UniqueCustomSerializer') <\/code><\/pre>\n<h3>\u041a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 (DRF Response)<\/h3>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e DRF \u043e\u0442\u0434\u0430\u0451\u0442 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0432\u0438\u0434\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u043b\u0435\u0439. \u0418\u043d\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u043d\u0435 \u043f\u043e\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435\u0445 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439 \u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u043e\u0442\u0432\u0435\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 <code>body: {}<\/code>, \u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 <code>errors: []<\/code>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>render()<\/code> \u0443 \u043a\u043b\u0430\u0441\u0441\u0430<code>rest_framework.renderers.JsonRenderer<\/code>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">from rest_framework.renderers import JSONRenderer from rest_framework.utils import json   class JSONResponseRenderer(JSONRenderer):     charset = 'utf-8'      def render(self, data, accepted_media_type=None, renderer_context=None):         errors = []         if isinstance(data, dict) and (error := data.get('errors')):             errors.extend(error)             del data['errors']         response_dict = {             'body': data if data else {},             'errors': errors,         }         return json.dumps(response_dict) <\/code><\/pre>\n<p>\u0438 \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <code>JSONResponseRenderer<\/code> \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e <code>REST_FRAMEWORK<\/code> \u0432 <code>settings.py<\/code>:<\/p>\n<pre><code class=\"python\">...'DEFAULT_RENDERER_CLASSES': ('path_to_module.JSONResponseRenderer', ),... <\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441 OpenAPI \u0441\u0445\u0435\u043c\u043e\u0439, \u0442.\u043a. <code>drf-spectacular<\/code> \u0431\u0443\u0434\u0435\u0442 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u0438\u0437 <code>responses<\/code> \u0432 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0435 <code>@extend_schema<\/code>, \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/drf-spectacular.readthedocs.io\/en\/latest\/faq.html#how-do-i-wrap-my-responses-my-endpoints-are-wrapped-in-a-generic-envelope\" rel=\"noopener noreferrer nofollow\">FAQ drf-spectacular<\/a>, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u0435\u0439 \u043f\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u043e\u043b\u0435\u0439 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"python\">def enveloper(serializer_class=None, many=False, fields=None, ref_name=None):     if serializer_class:         if issubclass(serializer_class, DynamicFieldsModelSerializer):             inner_serializer = serializer_class(many=many, fields=fields, ref_name=ref_name)         else:             inner_serializer = serializer_class(many=many)          component_name = 'Enveloped{}{}{}'.format(             serializer_class.__name__.replace('Serializer', ''),             'List' if many else '',             ref_name if ref_name else ''         )     else:         inner_serializer = serializers.JSONField()         component_name = 'Enveloped{}{}'.format(             ref_name if ref_name else '',             'List' if many else ''         )      @extend_schema_serializer(many=False, component_name=component_name)     class EnvelopeSerializer(serializers.Serializer):         body = inner_serializer         errors = ApiErrorSerializer(many=True)      return EnvelopeSerializer <\/code><\/pre>\n<h3>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u043e\u0448\u0438\u0431\u043e\u043a<\/h3>\n<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043a\u043e\u0434\u0430 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043d \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 <code>ApiErrorSerializer<\/code> \u0434\u043b\u044f, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043e\u0442\u0434\u0430\u0447\u0438 \u043e\u0448\u0438\u0431\u043e\u043a API \u0432 \u0442\u0435\u043b\u0435 \u043e\u0442\u0432\u0435\u0442\u0430. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u043d \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<pre><code class=\"python\">class ApiErrorSerializer(serializers.Serializer):     code = serializers.CharField(allow_null=True)     message = serializers.CharField()     field = serializers.CharField(allow_null=True) <\/code><\/pre>\n<p>\u041d\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u043a\u043e\u0434 \u0432\u044b\u0448\u0435 \u0431\u044b\u043b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u0445\u0435\u043c\u044b, \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0436\u0435 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c <a href=\"https:\/\/www.django-rest-framework.org\/api-guide\/exceptions\/#custom-exception-handling\" rel=\"noopener noreferrer nofollow\">\u0441\u0432\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439<\/a>, \u0438\u043b\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 <a href=\"https:\/\/github.com\/ghazi-git\/drf-standardized-errors\" rel=\"noopener noreferrer nofollow\">drf-standardized-errors<\/a>. \u0421 \u043d\u0435\u0439 \u043d\u0430\u0448\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"json\">{   \"type\": \"client_error\",   \"errors\": [     {       \"code\": \"authentication_failed\",       \"detail\": \"Incorrect authentication credentials.\",       \"attr\": null     }   ] } <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u0435\u0439 \u0438\u043b\u0438 \u0443\u0431\u0440\u0430\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442 type, \u0442\u043e \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c<code> ExceptionFormatter<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"python\">from drf_standardized_errors.formatter import ExceptionFormatter from drf_standardized_errors.types import ErrorResponse   class DRFExceptionFormatter(ExceptionFormatter):     def format_error_response(self, error_response: ErrorResponse):         errors_lst = [             {                 'code': err.code,                 'message': err.detail,                 'field': err.attr             }             for err in error_response.errors         ]         return {'errors': errors_lst, 'type': error_response.type}  <\/code><\/pre>\n<p>\u0418 \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0432 <code>settings.py<\/code>:<\/p>\n<pre><code class=\"python\">DRF_STANDARDIZED_ERRORS = {'EXCEPTION_FORMATTER_CLASS': 'path_to_module.DRFExceptionFormatter'} <\/code><\/pre>\n<h3>\u0421amelCase\/lowerCamelCase<\/h3>\n<p>\u041d\u0435 \u0431\u0443\u0434\u0435\u043c \u0432\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0434\u0435\u0442\u0430\u043b\u0438 \u043d\u0430 \u043a\u0430\u043a\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043b\u0443\u0447\u0448\u0435 \u043c\u0435\u043d\u044f\u0442\u044c \u0441\u0442\u0438\u043b\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043c \u0437\u0430 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f DRF \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u0432\u0438\u0434\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <a href=\"https:\/\/github.com\/vbabiy\/djangorestframework-camel-case\" rel=\"noopener noreferrer nofollow\">djangorestframework-camel-case<\/a>. \u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0432\u0441\u0451 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>REST_FRAMEWORK<\/code> \u0432 <code>settings.py<\/code>. \u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/github.com\/vbabiy\/djangorestframework-camel-case#installation\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u0414\u043b\u044f drf-spectacular \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0430\u0440\u0443 \u043f\u043e\u043b\u0435\u0439 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 <code>SPECTACULAR_SETTINGS<\/code> \u0432 <code>settings.py<\/code>:<\/p>\n<pre><code class=\"python\">SPECTACULAR_SETTINGS = {     ...     'POSTPROCESSING_HOOKS': [         'drf_spectacular.contrib.djangorestframework_camel_case.camelize_serializer_fields'],<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-405506","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/405506","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=405506"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/405506\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=405506"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=405506"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=405506"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}