Update api reference

From blaxel-ai/sandbox · View interactive version

Update api reference is an AI agent skill from the GitHub repository blaxel-ai/sandbox. Regenerate the OpenAPI reference documentation after adding, modifying, or removing API endpoints in sandbox-api. Run this whenever handler signatures, route paths, or swag annotations change.

How to use this skill

Skill file

Update the API Reference (OpenAPI Docs)

The OpenAPI spec is generated from swaggo annotations in the Go handler code. After changing any endpoint, regenerate the docs.

Run the Full Reference Update

make reference

This single command:

  1. Runs swag init to parse Go annotations → generates sandbox-api/docs/swagger.yaml and docs.go
  2. Fixes type name references (replaces filesystem.Directory with Directory)
  3. Converts Swagger 2.0 → OpenAPI 3.0 via swagger2openapi
  4. Adds Bearer auth security scheme to all endpoints
  5. Runs fixopenapi.sh for additional patches

The output file is sandbox-api/docs/openapi.yml.


How Swag Annotations Work

Annotations are Go comments above handler functions. Example:

// HandleGetFile retrieves a file from the sandbox filesystem.
//
// @Summary      Get file or directory
// @Description  Returns file content or directory listing
// @Tags         filesystem
// @Produce      application/octet-stream
// @Param        path  path  string  true  "File path"
// @Success      200   {string}  string  "File content"
// @Failure      404   {object}  ErrorResponse
// @Router       /filesystem/{path} [get]
func (h *FileSystemHandler) HandleGetFile(c *gin.Context) {

Key annotation fields:


Where the Docs Live

| File | Purpose |

|------|---------|

| sandbox-api/docs/openapi.yml | Final OpenAPI 3.0 spec (commit this) |

| sandbox-api/docs/docs.go | Auto-generated Go embed of the spec |

| sandbox-api/docs/fixopenapi.sh | Post-processing patches |


After Adding a New Endpoint

  1. Add swag annotations to your handler function
  2. Register the route in sandbox-api/src/api/router.go
  3. Run make reference
  4. Review the diff in sandbox-api/docs/openapi.yml to confirm your endpoint appears correctly
  5. Commit both the handler changes and the updated openapi.yml and docs.go

Verify the Generated Docs

Open the Swagger UI at http://localhost:8080/swagger/index.html while the dev server is running. It reads docs.go which is embedded at build time.


Troubleshooting

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.