Repository navigation
Document the API with OpenAPI, and follow HTTP for files - #13
Merged
Merged
Conversation
The server now describes its API in OpenAPI, at /api/openapi.json, and serves Swagger UI at /api/docs to browse it and try its requests. Swagger UI comes from the swagger-ui-dist package, so the page needs no internet connection. The description is written by hand in src/server/openapi.ts, and a test checks that every route it lists exists. The servers entry is the address the client reached the server at, so that Postman can import the description as is. The file routes follow HTTP more closely: a file is at /api/files/<path> instead of /api/file?path=<path>, PUT answers 201 Created when it creates the file and 200 OK when it overwrites it, and other methods on a file get 405 Method Not Allowed with an Allow header. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
API documentation
/api/openapi.jsonand serves Swagger UI at/api/docs, where each endpoint can be browsed and tried ("Try it out").swagger-ui-distnpm package, so the page works offline. The install script of its telemetry dependency@scarf/scarfis disabled inpnpm-workspace.yaml.src/server/openapi.ts. Itsserversentry is filled in with the address the client used (fromHost, andX-Forwarded-Protobehind a proxy), so Postman can import it without settingbaseUrl.HTTP conventions for files (breaking for other clients of the API; the editor's frontend is the only one and is updated)
PUT/DELETE /api/file?path=a/b.xml→PUT/DELETE /api/files/a/b.xml. Slashes may be sent plain or as%2F; everything still goes throughsafePath, and malformed encoding gets a 400.PUTanswers201 Createdwhen it creates the file,200 OKwhen it overwrites it.405 Method Not AllowedwithAllow: PUT, DELETE.Test plan
pnpm run typecheckandpnpm run test: 123 tests pass, including new ones for 201/200, 405 +Allow, encoded slashes, bad encoding, the docs page and its assets, and a check that every route in the spec existslint --extends=recommended: valid (one warning:GET /api/workspacehas no 4xx response, which is accurate)If-None-Match: *412, overwrite 200, POST 405, delete 200;/api/docsand its assets 200 on both the production and the dev server🤖 Generated with Claude Code