MCPcopy Index your code
hub / github.com/dataease/SQLBot / generate_openapi_for_lang

Function generate_openapi_for_lang

backend/main.py:114–150  ·  view source on GitHub ↗
(lang: str)

Source from the content-addressed store, hash-verified

112
113
114def generate_openapi_for_lang(lang: str) -> Dict[str, Any]:
115 if lang in _openapi_cache:
116 return _openapi_cache[lang]
117
118 # tags metadata
119 trans = get_translation(lang)
120 localized_tags = []
121 for tag in tags_metadata:
122 desc = tag["description"]
123 if desc.startswith(PLACEHOLDER_PREFIX):
124 key = desc[len(PLACEHOLDER_PREFIX):]
125 desc = trans.get(key, desc)
126 localized_tags.append({
127 "name": tag["name"],
128 "description": desc
129 })
130
131 # 1. create OpenAPI
132 openapi_schema = get_openapi(
133 title="SQLBot API Document" if lang == "en" else "SQLBot API 文档",
134 version="1.0.0",
135 routes=app.routes,
136 tags=localized_tags
137 )
138
139 # openapi version
140 openapi_schema.setdefault("openapi", "3.1.0")
141
142 # 2. get trans for lang
143 trans = get_translation(lang)
144
145 # 3. replace placeholder
146 replace_placeholders_in_schema(openapi_schema, trans)
147
148 # 4. cache
149 _openapi_cache[lang] = openapi_schema
150 return openapi_schema
151
152
153

Callers 1

custom_openapiFunction · 0.85

Calls 4

get_translationFunction · 0.90
getMethod · 0.65
appendMethod · 0.45

Tested by

no test coverage detected