-
-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Product Requirements Document: OpenAPI Test Generation
Overview
Feature Name: OpenAPI Test Generation
Version: 1.0
Target Release: Next minor version
Owner: Manny
Summary
Enable Doc Detective to automatically generate HTTP API tests from OpenAPI 3.x specifications provided as direct input files. This feature transforms OpenAPI definitions into executable test specifications that leverage Doc Detective's existing httpRequest action capabilities.
Background & Motivation
Currently, Doc Detective can reference OpenAPI definitions for individual httpRequest steps, but cannot automatically generate comprehensive test suites from OpenAPI specifications. This manual process limits test coverage and requires significant developer effort to maintain API tests as specifications evolve.
By automatically generating tests from OpenAPI definitions, teams can:
- Achieve comprehensive API test coverage with minimal manual effort
- Maintain test synchronization with API specification changes
- Leverage contract testing for API validation
- Reduce time-to-market for API testing initiatives
Goals & Success Criteria
Primary Goals
- Automatic Test Generation: Transform OpenAPI 3.x files into executable Doc Detective test specifications
- Safety-First Approach: Only generate tests for operations deemed safe to execute automatically
- Dependency Management: Support operation dependencies through
x-doc-detectiveextensions - Seamless Integration: Work within existing Doc Detective detection and resolution workflows
Success Criteria
- OpenAPI 3.x files can be provided as direct input to
doc-detectivecommand - Generated tests execute successfully against live APIs
- Tests leverage all existing Doc Detective
httpRequestcapabilities - Zero breaking changes to existing functionality
User Stories
Primary User Stories
- As an API developer, I want to provide my OpenAPI spec as input to Doc Detective so that comprehensive API tests are automatically generated
- As a QA engineer, I want unsafe operations (PUT/DELETE) to require explicit configuration so that automated tests don't accidentally modify production data
- As a DevOps engineer, I want dependency management between API operations so that complex test scenarios (create → read → delete) can be automated
Secondary User Stories
- As an API maintainer, I want root-level defaults in my OpenAPI spec so that common configuration applies to all operations
- As a test author, I want operation-level overrides so that specific endpoints can have custom test behavior
Functional Requirements
Core Functionality
FR-1: OpenAPI File Detection
- Requirement: Detect OpenAPI 3.x files in
inputparameter - Acceptance Criteria:
- Files with
.json,.yaml,.ymlextensions containing valid OpenAPI 3.x structure are identified - OpenAPI detection bypasses existing
fileTypesvalidation - Only OpenAPI 3.x specifications are supported (version starts with "3.")
- Invalid OpenAPI files are logged and skipped
- Files with
FR-2: Automatic Test Generation
- Requirement: Transform OpenAPI operations into Doc Detective test specifications
- Acceptance Criteria:
- Each operation becomes a separate test with unique
testId - Generated tests use
httpRequestaction withopenApi.operationIdreference - Test descriptions derived from operation
summaryordescription - OpenAPI definition is loaded, dereferenced, and included in spec's
openApiarray
- Each operation becomes a separate test with unique
FR-3: Operation Safety Classification
- Requirement: Only generate tests for operations deemed safe to execute
- Acceptance Criteria:
- GET operations are safe by default
- POST operations are safe by default
- PUT, PATCH, DELETE, HEAD, OPTIONS operations are unsafe by default
- Unsafe operations are skipped unless explicitly marked safe
- Safety decisions are logged at debug level
FR-4: Extension Property Support
- Requirement: Support
x-doc-detectiveextension for operation configuration - Acceptance Criteria:
x-doc-detectiveaccepted at OpenAPI root level (defaults for all operations)x-doc-detectiveaccepted at operation level (overrides root defaults)- Supports
safeboolean property to override default safety classification - Supports
beforearray for prerequisite operations - Supports
afterarray for cleanup operations - Supports all existing
openApischema properties:server,validateSchema,mockResponse,statusCodes,useExample,exampleKey,requestHeaders,responseHeaders
FR-5: Dependency Management
- Requirement: Execute prerequisite and cleanup operations
- Acceptance Criteria:
beforeoperations are added as steps before main operationafteroperations are added as steps after main operation- Dependencies referenced by
operationIdORpath+methodcombination - No nested dependencies supported (flat structure only)
- Dependency resolution failures are logged and operation is skipped
- Variables from
beforeoperations automatically propagate to subsequent steps
Integration Requirements
FR-6: Workflow Integration
- Requirement: Integrate with existing Doc Detective detection workflow
- Acceptance Criteria:
- OpenAPI detection occurs in
parseTests()function withinutils.js - Generated specs follow same structure as manually authored specs
- Generated tests go through normal resolution process (contexts, browsers, etc.)
- No changes required to
resolveTests()or execution logic
- OpenAPI detection occurs in
FR-7: Configuration Inheritance
- Requirement: Leverage existing Doc Detective configuration system
- Acceptance Criteria:
- Generated tests respect global configuration settings
- OpenAPI-specific configuration merges with global defaults
- Existing
loadDescription()function used for OpenAPI dereferencing - Environment variable substitution works in generated tests
Technical Requirements
TR-1: File Processing
- Modify
isValidSourceFile()to identify OpenAPI 3.x files - Add
isOpenApi3File()helper function for OpenAPI detection - Extend
parseTests()to handle OpenAPI transformation
TR-2: Code Organization
- Add transformation functions to
openapi.js:transformOpenApiToSpec()extractOperations()transformOperationToTest()createHttpRequestStep()createDependencySteps()isOperationSafe()findOperationById()findOperationByPath()
TR-3: Error Handling
- Graceful handling of malformed OpenAPI files
- Comprehensive logging for debugging generated tests
- Fallback behavior when dependencies cannot be resolved
TR-4: Performance Considerations
- Efficient operation extraction from large OpenAPI specifications
- Minimal memory overhead for dereferenced definitions
- Reasonable test generation time for complex APIs
Non-Functional Requirements
NFR-1: Backward Compatibility
- Zero breaking changes to existing Doc Detective functionality
- Existing test specifications and workflows remain unchanged
- Existing OpenAPI integration features remain functional
NFR-2: Maintainability
- Code follows existing Doc Detective patterns and conventions
- Comprehensive logging for troubleshooting
- Clear error messages for configuration issues
NFR-3: Extensibility
- Architecture supports future enhancements (retry logic, advanced dependency management)
- Clean separation between OpenAPI processing and core test logic
Implementation Phases
Phase 1: Core Implementation
- OpenAPI file detection in
isValidSourceFile() - Basic test generation in
parseTests() - Operation safety classification
- Simple
httpRequeststep generation
Phase 2: Extension Support
x-doc-detectiveproperty parsing- Root-level and operation-level configuration merging
- OpenAPI schema property integration
- Dependency management (
before/afteroperations)
Phase 3: Polish & Testing
- Comprehensive error handling and logging
- Integration testing with real OpenAPI specifications
- Documentation and examples
- Performance optimization
Testing Strategy
Unit Tests
- OpenAPI file detection accuracy
- Test generation logic for various operation types
- Safety classification for different HTTP methods
- Extension property parsing and merging
- Dependency resolution logic
Integration Tests
- End-to-end test generation from sample OpenAPI files
- Generated test execution against mock APIs
- Variable propagation between dependent operations
- Error handling for malformed specifications
Test Data
- Valid OpenAPI 3.x specifications with various operation types
- Specifications with
x-doc-detectiveextensions - Malformed/invalid OpenAPI files for error testing
- Complex dependency scenarios
Dependencies & Assumptions
Dependencies
- Existing
loadDescription()function for OpenAPI dereferencing - Existing
httpRequestaction implementation - Existing variable propagation system (
$$response.body.*) doc-detective-commonvalidation functions
Assumptions
- OpenAPI specifications are well-formed and valid
- Target APIs are accessible during test execution
- Users understand OpenAPI concepts and structure
- Existing OpenAPI integration patterns remain stable
Documentation Requirements
User Documentation
- Usage examples with sample OpenAPI files
x-doc-detectiveextension property reference- Safety classification explanation
- Dependency management patterns
Developer Documentation
- Implementation architecture overview
- Function documentation for new utilities
- Integration points with existing codebase
- Troubleshooting guide for common issues
Success Metrics
Adoption Metrics
- Number of OpenAPI files processed successfully
- Percentage of generated tests that execute without errors
- User adoption rate of
x-doc-detectiveextensions
Quality Metrics
- Test coverage of generated test logic
- Performance benchmarks for large OpenAPI specifications
- Error rate for malformed input files
Risks & Mitigations
Technical Risks
- Risk: Complex OpenAPI specifications may generate too many tests
- Mitigation: Implement filtering and safety checks
- Risk: Dependency cycles in
before/afteroperations- Mitigation: Flat dependency structure prevents cycles
- Risk: Performance impact on large specifications
- Mitigation: Efficient parsing and lazy evaluation
Product Risks
- Risk: Generated tests may not match user expectations
- Mitigation: Clear documentation and extensive examples
- Risk: Breaking changes to existing OpenAPI integration
- Mitigation: Comprehensive regression testing
Future Considerations
Potential Enhancements
- Support for OpenAPI 2.x (Swagger) specifications
- Advanced dependency management with cycle detection
- Custom test generation templates
- Integration with API mocking frameworks
- Parallel execution optimization for large test suites
Integration Opportunities
- CI/CD pipeline integration for contract testing
- API documentation generation from test results
- Integration with API gateway testing workflows