Skip to content

chore: update openapi files - #2348

Merged
Calcium-Ion merged 1 commit into
mainfrom
openapi
Dec 1, 2025
Merged

chore: update openapi files#2348
Calcium-Ion merged 1 commit into
mainfrom
openapi

Conversation

@t0ng7u

@t0ng7u t0ng7u commented Dec 1, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Documentation
    • Consolidated authentication documentation structure for clarity
    • Added new public API schemas including response models and data structures
    • Enhanced security scheme definitions with additional authentication options

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Dec 1, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Updated 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

Cohort / File(s) Summary
Authentication & Schema Consolidation
docs/openapi/api.json
Merged separate authentication tags into unified "用户登陆注册" tag; added new public schema definitions (ApiResponse, PageInfo, Log); introduced new security scheme entries (SessionAuth1, AccessToken1, NewApiUser1); added multiple combination security scheme entries; updated affected endpoints to reference new tag and security schemes

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Verify tag consolidation: ensure all endpoints previously tagged "用户认证" or "两步验证" are now consistently tagged "用户登陆注册"
  • Validate new schema definitions: confirm ApiResponse, PageInfo, and Log schemas are correctly structured and referenced
  • Review security scheme additions: cross-check all new SecurityAuth entries and combination schemes to ensure proper field definitions and consistency
  • Endpoint security references: audit that security references in endpoints match the new combination scheme identifiers without breaking existing API contracts

Poem

🐰 Tags are consolidated, schemas bloom and grow,
New security schemes in a springtime flow,
The API contract now dances anew,
With rabbits and API specs—magic they brew! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'chore: update openapi files' is generic and does not clearly convey the specific nature of the changes, such as the authentication tag consolidation or security scheme additions. Consider using a more descriptive title that highlights the main changes, such as 'chore: consolidate auth tags and expand OpenAPI security schemes' or 'chore: refactor authentication tags and add security definitions in OpenAPI'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch openapi

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@t0ng7u
t0ng7u requested a review from Calcium-Ion December 1, 2025 13:43
@t0ng7u t0ng7u self-assigned this Dec 1, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"]
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 86aeb72 and 46aca8f.

📒 Files selected for processing (1)
  • docs/openapi/api.json (15 hunks)

Comment thread docs/openapi/api.json
Comment on lines +5126 to +5210
"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"
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, get the file size and overall structure
wc -l docs/openapi/api.json

Repository: 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 -l

Repository: 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 -u

Repository: 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 -20

Repository: QuantumNous/new-api

Length of output: 502


🏁 Script executed:

# Extract the securitySchemes section to understand the structure
sed -n '5126,5210p' docs/openapi/api.json

Repository: QuantumNous/new-api

Length of output: 1856


🏁 Script executed:

# Find the securitySchemes section boundaries
grep -n '"securitySchemes"' docs/openapi/api.json

Repository: 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))
EOF

Repository: 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]}")
EOF

Repository: 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 -30

Repository: 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])}")
EOF

Repository: QuantumNous/new-api

Length of output: 470


🏁 Script executed:

# Count total combinations defined vs referenced
grep -c '"Combination[0-9]*"' docs/openapi/api.json

Repository: 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 -40

Repository: 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.json

Repository: 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 -20

Repository: 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 -5

Repository: 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 ''}")
EOF

Repository: 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.

@Calcium-Ion
Calcium-Ion merged commit d3ca454 into main Dec 1, 2025
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants