fix: schema access failure to https
This commit is contained in:
parent
f6e089daee
commit
b8960d57c8
@ -6,7 +6,7 @@
|
|||||||
@date:2023/9/5 14:01
|
@date:2023/9/5 14:01
|
||||||
@desc: 用于swagger 分组
|
@desc: 用于swagger 分组
|
||||||
"""
|
"""
|
||||||
|
from drf_yasg.generators import OpenAPISchemaGenerator
|
||||||
from drf_yasg.inspectors import SwaggerAutoSchema
|
from drf_yasg.inspectors import SwaggerAutoSchema
|
||||||
|
|
||||||
tags_dict = {
|
tags_dict = {
|
||||||
@ -20,10 +20,10 @@ class CustomSwaggerAutoSchema(SwaggerAutoSchema):
|
|||||||
if "api" in tags and operation_keys:
|
if "api" in tags and operation_keys:
|
||||||
return [tags_dict.get(operation_keys[1]) if operation_keys[1] in tags_dict else operation_keys[1]]
|
return [tags_dict.get(operation_keys[1]) if operation_keys[1] in tags_dict else operation_keys[1]]
|
||||||
return tags
|
return tags
|
||||||
|
|
||||||
|
|
||||||
|
class CustomOpenAPISchemaGenerator(OpenAPISchemaGenerator):
|
||||||
def get_schema(self, request=None, public=False):
|
def get_schema(self, request=None, public=False):
|
||||||
schema = super().get_schema(request, public)
|
schema = super().get_schema(request, public)
|
||||||
if request.is_secure():
|
schema.schemes = ['https', 'http']
|
||||||
schema.schemes = ['https']
|
return schema
|
||||||
else:
|
|
||||||
schema.schemes = ['http']
|
|
||||||
return schema
|
|
||||||
|
|||||||
@ -86,6 +86,7 @@ TEMPLATES = [
|
|||||||
|
|
||||||
SWAGGER_SETTINGS = {
|
SWAGGER_SETTINGS = {
|
||||||
'DEFAULT_AUTO_SCHEMA_CLASS': 'common.config.swagger_conf.CustomSwaggerAutoSchema',
|
'DEFAULT_AUTO_SCHEMA_CLASS': 'common.config.swagger_conf.CustomSwaggerAutoSchema',
|
||||||
|
'DEFAULT_GENERATOR_CLASS': 'common.config.swagger_conf.CustomOpenAPISchemaGenerator',
|
||||||
"DEFAULT_MODEL_RENDERING": "example",
|
"DEFAULT_MODEL_RENDERING": "example",
|
||||||
'USE_SESSION_AUTH': False,
|
'USE_SESSION_AUTH': False,
|
||||||
'SECURITY_DEFINITIONS': {
|
'SECURITY_DEFINITIONS': {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user