Skip to content

Commit 4d40a9b

Browse files
committed
documentation updates and openapi docs
1 parent 81c3771 commit 4d40a9b

5 files changed

Lines changed: 125 additions & 3 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ book/
5050
.book.toml.swp
5151
mermaid-init.js
5252
mermaid.min.js
53-
docs/output
53+
docs/output
54+
openapi.json

docs/src/SUMMARY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [Introduction](introduction.md)
99
- [Application Configuration](config.md)
1010
- [Application Architecture](architecture.md)
11+
- [OpenAPI Documentation](open-api-docs.md)
1112
- [Syncstorage API](syncstorage/api.md)
1213
- [API v1.5](syncstorage/api-1.5.md)
1314
- [API v1.1 (Obsolete)](syncstorage/api-1.1.md)
@@ -33,7 +34,7 @@
3334
- [Run Your Own Sync-1.5 Server (legacy)](how-to/how-to-run-sync-server.md)
3435
- [Configure Sync Server for TLS (legacy)](how-to/how-to-config-tls.md)
3536

36-
[Documentation and MdBook Notes](doc-notes.md)
37+
[Documentation and MdBook Notes](mdbook-doc-notes.md)
3738
[Glossary of Terms](glossary.md)
3839
[Response Codes](response-codes.md)
3940
[Terms of Service](terms-of-service.md)

