@nldoc/openapi-test-set-generator 1.2.26 → 1.3.0
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.
- package/README.md +39 -0
- package/dist/commands/extract-examples.js +8 -8
- package/dist/commands/extract-examples.js.map +1 -1
- package/dist/lib/condition/schema/schemaPropertyChecker.d.ts +2 -3
- package/dist/lib/condition/schema/schemaPropertyChecker.js +8 -1
- package/dist/lib/condition/schema/schemaPropertyChecker.js.map +1 -1
- package/dist/lib/condition/schemaPropertySelector.d.ts +7 -8
- package/dist/lib/condition/schemaPropertySelector.js +31 -7
- package/dist/lib/condition/schemaPropertySelector.js.map +1 -1
- package/dist/lib/isJsonObject.d.ts +2 -0
- package/dist/lib/isJsonObject.js +4 -0
- package/dist/lib/isJsonObject.js.map +1 -0
- package/dist/lib/modification/createExampleVariantsFromSchemaOnQueries.d.ts +5 -5
- package/dist/lib/modification/createExampleVariantsFromSchemaOnQueries.js +3 -1
- package/dist/lib/modification/createExampleVariantsFromSchemaOnQueries.js.map +1 -1
- package/dist/lib/modification/createExampleVariantsFromSchemaOnQuery.d.ts +6 -5
- package/dist/lib/modification/createExampleVariantsFromSchemaOnQuery.js +3 -0
- package/dist/lib/modification/createExampleVariantsFromSchemaOnQuery.js.map +1 -1
- package/dist/lib/modification/createExampleVariantsFromSchemasOnQueries.d.ts +5 -5
- package/dist/lib/modification/createExampleVariantsFromSchemasOnQueries.js +5 -5
- package/dist/lib/modification/createExampleVariantsFromSchemasOnQueries.js.map +1 -1
- package/dist/lib/modification/modifyPropertyInExample.d.ts +8 -7
- package/dist/lib/modification/modifyPropertyInExample.js +33 -15
- package/dist/lib/modification/modifyPropertyInExample.js.map +1 -1
- package/dist/lib/modification/modifyPropertyInSchemaExamples.d.ts +7 -10
- package/dist/lib/modification/modifyPropertyInSchemaExamples.js +35 -13
- package/dist/lib/modification/modifyPropertyInSchemaExamples.js.map +1 -1
- package/dist/lib/openapi/PropertyResolver.d.ts +2 -2
- package/dist/lib/openapi/PropertyResolver.js.map +1 -1
- package/dist/lib/openapi/SchemaPropertyResolver.d.ts +32 -9
- package/dist/lib/openapi/SchemaPropertyResolver.js +71 -17
- package/dist/lib/openapi/SchemaPropertyResolver.js.map +1 -1
- package/dist/lib/openapi/extractSchemaObjectsWithExamples.d.ts +6 -0
- package/dist/lib/openapi/extractSchemaObjectsWithExamples.js +10 -0
- package/dist/lib/openapi/extractSchemaObjectsWithExamples.js.map +1 -0
- package/dist/lib/openapi/isReferenceObject.d.ts +2 -0
- package/dist/lib/openapi/isReferenceObject.js +4 -0
- package/dist/lib/openapi/isReferenceObject.js.map +1 -0
- package/dist/lib/openapi/isSchemaObject.d.ts +2 -0
- package/dist/lib/openapi/isSchemaObject.js +4 -0
- package/dist/lib/openapi/isSchemaObject.js.map +1 -0
- package/dist/lib/openapi/isSchemaObjectWithExamples.d.ts +4 -0
- package/dist/lib/openapi/isSchemaObjectWithExamples.js +8 -0
- package/dist/lib/openapi/isSchemaObjectWithExamples.js.map +1 -0
- package/dist/lib/openapi/isSchemaObjectWithProperties.d.ts +4 -0
- package/dist/lib/openapi/isSchemaObjectWithProperties.js +9 -0
- package/dist/lib/openapi/isSchemaObjectWithProperties.js.map +1 -0
- package/dist/types/InputFile.d.ts +32 -32
- package/dist/types/condition/SchemaPropertySelectorCondition.d.ts +8 -8
- package/dist/types/modification/SchemaPropertyVariantQuery.d.ts +16 -16
- package/dist/types/openapi/HasExamples.d.ts +4 -0
- package/dist/types/openapi/HasExamples.js +2 -0
- package/dist/types/openapi/HasExamples.js.map +1 -0
- package/package.json +1 -1
- package/dist/lib/openapi/extractObjectSchemasWithExamples.d.ts +0 -8
- package/dist/lib/openapi/extractObjectSchemasWithExamples.js +0 -16
- package/dist/lib/openapi/extractObjectSchemasWithExamples.js.map +0 -1
- package/dist/types/openapi/HasObjectExamples.d.ts +0 -4
- package/dist/types/openapi/HasObjectExamples.js +0 -2
- package/dist/types/openapi/HasObjectExamples.js.map +0 -1
- package/dist/types/openapi/HasResolvedProperties.d.ts +0 -4
- package/dist/types/openapi/HasResolvedProperties.js +0 -2
- package/dist/types/openapi/HasResolvedProperties.js.map +0 -1
package/README.md
CHANGED
@@ -2,8 +2,47 @@
|
|
2
2
|
|
3
3
|
## Why
|
4
4
|
|
5
|
+
The OpenAPI Test Set Generator helps create test scenarios from OpenAPI specifications by generating valid and invalid examples based on schema definitions.
|
6
|
+
|
5
7
|
## How to use
|
6
8
|
|
9
|
+
### Property Modifications
|
10
|
+
|
11
|
+
The generator supports modifying properties in example objects to create test scenarios. It can now handle both top-level and nested properties.
|
12
|
+
|
13
|
+
#### Nested Property Support
|
14
|
+
|
15
|
+
The generator automatically finds and modifies properties at any level of nesting based on the conditions specified in the `where` clause:
|
16
|
+
|
17
|
+
```yaml
|
18
|
+
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.
|
45
|
+
|
7
46
|
## License
|
8
47
|
|
9
48
|
See [LICENSE.txt](LICENSE.txt).
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import { Command, Flags } from '@oclif/core';
|
2
|
-
import { importOpenAPIFile } from '../lib/importOpenAPIFile.js';
|
3
|
-
import { writeJsonToFile } from '../lib/writeJsonToFile.js';
|
4
|
-
import { extractObjectSchemasWithExamples } from '../lib/openapi/extractObjectSchemasWithExamples.js';
|
5
|
-
import { SchemaPropertyResolver } from '../lib/openapi/SchemaPropertyResolver.js';
|
6
|
-
import { PropertyResolver } from '../lib/openapi/PropertyResolver.js';
|
7
2
|
import { promises as fs } from 'fs';
|
8
3
|
import YAML from 'yaml';
|
4
|
+
import { importOpenAPIFile } from '../lib/importOpenAPIFile.js';
|
5
|
+
import { extractSchemaObjectsWithExamples } from '../lib/openapi/extractSchemaObjectsWithExamples.js';
|
6
|
+
import { PropertyResolver } from '../lib/openapi/PropertyResolver.js';
|
7
|
+
import { SchemaPropertyResolver } from '../lib/openapi/SchemaPropertyResolver.js';
|
8
|
+
import { writeJsonToFile } from '../lib/writeJsonToFile.js';
|
9
9
|
import { InputFile } from '../types/InputFile.js';
|
10
|
-
import { createExampleVariantsFromSchemasOnQueries } from '../lib/modification/createExampleVariantsFromSchemasOnQueries.js';
|
11
10
|
import path from 'node:path';
|
11
|
+
import { createExampleVariantsFromSchemasOnQueries } from '../lib/modification/createExampleVariantsFromSchemasOnQueries.js';
|
12
12
|
export default class ExtractExamples extends Command {
|
13
13
|
static flags = {
|
14
14
|
input: Flags.file({
|
@@ -31,8 +31,8 @@ export default class ExtractExamples extends Command {
|
|
31
31
|
.then((data) => InputFile.parseAsync(data));
|
32
32
|
const spec = await importOpenAPIFile(path.join(absolutePathToDirOfInput, input.openapi));
|
33
33
|
const schemaPropResolver = new SchemaPropertyResolver(new PropertyResolver(spec));
|
34
|
-
const
|
35
|
-
|
34
|
+
const schemas = extractSchemaObjectsWithExamples(spec);
|
35
|
+
const { valid, invalid } = await Promise.all(schemas.map((schema) => schemaPropResolver.resolve(schema)))
|
36
36
|
.then((resolvedSchemas) => createExampleVariantsFromSchemasOnQueries(resolvedSchemas, variantsOnExamples.property));
|
37
37
|
await writeJsonToFile(path.join(absolutePathToDirOfInput, output.valid), valid);
|
38
38
|
await writeJsonToFile(path.join(absolutePathToDirOfInput, output.invalid), invalid);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"extract-examples.js","sourceRoot":"","sources":["../../src/commands/extract-examples.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"extract-examples.js","sourceRoot":"","sources":["../../src/commands/extract-examples.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAA;AAEnC,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAC/D,OAAO,EAAE,gCAAgC,EAAE,MAAM,oDAAoD,CAAA;AACrG,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAA;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAA;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,yCAAyC,EAAE,MAAM,kEAAkE,CAAA;AAE5H,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,OAAO;IAChD,MAAM,CAAU,KAAK,GAAG;QACpB,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC;YACd,IAAI,EAAE,GAAG;YACT,WAAW,EACP,yFAAyF;YAC7F,QAAQ,EAAE,IAAI;SACjB,CAAC;KACL,CAAA;IAED,MAAM,CAAU,WAAW,GAAG,wDAAwD,CAAA;IAEtF,MAAM,CAAU,QAAQ,GAAG;QACvB,uDAAuD;QACvD,iDAAiD;KACpD,CAAA;IAEM,KAAK,CAAC,GAAG;QACZ,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAA;QAEnD,MAAM,wBAAwB,GAAG,IA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|
-
import { type SchemaObject } from 'openapi3-ts/oas31.js';
|
2
|
-
import { type HasResolvedProperties } from '../../../types/openapi/HasResolvedProperties.js';
|
1
|
+
import { type ReferenceObject, type SchemaObject } from 'openapi3-ts/oas31.js';
|
3
2
|
import { type SchemaPropertySelectorCondition } from '../../../types/condition/SchemaPropertySelectorCondition.js';
|
4
3
|
/**
|
5
4
|
* Check if a property modification condition is met.
|
@@ -11,4 +10,4 @@ import { type SchemaPropertySelectorCondition } from '../../../types/condition/S
|
|
11
10
|
*
|
12
11
|
* When property does not exist, this function returns false.
|
13
12
|
*/
|
14
|
-
export declare function schemaPropertyChecker(schema: SchemaObject
|
13
|
+
export declare function schemaPropertyChecker(schema: SchemaObject | ReferenceObject, property: string, condition: SchemaPropertySelectorCondition): boolean;
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { isDefined } from '../../../types/Defined.js';
|
2
|
+
import { isReferenceObject } from '../../openapi/isReferenceObject.js';
|
2
3
|
import { schemaObjectHasProperty } from '../../openapi/schemaObjectHasProperty.js';
|
3
|
-
import { simpleEqualityChecker } from '../value/simpleEqualityChecker.js';
|
4
4
|
import { numberChecker } from '../value/numberChecker.js';
|
5
|
+
import { simpleEqualityChecker } from '../value/simpleEqualityChecker.js';
|
5
6
|
/**
|
6
7
|
* Check if a property modification condition is met.
|
7
8
|
* @param schema
|
@@ -13,6 +14,9 @@ import { numberChecker } from '../value/numberChecker.js';
|
|
13
14
|
* When property does not exist, this function returns false.
|
14
15
|
*/
|
15
16
|
export function schemaPropertyChecker(schema, property, condition) {
|
17
|
+
if (isReferenceObject(schema)) {
|
18
|
+
return false;
|
19
|
+
}
|
16
20
|
if (!schemaObjectHasProperty(schema, property)) {
|
17
21
|
return false;
|
18
22
|
}
|
@@ -20,6 +24,9 @@ export function schemaPropertyChecker(schema, property, condition) {
|
|
20
24
|
return ((schema.required ?? []).includes(property) === condition.required &&
|
21
25
|
schemaPropertyChecker(schema, property, { ...condition, required: undefined }));
|
22
26
|
}
|
27
|
+
if (isReferenceObject(schema.properties?.[property])) {
|
28
|
+
return false;
|
29
|
+
}
|
23
30
|
if (isDefined(condition.hasDefault)) {
|
24
31
|
return (isDefined(schema.properties?.[property]?.default) === condition.hasDefault &&
|
25
32
|
schemaPropertyChecker(schema, property, { ...condition, hasDefault: undefined }));
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"schemaPropertyChecker.js","sourceRoot":"","sources":["../../../../src/lib/condition/schema/schemaPropertyChecker.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"schemaPropertyChecker.js","sourceRoot":"","sources":["../../../../src/lib/condition/schema/schemaPropertyChecker.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAA;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAA;AAClF,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;AAEzE;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CACjC,MAAsC,EACtC,QAAgB,EAChB,SAA0C;IAE1C,IAAI,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAA;IAChB,CAAC;IACD,IAAI,CAAC,uBAAuB,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC;QAC7C,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,IAAI,SAAS,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChC,OAAO,CACH,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,SAAS,CAAC,QAAQ;YACjE,qBAAqB,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,GAAG,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE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AAE,SAAS,CAAC,SAAS,CAAC;YACpF,qBAAqB,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,GAAG,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAClF,CAAA;IACL,CAAC;IAED,IAAI,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC;QACjC,OAAO,CACH,aAAa,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,QAAQ,CAAC,EAAE,SAAS,IAAI,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC;YACpF,qBAAqB,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,GAAG,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAClF,CAAA;IACL,CAAC;IAED,OAAO,IAAI,CAAA;AACf,CAAC"}
|
@@ -1,11 +1,10 @@
|
|
1
|
-
import { type SchemaObject } from 'openapi3-ts/oas31.js';
|
2
|
-
import { type HasResolvedProperties } from '../../types/openapi/HasResolvedProperties.js';
|
1
|
+
import { type ReferenceObject, type SchemaObject } from 'openapi3-ts/oas31.js';
|
3
2
|
import { type SchemaPropertySelectorCondition } from '../../types/condition/SchemaPropertySelectorCondition.js';
|
4
3
|
/**
|
5
|
-
*
|
6
|
-
* @param schema
|
7
|
-
* @param condition
|
8
|
-
* @
|
4
|
+
* Recursively select properties including nested ones from a schema that match a condition.
|
5
|
+
* @param schema The schema object to search in
|
6
|
+
* @param condition The condition to match properties against
|
7
|
+
* @param parentPath Optional path prefix for nested properties
|
8
|
+
* @returns list of property names (possibly with dot notation for nested) that match the condition
|
9
9
|
*/
|
10
|
-
declare function schemaPropertySelector(schema: SchemaObject
|
11
|
-
export { schemaPropertySelector };
|
10
|
+
export declare function schemaPropertySelector(schema: SchemaObject | ReferenceObject, condition: SchemaPropertySelectorCondition, parentPath?: string): string[];
|
@@ -1,12 +1,36 @@
|
|
1
|
+
import { isReferenceObject } from '../openapi/isReferenceObject.js';
|
2
|
+
import { isSchemaObjectWithProperties } from '../openapi/isSchemaObjectWithProperties.js';
|
1
3
|
import { schemaPropertyChecker } from './schema/schemaPropertyChecker.js';
|
2
4
|
/**
|
3
|
-
*
|
4
|
-
* @param schema
|
5
|
-
* @param condition
|
6
|
-
* @
|
5
|
+
* Recursively select properties including nested ones from a schema that match a condition.
|
6
|
+
* @param schema The schema object to search in
|
7
|
+
* @param condition The condition to match properties against
|
8
|
+
* @param parentPath Optional path prefix for nested properties
|
9
|
+
* @returns list of property names (possibly with dot notation for nested) that match the condition
|
7
10
|
*/
|
8
|
-
function schemaPropertySelector(schema, condition) {
|
9
|
-
|
11
|
+
export function schemaPropertySelector(schema, condition, parentPath = '') {
|
12
|
+
if (isReferenceObject(schema)) {
|
13
|
+
return [];
|
14
|
+
}
|
15
|
+
if (!schema.properties) {
|
16
|
+
return [];
|
17
|
+
}
|
18
|
+
let result = [];
|
19
|
+
const properties = schema.properties;
|
20
|
+
for (const key of Object.keys(properties)) {
|
21
|
+
const propValue = properties[key];
|
22
|
+
const fullPath = parentPath ? `${parentPath}.${key}` : key;
|
23
|
+
if (isReferenceObject(propValue)) {
|
24
|
+
continue;
|
25
|
+
}
|
26
|
+
if (isSchemaObjectWithProperties(propValue)) {
|
27
|
+
const nestedProperties = schemaPropertySelector(propValue, condition, fullPath);
|
28
|
+
result = result.concat(nestedProperties);
|
29
|
+
}
|
30
|
+
else if (schemaPropertyChecker(schema, key, condition)) {
|
31
|
+
result.push(fullPath);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
return result;
|
10
35
|
}
|
11
|
-
export { schemaPropertySelector };
|
12
36
|
//# sourceMappingURL=schemaPropertySelector.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"schemaPropertySelector.js","sourceRoot":"","sources":["../../../src/lib/condition/schemaPropertySelector.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"schemaPropertySelector.js","sourceRoot":"","sources":["../../../src/lib/condition/schemaPropertySelector.ts"],"names":[],"mappings":"AAEA,OAAO,EA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
1
|
+
{"version":3,"file":"isJsonObject.js","sourceRoot":"","sources":["../../src/lib/isJsonObject.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,YAAY,CAAC,KAAW;IACpC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC/E,CAAC"}
|
@@ -1,6 +1,4 @@
|
|
1
|
-
import { type SchemaObject } from 'openapi3-ts/oas31.js';
|
2
|
-
import { type HasObjectExamples } from '../../types/openapi/HasObjectExamples.js';
|
3
|
-
import { type HasResolvedProperties } from '../../types/openapi/HasResolvedProperties.js';
|
1
|
+
import { type ReferenceObject, type SchemaObject } from 'openapi3-ts/oas31.js';
|
4
2
|
import { type SchemaPropertyVariantQuery } from '../../types/modification/SchemaPropertyVariantQuery.js';
|
5
3
|
import { type TestScenario } from '../../types/TestScenario.js';
|
6
4
|
interface ByValidity<T> {
|
@@ -10,7 +8,9 @@ interface ByValidity<T> {
|
|
10
8
|
/**
|
11
9
|
* Creates variants of the examples in the schema based on the queries.
|
12
10
|
*
|
13
|
-
* @
|
11
|
+
* @param schema The schema containing examples to modify
|
12
|
+
* @param queries Array of query objects specifying the modifications to make
|
13
|
+
* @returns Variants of the schema with the modifications applied, separated into valid and invalid
|
14
14
|
*/
|
15
|
-
export declare function createExampleVariantsFromSchemaOnQueries(schema: SchemaObject
|
15
|
+
export declare function createExampleVariantsFromSchemaOnQueries(schema: SchemaObject | ReferenceObject, queries: SchemaPropertyVariantQuery[]): ByValidity<TestScenario[]>;
|
16
16
|
export {};
|
@@ -2,7 +2,9 @@ import { createExampleVariantsFromSchemaOnQuery } from './createExampleVariantsF
|
|
2
2
|
/**
|
3
3
|
* Creates variants of the examples in the schema based on the queries.
|
4
4
|
*
|
5
|
-
* @
|
5
|
+
* @param schema The schema containing examples to modify
|
6
|
+
* @param queries Array of query objects specifying the modifications to make
|
7
|
+
* @returns Variants of the schema with the modifications applied, separated into valid and invalid
|
6
8
|
*/
|
7
9
|
export function createExampleVariantsFromSchemaOnQueries(schema, queries) {
|
8
10
|
return queries.reduce((acc, query) => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"createExampleVariantsFromSchemaOnQueries.js","sourceRoot":"","sources":["../../../src/lib/modification/createExampleVariantsFromSchemaOnQueries.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"createExampleVariantsFromSchemaOnQueries.js","sourceRoot":"","sources":["../../../src/lib/modification/createExampleVariantsFromSchemaOnQueries.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sCAAsC,EAAE,MAAM,6CAA6C,CAAA;AAOpG;;;;;;GAMG;AACH,MAAM,UAAU,wCAAwC,CACpD,MAAsC,EACtC,OAAqC;IAErC,OAAO,OAAO,CAAC,MAAM,CACjB,CAAC,GAA+B,EAAE,KAAK,EAA8B,EAAE;QACnE,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAA;QACrD,MAAM,eAAe,GAAG,sCAAsC,CAC1D,MAAM,EACN,KAAK,CAAC,KAAK,EACX,KAAK,CAAC,EAAE,CACX,CAAA;QAED,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,CAAA;QAEzC,OAAO,GAAG,CAAA;IACd,CAAC,EACD,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAC7B,CAAA;AACL,CAAC"}
|
@@ -1,12 +1,13 @@
|
|
1
|
-
import { type SchemaObject } from 'openapi3-ts/oas31.js';
|
2
|
-
import { type HasObjectExamples } from '../../types/openapi/HasObjectExamples.js';
|
3
|
-
import { type HasResolvedProperties } from '../../types/openapi/HasResolvedProperties.js';
|
4
|
-
import { type SchemaPropertyVariantAction } from '../../types/modification/SchemaPropertyVariantAction.js';
|
1
|
+
import { type ReferenceObject, type SchemaObject } from 'openapi3-ts/oas31.js';
|
5
2
|
import { type SchemaPropertySelectorCondition } from '../../types/condition/SchemaPropertySelectorCondition.js';
|
3
|
+
import { type SchemaPropertyVariantAction } from '../../types/modification/SchemaPropertyVariantAction.js';
|
6
4
|
import { type TestScenario } from '../../types/TestScenario.js';
|
7
5
|
/**
|
8
6
|
* Creates modifications of the examples in the schema based on the modification.
|
9
7
|
*
|
8
|
+
* @param schema The schema containing examples to modify
|
9
|
+
* @param condition The condition for selecting properties
|
10
|
+
* @param action The modification action to apply
|
10
11
|
* @returns variants of the schema with the modifications applied.
|
11
12
|
*/
|
12
|
-
export declare function createExampleVariantsFromSchemaOnQuery(schema: SchemaObject
|
13
|
+
export declare function createExampleVariantsFromSchemaOnQuery(schema: SchemaObject | ReferenceObject, condition: SchemaPropertySelectorCondition, action: SchemaPropertyVariantAction): TestScenario[];
|
@@ -3,6 +3,9 @@ import { modifyPropertyInSchemaExamples } from './modifyPropertyInSchemaExamples
|
|
3
3
|
/**
|
4
4
|
* Creates modifications of the examples in the schema based on the modification.
|
5
5
|
*
|
6
|
+
* @param schema The schema containing examples to modify
|
7
|
+
* @param condition The condition for selecting properties
|
8
|
+
* @param action The modification action to apply
|
6
9
|
* @returns variants of the schema with the modifications applied.
|
7
10
|
*/
|
8
11
|
export function createExampleVariantsFromSchemaOnQuery(schema, condition, action) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"createExampleVariantsFromSchemaOnQuery.js","sourceRoot":"","sources":["../../../src/lib/modification/createExampleVariantsFromSchemaOnQuery.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"createExampleVariantsFromSchemaOnQuery.js","sourceRoot":"","sources":["../../../src/lib/modification/createExampleVariantsFromSchemaOnQuery.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAA;AAC/E,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAA;AAEpF;;;;;;;GAOG;AACH,MAAM,UAAU,sCAAsC,CAClD,MAAsC,EACtC,SAA0C,EAC1C,MAAmC;IAEnC,OAAO,sBAAsB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAClE,8BAA8B,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAC3D,CAAA;AACL,CAAC"}
|
@@ -1,6 +1,4 @@
|
|
1
|
-
import { type SchemaObject } from 'openapi3-ts/oas31.js';
|
2
|
-
import { type HasObjectExamples } from '../../types/openapi/HasObjectExamples.js';
|
3
|
-
import { type HasResolvedProperties } from '../../types/openapi/HasResolvedProperties.js';
|
1
|
+
import { type ReferenceObject, type SchemaObject } from 'openapi3-ts/oas31.js';
|
4
2
|
import { type SchemaPropertyVariantQuery } from '../../types/modification/SchemaPropertyVariantQuery.js';
|
5
3
|
import { type TestScenariosFile } from '../../types/TestScenariosFile.js';
|
6
4
|
interface ByValidity<T> {
|
@@ -10,10 +8,12 @@ interface ByValidity<T> {
|
|
10
8
|
/**
|
11
9
|
* Creates variants of the examples in the schema based on the queries.
|
12
10
|
*
|
13
|
-
* @
|
11
|
+
* @param schemas Array of schemas to process with their keys
|
12
|
+
* @param queries Array of query objects specifying the modifications to make
|
13
|
+
* @returns Variants of the schema with the modifications applied indexed by schema title, split into valid and invalid examples
|
14
14
|
*/
|
15
15
|
export declare function createExampleVariantsFromSchemasOnQueries(schemas: {
|
16
16
|
key: string;
|
17
|
-
schema: SchemaObject
|
17
|
+
schema: SchemaObject | ReferenceObject;
|
18
18
|
}[], queries: SchemaPropertyVariantQuery[]): ByValidity<TestScenariosFile>;
|
19
19
|
export {};
|
@@ -1,8 +1,6 @@
|
|
1
|
-
import { createExampleVariantsFromSchemaOnQueries } from './createExampleVariantsFromSchemaOnQueries.js';
|
2
1
|
import { createHash } from 'crypto';
|
3
|
-
|
4
|
-
|
5
|
-
}
|
2
|
+
import { isJsonObject } from '../isJsonObject.js';
|
3
|
+
import { createExampleVariantsFromSchemaOnQueries } from './createExampleVariantsFromSchemaOnQueries.js';
|
6
4
|
function sortObject(value) {
|
7
5
|
if (Array.isArray(value)) {
|
8
6
|
return value.map((item) => sortObject(item));
|
@@ -35,7 +33,9 @@ function filterUnique(items) {
|
|
35
33
|
/**
|
36
34
|
* Creates variants of the examples in the schema based on the queries.
|
37
35
|
*
|
38
|
-
* @
|
36
|
+
* @param schemas Array of schemas to process with their keys
|
37
|
+
* @param queries Array of query objects specifying the modifications to make
|
38
|
+
* @returns Variants of the schema with the modifications applied indexed by schema title, split into valid and invalid examples
|
39
39
|
*/
|
40
40
|
export function createExampleVariantsFromSchemasOnQueries(schemas, queries) {
|
41
41
|
return schemas.reduce((acc, { key, schema }) => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"createExampleVariantsFromSchemasOnQueries.js","sourceRoot":"","sources":["../../../src/lib/modification/createExampleVariantsFromSchemasOnQueries.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"createExampleVariantsFromSchemasOnQueries.js","sourceRoot":"","sources":["../../../src/lib/modification/createExampleVariantsFromSchemasOnQueries.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAGnC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,wCAAwC,EAAE,MAAM,+CAA+C,CAAA;AAOxG,SAAS,UAAU,CAAiB,KAAQ;IACxC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAiB,IAAO,EAAK,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAM,CAAA;IAC3E,CAAC;IAED,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;aACtC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CA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AiC,EAAE;QACnF,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,wCAAwC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAEpF,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,CAAA;QACpC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;QAExC,OAAO,GAAG,CAAA;IACd,CAAC,EACD,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAC7B,CAAA;AACL,CAAC"}
|
@@ -1,12 +1,13 @@
|
|
1
1
|
import { type JsonObject } from '../../types/Json.js';
|
2
2
|
import { type SchemaPropertyVariantAction } from '../../types/modification/SchemaPropertyVariantAction.js';
|
3
3
|
/**
|
4
|
-
* Creates
|
4
|
+
* Creates a modified version of a JSON object by applying a property action
|
5
|
+
* (set or remove) at a specified path.
|
6
|
+
* Does not mutate the original object.
|
5
7
|
*
|
6
|
-
* @
|
7
|
-
*
|
8
|
-
* @param
|
9
|
-
* @
|
10
|
-
* @param property
|
8
|
+
* @param example The source JSON object to modify
|
9
|
+
* @param action The modification action (set or remove)
|
10
|
+
* @param propertyPath Dot-notation path to the target property (e.g., 'user.address.city')
|
11
|
+
* @returns A new JSON object with the modification applied
|
11
12
|
*/
|
12
|
-
export declare function modifyPropertyInExample(example: JsonObject,
|
13
|
+
export declare function modifyPropertyInExample(example: JsonObject, action: SchemaPropertyVariantAction, propertyPath: string): JsonObject;
|
@@ -1,24 +1,42 @@
|
|
1
1
|
import { isDefined } from '../../types/Defined.js';
|
2
|
+
import { isJsonObject } from '../isJsonObject.js';
|
2
3
|
/**
|
3
|
-
* Creates
|
4
|
+
* Creates a modified version of a JSON object by applying a property action
|
5
|
+
* (set or remove) at a specified path.
|
6
|
+
* Does not mutate the original object.
|
4
7
|
*
|
5
|
-
* @
|
6
|
-
*
|
7
|
-
* @param
|
8
|
-
* @
|
9
|
-
* @param property
|
8
|
+
* @param example The source JSON object to modify
|
9
|
+
* @param action The modification action (set or remove)
|
10
|
+
* @param propertyPath Dot-notation path to the target property (e.g., 'user.address.city')
|
11
|
+
* @returns A new JSON object with the modification applied
|
10
12
|
*/
|
11
|
-
export function modifyPropertyInExample(example,
|
12
|
-
const
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
export function modifyPropertyInExample(example, action, propertyPath) {
|
14
|
+
const segments = propertyPath.split('.');
|
15
|
+
const [currentKey, ...remainingPath] = segments;
|
16
|
+
const isLeafNode = remainingPath.length === 0;
|
17
|
+
if (isLeafNode) {
|
18
|
+
if (action.remove) {
|
19
|
+
const { [currentKey]: _, ...rest } = example;
|
20
|
+
return rest;
|
21
|
+
}
|
22
|
+
else if (isDefined(action.set)) {
|
23
|
+
return { ...example, [currentKey]: action.set };
|
16
24
|
}
|
17
|
-
|
25
|
+
return { ...example };
|
18
26
|
}
|
19
|
-
|
20
|
-
|
27
|
+
const currentValue = example[currentKey];
|
28
|
+
const nestedObject = isJsonObject(currentValue)
|
29
|
+
? currentValue
|
30
|
+
: isDefined(action.set)
|
31
|
+
? {}
|
32
|
+
: null;
|
33
|
+
if (nestedObject === null) {
|
34
|
+
return { ...example };
|
21
35
|
}
|
22
|
-
|
36
|
+
const modifiedNested = modifyPropertyInExample(nestedObject, action, remainingPath.join('.'));
|
37
|
+
return {
|
38
|
+
...example,
|
39
|
+
[currentKey]: modifiedNested,
|
40
|
+
};
|
23
41
|
}
|
24
42
|
//# sourceMappingURL=modifyPropertyInExample.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"modifyPropertyInExample.js","sourceRoot":"","sources":["../../../src/lib/modification/modifyPropertyInExample.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"modifyPropertyInExample.js","sourceRoot":"","sources":["../../../src/lib/modification/modifyPropertyInExample.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAA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C,UAAU,CAAC,EAAE,cAAc;KAC/B,CAAA;AACL,CAAC"}
|
@@ -1,15 +1,12 @@
|
|
1
|
-
import { type SchemaObject } from 'openapi3-ts/oas31.js';
|
2
|
-
import { type HasObjectExamples } from '../../types/openapi/HasObjectExamples.js';
|
3
|
-
import { type HasResolvedProperties } from '../../types/openapi/HasResolvedProperties.js';
|
1
|
+
import { type ReferenceObject, type SchemaObject } from 'openapi3-ts/oas31.js';
|
4
2
|
import { type SchemaPropertyVariantAction } from '../../types/modification/SchemaPropertyVariantAction.js';
|
5
3
|
import { type TestScenario } from '../../types/TestScenario.js';
|
6
4
|
/**
|
7
|
-
* Creates
|
5
|
+
* Creates modified test examples for a schema by applying an action to a specific property.
|
8
6
|
*
|
9
|
-
* @
|
10
|
-
*
|
11
|
-
* @param
|
12
|
-
* @
|
13
|
-
* @param property
|
7
|
+
* @param schema The OpenAPI schema containing examples
|
8
|
+
* @param action The modification action (set or remove) to apply
|
9
|
+
* @param propertyPath The property path to modify (dot notation)
|
10
|
+
* @returns A TestScenario with a descriptive name and modified examples
|
14
11
|
*/
|
15
|
-
export declare function modifyPropertyInSchemaExamples(schema: SchemaObject
|
12
|
+
export declare function modifyPropertyInSchemaExamples(schema: SchemaObject | ReferenceObject, action: SchemaPropertyVariantAction, propertyPath: string): TestScenario;
|
@@ -1,22 +1,44 @@
|
|
1
|
+
import { isJsonObject } from '../isJsonObject.js';
|
2
|
+
import { isReferenceObject } from '../openapi/isReferenceObject.js';
|
1
3
|
import { modifyPropertyInExample } from './modifyPropertyInExample.js';
|
2
4
|
import { truncate } from './truncateString.js';
|
3
5
|
/**
|
4
|
-
* Creates
|
6
|
+
* Creates modified test examples for a schema by applying an action to a specific property.
|
5
7
|
*
|
6
|
-
* @
|
7
|
-
*
|
8
|
-
* @param
|
9
|
-
* @
|
10
|
-
* @param property
|
8
|
+
* @param schema The OpenAPI schema containing examples
|
9
|
+
* @param action The modification action (set or remove) to apply
|
10
|
+
* @param propertyPath The property path to modify (dot notation)
|
11
|
+
* @returns A TestScenario with a descriptive name and modified examples
|
11
12
|
*/
|
12
|
-
export function modifyPropertyInSchemaExamples(schema,
|
13
|
+
export function modifyPropertyInSchemaExamples(schema, action, propertyPath) {
|
14
|
+
const scenarioDescription = getScenarioDescription(action, propertyPath);
|
15
|
+
const examples = getModifiedExamples(schema, action, propertyPath);
|
13
16
|
return {
|
14
|
-
scenario:
|
15
|
-
|
16
|
-
: modificationAction.remove !== undefined
|
17
|
-
? `Remove property ${property}`
|
18
|
-
: `Valid schema examples`,
|
19
|
-
examples: schema.examples.map((example) => modifyPropertyInExample(example, modificationAction, property)),
|
17
|
+
scenario: scenarioDescription,
|
18
|
+
examples,
|
20
19
|
};
|
21
20
|
}
|
21
|
+
/**
|
22
|
+
* Creates a human-readable description of the modification scenario
|
23
|
+
*/
|
24
|
+
function getScenarioDescription(action, propertyPath) {
|
25
|
+
if (action.set !== undefined) {
|
26
|
+
return `Set property ${propertyPath} to ${truncate(JSON.stringify(action.set))}`;
|
27
|
+
}
|
28
|
+
if (action.remove) {
|
29
|
+
return `Remove property ${propertyPath}`;
|
30
|
+
}
|
31
|
+
return 'Valid schema examples';
|
32
|
+
}
|
33
|
+
/**
|
34
|
+
* Returns modified examples based on the action and schema
|
35
|
+
*/
|
36
|
+
function getModifiedExamples(schema, action, propertyPath) {
|
37
|
+
if (isReferenceObject(schema) || !schema.examples) {
|
38
|
+
return [];
|
39
|
+
}
|
40
|
+
return schema.examples
|
41
|
+
.filter(isJsonObject)
|
42
|
+
.map((example) => modifyPropertyInExample(example, action, propertyPath));
|
43
|
+
}
|
22
44
|
//# sourceMappingURL=modifyPropertyInSchemaExamples.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"modifyPropertyInSchemaExamples.js","sourceRoot":"","sources":["../../../src/lib/modification/modifyPropertyInSchemaExamples.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"modifyPropertyInSchemaExamples.js","sourceRoot":"","sources":["../../../src/l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BAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAA;AACjF,CAAC"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { type OpenAPIObject, type SchemaObject } from 'openapi3-ts/oas31.js';
|
1
|
+
import { type OpenAPIObject, type ReferenceObject, type SchemaObject } from 'openapi3-ts/oas31.js';
|
2
2
|
/**
|
3
3
|
* @see [RFC 6901](https://datatracker.ietf.org/doc/html/rfc6901)
|
4
4
|
* @see [RFC 8259](https://datatracker.ietf.org/doc/html/rfc8259)
|
@@ -19,5 +19,5 @@ export declare class PropertyResolver {
|
|
19
19
|
* @todo Support for external references.
|
20
20
|
* @todo Properly parse JSON.
|
21
21
|
*/
|
22
|
-
resolve(reference: string): Promise<SchemaObject>;
|
22
|
+
resolve(reference: string): Promise<SchemaObject | ReferenceObject>;
|
23
23
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"PropertyResolver.js","sourceRoot":"","sources":["../../../src/lib/openapi/PropertyResolver.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"PropertyResolver.js","sourceRoot":"","sources":["../../../src/lib/openapi/PropertyResolver.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,aAAa,CAAA;AAGrC;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IAIL;IAHpB;;OAEG;IACH,YAAoB,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAE7C;;;;;;;;;OASG;IACH,4DAA4D;IACrD,KAAK,CAAC,OAAO,CAAC,SAAiB;QAClC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAA;QACvF,CAAC;QAED,6BAA6B;QAC7B,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAGjD,CAAA;QAEf,IAAI,CAAC,QAAQ,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,gCAAgC,SAAS,EAAE,CAAC,CAAA;QAChE,CAAC;QAED,OAAO,QAAQ,CAAA;IACnB,CAAC;CACJ"}
|