@nldoc/openapi-test-set-generator 1.3.85 → 1.3.86

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +316 -35
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,48 +1,329 @@
1
- # OpenAPI Test Set Generator
1
+ # NLdoc OpenAPI Test Set Generator
2
2
 
3
- ## Why
3
+ [![pipeline status](https://gitlab.com/logius/nldoc/lib/typescript/openapi-test-set-generator/badges/main/pipeline.svg)](https://gitlab.com/logius/nldoc/lib/typescript/openapi-test-set-generator/-/commits/main)
4
+ [![coverage report](https://gitlab.com/logius/nldoc/lib/typescript/openapi-test-set-generator/badges/main/coverage.svg?job=test)](https://gitlab.com/logius/nldoc/lib/typescript/openapi-test-set-generator/-/commits/main)
5
+ [![Latest Release](https://gitlab.com/logius/nldoc/lib/typescript/openapi-test-set-generator/-/badges/release.svg)](https://gitlab.com/logius/nldoc/lib/typescript/openapi-test-set-generator/-/releases)
6
+ [![NPM Version](https://img.shields.io/npm/v/@nldoc/openapi-test-set-generator)](https://www.npmjs.com/package/@nldoc/openapi-test-set-generator)
4
7
 
5
- The OpenAPI Test Set Generator helps create test scenarios from OpenAPI specifications by generating valid and invalid examples based on schema definitions.
8
+ A powerful CLI tool for generating comprehensive test sets from OpenAPI 3.1.0 specifications. This TypeScript library automatically creates valid and invalid test examples based on schema definitions, enabling robust API validation testing.
6
9
 
7
- ## How to use
10
+ ## Overview
8
11
 
9
- ### Property Modifications
12
+ The OpenAPI Test Set Generator extracts examples from OpenAPI specifications and systematically creates test variants to validate API implementations. It processes schema definitions and generates:
10
13
 
11
- The generator supports modifying properties in example objects to create test scenarios. It can now handle both top-level and nested properties.
14
+ - **Valid examples**: Test cases that conform to the API specification
15
+ - **Invalid examples**: Test cases that deliberately violate schema constraints for negative testing
16
+ - **Property variants**: Multiple variations of examples with modified properties based on configurable rules
12
17
 
13
- #### Nested Property Support
18
+ This tool is essential for:
19
+ - Automated API testing and validation
20
+ - Schema compliance verification
21
+ - Test-driven API development
22
+ - Generating comprehensive test suites from API specifications
14
23
 
15
- The generator automatically finds and modifies properties at any level of nesting based on the conditions specified in the `where` clause:
24
+ ## Getting Started
25
+
26
+ ### Prerequisites
27
+
28
+ - Node.js >= 22.0.0
29
+ - npm >= 10.0.0
30
+
31
+ ### Installation
32
+
33
+ Install the package globally:
34
+
35
+ ```bash
36
+ npm install -g @nldoc/openapi-test-set-generator
37
+ ```
38
+
39
+ Or as a development dependency:
40
+
41
+ ```bash
42
+ npm install --save-dev @nldoc/openapi-test-set-generator
43
+ ```
44
+
45
+ ### Basic Usage
46
+
47
+ Create a configuration file (e.g., `test-generator.yaml`):
16
48
 
17
49
  ```yaml
50
+ input:
51
+ openapi: ./api/openapi.json
52
+ output:
53
+ valid: ./tests/examples.valid.json
54
+ invalid: ./tests/examples.invalid.json
18
55
  variantsOnExamples:
19
- property:
20
- # This will find and modify all string properties, including nested ones
21
- - where:
22
- type: 'string'
23
- do:
24
- set: 'modified value'
25
- valid: true
26
-
27
- # This will find and modify all object properties
28
- - where:
29
- type: 'object'
30
- do:
31
- set: null
32
- valid: false
33
-
34
- # This will find and modify all string properties with format "email",
35
- # even if they are nested deep in the object structure
36
- - where:
37
- type: 'string'
38
- format: 'email'
39
- do:
40
- set: 'modified@example.com'
41
- valid: true
42
- ```
43
-
44
- The generator will recursively traverse the object structure to find and modify all properties that match the specified conditions, regardless of how deeply they are nested.
56
+ property:
57
+ # All examples in openapi.json are valid by default
58
+ - where: {}
59
+ do: {}
60
+ valid: true
61
+
62
+ # Generate invalid examples by removing required properties
63
+ - where:
64
+ required: true
65
+ hasDefault: false
66
+ do:
67
+ remove: true
68
+ valid: false
69
+ ```
70
+
71
+ Run the generator:
72
+
73
+ ```bash
74
+ openapi-test-set-generator extract-examples --input test-generator.yaml
75
+ ```
76
+
77
+ Or using npx:
78
+
79
+ ```bash
80
+ npx @nldoc/openapi-test-set-generator extract-examples -i test-generator.yaml
81
+ ```
82
+
83
+ ## Configuration
84
+
85
+ ### Configuration File Structure
86
+
87
+ The generator uses a YAML configuration file with the following structure:
88
+
89
+ ```yaml
90
+ input:
91
+ openapi: <path-to-openapi-spec> # Path to your OpenAPI specification (JSON/YAML)
92
+
93
+ output:
94
+ valid: <output-path-for-valid-examples> # Where to save valid test examples
95
+ invalid: <output-path-for-invalid-examples> # Where to save invalid test examples
96
+
97
+ variantsOnExamples:
98
+ property:
99
+ - where: <conditions> # Conditions to match properties
100
+ do: <action> # Action to perform on matched properties
101
+ valid: <boolean> # Whether the result should be valid or invalid
102
+ ```
103
+
104
+ ### Property Modification Rules
105
+
106
+ The generator supports sophisticated property selection and modification:
107
+
108
+ #### Where Conditions
109
+
110
+ Select properties based on their schema characteristics:
111
+
112
+ ```yaml
113
+ where:
114
+ type: 'string' # Match by type
115
+ format: 'email' # Match by format
116
+ required: true # Match required properties
117
+ hasDefault: false # Match properties without defaults
118
+ minLength:
119
+ $gte: 1 # Match strings with minLength >= 1
120
+ maxLength:
121
+ $lte: 100 # Match strings with maxLength <= 100
122
+ ```
123
+
124
+ #### Modification Actions
125
+
126
+ ```yaml
127
+ do:
128
+ set: <value> # Set property to a specific value
129
+ remove: true # Remove the property entirely
130
+ truncate: 10 # Truncate string to specified length
131
+ ```
132
+
133
+ ### Nested Property Support
134
+
135
+ The generator automatically traverses nested object structures to find and modify properties at any depth:
136
+
137
+ ```yaml
138
+ variantsOnExamples:
139
+ property:
140
+ # Modifies all email fields, even deeply nested ones
141
+ - where:
142
+ type: 'string'
143
+ format: 'email'
144
+ do:
145
+ set: 'invalid-email'
146
+ valid: false
147
+
148
+ # Removes all non-required nested properties
149
+ - where:
150
+ required: false
151
+ do:
152
+ remove: true
153
+ valid: true
154
+ ```
155
+
156
+ ## Development
157
+
158
+ ### Local Setup
159
+
160
+ 1. Clone the repository:
161
+ ```bash
162
+ git clone https://gitlab.com/logius/nldoc/lib/typescript/openapi-test-set-generator.git
163
+ cd openapi-test-set-generator
164
+ ```
165
+
166
+ 2. Install dependencies:
167
+ ```bash
168
+ npm install
169
+ ```
170
+
171
+ 3. Build the project:
172
+ ```bash
173
+ npm run build
174
+ ```
175
+
176
+ ### Available Scripts
177
+
178
+ - `npm run build` - Compile TypeScript to JavaScript
179
+ - `npm run build:check` - Type-check without emitting files
180
+ - `npm test` - Run test suite with coverage
181
+ - `npm run test:watch` - Run tests in watch mode
182
+ - `npm run lint` - Lint the codebase
183
+ - `npm run format` - Format code with Prettier
184
+ - `npm run format:check` - Check code formatting
185
+ - `npm run fix` - Auto-fix linting and formatting issues
186
+
187
+ ## API Documentation
188
+
189
+ ### CLI Commands
190
+
191
+ #### extract-examples
192
+
193
+ Extract and generate test examples from an OpenAPI specification.
194
+
195
+ ```bash
196
+ openapi-test-set-generator extract-examples --input <config-file>
197
+ ```
198
+
199
+ **Options:**
200
+ - `-i, --input <file>` - Path to the configuration file (required)
201
+
202
+ **Examples:**
203
+ ```bash
204
+ openapi-test-set-generator extract-examples --input otsg.yaml
205
+ openapi-test-set-generator extract-examples -i otsg.yml
206
+ ```
207
+
208
+ ### Programmatic Usage
209
+
210
+ ```typescript
211
+ import {
212
+ importOpenAPIFile,
213
+ extractSchemaObjectsWithExamples,
214
+ createExampleVariantsFromSchemasOnQueries
215
+ } from '@nldoc/openapi-test-set-generator';
216
+
217
+ // Load OpenAPI specification
218
+ const spec = await importOpenAPIFile('path/to/openapi.json');
219
+
220
+ // Extract schemas with examples
221
+ const schemas = extractSchemaObjectsWithExamples(spec);
222
+
223
+ // Generate test variants
224
+ const { valid, invalid } = await createExampleVariantsFromSchemasOnQueries(
225
+ schemas,
226
+ variantQueries
227
+ );
228
+ ```
229
+
230
+ ## Example Scenarios
231
+
232
+ ### Common Test Patterns
233
+
234
+ 1. **Required Field Validation**
235
+ ```yaml
236
+ - where:
237
+ required: true
238
+ hasDefault: false
239
+ do:
240
+ remove: true
241
+ valid: false
242
+ ```
243
+
244
+ 2. **String Format Validation**
245
+ ```yaml
246
+ - where:
247
+ type: 'string'
248
+ format: 'uuid'
249
+ do:
250
+ set: 'invalid-uuid'
251
+ valid: false
252
+ ```
253
+
254
+ 3. **Array Constraints**
255
+ ```yaml
256
+ - where:
257
+ type: 'array'
258
+ required: true
259
+ hasDefault: false
260
+ do:
261
+ set: []
262
+ valid: false
263
+ ```
264
+
265
+ 4. **Boolean Value Testing**
266
+ ```yaml
267
+ - where:
268
+ type: 'boolean'
269
+ do:
270
+ set: true
271
+ valid: true
272
+ - where:
273
+ type: 'boolean'
274
+ do:
275
+ set: false
276
+ valid: true
277
+ ```
278
+
279
+ ## Integration Examples
280
+
281
+ This generator can be integrated into any project that uses OpenAPI specifications. Common integration patterns include:
282
+
283
+ 1. Generate comprehensive test sets for API schemas
284
+ 2. Validate API implementation compliance
285
+ 3. Create edge cases for robust testing
286
+ 4. Ensure API specification accuracy
287
+
288
+ Example integration in `package.json`:
289
+ ```json
290
+ {
291
+ "scripts": {
292
+ "build:examples": "openapi-test-set-generator extract-examples -i ./example-generator.yaml"
293
+ }
294
+ }
295
+ ```
296
+
297
+ ## Testing
298
+
299
+ Run the test suite:
300
+
301
+ ```bash
302
+ npm test
303
+ ```
304
+
305
+ Run tests with coverage:
306
+
307
+ ```bash
308
+ npm run test:watch run
309
+ ```
310
+
311
+ ## Contributing
312
+
313
+ We welcome contributions! Please ensure:
314
+
315
+ 1. All tests pass (`npm test`)
316
+ 2. Code is properly formatted (`npm run format:check`)
317
+ 3. Linting rules are followed (`npm run lint`)
318
+ 4. TypeScript compilation succeeds (`npm run build:check`)
45
319
 
46
320
  ## License
47
321
 
48
- See [LICENSE.txt](LICENSE.txt).
322
+ This project is licensed under the European Union Public License 1.2 - see [LICENSE](LICENSE) for details.
323
+
324
+ ## Acknowledgements
325
+
326
+ - Built with [Oclif](https://oclif.io/) CLI framework
327
+ - Supports [OpenAPI 3.1.0](https://spec.openapis.org/oas/v3.1.0) specifications
328
+ - Uses [Vitest](https://vitest.dev/) for testing
329
+ - Part of the [NLdoc](https://gitlab.com/logius/nldoc) ecosystem
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nldoc/openapi-test-set-generator",
3
- "version": "1.3.85",
3
+ "version": "1.3.86",
4
4
  "description": "OpenApi test set generator",
5
5
  "author": "NLdoc",
6
6
  "license": "EUPL-1.2",
@@ -16,8 +16,8 @@
16
16
  "scripts": {
17
17
  "build": "tsc --project tsconfig.dist.json",
18
18
  "build:check": "tsc",
19
- "test": "npm run test:watch run",
20
- "test:watch": "vitest --coverage",
19
+ "test": "npx vitest run --coverage",
20
+ "test:watch": "npx vitest run --watch",
21
21
  "commit": "cz",
22
22
  "format": "prettier . --write",
23
23
  "format:check": "prettier . --check",