API specifications are the foundation of testing in Sentinel. This guide covers everything you need to know about uploading, managing, and optimizing your OpenAPI/Swagger specifications.
Sentinel supports:
- OpenAPI 3.0.x (Recommended)
- OpenAPI 3.1.x
- Swagger 2.0
- JSON and YAML formats
-
Navigate to Specifications in the main menu
-
Click "Upload New Specification"
-
Choose your upload method:
- File Upload: Select a
.jsonor.yamlfile - URL Import: Provide a URL to your specification
- Direct Input: Paste specification content directly
- File Upload: Select a
-
Provide metadata:
- Name: A descriptive name for your API
- Version: Version identifier (e.g., "1.0.0", "v2")
- Description: Optional description
- Tags: Optional tags for organization
-
Click "Upload" to process the specification
# Upload from file
curl -X POST "http://localhost:8000/specifications" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d @specification.json
# Upload with metadata
curl -X POST "http://localhost:8000/specifications" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "User Management API",
"version": "2.1.0",
"description": "API for user management operations",
"tags": ["users", "authentication"],
"spec_data": { ... }
}'# Upload a local file
sentinel spec upload ./api-spec.yaml --name "My API" --version "1.0.0"
# Upload from URL
sentinel spec upload https://api.example.com/openapi.json
# Upload with tags
sentinel spec upload ./spec.yaml --tags "production,critical"Sentinel automatically validates specifications upon upload:
-
Syntax Validation
- Valid JSON/YAML structure
- Correct OpenAPI schema
-
Semantic Validation
- Required fields present
- Valid data types
- Reference resolution
-
Best Practices
- Descriptive operation IDs
- Complete response schemas
- Security definitions
After upload, you'll receive a validation report:
{
"status": "valid_with_warnings",
"errors": [],
"warnings": [
{
"path": "/paths/users/get",
"message": "Missing operationId"
},
{
"path": "/components/schemas/User",
"message": "No example provided"
}
],
"info": {
"endpoints": 15,
"schemas": 8,
"security_schemes": 2
}
}Good:
components:
schemas:
User:
type: object
required:
- id
- email
- name
properties:
id:
type: integer
minimum: 1
description: Unique user identifier
email:
type: string
format: email
maxLength: 255
description: User email address
name:
type: string
minLength: 1
maxLength: 100
description: User full name
age:
type: integer
minimum: 0
maximum: 150
description: User age in yearsWhy it helps:
- Enables accurate data generation
- Improves boundary value testing
- Supports better validation
paths:
/users:
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/User'
examples:
valid_user:
value:
email: "john.doe@example.com"
name: "John Doe"
age: 30
minimal_user:
value:
email: "jane@example.com"
name: "Jane"components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
apiKey:
type: apiKey
in: header
name: X-API-Key
security:
- bearerAuth: []
- apiKey: []paths:
/users/{id}:
get:
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/User'
404:
description: User not found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
401:
description: Unauthorized
500:
description: Internal server error- Semantic Versioning: Use versions like "1.0.0", "1.1.0", "2.0.0"
- Date-based: Use versions like "2024-01-15", "2024-02-01"
- Custom: Any string that makes sense for your team
View differences between specification versions:
# Via CLI
sentinel spec diff --spec1 1 --spec2 2
# Via API
curl -X GET "http://localhost:8000/specifications/compare?spec1=1&spec2=2" \
-H "Authorization: Bearer YOUR_TOKEN"- Keep History: Don't delete old versions, mark them as deprecated
- Document Changes: Include change notes with each version
- Test Compatibility: Run tests against multiple versions
- Use Tags: Tag versions as "stable", "beta", "deprecated"
Organize specifications with tags:
# Add tags
sentinel spec tag --id 1 --tags "production,customer-facing"
# Filter by tags
sentinel spec list --tags "production"Group related specifications:
{
"name": "E-commerce Platform",
"specifications": [
{"id": 1, "name": "User API"},
{"id": 2, "name": "Product API"},
{"id": 3, "name": "Order API"}
]
}Apply transformations before testing:
# Custom preprocessor example
def preprocess_spec(spec_data):
# Add default security to all endpoints
for path in spec_data.get('paths', {}).values():
for operation in path.values():
if 'security' not in operation:
operation['security'] = [{'bearerAuth': []}]
return spec_dataUse environment-specific configurations:
servers:
- url: ${API_BASE_URL}
description: API server
variables:
protocol:
default: https
enum: [http, https]
environment:
default: production
enum: [development, staging, production]Include external schema definitions:
components:
schemas:
User:
$ref: 'https://schemas.example.com/user.yaml#/User'
Address:
$ref: './schemas/address.yaml#/Address'-
Invalid JSON/YAML
- Use a validator: https://jsonlint.com or http://www.yamllint.com
- Check for syntax errors in your editor
-
Missing Required Fields
- Ensure
openapiorswaggerversion is specified - Include
infoobject withtitleandversion
- Ensure
-
Unresolved References
- Check all
$refpaths are correct - Ensure referenced schemas exist
- Check all
-
Large Specifications
- Split into multiple files using
$ref - Use specification collections
- Consider API versioning
- Split into multiple files using
Use the built-in linter to improve specification quality:
# Lint a specification
sentinel spec lint ./api-spec.yaml
# Auto-fix common issues
sentinel spec lint ./api-spec.yaml --fix- Keep Specifications Updated: Sync with your API implementation
- Use Descriptive Names: Clear operation IDs and schema names
- Document Everything: Include descriptions for all elements
- Provide Examples: Add request/response examples
- Define Constraints: Specify min/max values, patterns, enums
- Version Control: Store specifications in Git
- Automate Updates: Generate specs from code when possible
- Review Regularly: Audit specifications for completeness
- Learn about different test types
- Configure test execution
- Set up CI/CD integration