2
0
Files
gitcaddy-server/routers/api/v2/misc.go
logikonline c3576c5426 feat(api): add v2 API with AI-friendly features (Phase 2)
This introduces a new v2 API at /api/v2/ with features designed for
AI agents and automation tools while maintaining full backward
compatibility with the existing v1 API.

New features:
- Structured error codes (70+ machine-readable codes) for precise
  error handling by automated tools
- Scalar API documentation at /api/v2/docs (modern replacement for
  Swagger UI)
- Batch operations for bulk file and repository fetching
- NDJSON streaming endpoints for files, commits, and issues
- AI context endpoints providing rich repository summaries,
  navigation hints, and issue context

Files added:
- modules/errors/codes.go - Error code definitions and catalog
- modules/errors/api_error.go - Rich API error response builder
- routers/api/v2/api.go - v2 router with auth middleware
- routers/api/v2/docs.go - Scalar docs and OpenAPI spec
- routers/api/v2/batch.go - Batch file/repo operations
- routers/api/v2/streaming.go - NDJSON streaming endpoints
- routers/api/v2/ai_context.go - AI context endpoints
- routers/api/v2/misc.go - Version and user endpoints

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 11:41:10 -05:00

36 lines
793 B
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package v2
import (
"net/http"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/services/context"
)
// VersionResponse contains version information
type VersionResponse struct {
Version string `json:"version"`
API string `json:"api"`
}
// Version returns the Gitea version
func Version(ctx *context.APIContext) {
ctx.JSON(http.StatusOK, VersionResponse{
Version: setting.AppVer,
API: "v2",
})
}
// GetAuthenticatedUser returns the authenticated user
func GetAuthenticatedUser(ctx *context.APIContext) {
ctx.JSON(http.StatusOK, map[string]any{
"id": ctx.Doer.ID,
"login": ctx.Doer.Name,
"email": ctx.Doer.Email,
"is_admin": ctx.Doer.IsAdmin,
})
}