Skip to content

Commit b8960d5

Browse files
committed
fix: schema access failure to https
1 parent f6e089d commit b8960d5

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

apps/common/config/swagger_conf.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@date:2023/9/5 14:01
77
@desc: 用于swagger 分组
88
"""
9-
9+
from drf_yasg.generators import OpenAPISchemaGenerator
1010
from drf_yasg.inspectors import SwaggerAutoSchema
1111

1212
tags_dict = {
@@ -20,10 +20,10 @@ def get_tags(self, operation_keys=None):
2020
if "api" in tags and operation_keys:
2121
return [tags_dict.get(operation_keys[1]) if operation_keys[1] in tags_dict else operation_keys[1]]
2222
return tags
23+
24+
25+
class CustomOpenAPISchemaGenerator(OpenAPISchemaGenerator):
2326
def get_schema(self, request=None, public=False):
2427
schema = super().get_schema(request, public)
25-
if request.is_secure():
26-
schema.schemes = ['https']
27-
else:
28-
schema.schemes = ['http']
29-
return schema
28+
schema.schemes = ['https', 'http']
29+
return schema

apps/smartdoc/settings/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686

8787
SWAGGER_SETTINGS = {
8888
'DEFAULT_AUTO_SCHEMA_CLASS': 'common.config.swagger_conf.CustomSwaggerAutoSchema',
89+
'DEFAULT_GENERATOR_CLASS': 'common.config.swagger_conf.CustomOpenAPISchemaGenerator',
8990
"DEFAULT_MODEL_RENDERING": "example",
9091
'USE_SESSION_AUTH': False,
9192
'SECURITY_DEFINITIONS': {

0 commit comments

Comments
 (0)