Open API Documentation
OpenAPI / Swagger UI
This project uses utoipa and utoipa-swagger-ui to provide interactive API documentation.
Accessing and Working With the Documentation
It is suggested to use the stage instance of Sync and/or Tokenserver when playing with the API, though you may also interact with your data in the production instance.
Please take care to select the URL for Tokenserver for Tokenserver requests and the Syncstorage URL for Syncstorage requests.
The Prod and Stage environments below will be available as a drop-down in the SwaggerUI:
- Sync Stage:
https://sync-us-west1-g.sync.services.allizom.org. - Sync Prod:
https://sync-1-us-west1-g.sync.services.mozilla.com. - Tokenserver Stage:
https://stage-tokenserver.sync.nonprod.webservices.mozgcp.net. - Tokenserver Prod:
https://prod-tokenserver.sync.prod.webservices.mozgcp.net.
On GitHub Pages (Static Documentation):
The project automatically publishes API documentation to GitHub Pages:
- Main Documentation: https://mozilla-services.github.io/syncstorage-rs/
- Rust API Docs (cargo doc): https://mozilla-services.github.io/syncstorage-rs/api/
- OpenAPI/Swagger UI: https://mozilla-services.github.io/syncstorage-rs/swagger-ui/
When the service is running (live deployment):
URLs for Swagger and OpenAPI Spec:
- Swagger UI (Interactive):
https://<your-deployment-url>/swagger-ui/ - OpenAPI Spec (JSON):
https://<your-deployment-url>/api-doc/openapi.json
Replace <your-deployment-url> with:
- Production/Stage: [Add your prod/stage URL here]
- Local Development:
http://localhost:8000(or your configured port)
API Endpoints
The API is organized into three main categories:
Syncstorage Endpoints
Endpoints for Firefox Sync data storage operations:
GET /1.5/{uid}/info/collections- Get collection timestampsGET /1.5/{uid}/info/collection_counts- Get collection countsGET /1.5/{uid}/info/collection_usage- Get collection usageGET /1.5/{uid}/info/configuration- Get server configurationGET /1.5/{uid}/info/quota- Get quota informationDELETE /1.5/{uid}/storage- Delete all user dataGET /1.5/{uid}/storage/{collection}- Get BSOs from a collectionPOST /1.5/{uid}/storage/{collection}- Add or update BSOsDELETE /1.5/{uid}/storage/{collection}- Delete a collection or BSOsGET /1.5/{uid}/storage/{collection}/{bso}- Get a specific BSOPUT /1.5/{uid}/storage/{collection}/{bso}- Create or update a BSODELETE /1.5/{uid}/storage/{collection}/{bso}- Delete a specific BSO
Tokenserver Endpoints
Endpoints for Sync node allocation and authentication:
GET /1.0/{application}/{version}- Get sync tokenGET /__heartbeat__- Tokenserver health check
Dockerflow Endpoints
Service health and monitoring endpoints:
GET /__heartbeat__- Service health checkGET /__lbheartbeat__- Load balancer health checkGET /__version__- Service version information
Exploring the Sync API
To aid in exploring your own Sync API with Swagger, you may want to acquire your UID and other details about your Sync account. The easiest way to do so is to use the About Sync Extension. Note that this extension only works on Desktop.
Firefox Extensions Page for About Sync GitHub Repository for About Sync
Maintenance
When adding new endpoints:
- Add
#[utoipa::path(...)]annotation to the handler function. - Add the handler path to
ApiDocinsyncserver/src/server/mod.rs - If using custom types, derive
ToSchemaon request/response structs. - Run
cargo run --example generate_openapi_specto verify the spec generates correctly. Follow instructions below.
Generating the OpenAPI Spec Locally
If you don’t want to compile the Sync server on your machine to view the API docs, follow these instructions:
Use make api-prev
We created a handy Makefile command called make api-prev that automatically generates the specification file, runs Swagger in Docker and opens your browser to localhost:8080. See the steps below to understand this process. Note this attempts to be platform agnostic, but might require some adaptation depending on your operating system.
Commands to generate the OpenAPI specification without running the server:
# Generate the spec to stdout
cargo run --example generate_openapi_spec
# Save to a file
cargo run --example generate_openapi_spec > openapi.json
Other options:
-
Use Docker (simplest - used in
make api-prev): This option requires you to have runcargo run --example generate_openapi_spec > openapi.json.docker run -p 8080:8080 -e SWAGGER_JSON=/openapi.json -v $(pwd)/openapi.json:/openapi.json swaggerapi/swagger-uiThen open http://localhost:8080
-
Use online Swagger Editor:
- Go to https://editor.swagger.io/
- Copy the contents of
openapi.json - Paste into the editor
- View the interactive documentation
-
Use VS Code extension:
- Install “OpenAPI (Swagger) Editor” extension
- Open
openapi.jsonin VS Code - Click “Preview Swagger” to view interactive docs
Publishing to GitHub Pages
The .github/workflows/publish-docs.yaml workflow automatically publishes these docs:
- Generates the OpenAPI spec using the
generate_openapi_specexample file. - Downloads Swagger UI from the official GitHub releases.
- Replaces the default example Swagger API with your Sync API:
- The default Swagger UI comes configured to display a demo “Pet Store” API
- We use
sedto replacehttps://petstore.swagger.io/v2/swagger.jsonwith ouropenapi.json
- Deploys everything to GitHub Pages at:
- https://mozilla-services.github.io/syncstorage-rs/swagger-ui/
The workflow runs in parallel:
build-mdbookjob: Builds mdBook docs + Rust cargo docsbuild-openapijob: Generates OpenAPI spec + sets up Swagger UIcombine-and-preparejob: Combines both outputsdeployjob: Deploys to GitHub Pages