CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-swagger

Command-line interface for designing and building Swagger-compliant APIs in Node.js

Pending
Overview
Eval results
Files

project-management.mddocs/

Project Management

Complete project lifecycle management for Swagger-based Node.js APIs, including project creation, development server management, verification, and testing.

Capabilities

Project Creation

Creates a new Swagger project with the specified framework and directory structure.

swagger project create [name] [options]

# Options:
# -f, --framework <framework>  One of: connect|express|hapi|restify|sails

Usage Examples:

# Create project with Express framework
swagger project create my-api --framework express

# Interactive creation (prompts for name and framework)
swagger project create

# Create with default framework (connect)
swagger project create my-api

Programmatic Usage:

/**
 * Create a new Swagger project
 * @param {string} name - Project name
 * @param {Object} options - Configuration options
 * @param {string} options.framework - Target framework
 * @param {Function} cb - Callback function
 */
function create(name, options, cb);

Development Server

Starts the project development server with hot reloading, debugging support, and mock mode.

swagger project start [directory] [options]

# Options:
# -d, --debug [port]        Start in remote debug mode
# -b, --debug-brk [port]    Start in remote debug mode, wait for debugger
# -m, --mock               Start in mock mode
# -o, --open               Open browser as client to the project
# -n, --node-args <args>   Run node with extra arguments

Usage Examples:

# Start server in current directory
swagger project start

# Start with debugging on port 5858
swagger project start --debug 5858

# Start in mock mode and open browser
swagger project start --mock --open

# Start with Node.js harmony features
swagger project start --node-args "--harmony"

Programmatic Usage:

/**
 * Start project development server
 * @param {string} directory - Project directory
 * @param {Object} options - Server options
 * @param {boolean} options.debug - Enable debug mode
 * @param {boolean} options.debugBrk - Enable debug-brk mode
 * @param {boolean} options.mock - Enable mock mode
 * @param {boolean} options.open - Open browser
 * @param {string} options.nodeArgs - Additional Node.js arguments
 * @param {Function} cb - Callback function
 */
function start(directory, options, cb);

Project Verification

Verifies project configuration and Swagger specification validity.

swagger project verify [directory] [options]

# Options:
# -j, --json  Output results as JSON

Usage Examples:

# Verify current project
swagger project verify

# Verify specific directory with JSON output
swagger project verify ./my-api --json

Programmatic Usage:

/**
 * Verify project configuration and Swagger spec
 * @param {string} directory - Project directory
 * @param {Object} options - Verification options
 * @param {boolean} options.json - Output as JSON
 * @param {Function} cb - Callback function
 */
function verify(directory, options, cb);

Project Testing

Runs project tests using Mocha with support for debugging and mock mode.

swagger project test [directory_or_file] [options]

# Options:
# -d, --debug [port]       Start in remote debug mode
# -b, --debug-brk [port]   Start in remote debug mode, wait for debugger
# -m, --mock              Run in mock mode

Usage Examples:

# Run all tests
swagger project test

# Run specific test file
swagger project test test/api/controllers/hello_world.js

# Run tests in mock mode with debugging
swagger project test --mock --debug 5858

Programmatic Usage:

/**
 * Run project tests
 * @param {string} directory - Project directory or specific test file
 * @param {Object} options - Test options
 * @param {boolean} options.debug - Enable debug mode
 * @param {boolean} options.debugBrk - Enable debug-brk mode
 * @param {boolean} options.mock - Enable mock mode
 * @param {Function} cb - Callback function
 */
function test(directory, options, cb);

Test Generation

Generates test templates for API endpoints with configurable test frameworks and assertion libraries.

swagger project generate-test [directory] [options]

# Options:
# -p, --path-name [path]           Specific API path (supports regex)
# -f, --test-module <module>       Test module: supertest|request
# -t, --assertion-format <type>    Assertion format: expect|should|assert
# -o, --force                      Overwrite existing test files
# -l, --load-test [path]           Generate load tests for specified operations

Usage Examples:

# Generate tests for all endpoints
swagger project generate-test

# Generate tests for specific path with supertest
swagger project generate-test --path-name "/users" --test-module supertest

# Generate tests with should assertions and force overwrite
swagger project generate-test --assertion-format should --force

# Generate load tests
swagger project generate-test --load-test load-config.json

Programmatic Usage:

/**
 * Generate test templates for API endpoints
 * @param {string} directory - Project directory
 * @param {Object} options - Generation options
 * @param {string} options.pathName - Specific API path pattern
 * @param {string} options.testModule - Test module to use
 * @param {string} options.assertionFormat - Assertion format
 * @param {boolean} options.force - Force overwrite existing files
 * @param {string} options.loadTest - Load test configuration
 * @param {Function} cb - Callback function
 */
function generateTest(directory, options, cb);

Framework Support

Supported Frameworks

const FRAMEWORKS = {
  connect: { source: 'connect' },
  express: { source: 'connect', overlay: 'express' },
  hapi: { source: 'connect', overlay: 'hapi' },
  restify: { source: 'connect', overlay: 'restify' },
  sails: { source: 'sails' }
};

Test Configuration

const TEST_ASSERTION_TYPES = ['expect', 'should', 'assert'];
const TEST_MODULES = ['supertest', 'request'];
const TEST_DEPENDENCIES = {
  'z-schema': '^3.12.0',
  'request': '^2.58.0',
  'chai': '^3.0.0',
  'mocha': '^2.2.5',
  'dotenv': '^1.2.0'
};

Project Structure

When creating a project, the following structure is generated:

my-project/
├── api/
│   ├── controllers/        # Controller implementation files
│   ├── helpers/           # Helper modules
│   ├── mocks/            # Mock data for development
│   └── swagger/          # Swagger specification files
│       └── swagger.yaml  # Main API specification
├── app.js                # Main application entry point
├── config/               # Configuration files
├── package.json          # Project dependencies and scripts
└── test/                 # Test files and configuration
    └── api/
        └── controllers/  # Generated test files

Install with Tessl CLI

npx tessl i tessl/npm-swagger

docs

editor-integration.md

index.md

programmatic-api.md

project-management.md

validation-conversion.md

tile.json