API Documentation
This page covers standards for documenting APIs using OpenAPI specifications across all Decentraland services.
Goals
Our API documentation approach ensures:
Standardization - Consistent OpenAPI specs across all services
Automation - Validation, bundling, and deployment via GitHub Actions
Centralization - All service documentation published through GitBook
Ownership - Documentation lives with each service repository
Accessibility - Contributor-friendly, up-to-date API references
Repository Structure
Each service repository MUST include a /docs directory with the following structure:
/docs
openapi.yaml # Source of truth (OpenAPI 3.1)
openapi.json # Auto-generated in CI for Hugo/renderers
index.html # Auto-generated standalone docs (optional)File Requirements
openapi.yaml
openapi.yamlMUST be the canonical source file
MUST use OpenAPI 3.1 specification
MAY have a service-identifying prefix (e.g.,
worlds-openapi.yaml)MAY split into
components/orexamples/directories if needed
openapi.json
openapi.jsonAuto-generated during CI/CD
Used by Hugo and other renderers
Do not edit manually
index.html
index.htmlAuto-generated standalone documentation
Built using Redocly
Deployed to GitHub Pages
OpenAPI Standards
When writing openapi.yaml, follow these conventions to ensure consistency and clarity.
Endpoint Summary
MUST reflect the actual endpoint path:
Operation ID
MUST include the service name for global uniqueness:
Naming convention: {serviceName}_{operationDescription}
Use camelCase
Be descriptive but concise
Include HTTP method context when helpful (e.g.,
createUser,deleteParcel)
Versioning
MUST use semantic versioning (MAJOR.MINOR.PATCH) in info.version:
Version bumping rules:
MAJOR: Breaking changes (incompatible API changes)
MINOR: New functionality (backward-compatible)
PATCH: Bug fixes (backward-compatible)
Tags and Grouping
MUST use tags to group related endpoints:
Complete Example
Local Development
Preview Documentation Locally
Use Redocly CLI to preview your OpenAPI documentation:
Add to package.json
Add a build script for convenience:
Install Redocly CLI
Validate OpenAPI Spec
Automation Setup
Step 1: Configure GitBook Secrets
To publish API specs to GitBook, add these secrets to your repository:
Settings → Secrets and variables → Actions → New repository secret
GITBOOK_ORGANIZATION_ID
Your GitBook organization ID
GitBook Settings → Organization
GITBOOK_TOKEN
GitBook API token
GitBook Settings → API Tokens
These secrets MUST be configured for the automated workflow to publish to GitBook.
Step 2: Add GitHub Actions Workflow
Create .github/workflows/build-api-docs.yml in your repository:
Parameters:
api-spec-file: Path to your OpenAPI spec (usuallydocs/openapi.yaml)output-file: Where to generate HTML docsoutput-directory: Directory for output filesapi-spec-name: Unique name for your API spec (used in GitBook)node-version: Node.js version to use
This workflow will:
✅ Validate the OpenAPI spec
✅ Bundle the spec into a single file
✅ Build static HTML documentation using Redocly
✅ Deploy automatically to GitHub Pages
✅ Publish spec to GitBook (if secrets are configured)
Step 3: Enable GitHub Pages
Configure GitHub Pages in your repository:
Go to Settings → Pages
Under Build and deployment:
Set Source to GitHub Actions
Ensure there is an environment named github-pages
Save settings
After the first successful workflow run, your documentation will be available at:
HTML Docs:
https://decentraland.github.io/<repo>/index.htmlOpenAPI Spec:
https://decentraland.github.io/<repo>/openapi.yamlBundled JSON:
https://decentraland.github.io/<repo>/openapi.json
These URLs remain valid as long as the repository exists and GitHub Pages is enabled.
Adding to GitBook
Once your API documentation is deployed, add it to the centralized GitBook documentation.
Manual Addition (Current Process)
Navigate to the GitBook space
Go to the API Reference section
Click Add API Reference
Enter your service details:
Name: Your service name (e.g., "Social Service")
OpenAPI URL:
https://decentraland.github.io/{repo-name}/openapi.yaml
Save
GitBook Integration Features
GitBook will automatically:
Parse your OpenAPI spec
Generate interactive API documentation
Create endpoint navigation based on tags
Provide "Try it" functionality
Keep docs in sync when you update the spec
Complete Setup Flow
Initial Setup
Ongoing Updates
Best Practices
Documentation Quality
Be descriptive: Write clear summaries and descriptions
Provide examples: Include request/response examples
Document errors: Describe all possible error responses
Use components: Reuse schemas via
$refto avoid duplicationAdd descriptions: Every parameter, property, and response should have a description
Example with Best Practices
Schema Reusability
Security Schemas
Validation and Quality Checks
Pre-Commit Validation
Add a pre-commit hook or CI check:
Common Validation Rules
All paths have operation IDs
All operations have tags
All parameters have descriptions
All responses are documented
Examples are provided
Schemas are properly referenced
Troubleshooting
Workflow Fails
Problem: GitHub Actions workflow fails
Solutions:
Check workflow logs for validation errors
Run
redocly lint docs/openapi.yamllocallyVerify file paths in workflow configuration
Ensure secrets are properly configured
GitHub Pages Not Working
Problem: Docs not appearing at GitHub Pages URL
Solutions:
Verify GitHub Pages is enabled in repository settings
Check that workflow completed successfully
Wait a few minutes for GitHub Pages to update
Verify the
github-pagesenvironment exists
GitBook Not Syncing
Problem: GitBook not showing updated API docs
Solutions:
Verify GitBook secrets are correct
Check that the OpenAPI URL is accessible
Manually trigger a refresh in GitBook
Verify OpenAPI spec is valid
Migration from Existing Docs
If you have existing API documentation:
Export to OpenAPI: Convert existing docs to OpenAPI 3.1 format
Validate: Use
redocly lintto ensure complianceAdd workflow: Set up GitHub Actions automation
Test: Verify docs build and deploy correctly
Update links: Point old documentation links to new GitHub Pages URL
Archive old docs: Keep old docs for reference during transition
Next Steps
Review the Well-Known Components standards for API implementation
See Testing Standards for API testing guidelines
Check out existing API examples in the API Reference section
Resources
OpenAPI Specification: spec.openapis.org
Redocly CLI: redocly.com/docs/cli
GitBook API Integration: docs.gitbook.com
Platform Actions Repo: github.com/decentraland/platform-actions
Last updated