v0.5.8: openapi.json — готовая JSON-строка в памяти, без jsonify на каждый запрос

This commit is contained in:
2026-08-02 12:32:56 +04:00
parent 32d1ecc5a3
commit e206b65dc6
2 changed files with 7 additions and 5 deletions
+1 -1
View File
@@ -80,7 +80,7 @@ SERVICES = _DF["SERVICES"]
OPS_INDEX = _DF["OPS_INDEX"] OPS_INDEX = _DF["OPS_INDEX"]
DELAY = float(os.getenv("MOCK_OP_DELAY", "0.1")) DELAY = float(os.getenv("MOCK_OP_DELAY", "0.1"))
VERSION = "0.5.7" VERSION = "0.5.8"
def get_services(stand_id): def get_services(stand_id):
+6 -4
View File
@@ -10,7 +10,9 @@ Swagger UI загружает этот JSON через /swagger и рендер
import os import os
from flask import Blueprint, jsonify import json
from flask import Blueprint, jsonify, Response
import config.loader as _cfg import config.loader as _cfg
@@ -36,11 +38,11 @@ def _build_servers():
@bp.route("/openapi.json", methods=["GET"]) @bp.route("/openapi.json", methods=["GET"])
def openapi_spec(): def openapi_spec():
"""GET /api/v1/svc/openapi.json — OpenAPI 3.1.0 спецификация (кешируется).""" """GET /api/v1/svc/openapi.json — OpenAPI 3.1.0 спецификация (кеш в памяти)."""
global _SPEC_CACHE global _SPEC_CACHE
if _SPEC_CACHE is None: if _SPEC_CACHE is None:
_SPEC_CACHE = _build_spec() _SPEC_CACHE = json.dumps(_build_spec(), ensure_ascii=False)
return jsonify(_SPEC_CACHE) return Response(_SPEC_CACHE, mimetype="application/json")
def _build_spec(): def _build_spec():