# -*- coding: utf-8 -*- # 票 04 / t12 验收:knife4j/swagger 抽查 —— OpenAPI tags = 深路径 tag 原文 import json, sys, io, urllib.request sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') URL = 'http://localhost:8080/v3/api-docs' try: with urllib.request.urlopen(URL, timeout=15) as r: spec = json.loads(r.read().decode('utf-8')) except Exception as e: print('FETCH FAILED:', e) raise SystemExit(1) tags = sorted(t.get('name', '') for t in spec.get('tags', [])) print(f'openapi={spec.get("openapi")} tags={len(tags)}') for t in tags: print(' TAG:', t) # 抽查:(路径, method, 期望 tag) CHECKS = [ ('/api/auth/login/dingtalk', 'post', 'A0 登录界面'), ('/api/opportunity/customer/list', 'get', 'A3 商机管理/商机详情/客户'), ('/api/roles/page', 'post', 'A7 后台管理/权限管理/角色管理'), ('/api/file/upload', 'post', '公共依赖/文件'), ] ok = True paths = spec.get('paths', {}) for p, m, expect in CHECKS: node = paths.get(p, {}).get(m) got = (node or {}).get('tags', []) hit = expect in got ok = ok and hit print(f'{"OK " if hit else "DIFF"} {m.upper()} {p} -> {got} (期望 {expect})') # 双归属抽查:LeadPool 5 端点应同时挂两个 tag pool = [p for p in paths if p.startswith('/api/rule/pool/')] for p in sorted(pool): for m, node in paths[p].items(): if m in ('get', 'post', 'put', 'delete', 'patch'): got = node.get('tags', []) hit = ('A2 线索管理/线索设置' in got) and ('A7 后台管理/线索规则' in got) ok = ok and hit print(f'{"OK " if hit else "DIFF"} {m.upper()} {p} -> {got}') print('RESULT:', 'ALL MATCH' if ok else 'HAS DIFF')