Documentation
Documentation protocol schemas
API Documentation & Testing Interface Protocol
Provides schemas for generating interactive API documentation and testing
interfaces similar to Swagger UI, Postman, etc.
Features:
- OpenAPI/Swagger specification generation
- Interactive API testing playground
- API versioning and changelog
- Code generation templates
- Mock server configuration
Architecture Alignment:
- Swagger UI: Interactive API documentation
- Postman: API testing collections
- Redoc: Documentation rendering
@example Documentation Config
const docConfig: ApiDocumentationConfig = {
enabled: true,
title: 'ObjectStack API',
version: '1.0.0',
servers: [{ url: 'https://api.example.com', description: 'Production' }],
ui: {
type: 'swagger-ui',
theme: 'light',
enableTryItOut: true
}
}
Source: packages/spec/src/api/documentation.zod.ts
import { ApiChangelogEntrySchema, ApiDocumentationConfigSchema, ApiTestCollectionSchema, ApiTestRequestSchema, ApiTestingUiConfigSchema, ApiTestingUiType, CodeGenerationTemplateSchema, GeneratedApiDocumentationSchema, OpenApiSecuritySchemeSchema, OpenApiServerSchema, OpenApiSpecSchema } from '@objectstack/spec/api';
import type { ApiChangelogEntry, ApiDocumentationConfig, ApiTestCollection, ApiTestRequest, ApiTestingUiConfig, ApiTestingUiType, CodeGenerationTemplate, GeneratedApiDocumentation, OpenApiSecurityScheme, OpenApiServer, OpenApiSpec } from '@objectstack/spec/api';
// Validate data
const result = ApiChangelogEntrySchema.parse(data);
| Property | Type | Required | Description |
|---|
| version | string | ✅ | API version |
| date | string | ✅ | Release date |
| changes | { added: string[]; changed: string[]; deprecated: string[]; removed: string[]; … } | ✅ | Version changes |
| migrationGuide | string | optional | Migration guide URL or text |
| Property | Type | Required | Description |
|---|
| enabled | boolean | ✅ | Enable API documentation |
| title | string | ✅ | Documentation title |
| version | string | ✅ | API version |
| description | string | optional | API description |
| servers | { url: string; description?: string; variables?: Record<string, object> }[] | ✅ | API server URLs |
| ui | { type: Enum<'swagger-ui' | 'redoc' | 'rapidoc' | 'stoplight' | 'scalar' | 'graphiql' | 'postman' | 'custom'>; path: string; theme: Enum<'light' | 'dark' | 'auto'>; enableTryItOut: boolean; … } | optional | Testing UI configuration |
| generateOpenApi | boolean | ✅ | Generate OpenAPI 3.0 specification |
| generateTestCollections | boolean | ✅ | Generate API test collections |
| testCollections | { name: string; description?: string; variables: Record<string, any>; requests: object[]; … }[] | ✅ | Predefined test collections |
| changelog | { version: string; date: string; changes: object; migrationGuide?: string }[] | ✅ | API version changelog |
| codeTemplates | { language: string; name: string; template: string; variables?: string[] }[] | ✅ | Code generation templates |
| termsOfService | string | optional | Terms of service URL |
| contact | { name?: string; url?: string; email?: string } | optional | Contact information |
| license | { name: string; url?: string } | optional | API license |
| externalDocs | { description?: string; url: string } | optional | External documentation link |
| securitySchemes | Record<string, { type: Enum<'apiKey' | 'http' | 'oauth2' | 'openIdConnect'>; scheme?: string; bearerFormat?: string; name?: string; … }> | optional | Security scheme definitions |
| tags | { name: string; description?: string; externalDocs?: object }[] | optional | Global tag definitions |
| Property | Type | Required | Description |
|---|
| name | string | ✅ | Collection name |
| description | string | optional | Collection description |
| variables | Record<string, any> | ✅ | Shared variables |
| requests | { name: string; description?: string; method: Enum<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS'>; url: string; … }[] | ✅ | Test requests in this collection |
| folders | { name: string; description?: string; requests: object[] }[] | optional | Request folders for organization |
| Property | Type | Required | Description |
|---|
| name | string | ✅ | Test request name |
| description | string | optional | Request description |
| method | Enum<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS'> | ✅ | HTTP method |
| url | string | ✅ | Request URL (can include variables) |
| headers | Record<string, string> | ✅ | Request headers |
| queryParams | Record<string, string | number | boolean> | ✅ | Query parameters |
| body | any | optional | Request body |
| variables | Record<string, any> | ✅ | Template variables |
| expectedResponse | { statusCode: integer; body?: any } | optional | Expected response for validation |
| Property | Type | Required | Description |
|---|
| type | Enum<'swagger-ui' | 'redoc' | 'rapidoc' | 'stoplight' | 'scalar' | 'graphiql' | 'postman' | 'custom'> | ✅ | Testing UI implementation |
| path | string | ✅ | URL path for documentation UI |
| theme | Enum<'light' | 'dark' | 'auto'> | ✅ | UI color theme |
| enableTryItOut | boolean | ✅ | Enable interactive API testing |
| enableFilter | boolean | ✅ | Enable endpoint filtering |
| enableCors | boolean | ✅ | Enable CORS for browser testing |
| defaultModelsExpandDepth | integer | ✅ | Default expand depth for schemas (-1 = fully expand) |
| displayRequestDuration | boolean | ✅ | Show request duration |
| syntaxHighlighting | boolean | ✅ | Enable syntax highlighting |
| customCssUrl | string | optional | Custom CSS stylesheet URL |
| customJsUrl | string | optional | Custom JavaScript URL |
| layout | { showExtensions: boolean; showCommonExtensions: boolean; deepLinking: boolean; displayOperationId: boolean; … } | optional | Layout configuration |
swagger-ui
redoc
rapidoc
stoplight
scalar
graphiql
postman
custom
| Property | Type | Required | Description |
|---|
| language | string | ✅ | Target language/framework (e.g., typescript, python, curl) |
| name | string | ✅ | Template name |
| template | string | ✅ | Code template with placeholders |
| variables | string[] | optional | Required template variables |
| Property | Type | Required | Description |
|---|
| openApiSpec | { openapi: string; info: object; servers: object[]; paths: Record<string, any>; … } | optional | Generated OpenAPI specification |
| testCollections | { name: string; description?: string; variables: Record<string, any>; requests: object[]; … }[] | optional | Generated test collections |
| markdown | string | optional | Generated markdown documentation |
| html | string | optional | Generated HTML documentation |
| generatedAt | string | ✅ | Generation timestamp |
| sourceApis | string[] | ✅ | Source API IDs used for generation |
| Property | Type | Required | Description |
|---|
| type | Enum<'apiKey' | 'http' | 'oauth2' | 'openIdConnect'> | ✅ | Security type |
| scheme | string | optional | HTTP auth scheme (bearer, basic, etc.) |
| bearerFormat | string | optional | Bearer token format (e.g., JWT) |
| name | string | optional | API key parameter name |
| in | Enum<'header' | 'query' | 'cookie'> | optional | API key location |
| flows | { implicit?: any; password?: any; clientCredentials?: any; authorizationCode?: any } | optional | OAuth2 flows |
| openIdConnectUrl | string | optional | OpenID Connect discovery URL |
| description | string | optional | Security scheme description |
| Property | Type | Required | Description |
|---|
| url | string | ✅ | Server base URL |
| description | string | optional | Server description |
| variables | Record<string, { default: string; description?: string; enum?: string[] }> | optional | URL template variables |
| Property | Type | Required | Description |
|---|
| openapi | string | ✅ | OpenAPI specification version |
| info | { title: string; version: string; description?: string; termsOfService?: string; … } | ✅ | API metadata |
| servers | { url: string; description?: string; variables?: Record<string, object> }[] | ✅ | API servers |
| paths | Record<string, any> | ✅ | API paths and operations |
| components | { schemas?: Record<string, any>; responses?: Record<string, any>; parameters?: Record<string, any>; examples?: Record<string, any>; … } | optional | Reusable components |
| security | Record<string, string[]>[] | optional | Global security requirements |
| tags | { name: string; description?: string; externalDocs?: object }[] | optional | Tag definitions |
| externalDocs | { description?: string; url: string } | optional | External documentation |