chore: update openapi files - #2348
Conversation
WalkthroughUpdated OpenAPI specification document by consolidating authentication tags from "用户认证" and "两步验证" into a single "用户登陆注册" tag, added new public schemas (ApiResponse, PageInfo, Log), and introduced new security scheme definitions with composite security entries. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
docs/openapi/api.json (2)
8-60: Tag consolidation is incomplete: "两步验证" tag still active but should be consolidated.The PR summary states that "用户认证" and "两步验证" tags were removed and consolidated into "用户登陆注册", but line 24-26 shows "两步验证" remains in the tag definitions. Additionally, endpoints at lines 2116, 2141, 2166, 2205, 2244, 2269 still reference "两步验证" instead of the new consolidated tag. Either remove the old tag completely and migrate all references, or clarify the consolidation strategy.
2110-2287: 2FA endpoints still reference "两步验证" tag instead of consolidated "用户登陆注册".Lines 2116, 2141, 2166, 2205, 2244, 2269 all reference the "两步验证" tag. If the goal is to consolidate authentication-related endpoints, these should align with the consolidation strategy mentioned in the PR summary. Clarify whether this is intentional or an oversight.
🧹 Nitpick comments (1)
docs/openapi/api.json (1)
4949-4998: New schemas lack sufficient type detail for API consumers.The three newly added schemas (ApiResponse, PageInfo, Log) use overly generic property definitions:
"data": {}in ApiResponse has no type or structure information"items": {}in PageInfo lacks item schema details- All properties should specify type and format constraints
Consider refining these to include proper type annotations, required fields, and examples where applicable.
"ApiResponse": { "type": "object", "properties": { "success": { "type": "boolean" }, "message": { "type": "string" }, "data": { "type": "object", "description": "Response data payload (type varies by endpoint)" } }, "required": ["success"] }
| "securitySchemes": { | ||
| "SessionAuth1": { | ||
| "type": "apiKey", | ||
| "in": "cookie", | ||
| "name": "session", | ||
| "description": "Session认证,通过登录接口获取" | ||
| }, | ||
| "AccessToken1": { | ||
| "type": "apiKey", | ||
| "in": "header", | ||
| "name": "Authorization", | ||
| "description": "Access Token认证,格式: Bearer {access_token},通过 /api/user/token 接口生成" | ||
| }, | ||
| "NewApiUser1": { | ||
| "type": "apiKey", | ||
| "in": "header", | ||
| "name": "New-Api-User", | ||
| "description": "用户ID请求头,必须与当前登录用户ID匹配,使用Session或AccessToken认证时必须提供" | ||
| }, | ||
| "Combination222": { | ||
| "group": [ | ||
| { | ||
| "id": 573666 | ||
| }, | ||
| { | ||
| "id": 573668 | ||
| } | ||
| ], | ||
| "type": "combination" | ||
| }, | ||
| "Combination1122": { | ||
| "group": [ | ||
| { | ||
| "id": 573667 | ||
| }, | ||
| { | ||
| "id": 573668 | ||
| } | ||
| ], | ||
| "type": "combination" | ||
| }, | ||
| "Combination223": { | ||
| "group": [ | ||
| { | ||
| "id": "SessionAuth" | ||
| }, | ||
| { | ||
| "id": "NewApiUser" | ||
| } | ||
| ], | ||
| "type": "combination" | ||
| }, | ||
| "Combination1123": { | ||
| "group": [ | ||
| { | ||
| "id": "AccessToken" | ||
| }, | ||
| { | ||
| "id": "NewApiUser" | ||
| } | ||
| ], | ||
| "type": "combination" | ||
| }, | ||
| "Combination224": { | ||
| "group": [ | ||
| { | ||
| "id": "SessionAuth" | ||
| }, | ||
| { | ||
| "id": "NewApiUser" | ||
| } | ||
| ], | ||
| "type": "combination" | ||
| }, | ||
| "Combination1124": { | ||
| "group": [ | ||
| { | ||
| "id": "AccessToken" | ||
| }, | ||
| { | ||
| "id": "NewApiUser" | ||
| } | ||
| ], | ||
| "type": "combination" | ||
| }, |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, get the file size and overall structure
wc -l docs/openapi/api.jsonRepository: QuantumNous/new-api
Length of output: 89
🏁 Script executed:
# Count the total number of Combination entries in securitySchemes
grep -o '"Combination[0-9]*"' docs/openapi/api.json | sort | uniq | wc -lRepository: QuantumNous/new-api
Length of output: 66
🏁 Script executed:
# Get a sample of all Combination names to see the range
grep -o '"Combination[0-9]*"' docs/openapi/api.json | sort -uRepository: QuantumNous/new-api
Length of output: 4332
🏁 Script executed:
# Search for security references in the endpoints to see how many combinations are actually used
grep -E '"security"\s*:\s*\[' docs/openapi/api.json | head -20Repository: QuantumNous/new-api
Length of output: 502
🏁 Script executed:
# Extract the securitySchemes section to understand the structure
sed -n '5126,5210p' docs/openapi/api.jsonRepository: QuantumNous/new-api
Length of output: 1856
🏁 Script executed:
# Find the securitySchemes section boundaries
grep -n '"securitySchemes"' docs/openapi/api.jsonRepository: QuantumNous/new-api
Length of output: 92
🏁 Script executed:
# Get the full structure of a few sample combinations to see if they're identical
python3 << 'EOF'
import json
with open('docs/openapi/api.json', 'r') as f:
data = json.load(f)
security_schemes = data.get('components', {}).get('securitySchemes', {})
# Sample combinations to check structure
samples = ['Combination222', 'Combination223', 'Combination224', 'Combination1122', 'Combination1123']
for combo in samples:
if combo in security_schemes:
print(f"\n{combo}:")
print(json.dumps(security_schemes[combo], indent=2))
EOFRepository: QuantumNous/new-api
Length of output: 149
🏁 Script executed:
# Count how many endpoints reference each combination type
python3 << 'EOF'
import json
import re
from collections import defaultdict
with open('docs/openapi/api.json', 'r') as f:
content = f.read()
data = json.loads(content)
# Find all endpoint definitions and their security requirements
combo_usage = defaultdict(int)
paths = data.get('paths', {})
for path, methods in paths.items():
for method, details in methods.items():
if isinstance(details, dict) and 'security' in details:
security_list = details['security']
if isinstance(security_list, list):
for sec_item in security_list:
if isinstance(sec_item, dict):
for key in sec_item.keys():
if 'Combination' in key:
combo_usage[key] += 1
# Show statistics
print(f"Total unique combinations used in endpoints: {len(combo_usage)}")
print(f"\nTop 20 most used combinations:")
for combo, count in sorted(combo_usage.items(), key=lambda x: x[1], reverse=True)[:20]:
print(f" {combo}: {count} endpoint(s)")
# Check if all defined combinations are used
security_schemes = data.get('components', {}).get('securitySchemes', {})
all_combos = {k for k in security_schemes.keys() if 'Combination' in k}
used_combos = set(combo_usage.keys())
unused = all_combos - used_combos
print(f"\nTotal combinations defined: {len(all_combos)}")
print(f"Total combinations used: {len(used_combos)}")
print(f"Total combinations unused: {len(unused)}")
if len(unused) <= 20:
print(f"Unused combinations: {sorted(unused)}")
else:
print(f"Unused combinations (showing first 20): {sorted(unused)[:20]}")
EOFRepository: QuantumNous/new-api
Length of output: 149
🏁 Script executed:
# More efficient check: count how many times each Combination is referenced
grep -o '"Combination[0-9]*"' docs/openapi/api.json | sort | uniq -c | sort -rn | head -30Repository: QuantumNous/new-api
Length of output: 813
🏁 Script executed:
# Check if Combination223 and Combination224 are truly identical by extracting their full definitions
python3 << 'EOF'
import json
with open('docs/openapi/api.json', 'r', encoding='utf-8') as f:
data = json.load(f)
schemes = data.get('components', {}).get('securitySchemes', {})
# Compare specific combinations
test_combos = ['Combination223', 'Combination224', 'Combination1123', 'Combination1124']
results = {}
for combo in test_combos:
if combo in schemes:
results[combo] = schemes[combo]
# Find which are identical
print("Structure comparison:")
for combo in test_combos:
if combo in results:
print(f"{combo}: {json.dumps(results[combo])}")
EOFRepository: QuantumNous/new-api
Length of output: 470
🏁 Script executed:
# Count total combinations defined vs referenced
grep -c '"Combination[0-9]*"' docs/openapi/api.jsonRepository: QuantumNous/new-api
Length of output: 66
🏁 Script executed:
# Look for patterns in how combinations are used in security definitions
# Extract a few security definitions from endpoints
sed -n '1,2000p' docs/openapi/api.json | grep -A 2 '"security"' | head -40Repository: QuantumNous/new-api
Length of output: 762
🏁 Script executed:
# Check if this file is auto-generated - look for generation markers or scripts
head -20 docs/openapi/api.json
tail -20 docs/openapi/api.jsonRepository: QuantumNous/new-api
Length of output: 600
🏁 Script executed:
# Find build scripts or documentation about OpenAPI generation
find . -type f \( -name "*openapi*" -o -name "*swagger*" -o -name "*.sh" -o -name "*.py" \) -not -path "*/node_modules/*" | grep -v ".json" | head -20Repository: QuantumNous/new-api
Length of output: 101
🏁 Script executed:
# Check git history for this file to understand its origin
git log --oneline --follow docs/openapi/api.json | head -5Repository: QuantumNous/new-api
Length of output: 99
🏁 Script executed:
# Count how many truly unique combination definitions exist (by content, not name)
python3 << 'EOF'
import json
from collections import defaultdict
with open('docs/openapi/api.json', 'r', encoding='utf-8') as f:
data = json.load(f)
schemes = data.get('components', {}).get('securitySchemes', {})
# Get all combinations and group by content
combo_contents = defaultdict(list)
for name, definition in schemes.items():
if 'Combination' in name:
# Create a hashable representation
content_str = json.dumps(definition, sort_keys=True)
combo_contents[content_str].append(name)
print(f"Total unique combinations defined: {len(schemes) - 3}") # -3 for SessionAuth1, AccessToken1, NewApiUser1
print(f"Truly unique combination definitions (by content): {len(combo_contents)}")
print(f"\nDuplication ratio: {(len(schemes) - 3 - len(combo_contents)) / (len(schemes) - 3) * 100:.1f}% are duplicates")
# Show examples of duplication
print("\nExamples of duplicated definitions:")
for content, names in sorted(combo_contents.items(), key=lambda x: len(x[1]), reverse=True)[:5]:
if len(names) > 1:
print(f" {len(names)} combinations share: {content}")
print(f" Names: {names[:5]}{'...' if len(names) > 5 else ''}")
EOFRepository: QuantumNous/new-api
Length of output: 659
Critical: Eliminate 98.3% redundant security scheme definitions—only 4 unique combinations needed.
The securitySchemes section contains 242 Combination entries, but analysis reveals only 4 truly unique definitions by content. 120 combinations are identical copies of {SessionAuth + NewApiUser}, and 120 more are identical copies of {AccessToken + NewApiUser}. The remaining entries reference obsolete numeric IDs (573666, 573667, 573668) that appear unused.
In practice, only Combination343 and Combination1243 are meaningfully used (158 references each). All others have minimal or single references, suggesting auto-generated boilerplate that was never deduplicated.
Replace all 242 entries with the 4 unique definitions and refactor endpoints to reference only those. This will eliminate ~7KB of redundant JSON while improving maintainability and API clarity.
chore: update openapi files
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.