docs/src/introduction.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![License: MPL 2.0][mpl-svg]][mpl] [![Build Status][circleci-badge]][circleci] [![Connect to Matrix via the Riot webapp][matrix-badge]][matrix]
1+
[![License: MPL 2.0][mpl-svg]][mpl] [![Build Status][circleci-badge]][circleci] [![Connect to Matrix via the Riot webapp][matrix-badge]][matrix][![Swagger OpenAPI Docs](https://img.shields.io/badge/API-Documentation-blue.svg)][swagger-ui]
22

33
# Syncstorage-rs
44

@@ -332,3 +332,4 @@ If you see a problem related to `libssl` you may need to specify the `cargo` opt
332332
[circleci]: https://circleci.com/gh/mozilla-services/syncstorage-rs
333333
[matrix-badge]: https://img.shields.io/badge/chat%20on%20[m]-%23services%3Amozilla.org-blue
334334
[matrix]: https://chat.mozilla.org/#/room/#services:mozilla.org
335+
[swagger-ui]: https://mozilla-services.github.io/syncstorage-rs/swagger-ui/
File renamed without changes.

docs/src/open-api-docs.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Open API Documentation
2+
3+
## OpenAPI / Swagger UI
4+
5+
This project uses [utoipa](https://crates.io/crates/utoipa) and [utoipa-swagger-ui](https://crates.io/crates/utoipa-swagger-ui) to provide interactive API documentation.
6+
7+
### Accessing the Documentation
8+
9+
#### On GitHub Pages (Static Documentation):
10+
11+
The project automatically publishes API documentation to GitHub Pages:
12+
13+
- **Main Documentation**: https://mozilla-services.github.io/syncstorage-rs/
14+
- **Rust API Docs (cargo doc)**: https://mozilla-services.github.io/syncstorage-rs/api/
15+
- **OpenAPI/Swagger UI**: https://mozilla-services.github.io/syncstorage-rs/swagger-ui/
16+
17+
#### When the service is running (live deployment):
18+
19+
- **Swagger UI (Interactive)**: `https://<your-deployment-url>/swagger-ui/`
20+
- **OpenAPI Spec (JSON)**: `https://<your-deployment-url>/api-doc/openapi.json`
21+
22+
Replace `<your-deployment-url>` with:
23+
- **Production/Stage**: [Add your prod/stage URL here]
24+
- **Local Development**: `http://localhost:8000` (or your configured port)
25+
26+
### API Endpoints
27+
28+
The API is organized into three main categories:
29+
30+
#### Syncstorage Endpoints
31+
Endpoints for Firefox Sync data storage operations:
32+
- `GET /1.5/{uid}/info/collections` - Get collection timestamps
33+
- `GET /1.5/{uid}/info/collection_counts` - Get collection counts
34+
- `GET /1.5/{uid}/info/collection_usage` - Get collection usage
35+
- `GET /1.5/{uid}/info/configuration` - Get server configuration
36+
- `GET /1.5/{uid}/info/quota` - Get quota information
37+
- `DELETE /1.5/{uid}/storage` - Delete all user data
38+
- `GET /1.5/{uid}/storage/{collection}` - Get BSOs from a collection
39+
- `POST /1.5/{uid}/storage/{collection}` - Add or update BSOs
40+
- `DELETE /1.5/{uid}/storage/{collection}` - Delete a collection or BSOs
41+
- `GET /1.5/{uid}/storage/{collection}/{bso}` - Get a specific BSO
42+
- `PUT /1.5/{uid}/storage/{collection}/{bso}` - Create or update a BSO
43+
- `DELETE /1.5/{uid}/storage/{collection}/{bso}` - Delete a specific BSO
44+
45+
#### Tokenserver Endpoints
46+
Endpoints for Sync node allocation and authentication:
47+
- `GET /1.0/{application}/{version}` - Get sync token
48+
- `GET /__heartbeat__` - Tokenserver health check
49+
50+
#### Dockerflow Endpoints
51+
Service health and monitoring endpoints:
52+
- `GET /__heartbeat__` - Service health check
53+
- `GET /__lbheartbeat__` - Load balancer health check
54+
- `GET /__version__` - Service version information
55+
56+
### Maintenance
57+
58+
When adding new endpoints:
59+
1. Add `#[utoipa::path(...)]` annotation to the handler function.
60+
2. Add the handler path to `ApiDoc` in `syncserver/src/server/mod.rs`
61+
3. If using custom types, derive `ToSchema` on request/response structs.
62+
4. Run `cargo run --example generate_openapi_spec` to verify the spec generates correctly. Follow instructions below.
63+
64+
### Generating the OpenAPI Spec Locally
65+
66+
You can generate the OpenAPI specification without running the server:
67+
68+
```bash
69+
# Generate the spec to stdout
70+
cargo run --example generate_openapi_spec
71+
72+
# Save to a file
73+
cargo run --example generate_openapi_spec > openapi.json
74+
```
75+
76+
### Viewing the Spec Locally (Without Running the Server)
77+
78+
If you don't want to compile the server on your machine, you can still view the API documentation:
79+
80+
1. **Use Docker** (simplest):
81+
This option requires you to have run `cargo run --example generate_openapi_spec > openapi.json`.
82+
```bash
83+
docker run -p 8080:8080 -e SWAGGER_JSON=/openapi.json -v $(pwd)/openapi.json:/openapi.json swaggerapi/swagger-ui
84+
```
85+
Then open http://localhost:8080
86+
87+
2. **Generate the spec on a compatible machine** (or use CI):
88+
```bash
89+
cargo run --example generate_openapi_spec > openapi.json
90+
```
91+
92+
3. **Use online Swagger Editor**:
93+
- Go to https://editor.swagger.io/
94+
- Copy the contents of `openapi.json`
95+
- Paste into the editor
96+
- View the interactive documentation
97+
98+
4. **Use VS Code extension**:
99+
- Install "OpenAPI (Swagger) Editor" extension
100+
- Open `openapi.json` in VS Code
101+
- Click "Preview Swagger" to view interactive docs
102+
103+
### Publishing to GitHub Pages
104+
105+
The `.github/workflows/publish-docs.yaml` workflow automatically publishes these docs:
106+
107+
1. **Generates the OpenAPI spec** using the `generate_openapi_spec` example file.
108+
2. **Downloads Swagger UI** from the official GitHub releases.
109+
3. **Replaces the default example Swagger API** with your Sync API:
110+
- The default Swagger UI comes configured to display a demo "Pet Store" API
111+
- We use `sed` to replace `https://petstore.swagger.io/v2/swagger.json` with our `openapi.json`
112+
4. **Deploys everything to GitHub Pages** at:
113+
- https://mozilla-services.github.io/syncstorage-rs/swagger-ui/
114+
115+
The workflow runs in parallel:
116+
- `build-mdbook` job: Builds mdBook docs + Rust cargo docs
117+
- `build-openapi` job: Generates OpenAPI spec + sets up Swagger UI
118+
- `combine-and-prepare` job: Combines both outputs
119+
- `deploy` job: Deploys to GitHub Pages

0 commit comments

Comments
 (0)