6.5 KiB
OpenAPI Configuration Guide
This guide explains how to configure and use the enhanced OpenAPI documentation features in the Corrad AF 2024 API Platform.
Overview
The platform now supports three methods for providing OpenAPI specifications:
- OpenAPI URL - Traditional URL-based specification loading
- Generate from Collections - Auto-generate from saved API collections
- Custom JSON - Manual specification editing with validation
Access Configuration
Navigate to your API platform and open the Scalar Configuration Modal to access these features:
- Go to
/api-platform
- Look for the "API Documentation Settings" or configuration icon
- Click on the Basic Info tab
Configuration Options
1. OpenAPI URL (Default)
Use this option when you have an existing OpenAPI specification available via URL.
Features:
- Support for both JSON and Markdown files
- Dynamic server URL detection
- Proxy support for CORS issues
Usage:
- Select "OpenAPI URL" radio button
- Enter your specification URL in the "OpenAPI Specification URL" field
- Optionally configure a proxy URL if needed
2. Generate from Collections
Automatically generate OpenAPI specifications from your saved API collections.
Features:
- Auto-detection of endpoints from collections
- Schema inference from request/response bodies
- Automatic tagging by collection names
- Parameter extraction from queries and headers
Usage:
- Select "Generate from Collections" radio button
- Review available collections displayed
- Click "Generate" button
- The system will:
- Create an OpenAPI 3.0.3 specification
- Generate markdown documentation
- Save to
/docs/openapi-collections.md
- Switch to custom editor for review
Generated Features:
- Collection names become API tags
- Request names become operation summaries
- Query parameters and headers become OpenAPI parameters
- Request bodies are analyzed for schema generation
- Basic response schemas (success/error) are included
3. Custom JSON
Manually create or edit OpenAPI specifications with real-time validation.
Features:
- Live JSON validation
- File import support (JSON/YAML)
- Syntax highlighting
- Error reporting
- Auto-save functionality
Usage:
- Select "Custom JSON" radio button
- Either:
- Paste JSON directly into the editor
- Click "Import" to upload a file
- Use "Generate" from collections first, then edit
- The editor provides:
- Real-time validation feedback
- Error highlighting
- Valid JSON confirmation
- Click "Save Custom JSON" to save changes
File Management
Generated Files
When using collection generation or custom JSON, files are saved to:
- Collections:
/docs/openapi-collections.md
- Custom:
/docs/openapi-custom.md
- Original:
/docs/openapi.md
File Access
All generated files are accessible via:
- Web Interface:
/api-docs
(interactive documentation) - Direct Access:
/docs/[filename]
(raw file content) - API Endpoint:
/api/openapi
(dynamic markdown)
API Endpoints
Generate from Collections
POST /api/openapi/generate-from-collections
Request Body:
{
"collections": [/* array of collections */],
"config": {
"title": "API Title",
"description": "API Description",
"version": "1.0.0",
"contact": {
"name": "Support",
"email": "support@example.com"
}
}
}
Save OpenAPI File
POST /api/docs/save-openapi
Request Body:
{
"content": "file content",
"filename": "openapi.md"
}
Serve Documentation Files
GET /docs/[filename]
Schema Generation
When generating from collections, the system automatically:
1. Infers Request Schemas
- Parses JSON request bodies
- Creates type-appropriate schemas
- Handles nested objects and arrays
- Provides example values
2. Creates Parameters
- Query parameters from URL params
- Header parameters (excluding standard headers)
- Path parameters from URL structure
3. Generates Responses
- Standard success/error response schemas
- Content-type detection
- Status code mapping
4. Security Configuration
- Automatic bearer token detection
- Auth method mapping from collection settings
Best Practices
Collection Organization
- Naming: Use descriptive collection names (become API tags)
- Grouping: Group related endpoints in same collection
- Documentation: Add descriptions to requests for better summaries
Request Configuration
- URLs: Use full URLs with proper base paths
- Parameters: Configure active parameters with descriptions
- Bodies: Use valid JSON for better schema inference
- Headers: Include necessary headers, exclude standard ones
Custom Editing
- Validation: Always validate before saving
- Backup: Export configurations before major changes
- Testing: Use preview mode to test changes
- Structure: Follow OpenAPI 3.0.3 specification
Troubleshooting
Common Issues
Generation Fails
- Ensure collections contain valid requests
- Check request URLs are properly formatted
- Verify JSON bodies are valid
Validation Errors
- Missing required OpenAPI fields (
openapi
,info
) - Invalid JSON syntax
- Incorrect schema structure
Display Issues
- Check markdown JSON extraction
- Verify Scalar initialization
- Review browser console for errors
Debug Mode
Enable debug logging by checking browser console when:
- Configuration loading fails
- Generation produces unexpected results
- Scalar fails to initialize
Migration Guide
From Static OpenAPI
- Access configuration modal
- Select "Custom JSON"
- Import existing specification
- Save as new file
- Update configuration
From External URLs
- Download current specification
- Use "Custom JSON" import feature
- Edit as needed
- Save locally for better control
Integration Examples
Postman Integration
- Generate or configure OpenAPI spec
- Access via
/docs/openapi-collections.md
- Extract JSON from markdown
- Import into Postman
Insomnia Integration
- Use same process as Postman
- Import OpenAPI JSON directly
- All endpoints and schemas preserved
Development Workflow
- Create API collections during development
- Generate OpenAPI specification automatically
- Review and edit as needed
- Deploy documentation
- Keep collections updated for regeneration
This enhanced system provides flexibility while maintaining automation, allowing both rapid prototyping and detailed customization of API documentation.