Package: pik-openapi
PIK OPENAPI ToolsSome PIK protocol DRF openapi extensions:inspectionSchema version fetching fromRELEASEenv variable.Schema title generation asf'{settings.SERVICE_TITLE} API'.Components schemas generation from ModelSerializers.Schema description fetching fromsettings.SERVICE_DESCRIPTIONSerializerMethodFieldtype hint introspection.type fieldenummodel introspection:
-labelastitlehelp_textasdescriptionlabelasx-title-pluralcorrectListFielditem typingchoice labels asx-enumNamesdeprecated fields markingNullBooleanFieldtype fixType hints forSerializerMethodFieldJSONFieldschemainspect filters for list endpoint onlySchema customization withupdate_schemaproperty or methodOperation labels & descriptionRESTQL parameter schemaetcAutomatic camelCase translationschemafiltersparamsrestqlPIK OpenID SchemarenderersCachedRenderer mixin - returns pre-rendenred file if exists:replaces "/" with "_" to get filename/api/v1/schema/searches{STATIC_ROOT}/_api_v1_schema_.html/api/v1/schema/?format=openapisearches{STATIC_ROOT}/_api_v1_schema_.yaml/api/v1/schema/?format=openapi.jsonsearches{STATIC_ROOT}/_api_v1_schema_.jsonJSONOpenPrettyRendererRedocOpenAPIRenderergenerateopenapi management commandInstallationAddpik_openapitoINSTALLED_APPSinsettings.pyINSTALLED_APPS=[...'pik_openapi',]Setup default schema inspector class withsettings.pyREST_FRAMEWORK={'DEFAULT_SCHEMA_CLASS':'core.api.openapi.openapi.PIKAutoSchema',...}Setup schema url withurls.pyfromcore.api.openapi.viewsimportget_pik_schema_viewrouter_api_v1=DefaultRouter()api_v1_path=[path('api/v1/',include((router_api_v1.urls,'api_v1')))]urlpatterns=[*api_v1_path,path('api/v1/schema/',get_pik_schema_view(title=f'API Schema',patterns=api_v1_path),name='api_v1_schema'),]UsageRedoc schema is available at /api/v1/schema/ and /api/v1/schema/?format=redocJson schema format available at /api/v1/schema/?format=openapi-jsonYAML schema format available at /api/v1/schema/?format=openapiGenerate pre-rendered json schema file:./manage.pygenerateopenapi\--format=openapi-json\--urlpatterns=_project_.urls.api_v1_path\>${STATIC_ROOT}/_api_v1_schema_.jsonGenerate pre-rendered openapi schema file:./manage.pygenerateopenapi\--format=openapi\--urlpatterns=_project_.urls.api_v1_path\>${STATIC_ROOT}/_api_v1_schema_.yamlGenerate redoc bundle withredoc-cliredoc-clibundle${STATIC_ROOT}/_api_v1_schema_.json\--output${STATIC_ROOT}/_api_v1_schema_.html\--options.showExtensions=trueFeaturesSchema CustomizationSerializer schema customizationInject schema customization, throughupdate_schemadict:classMySerializer(ModelSerializer):update_schema={'properties':{'uid':{'deprecated':True}}}Inject schema customization, thoughupdate_schemacallback:classMySerializer(ModelSerializer):defupdate_schema(self,schema):schema['properties']['_uid']['deprecated']=TruereturnschemaViewSet Schema customizationInject schema customization, throughupdate_schemadict:classMyViewSet(ViewSet):update_schema={'/api/v1/comment-list/':{'get':{'deprecated':True,}}}Inject schema customization, thoughupdate_schemacallback:classMyViewSet(ViewSet):defupdate_schema(self,schema):schema['/api/v1/comment-list/']['get']['deprecated']=TruereturnschemaGenerate Schema as HTML FileFor generate schema as HTML file:Installredoc-clinpminstall-gredoc-cliGet your schema fileGenerate HTML file withredoc-cliredoc-clibundlestatic/_api_v1_schema_.json\--outputstatic/_api_v1_schema_.htmlMore info ``