@nldoc/openapi-test-set-generator 1.2.18
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/LICENSE.txt +287 -0
- package/README.md +9 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +5 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +5 -0
- package/dist/commands/extract-examples.d.ts +9 -0
- package/dist/commands/extract-examples.js +42 -0
- package/dist/commands/extract-examples.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/condition/schema/schemaPropertyChecker.d.ts +14 -0
- package/dist/lib/condition/schema/schemaPropertyChecker.js +44 -0
- package/dist/lib/condition/schema/schemaPropertyChecker.js.map +1 -0
- package/dist/lib/condition/schemaPropertySelector.d.ts +11 -0
- package/dist/lib/condition/schemaPropertySelector.js +12 -0
- package/dist/lib/condition/schemaPropertySelector.js.map +1 -0
- package/dist/lib/condition/value/numberChecker.d.ts +2 -0
- package/dist/lib/condition/value/numberChecker.js +34 -0
- package/dist/lib/condition/value/numberChecker.js.map +1 -0
- package/dist/lib/condition/value/simpleEqualityChecker.d.ts +5 -0
- package/dist/lib/condition/value/simpleEqualityChecker.js +17 -0
- package/dist/lib/condition/value/simpleEqualityChecker.js.map +1 -0
- package/dist/lib/importOpenAPIFile.d.ts +10 -0
- package/dist/lib/importOpenAPIFile.js +11 -0
- package/dist/lib/importOpenAPIFile.js.map +1 -0
- package/dist/lib/modification/createExampleVariantsFromSchemaOnQueries.d.ts +16 -0
- package/dist/lib/modification/createExampleVariantsFromSchemaOnQueries.js +15 -0
- package/dist/lib/modification/createExampleVariantsFromSchemaOnQueries.js.map +1 -0
- package/dist/lib/modification/createExampleVariantsFromSchemaOnQuery.d.ts +12 -0
- package/dist/lib/modification/createExampleVariantsFromSchemaOnQuery.js +11 -0
- package/dist/lib/modification/createExampleVariantsFromSchemaOnQuery.js.map +1 -0
- package/dist/lib/modification/createExampleVariantsFromSchemasOnQueries.d.ts +19 -0
- package/dist/lib/modification/createExampleVariantsFromSchemasOnQueries.js +48 -0
- package/dist/lib/modification/createExampleVariantsFromSchemasOnQueries.js.map +1 -0
- package/dist/lib/modification/modifyPropertyInExample.d.ts +12 -0
- package/dist/lib/modification/modifyPropertyInExample.js +24 -0
- package/dist/lib/modification/modifyPropertyInExample.js.map +1 -0
- package/dist/lib/modification/modifyPropertyInSchemaExamples.d.ts +15 -0
- package/dist/lib/modification/modifyPropertyInSchemaExamples.js +22 -0
- package/dist/lib/modification/modifyPropertyInSchemaExamples.js.map +1 -0
- package/dist/lib/modification/truncateString.d.ts +9 -0
- package/dist/lib/modification/truncateString.js +12 -0
- package/dist/lib/modification/truncateString.js.map +1 -0
- package/dist/lib/openapi/PropertyResolver.d.ts +23 -0
- package/dist/lib/openapi/PropertyResolver.js +37 -0
- package/dist/lib/openapi/PropertyResolver.js.map +1 -0
- package/dist/lib/openapi/SchemaPropertyResolver.d.ts +21 -0
- package/dist/lib/openapi/SchemaPropertyResolver.js +33 -0
- package/dist/lib/openapi/SchemaPropertyResolver.js.map +1 -0
- package/dist/lib/openapi/extractObjectSchemasWithExamples.d.ts +8 -0
- package/dist/lib/openapi/extractObjectSchemasWithExamples.js +16 -0
- package/dist/lib/openapi/extractObjectSchemasWithExamples.js.map +1 -0
- package/dist/lib/openapi/schemaObjectHasProperty.d.ts +6 -0
- package/dist/lib/openapi/schemaObjectHasProperty.js +8 -0
- package/dist/lib/openapi/schemaObjectHasProperty.js.map +1 -0
- package/dist/lib/writeJsonToFile.d.ts +8 -0
- package/dist/lib/writeJsonToFile.js +13 -0
- package/dist/lib/writeJsonToFile.js.map +1 -0
- package/dist/types/Defined.d.ts +2 -0
- package/dist/types/Defined.js +2 -0
- package/dist/types/Defined.js.map +1 -0
- package/dist/types/InputFile.d.ts +432 -0
- package/dist/types/InputFile.js +24 -0
- package/dist/types/InputFile.js.map +1 -0
- package/dist/types/Json.d.ts +9 -0
- package/dist/types/Json.js +5 -0
- package/dist/types/Json.js.map +1 -0
- package/dist/types/TestScenario.d.ts +12 -0
- package/dist/types/TestScenario.js +7 -0
- package/dist/types/TestScenario.js.map +1 -0
- package/dist/types/TestScenariosFile.d.ts +12 -0
- package/dist/types/TestScenariosFile.js +4 -0
- package/dist/types/TestScenariosFile.js.map +1 -0
- package/dist/types/condition/IntegerCondition.d.ts +27 -0
- package/dist/types/condition/IntegerCondition.js +15 -0
- package/dist/types/condition/IntegerCondition.js.map +1 -0
- package/dist/types/condition/SchemaPropertySelectorCondition.d.ts +144 -0
- package/dist/types/condition/SchemaPropertySelectorCondition.js +15 -0
- package/dist/types/condition/SchemaPropertySelectorCondition.js.map +1 -0
- package/dist/types/condition/StringCondition.d.ts +15 -0
- package/dist/types/condition/StringCondition.js +10 -0
- package/dist/types/condition/StringCondition.js.map +1 -0
- package/dist/types/modification/SchemaPropertyVariantAction.d.ts +13 -0
- package/dist/types/modification/SchemaPropertyVariantAction.js +7 -0
- package/dist/types/modification/SchemaPropertyVariantAction.js.map +1 -0
- package/dist/types/modification/SchemaPropertyVariantQuery.d.ts +233 -0
- package/dist/types/modification/SchemaPropertyVariantQuery.js +11 -0
- package/dist/types/modification/SchemaPropertyVariantQuery.js.map +1 -0
- package/dist/types/openapi/HasObjectExamples.d.ts +4 -0
- package/dist/types/openapi/HasObjectExamples.js +2 -0
- package/dist/types/openapi/HasObjectExamples.js.map +1 -0
- package/dist/types/openapi/HasResolvedProperties.d.ts +4 -0
- package/dist/types/openapi/HasResolvedProperties.js +2 -0
- package/dist/types/openapi/HasResolvedProperties.js.map +1 -0
- package/package.json +71 -0
@@ -0,0 +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';
|
4
|
+
import { type SchemaPropertyVariantAction } from '../../types/modification/SchemaPropertyVariantAction.js';
|
5
|
+
import { type SchemaPropertySelectorCondition } from '../../types/condition/SchemaPropertySelectorCondition.js';
|
6
|
+
import { type TestScenario } from '../../types/TestScenario.js';
|
7
|
+
/**
|
8
|
+
* Creates modifications of the examples in the schema based on the modification.
|
9
|
+
*
|
10
|
+
* @returns variants of the schema with the modifications applied.
|
11
|
+
*/
|
12
|
+
export declare function createExampleVariantsFromSchemaOnQuery(schema: SchemaObject & HasObjectExamples & HasResolvedProperties, condition: SchemaPropertySelectorCondition, action: SchemaPropertyVariantAction): TestScenario[];
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { schemaPropertySelector } from '../condition/schemaPropertySelector.js';
|
2
|
+
import { modifyPropertyInSchemaExamples } from './modifyPropertyInSchemaExamples.js';
|
3
|
+
/**
|
4
|
+
* Creates modifications of the examples in the schema based on the modification.
|
5
|
+
*
|
6
|
+
* @returns variants of the schema with the modifications applied.
|
7
|
+
*/
|
8
|
+
export function createExampleVariantsFromSchemaOnQuery(schema, condition, action) {
|
9
|
+
return schemaPropertySelector(schema, condition).flatMap((property) => modifyPropertyInSchemaExamples(schema, action, property));
|
10
|
+
}
|
11
|
+
//# sourceMappingURL=createExampleVariantsFromSchemaOnQuery.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"createExampleVariantsFromSchemaOnQuery.js","sourceRoot":"","sources":["../../../src/lib/modification/createExampleVariantsFromSchemaOnQuery.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAA;AAG/E,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAA;AAGpF;;;;GAIG;AACH,MAAM,UAAU,sCAAsC,CAClD,MAAgE,EAChE,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"}
|
@@ -0,0 +1,19 @@
|
|
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 SchemaPropertyVariantQuery } from '../../types/modification/SchemaPropertyVariantQuery.js';
|
5
|
+
import { type TestScenariosFile } from '../../types/TestScenariosFile.js';
|
6
|
+
interface ByValidity<T> {
|
7
|
+
valid: T;
|
8
|
+
invalid: T;
|
9
|
+
}
|
10
|
+
/**
|
11
|
+
* Creates variants of the examples in the schema based on the queries.
|
12
|
+
*
|
13
|
+
* @returns Variants of the schema with the modifications applied indexed by schema title.
|
14
|
+
*/
|
15
|
+
export declare function createExampleVariantsFromSchemasOnQueries(schemas: {
|
16
|
+
key: string;
|
17
|
+
schema: SchemaObject & HasObjectExamples & HasResolvedProperties;
|
18
|
+
}[], queries: SchemaPropertyVariantQuery[]): ByValidity<TestScenariosFile>;
|
19
|
+
export {};
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { createExampleVariantsFromSchemaOnQueries } from './createExampleVariantsFromSchemaOnQueries.js';
|
2
|
+
import { createHash } from 'crypto';
|
3
|
+
function isJsonObject(value) {
|
4
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
5
|
+
}
|
6
|
+
function sortObject(value) {
|
7
|
+
if (Array.isArray(value)) {
|
8
|
+
return value.map((item) => sortObject(item));
|
9
|
+
}
|
10
|
+
if (isJsonObject(value)) {
|
11
|
+
const sortedEntries = Object.entries(value)
|
12
|
+
.sort(([keyA, _valueA], [keyB, _valueB]) => keyA.localeCompare(keyB))
|
13
|
+
.map(([key, objectValue]) => [
|
14
|
+
key,
|
15
|
+
sortObject(objectValue),
|
16
|
+
]);
|
17
|
+
return Object.fromEntries(sortedEntries);
|
18
|
+
}
|
19
|
+
return value;
|
20
|
+
}
|
21
|
+
function hashObject(value) {
|
22
|
+
const serializedObject = JSON.stringify(sortObject(value));
|
23
|
+
return createHash('sha256').update(serializedObject).digest('hex');
|
24
|
+
}
|
25
|
+
function filterUnique(items) {
|
26
|
+
return items.reduce(({ hashes, values }, value) => {
|
27
|
+
const hash = hashObject(value);
|
28
|
+
if (!hashes.includes(hash)) {
|
29
|
+
hashes.push(hash);
|
30
|
+
values.push(value);
|
31
|
+
}
|
32
|
+
return { hashes, values };
|
33
|
+
}, { hashes: [], values: [] }).values;
|
34
|
+
}
|
35
|
+
/**
|
36
|
+
* Creates variants of the examples in the schema based on the queries.
|
37
|
+
*
|
38
|
+
* @returns Variants of the schema with the modifications applied indexed by schema title.
|
39
|
+
*/
|
40
|
+
export function createExampleVariantsFromSchemasOnQueries(schemas, queries) {
|
41
|
+
return schemas.reduce((acc, { key, schema }) => {
|
42
|
+
const { valid, invalid } = createExampleVariantsFromSchemaOnQueries(schema, queries);
|
43
|
+
acc.valid[key] = filterUnique(valid);
|
44
|
+
acc.invalid[key] = filterUnique(invalid);
|
45
|
+
return acc;
|
46
|
+
}, { valid: {}, invalid: {} });
|
47
|
+
}
|
48
|
+
//# sourceMappingURL=createExampleVariantsFromSchemasOnQueries.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"createExampleVariantsFromSchemasOnQueries.js","sourceRoot":"","sources":["../../../src/lib/modification/createExampleVariantsFromSchemasOnQueries.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,wCAAwC,EAAE,MAAM,+CAA+C,CAAA;AACxG,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAQnC,SAAS,YAAY,CAAC,KAAW;IAC7B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC/E,CAAC;AAED,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,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;aACpE,GAAG,CAAC,CAAiB,CAAC,GAAG,EAAE,WAAW,CAAc,EAAe,EAAE,CAAC;YACnE,GAAG;YACH,UAAU,CAAC,WAAW,CAAC;SAC1B,CAAC,CAAA;QAEN,OAAO,MAAM,CAAC,WAAW,CAAC,aAAa,CAAM,CAAA;IACjD,CAAC;IAED,OAAO,KAAK,CAAA;AAChB,CAAC;AAED,SAAS,UAAU,CAAC,KAAiB;IACjC,MAAM,gBAAgB,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAA;IAC1D,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACtE,CAAC;AAOD,SAAS,YAAY,CAAuB,KAAU;IAClD,OAAO,KAAK,CAAC,MAAM,CACf,CAAC,EAAE,MAAM,EAAE,MAAM,EAA6B,EAAE,KAAQ,EAA6B,EAAE;QACnF,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,CAAA;QAE9B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACjB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACtB,CAAC;QAED,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAA;IAC7B,CAAC,EACD,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAC7B,CAAC,MAAM,CAAA;AACZ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yCAAyC,CACrD,OAA4F,EAC5F,OAAqC;IAErC,OAAO,OAAO,CAAC,MAAM,CACjB,CAAC,GAAkC,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,EAAiC,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"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { type JsonObject } from '../../types/Json.js';
|
2
|
+
import { type SchemaPropertyVariantAction } from '../../types/modification/SchemaPropertyVariantAction.js';
|
3
|
+
/**
|
4
|
+
* Creates modifications on a single example for a single property based on the modification.
|
5
|
+
*
|
6
|
+
* @returns Variants of the schema with the modifications applied.
|
7
|
+
*
|
8
|
+
* @param example
|
9
|
+
* @param modificationAction
|
10
|
+
* @param property
|
11
|
+
*/
|
12
|
+
export declare function modifyPropertyInExample(example: JsonObject, modificationAction: SchemaPropertyVariantAction, property: string): JsonObject;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { isDefined } from '../../types/Defined.js';
|
2
|
+
/**
|
3
|
+
* Creates modifications on a single example for a single property based on the modification.
|
4
|
+
*
|
5
|
+
* @returns Variants of the schema with the modifications applied.
|
6
|
+
*
|
7
|
+
* @param example
|
8
|
+
* @param modificationAction
|
9
|
+
* @param property
|
10
|
+
*/
|
11
|
+
export function modifyPropertyInExample(example, modificationAction, property) {
|
12
|
+
const newExample = {};
|
13
|
+
for (const key in example) {
|
14
|
+
if (modificationAction.remove && key === property) {
|
15
|
+
continue;
|
16
|
+
}
|
17
|
+
newExample[key] = example[key];
|
18
|
+
}
|
19
|
+
if (isDefined(modificationAction.set)) {
|
20
|
+
newExample[property] = modificationAction.set;
|
21
|
+
}
|
22
|
+
return newExample;
|
23
|
+
}
|
24
|
+
//# sourceMappingURL=modifyPropertyInExample.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"modifyPropertyInExample.js","sourceRoot":"","sources":["../../../src/lib/modification/modifyPropertyInExample.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAElD;;;;;;;;GAQG;AACH,MAAM,UAAU,uBAAuB,CACnC,OAAmB,EACnB,kBAA+C,EAC/C,QAAgB;IAEhB,MAAM,UAAU,GAAe,EAAE,CAAA;IAEjC,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QACxB,IAAI,kBAAkB,CAAC,MAAM,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;YAChD,SAAQ;QACZ,CAAC;QAED,UAAU,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;IAClC,CAAC;IAED,IAAI,SAAS,CAAC,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC;QACpC,UAAU,CAAC,QAAQ,CAAC,GAAG,kBAAkB,CAAC,GAAG,CAAA;IACjD,CAAC;IAED,OAAO,UAAU,CAAA;AACrB,CAAC"}
|
@@ -0,0 +1,15 @@
|
|
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';
|
5
|
+
import { type TestScenario } from '../../types/TestScenario.js';
|
6
|
+
/**
|
7
|
+
* Creates modifications of the examples in the schema for a single property based on the modification.
|
8
|
+
*
|
9
|
+
* @returns variants of the schema with the modifications applied.
|
10
|
+
*
|
11
|
+
* @param schema
|
12
|
+
* @param modificationAction
|
13
|
+
* @param property
|
14
|
+
*/
|
15
|
+
export declare function modifyPropertyInSchemaExamples(schema: SchemaObject & HasObjectExamples & HasResolvedProperties, modificationAction: SchemaPropertyVariantAction, property: string): TestScenario;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { modifyPropertyInExample } from './modifyPropertyInExample.js';
|
2
|
+
import { truncate } from './truncateString.js';
|
3
|
+
/**
|
4
|
+
* Creates modifications of the examples in the schema for a single property based on the modification.
|
5
|
+
*
|
6
|
+
* @returns variants of the schema with the modifications applied.
|
7
|
+
*
|
8
|
+
* @param schema
|
9
|
+
* @param modificationAction
|
10
|
+
* @param property
|
11
|
+
*/
|
12
|
+
export function modifyPropertyInSchemaExamples(schema, modificationAction, property) {
|
13
|
+
return {
|
14
|
+
scenario: modificationAction.set !== undefined
|
15
|
+
? `Set property ${property} to ${truncate(JSON.stringify(modificationAction.set))}`
|
16
|
+
: modificationAction.remove !== undefined
|
17
|
+
? `Remove property ${property}`
|
18
|
+
: `Valid schema examples`,
|
19
|
+
examples: schema.examples.map((example) => modifyPropertyInExample(example, modificationAction, property)),
|
20
|
+
};
|
21
|
+
}
|
22
|
+
//# sourceMappingURL=modifyPropertyInSchemaExamples.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"modifyPropertyInSchemaExamples.js","sourceRoot":"","sources":["../../../src/lib/modification/modifyPropertyInSchemaExamples.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAG9C;;;;;;;;GAQG;AACH,MAAM,UAAU,8BAA8B,CAC1C,MAAgE,EAChE,kBAA+C,EAC/C,QAAgB;IAEhB,OAAO;QACH,QAAQ,EACJ,kBAAkB,CAAC,GAAG,KAAK,SAAS;YAChC,CAAC,CAAC,gBAAgB,QAAQ,OAAO,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,EAAE;YACnF,CAAC,CAAC,kBAAkB,CAAC,MAAM,KAAK,SAAS;gBACvC,CAAC,CAAC,mBAAmB,QAAQ,EAAE;gBAC/B,CAAC,CAAC,uBAAuB;QACnC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAmB,EAAE,EAAE,CAClD,uBAAuB,CAAC,OAAO,EAAE,kBAAkB,EAAE,QAAQ,CAAC,CACjE;KACJ,CAAA;AACL,CAAC"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/**
|
2
|
+
* Truncate a string that exceeds the maximum length and add '...'.
|
3
|
+
*
|
4
|
+
* @returns truncated string
|
5
|
+
*
|
6
|
+
* @param text
|
7
|
+
* @param maxLength
|
8
|
+
*/
|
9
|
+
export function truncate(text, maxLength = 50) {
|
10
|
+
return text.length > maxLength ? text.slice(0, maxLength) + '...' : text;
|
11
|
+
}
|
12
|
+
//# sourceMappingURL=truncateString.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"truncateString.js","sourceRoot":"","sources":["../../../src/lib/modification/truncateString.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,SAAS,GAAG,EAAE;IACjD,OAAO,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAA;AAC5E,CAAC"}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { type OpenAPIObject, type SchemaObject } from 'openapi3-ts/oas31.js';
|
2
|
+
/**
|
3
|
+
* @see [RFC 6901](https://datatracker.ietf.org/doc/html/rfc6901)
|
4
|
+
* @see [RFC 8259](https://datatracker.ietf.org/doc/html/rfc8259)
|
5
|
+
*/
|
6
|
+
export declare class PropertyResolver {
|
7
|
+
private schema;
|
8
|
+
/**
|
9
|
+
* @param {OpenAPIObject} schema - The schema that contains the reference(s).
|
10
|
+
*/
|
11
|
+
constructor(schema: OpenAPIObject);
|
12
|
+
/**
|
13
|
+
* @param {string} reference - The reference to resolve
|
14
|
+
* @returns Resolved property
|
15
|
+
*
|
16
|
+
* @throws Error Property was not resolvable due to it being an external resource
|
17
|
+
* @throws Error Property was not resolvable
|
18
|
+
*
|
19
|
+
* @todo Support for external references.
|
20
|
+
* @todo Properly parse JSON.
|
21
|
+
*/
|
22
|
+
resolve(reference: string): Promise<SchemaObject>;
|
23
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import JsonPointer from 'jsonpointer';
|
2
|
+
/**
|
3
|
+
* @see [RFC 6901](https://datatracker.ietf.org/doc/html/rfc6901)
|
4
|
+
* @see [RFC 8259](https://datatracker.ietf.org/doc/html/rfc8259)
|
5
|
+
*/
|
6
|
+
export class PropertyResolver {
|
7
|
+
schema;
|
8
|
+
/**
|
9
|
+
* @param {OpenAPIObject} schema - The schema that contains the reference(s).
|
10
|
+
*/
|
11
|
+
constructor(schema) {
|
12
|
+
this.schema = schema;
|
13
|
+
}
|
14
|
+
/**
|
15
|
+
* @param {string} reference - The reference to resolve
|
16
|
+
* @returns Resolved property
|
17
|
+
*
|
18
|
+
* @throws Error Property was not resolvable due to it being an external resource
|
19
|
+
* @throws Error Property was not resolvable
|
20
|
+
*
|
21
|
+
* @todo Support for external references.
|
22
|
+
* @todo Properly parse JSON.
|
23
|
+
*/
|
24
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
25
|
+
async resolve(reference) {
|
26
|
+
if (!reference.startsWith('#')) {
|
27
|
+
throw new Error('Property was not resolvable due to it being an external resource');
|
28
|
+
}
|
29
|
+
// @todo Properly parse JSON.
|
30
|
+
const resolved = JsonPointer.get(this.schema, reference.slice(1));
|
31
|
+
if (!resolved) {
|
32
|
+
throw new Error(`Property was not resolvable: ${reference}`);
|
33
|
+
}
|
34
|
+
return resolved;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
//# sourceMappingURL=PropertyResolver.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"PropertyResolver.js","sourceRoot":"","sources":["../../../src/lib/openapi/PropertyResolver.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,aAAa,CAAA;AAErC;;;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,CAEjD,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"}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { type PropertyResolver } from './PropertyResolver.js';
|
2
|
+
import { type SchemaObject } from 'openapi3-ts/oas31.js';
|
3
|
+
import { type HasResolvedProperties } from '../../types/openapi/HasResolvedProperties.js';
|
4
|
+
export declare class SchemaPropertyResolver {
|
5
|
+
private resolver;
|
6
|
+
constructor(resolver: PropertyResolver);
|
7
|
+
/**
|
8
|
+
* Resolve all properties of a schema.
|
9
|
+
*
|
10
|
+
* @param {SchemaObject} schema - The schema that contains the properties to resolve
|
11
|
+
*
|
12
|
+
* @todo Use `Promise.all` to resolve all properties concurrently.
|
13
|
+
*/
|
14
|
+
resolveProperties<T extends SchemaObject>({ key, schema, }: {
|
15
|
+
key: string;
|
16
|
+
schema: T;
|
17
|
+
}): Promise<{
|
18
|
+
key: string;
|
19
|
+
schema: T & HasResolvedProperties;
|
20
|
+
}>;
|
21
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
function isReferenceObject(schema) {
|
2
|
+
return '$ref' in schema;
|
3
|
+
}
|
4
|
+
export class SchemaPropertyResolver {
|
5
|
+
resolver;
|
6
|
+
constructor(resolver) {
|
7
|
+
this.resolver = resolver;
|
8
|
+
}
|
9
|
+
/**
|
10
|
+
* Resolve all properties of a schema.
|
11
|
+
*
|
12
|
+
* @param {SchemaObject} schema - The schema that contains the properties to resolve
|
13
|
+
*
|
14
|
+
* @todo Use `Promise.all` to resolve all properties concurrently.
|
15
|
+
*/
|
16
|
+
async resolveProperties({ key, schema, }) {
|
17
|
+
if (!schema.properties) {
|
18
|
+
return { key, schema: { ...schema, properties: undefined } };
|
19
|
+
}
|
20
|
+
const resolvedProperties = {};
|
21
|
+
for (const key in schema.properties) {
|
22
|
+
const property = schema.properties[key];
|
23
|
+
if (isReferenceObject(property)) {
|
24
|
+
resolvedProperties[key] = await this.resolver.resolve(property.$ref);
|
25
|
+
}
|
26
|
+
else {
|
27
|
+
resolvedProperties[key] = property;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
return { key, schema: { ...schema, properties: resolvedProperties } };
|
31
|
+
}
|
32
|
+
}
|
33
|
+
//# sourceMappingURL=SchemaPropertyResolver.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"SchemaPropertyResolver.js","sourceRoot":"","sources":["../../../src/lib/openapi/SchemaPropertyResolver.ts"],"names":[],"mappings":"AAIA,SAAS,iBAAiB,CAAC,MAAsC;IAC7D,OAAO,MAAM,IAAI,MAAM,CAAA;AAC3B,CAAC;AAED,MAAM,OAAO,sBAAsB;IACX;IAApB,YAAoB,QAA0B;QAA1B,aAAQ,GAAR,QAAQ,CAAkB;IAAG,CAAC;IAElD;;;;;;OAMG;IACI,KAAK,CAAC,iBAAiB,CAAyB,EACnD,GAAG,EACH,MAAM,GAIT;QACG,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YACrB,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,CAAA;QAChE,CAAC;QAED,MAAM,kBAAkB,GAAiC,EAAE,CAAA;QAE3D,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YAClC,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;YAEvC,IAAI,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC9B,kBAAkB,CAAC,GAAG,CAAC,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;YACxE,CAAC;iBAAM,CAAC;gBACJ,kBAAkB,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAA;YACtC,CAAC;QACL,CAAC;QAED,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE,EAAE,CAAA;IACzE,CAAC;CACJ"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { type OpenAPIObject, type SchemaObject } from 'openapi3-ts/oas31.js';
|
2
|
+
import { type HasObjectExamples } from '../../types/openapi/HasObjectExamples.js';
|
3
|
+
type SchemaWithExamples = SchemaObject & HasObjectExamples;
|
4
|
+
export declare function extractObjectSchemasWithExamples(openApi: OpenAPIObject): Promise<{
|
5
|
+
key: string;
|
6
|
+
schema: SchemaWithExamples;
|
7
|
+
}[]>;
|
8
|
+
export {};
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { JsonObject } from '../../types/Json.js';
|
2
|
+
import { z } from 'zod';
|
3
|
+
const isSchemaObjectWithExamples = (schema) => 'examples' in schema[1] && (schema[1].examples?.length ?? 0) > 0 && schema[1].type === 'object';
|
4
|
+
export async function extractObjectSchemasWithExamples(openApi) {
|
5
|
+
const promisedSchemas = Object.entries(openApi.components?.schemas ?? {})
|
6
|
+
.filter(isSchemaObjectWithExamples)
|
7
|
+
.map((schema) => z
|
8
|
+
.array(JsonObject)
|
9
|
+
.parseAsync(schema[1].examples)
|
10
|
+
.then((examples) => ({
|
11
|
+
key: schema[0],
|
12
|
+
schema: { ...schema[1], examples: examples },
|
13
|
+
})));
|
14
|
+
return Promise.all(promisedSchemas);
|
15
|
+
}
|
16
|
+
//# sourceMappingURL=extractObjectSchemasWithExamples.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"extractObjectSchemasWithExamples.js","sourceRoot":"","sources":["../../../src/lib/openapi/extractObjectSchemasWithExamples.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAKvB,MAAM,0BAA0B,GAAG,CAC/B,MAAgD,EAChB,EAAE,CAClC,UAAU,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAA;AAEnG,MAAM,CAAC,KAAK,UAAU,gCAAgC,CAClD,OAAsB;IAEtB,MAAM,eAAe,GAA2D,MAAM,CAAC,OAAO,CAC1F,OAAO,CAAC,UAAU,EAAE,OAAO,IAAI,EAAE,CACpC;SACI,MAAM,CAAC,0BAA0B,CAAC;SAClC,GAAG,CACA,CAAC,MAAM,EAAwD,EAAE,CAC7D,CAAC;SACI,KAAK,CAAC,UAAU,CAAC;SACjB,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;SAC9B,IAAI,CAAC,CAAC,QAAsB,EAAE,EAAE,CAAC,CAAC;QAC/B,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC;QACd,MAAM,EAAE,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE;KAC/C,CAAC,CAAC,CACd,CAAA;IAEL,OAAO,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;AACvC,CAAC"}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { type SchemaObject } from 'openapi3-ts/oas31.js';
|
2
|
+
declare function schemaObjectHasProperty(schema: SchemaObject & {
|
3
|
+
properties?: undefined | Record<string, never>;
|
4
|
+
}, _propertyKey: string): false;
|
5
|
+
declare function schemaObjectHasProperty(schema: SchemaObject, propertyKey: string): boolean;
|
6
|
+
export { schemaObjectHasProperty };
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"schemaObjectHasProperty.js","sourceRoot":"","sources":["../../../src/lib/openapi/schemaObjectHasProperty.ts"],"names":[],"mappings":"AAOA,SAAS,uBAAuB,CAAC,MAAoB,EAAE,WAAmB;IACtE,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QACrB,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,OAAO,WAAW,IAAI,MAAM,CAAC,UAAU,CAAA;AAC3C,CAAC;AAED,OAAO,EAAE,uBAAuB,EAAE,CAAA"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { type Json } from '../types/Json.js';
|
2
|
+
/**
|
3
|
+
* Export JSON to a file. Creates base directory if it does not exist.
|
4
|
+
*
|
5
|
+
* @param {string} destinationPath - The path to write to.
|
6
|
+
* @param {Json} data - The contents to write to the file.
|
7
|
+
*/
|
8
|
+
export declare const writeJsonToFile: (destinationPath: string, data: Json) => Promise<void>;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { promises as fs } from 'fs';
|
2
|
+
import path from 'node:path';
|
3
|
+
/**
|
4
|
+
* Export JSON to a file. Creates base directory if it does not exist.
|
5
|
+
*
|
6
|
+
* @param {string} destinationPath - The path to write to.
|
7
|
+
* @param {Json} data - The contents to write to the file.
|
8
|
+
*/
|
9
|
+
export const writeJsonToFile = async (destinationPath, data) => {
|
10
|
+
await fs.mkdir(path.dirname(destinationPath), { recursive: true });
|
11
|
+
await fs.writeFile(destinationPath, JSON.stringify(data, null, 2) + '\n', 'utf-8');
|
12
|
+
};
|
13
|
+
//# sourceMappingURL=writeJsonToFile.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"writeJsonToFile.js","sourceRoot":"","sources":["../../src/lib/writeJsonToFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAA;AAEnC,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,eAAuB,EAAE,IAAU,EAAiB,EAAE;IACxF,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAClE,MAAM,EAAE,CAAC,SAAS,CAAC,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,CAAC,CAAA;AACtF,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Defined.js","sourceRoot":"","sources":["../../src/types/Defined.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAI,KAAoB,EAAuB,EAAE,CAAC,KAAK,KAAK,SAAS,CAAA"}
|