Skip to content

docs(larql-server): Added Swagger UI for API Documentation#47

Open
priyanshu891 wants to merge 1 commit intochrishayuk:mainfrom
priyanshu891:dev
Open

docs(larql-server): Added Swagger UI for API Documentation#47
priyanshu891 wants to merge 1 commit intochrishayuk:mainfrom
priyanshu891:dev

Conversation

@priyanshu891
Copy link
Copy Markdown

@priyanshu891 priyanshu891 commented May 6, 2026

Summary

Adds interactive API documentation to larql-server via an auto-generated OpenAPI 3 spec and an embedded Swagger UI. Every HTTP handler on the server is now annotated with #[utoipa::path(...)], request/response bodies have typed ToSchema mirrors, and the spec is served live from the running process — no build step, no hand-maintained YAML.

What's new

  • GET /swagger-ui — browse-friendly, try-it-out Swagger UI.
  • GET /v1/openapi.json — the raw OpenAPI 3 spec (useful for codegen, Postman, Insomnia, etc.).
  • --no-docs CLI flag to disable both endpoints for hardened deployments.

Docs are mounted before the auth middleware (consistent with --cors) so they stay reachable without an API key. Flip the ordering in bootstrap.rs if you want docs gated behind the key.

Coverage

All public HTTP surfaces are documented and grouped under the following tags:

Tag Endpoints
browse /v1/describe, /v1/walk, /v1/relations, /v1/stats, /v1/topology, /v1/models
inference /v1/select, /v1/infer, /v1/explain, /v1/insert, /v1/warmup
patches /v1/patches (apply / list / remove)
expert /v1/walk-ffn, /v1/walk-ffn-q8k, /v1/expert, /v1/expert/batch, /v1/experts/layer-batch(-f16), /v1/experts/multi-layer-batch(-q8k)
openai /v1/embeddings, /v1/completions, /v1/chat/completions
admin /v1/health, /v1/embed, /v1/logits, /v1/token/{encode,decode}, /v1/stream

Multi-model variants (/v1/{model_id}/...) are documented alongside their single-model counterparts.

Implementation notes

  • New aggregator module openapi.rs owns the #[derive(OpenApi)] ApiDoc, a schemas submodule with Serialize + ToSchema response mirrors for handlers returning Json<serde_json::Value>, shared path params (e.g. ModelIdParam), and a swagger_router() helper that merges into the main app router.
  • ServerError now serialises through a typed ErrorBody { error: String } (see error.rs) so error responses appear in the spec instead of being untyped JSON.
  • New deps: utoipa = "5" (with axum_extras + preserve_order) and utoipa-swagger-ui = "9" (with axum).
  • The synthetic schema structs are #[allow(dead_code)] / never constructed at runtime — they exist solely to drive spec generation.

Test plan

  • cargo build -p larql-server succeeds.
  • cargo test -p larql-server passes.
  • Start the server against any vindex and verify:
    • GET /swagger-ui renders the interactive UI.
    • GET /v1/openapi.json returns a valid OpenAPI 3 document (e.g. paste into https://editor.swagger.io).
    • Every tag (browse, inference, expert, openai, patches, admin) is populated.
    • "Try it out" for /v1/health and /v1/describe?entity=France works.
  • Start with --no-docs and confirm both endpoints return 404.
  • Start with --api-key <key> and confirm /swagger-ui + /v1/openapi.json remain reachable without the key (by design — same as --cors).
  • Multi-model mode: verify /v1/{model_id}/describe etc. appear in the spec.

@priyanshu891
Copy link
Copy Markdown
Author

image

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.

1 participant