Skip to content

feat(UI): update Axum router to OpenApiRouter for swagger generate#1046

Merged
genedna merged 1 commit into
gitmono-dev:mainfrom
benjamin-747:main
May 20, 2025
Merged

feat(UI): update Axum router to OpenApiRouter for swagger generate#1046
genedna merged 1 commit into
gitmono-dev:mainfrom
benjamin-747:main

Conversation

@benjamin-747

Copy link
Copy Markdown
Collaborator

No description provided.

@vercel

vercel Bot commented May 20, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
mega ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 20, 2025 0:17am

Copilot AI 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.

Pull Request Overview

This PR replaces manual Axum routers with OpenApiRouter to generate Swagger documentation and updates the TypeScript client to call new Git-related endpoints.

  • Switch core and gateway server routers to use utoipa_axum::OpenApiRouter and serve Swagger UI
  • Add OpenAPI annotations (IntoParams, ToSchema) and ApiDoc structs for auto-generated docs
  • Extend the TS client (generated.ts) with types and methods for blob, file creation, commit, tree, and clone-check APIs

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
moon/packages/types/generated.ts Added new result types and client methods for Git endpoints
mono/src/server/https_server.rs Switched to OpenApiRouter, integrated Swagger UI, defined ApiDoc
mono/src/api//_router.rs Migrated all sub-routers to OpenApiRouter
mono/src/api/api_router.rs Refactored main API router to use routes! and OpenAPI annotations
mono/Cargo.toml Added utoipa-axum and utoipa-swagger-ui dependencies
gateway/src/https_server.rs Integrated OpenApiRouter and updated mega_routers
gateway/src/api/github_router.rs Migrated GitHub webhook router to OpenApiRouter
gateway/Cargo.toml Added utoipa-axum and Swagger UI deps
ceres/src/model/git.rs Derive IntoParams/ToSchema for OpenAPI schema and params
Cargo.toml (root) Added utoipa-axum and utoipa-swagger-ui versions
.github/workflows/base.yml Corrected workflow path glob to .github/workflows/web-test*
Comments suppressed due to low confidence (2)

moon/packages/types/generated.ts:3042

  • The type CommonResultVecTreeBriefItem is missing the err_message property, which is present in similar result types; add err_message: string for consistency.
export type CommonResultVecTreeBriefItem = {

moon/packages/types/generated.ts:12586

  • The create-file endpoint is defined as GET but performs a side-effect and accepts a request body; consider changing this to POST for correct HTTP semantics.
* @request GET:/api/v1/create-file

Comment thread moon/packages/types/generated.ts Outdated
Comment thread mono/src/api/api_router.rs Outdated
Comment thread moon/packages/types/generated.ts Outdated

Copilot AI 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.

Pull Request Overview

This PR migrates existing Axum routers to OpenApiRouter to enable automatic Swagger/OpenAPI generation across services.

  • Replaced Router with OpenApiRouter in all endpoint modules and updated route annotations.
  • Integrated utoipa derive macros and SwaggerUi setup in HTTPS servers for both mono and gateway.
  • Added corresponding TypeScript definitions and updated Cargo.toml and workflow configurations.

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
moon/packages/types/generated.ts Added common result & endpoint types for new Git file APIs
mono/src/server/https_server.rs Switched to OpenApiRouter, exposed ApiDoc and Swagger UI
mono/src/api/user/user_router.rs Migrated user routes to OpenApiRouter
mono/src/api/oauth/mod.rs Migrated OAuth routes to OpenApiRouter
mono/src/api/mr/mr_router.rs Migrated MR routes to OpenApiRouter
mono/src/api/lfs/lfs_router.rs Migrated LFS routes to OpenApiRouter
mono/src/api/issue/issue_router.rs Migrated issue routes to OpenApiRouter
mono/src/api/api_router.rs Migrated aggregated API router and added #[utoipa::path] tags
mono/Cargo.toml Added utoipa-axum & utoipa-swagger-ui dependencies
gateway/src/https_server.rs Switched gateway to OpenApiRouter and added empty ApiDoc
gateway/src/api/github_router.rs Migrated GitHub webhook to OpenApiRouter
gateway/Cargo.toml Added utoipa-axum & utoipa-swagger-ui dependencies
docker/mono-pg-dockerfile Removed database initialization script
ceres/src/model/git.rs Derived ToSchema/IntoParams for OpenAPI support
Cargo.toml Added top-level utoipa-axum & utoipa-swagger-ui versions
.github/workflows/base.yml Fixed workflow path pattern for web-test files
Comments suppressed due to low confidence (2)

docker/mono-pg-dockerfile:17

  • Removing the database initialization script will prevent automatic schema setup on container startup. Ensure migrations or initialization steps are handled elsewhere or restore the copy.
COPY ./sql/postgres/pg_20241204__init.sql /docker-entrypoint-initdb.d/

mono/src/api/api_router.rs:111

  • The documented response body is LatestCommitInfo but the handler actually returns CommonResult<LatestCommitInfo>. Update the annotation to match the wrapper type.
(status = 200, body = LatestCommitInfo, content_type = "application/json")


/// Create file in web UI
#[utoipa::path(
get,

Copilot AI May 20, 2025

Copy link

Choose a reason for hiding this comment

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

This endpoint uses GET but also accepts a request body (CreateFileInfo). According to HTTP semantics, GET should not have a body—consider switching to POST or another appropriate verb for creating resources.

Suggested change
get,
post,

Copilot uses AI. Check for mistakes.
};
}

#[derive(OpenApi)]

Copilot AI May 20, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] ApiDoc is derived but no paths or tags are specified, so the generated OpenAPI document will be empty. Add a #[openapi(paths(...), tags(...))] attribute to include gateway endpoints.

Suggested change
#[derive(OpenApi)]
#[derive(OpenApi)]
#[openapi(
paths(
github_router::routers,
lfs_router::routers,
mono::api::api_router::routers
),
tags(
(name = "GitHub", description = "GitHub-related endpoints"),
(name = "LFS", description = "Large File Storage endpoints"),
(name = "Mono", description = "Mono API endpoints")
)
)]

Copilot uses AI. Check for mistakes.

pub fn routers() -> Router<MonoApiServiceState> {
Router::new().nest(
pub fn routers() -> OpenApiRouter<MonoApiServiceState> {

Copilot AI May 20, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] The MR routes lack OpenAPI annotations (#[utoipa::path]), so they won't appear under the merge_request tag. Add path annotations and tags for each MR endpoint.

Copilot uses AI. Check for mistakes.
@genedna
genedna enabled auto-merge May 20, 2025 12:52
@genedna
genedna added this pull request to the merge queue May 20, 2025
Merged via the queue into gitmono-dev:main with commit 0d8de13 May 20, 2025
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.

3 participants