0
# Project Management
1
2
Complete project lifecycle management for Swagger-based Node.js APIs, including project creation, development server management, verification, and testing.
3
4
## Capabilities
5
6
### Project Creation
7
8
Creates a new Swagger project with the specified framework and directory structure.
9
10
```bash { .api }
11
swagger project create [name] [options]
12
13
# Options:
14
# -f, --framework <framework> One of: connect|express|hapi|restify|sails
15
```
16
17
**Usage Examples:**
18
19
```bash
20
# Create project with Express framework
21
swagger project create my-api --framework express
22
23
# Interactive creation (prompts for name and framework)
24
swagger project create
25
26
# Create with default framework (connect)
27
swagger project create my-api
28
```
29
30
**Programmatic Usage:**
31
32
```javascript { .api }
33
/**
34
* Create a new Swagger project
35
* @param {string} name - Project name
36
* @param {Object} options - Configuration options
37
* @param {string} options.framework - Target framework
38
* @param {Function} cb - Callback function
39
*/
40
function create(name, options, cb);
41
```
42
43
### Development Server
44
45
Starts the project development server with hot reloading, debugging support, and mock mode.
46
47
```bash { .api }
48
swagger project start [directory] [options]
49
50
# Options:
51
# -d, --debug [port] Start in remote debug mode
52
# -b, --debug-brk [port] Start in remote debug mode, wait for debugger
53
# -m, --mock Start in mock mode
54
# -o, --open Open browser as client to the project
55
# -n, --node-args <args> Run node with extra arguments
56
```
57
58
**Usage Examples:**
59
60
```bash
61
# Start server in current directory
62
swagger project start
63
64
# Start with debugging on port 5858
65
swagger project start --debug 5858
66
67
# Start in mock mode and open browser
68
swagger project start --mock --open
69
70
# Start with Node.js harmony features
71
swagger project start --node-args "--harmony"
72
```
73
74
**Programmatic Usage:**
75
76
```javascript { .api }
77
/**
78
* Start project development server
79
* @param {string} directory - Project directory
80
* @param {Object} options - Server options
81
* @param {boolean} options.debug - Enable debug mode
82
* @param {boolean} options.debugBrk - Enable debug-brk mode
83
* @param {boolean} options.mock - Enable mock mode
84
* @param {boolean} options.open - Open browser
85
* @param {string} options.nodeArgs - Additional Node.js arguments
86
* @param {Function} cb - Callback function
87
*/
88
function start(directory, options, cb);
89
```
90
91
### Project Verification
92
93
Verifies project configuration and Swagger specification validity.
94
95
```bash { .api }
96
swagger project verify [directory] [options]
97
98
# Options:
99
# -j, --json Output results as JSON
100
```
101
102
**Usage Examples:**
103
104
```bash
105
# Verify current project
106
swagger project verify
107
108
# Verify specific directory with JSON output
109
swagger project verify ./my-api --json
110
```
111
112
**Programmatic Usage:**
113
114
```javascript { .api }
115
/**
116
* Verify project configuration and Swagger spec
117
* @param {string} directory - Project directory
118
* @param {Object} options - Verification options
119
* @param {boolean} options.json - Output as JSON
120
* @param {Function} cb - Callback function
121
*/
122
function verify(directory, options, cb);
123
```
124
125
### Project Testing
126
127
Runs project tests using Mocha with support for debugging and mock mode.
128
129
```bash { .api }
130
swagger project test [directory_or_file] [options]
131
132
# Options:
133
# -d, --debug [port] Start in remote debug mode
134
# -b, --debug-brk [port] Start in remote debug mode, wait for debugger
135
# -m, --mock Run in mock mode
136
```
137
138
**Usage Examples:**
139
140
```bash
141
# Run all tests
142
swagger project test
143
144
# Run specific test file
145
swagger project test test/api/controllers/hello_world.js
146
147
# Run tests in mock mode with debugging
148
swagger project test --mock --debug 5858
149
```
150
151
**Programmatic Usage:**
152
153
```javascript { .api }
154
/**
155
* Run project tests
156
* @param {string} directory - Project directory or specific test file
157
* @param {Object} options - Test options
158
* @param {boolean} options.debug - Enable debug mode
159
* @param {boolean} options.debugBrk - Enable debug-brk mode
160
* @param {boolean} options.mock - Enable mock mode
161
* @param {Function} cb - Callback function
162
*/
163
function test(directory, options, cb);
164
```
165
166
### Test Generation
167
168
Generates test templates for API endpoints with configurable test frameworks and assertion libraries.
169
170
```bash { .api }
171
swagger project generate-test [directory] [options]
172
173
# Options:
174
# -p, --path-name [path] Specific API path (supports regex)
175
# -f, --test-module <module> Test module: supertest|request
176
# -t, --assertion-format <type> Assertion format: expect|should|assert
177
# -o, --force Overwrite existing test files
178
# -l, --load-test [path] Generate load tests for specified operations
179
```
180
181
**Usage Examples:**
182
183
```bash
184
# Generate tests for all endpoints
185
swagger project generate-test
186
187
# Generate tests for specific path with supertest
188
swagger project generate-test --path-name "/users" --test-module supertest
189
190
# Generate tests with should assertions and force overwrite
191
swagger project generate-test --assertion-format should --force
192
193
# Generate load tests
194
swagger project generate-test --load-test load-config.json
195
```
196
197
**Programmatic Usage:**
198
199
```javascript { .api }
200
/**
201
* Generate test templates for API endpoints
202
* @param {string} directory - Project directory
203
* @param {Object} options - Generation options
204
* @param {string} options.pathName - Specific API path pattern
205
* @param {string} options.testModule - Test module to use
206
* @param {string} options.assertionFormat - Assertion format
207
* @param {boolean} options.force - Force overwrite existing files
208
* @param {string} options.loadTest - Load test configuration
209
* @param {Function} cb - Callback function
210
*/
211
function generateTest(directory, options, cb);
212
```
213
214
## Framework Support
215
216
### Supported Frameworks
217
218
```javascript { .api }
219
const FRAMEWORKS = {
220
connect: { source: 'connect' },
221
express: { source: 'connect', overlay: 'express' },
222
hapi: { source: 'connect', overlay: 'hapi' },
223
restify: { source: 'connect', overlay: 'restify' },
224
sails: { source: 'sails' }
225
};
226
```
227
228
### Test Configuration
229
230
```javascript { .api }
231
const TEST_ASSERTION_TYPES = ['expect', 'should', 'assert'];
232
const TEST_MODULES = ['supertest', 'request'];
233
const TEST_DEPENDENCIES = {
234
'z-schema': '^3.12.0',
235
'request': '^2.58.0',
236
'chai': '^3.0.0',
237
'mocha': '^2.2.5',
238
'dotenv': '^1.2.0'
239
};
240
```
241
242
## Project Structure
243
244
When creating a project, the following structure is generated:
245
246
```
247
my-project/
248
├── api/
249
│ ├── controllers/ # Controller implementation files
250
│ ├── helpers/ # Helper modules
251
│ ├── mocks/ # Mock data for development
252
│ └── swagger/ # Swagger specification files
253
│ └── swagger.yaml # Main API specification
254
├── app.js # Main application entry point
255
├── config/ # Configuration files
256
├── package.json # Project dependencies and scripts
257
└── test/ # Test files and configuration
258
└── api/
259
└── controllers/ # Generated test files
260
```