@unispechq/unispec-core 0.3.2 → 0.3.3
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/dist/cjs/src/cache/cache-factory.js +1 -1
- package/dist/cjs/src/cache/cache-manager.js +2 -2
- package/dist/cjs/src/cache/hash-utils.js +1 -1
- package/dist/cjs/src/cache/hashing.js +1 -1
- package/dist/cjs/src/cache/index.js +5 -5
- package/dist/cjs/src/cache/lru-cache.js +1 -1
- package/dist/cjs/src/diff/core.js +2 -2
- package/dist/cjs/src/diff/enhanced-diff.js +5 -5
- package/dist/cjs/src/diff/index.js +8 -8
- package/dist/cjs/src/errors/config-error.js +1 -1
- package/dist/cjs/src/errors/error-factory.js +7 -7
- package/dist/cjs/src/errors/index.js +8 -8
- package/dist/cjs/src/errors/loader-error.js +1 -1
- package/dist/cjs/src/errors/reference-error.js +1 -1
- package/dist/cjs/src/errors/schema-error.js +1 -1
- package/dist/cjs/src/errors/security-error.js +1 -1
- package/dist/cjs/src/errors/semantic-error.js +1 -1
- package/dist/cjs/src/index.js +13 -13
- package/dist/cjs/src/loader/index.js +4 -4
- package/dist/cjs/src/loader/security-validator.js +1 -1
- package/dist/cjs/src/loader/unispec-loader.js +3 -3
- package/dist/cjs/src/loader/yaml-loader.js +1 -1
- package/dist/cjs/src/normalizer/core.js +4 -4
- package/dist/cjs/src/normalizer/index.js +1 -1
- package/dist/cjs/src/optimizer/core.js +2 -2
- package/dist/cjs/src/optimizer/index.js +3 -3
- package/dist/cjs/src/optimizer/optimization-functions.js +2 -2
- package/dist/cjs/src/schemas/dedupe.js +1 -1
- package/dist/cjs/src/schemas/index.js +3 -3
- package/dist/cjs/src/schemas/resolver.js +1 -1
- package/dist/cjs/src/validator/ajv-validator.js +1 -1
- package/dist/cjs/src/validator/config-validator-main.js +4 -4
- package/dist/cjs/src/validator/config-validator.js +1 -1
- package/dist/cjs/src/validator/index.js +7 -7
- package/dist/cjs/src/validator/reference-validator.js +1 -1
- package/dist/cjs/src/validator/tests-validator.js +2 -2
- package/dist/cjs/src/validator/unispec-validator.js +5 -5
- package/dist/cjs/src/validator/validator-factory.js +1 -1
- package/dist/cjs/tests/cache/cache.test.js +4 -4
- package/dist/cjs/tests/cache/utils.js +1 -1
- package/dist/cjs/tests/diff/diff-annotators.test.js +2 -2
- package/dist/cjs/tests/diff/diff-comprehensive.test.js +2 -2
- package/dist/cjs/tests/diff/diff-extended.test.js +2 -2
- package/dist/cjs/tests/diff/diff.test.js +2 -2
- package/dist/cjs/tests/diff/utils.js +1 -1
- package/dist/cjs/tests/errors/errors-integration.test.js +3 -3
- package/dist/cjs/tests/errors/errors.test.js +2 -2
- package/dist/cjs/tests/errors/utils.js +1 -1
- package/dist/cjs/tests/loader/integration.test.js +2 -2
- package/dist/cjs/tests/loader/loader.test.js +2 -2
- package/dist/cjs/tests/normalizer/normalizer-comprehensive.test.js +2 -2
- package/dist/cjs/tests/normalizer/normalizer-invalid.test.js +2 -2
- package/dist/cjs/tests/normalizer/normalizer-valid.test.js +2 -2
- package/dist/cjs/tests/normalizer/utils.js +1 -1
- package/dist/cjs/tests/optimizer/compress-references.test.js +2 -2
- package/dist/cjs/tests/optimizer/deduplication.test.js +2 -2
- package/dist/cjs/tests/optimizer/integration.test.js +3 -3
- package/dist/cjs/tests/optimizer/optimization-report.test.js +2 -2
- package/dist/cjs/tests/optimizer/optimize-document.test.js +2 -2
- package/dist/cjs/tests/optimizer/orphaned-schemas.test.js +2 -2
- package/dist/cjs/tests/optimizer/sort-schemas.test.js +2 -2
- package/dist/cjs/tests/optimizer/utils.js +1 -1
- package/dist/cjs/tests/schemas/schemas-edge-cases.test.js +3 -3
- package/dist/cjs/tests/schemas/schemas.test.js +3 -3
- package/dist/cjs/tests/schemas/utils.js +1 -1
- package/dist/cjs/tests/validator/config-validator.test.js +2 -2
- package/dist/cjs/tests/validator/unispec-validator.test.js +2 -2
- package/dist/cjs/tests/validator/utils.js +1 -1
- package/package.json +1 -1
- package/dist/cache/cache-factory.d.ts +0 -31
- package/dist/cache/cache-factory.js +0 -65
- package/dist/cache/cache-manager.d.ts +0 -62
- package/dist/cache/cache-manager.js +0 -122
- package/dist/cache/constants.d.ts +0 -21
- package/dist/cache/constants.js +0 -22
- package/dist/cache/hash-utils.d.ts +0 -21
- package/dist/cache/hash-utils.js +0 -35
- package/dist/cache/hashing.d.ts +0 -19
- package/dist/cache/hashing.js +0 -197
- package/dist/cache/index.d.ts +0 -6
- package/dist/cache/index.js +0 -10
- package/dist/cache/lru-cache.d.ts +0 -56
- package/dist/cache/lru-cache.js +0 -161
- package/dist/cache/types.d.ts +0 -24
- package/dist/cache/types.js +0 -4
- package/dist/cjs/cache/cache-factory.js +0 -72
- package/dist/cjs/cache/cache-manager.js +0 -126
- package/dist/cjs/cache/constants.js +0 -25
- package/dist/cjs/cache/hash-utils.js +0 -41
- package/dist/cjs/cache/hashing.js +0 -236
- package/dist/cjs/cache/index.js +0 -26
- package/dist/cjs/cache/lru-cache.js +0 -165
- package/dist/cjs/cache/types.js +0 -5
- package/dist/cjs/diff/annotators.js +0 -159
- package/dist/cjs/diff/change-reports.js +0 -369
- package/dist/cjs/diff/core.js +0 -158
- package/dist/cjs/diff/enhanced-diff.js +0 -79
- package/dist/cjs/diff/impact-strategies-refactored.js +0 -230
- package/dist/cjs/diff/impact-strategies.js +0 -219
- package/dist/cjs/diff/index.js +0 -27
- package/dist/cjs/diff/metrics-calculator.js +0 -69
- package/dist/cjs/diff/risk-calculator.js +0 -58
- package/dist/cjs/diff/suggestion-generator.js +0 -78
- package/dist/cjs/diff/types.js +0 -11
- package/dist/cjs/errors/base-error.js +0 -33
- package/dist/cjs/errors/config-error.js +0 -11
- package/dist/cjs/errors/error-factory.js +0 -48
- package/dist/cjs/errors/index.js +0 -19
- package/dist/cjs/errors/loader-error.js +0 -11
- package/dist/cjs/errors/reference-error.js +0 -11
- package/dist/cjs/errors/schema-error.js +0 -11
- package/dist/cjs/errors/security-error.js +0 -11
- package/dist/cjs/errors/semantic-error.js +0 -11
- package/dist/cjs/generated-schemas.js +0 -2100
- package/dist/cjs/index.js +0 -59
- package/dist/cjs/loader/index.js +0 -13
- package/dist/cjs/loader/security-validator.js +0 -53
- package/dist/cjs/loader/types.js +0 -11
- package/dist/cjs/loader/unispec-loader.js +0 -84
- package/dist/cjs/loader/yaml-loader.js +0 -76
- package/dist/cjs/normalizer/core.js +0 -32
- package/dist/cjs/normalizer/graphql-normalizer.js +0 -67
- package/dist/cjs/normalizer/index.js +0 -7
- package/dist/cjs/normalizer/rest-normalizer.js +0 -51
- package/dist/cjs/normalizer/types.js +0 -2
- package/dist/cjs/normalizer/utils.js +0 -33
- package/dist/cjs/normalizer/websocket-normalizer.js +0 -81
- package/dist/cjs/optimizer/core.js +0 -115
- package/dist/cjs/optimizer/index.js +0 -17
- package/dist/cjs/optimizer/optimization-functions.js +0 -185
- package/dist/cjs/optimizer/types.js +0 -2
- package/dist/cjs/optimizer/utils.js +0 -32
- package/dist/cjs/schemas/dedupe.js +0 -100
- package/dist/cjs/schemas/index.js +0 -14
- package/dist/cjs/schemas/resolver.js +0 -41
- package/dist/cjs/schemas/utils.js +0 -53
- package/dist/cjs/types/index.js +0 -2
- package/dist/cjs/validator/ajv-validator.js +0 -82
- package/dist/cjs/validator/config-validator-main.js +0 -34
- package/dist/cjs/validator/config-validator.js +0 -17
- package/dist/cjs/validator/index.js +0 -23
- package/dist/cjs/validator/object-traversal.js +0 -112
- package/dist/cjs/validator/reference-validator.js +0 -233
- package/dist/cjs/validator/schema-references.js +0 -116
- package/dist/cjs/validator/semantic-validator.js +0 -328
- package/dist/cjs/validator/tests-validator.js +0 -16
- package/dist/cjs/validator/types.js +0 -2
- package/dist/cjs/validator/unispec-validator.js +0 -84
- package/dist/cjs/validator/validator-factory.js +0 -77
- package/dist/cjs/versions.js +0 -147
- package/dist/diff/annotators.d.ts +0 -4
- package/dist/diff/annotators.js +0 -154
- package/dist/diff/change-reports.d.ts +0 -37
- package/dist/diff/change-reports.js +0 -366
- package/dist/diff/core.d.ts +0 -26
- package/dist/diff/core.js +0 -155
- package/dist/diff/enhanced-diff.d.ts +0 -51
- package/dist/diff/enhanced-diff.js +0 -76
- package/dist/diff/impact-strategies-refactored.d.ts +0 -69
- package/dist/diff/impact-strategies-refactored.js +0 -223
- package/dist/diff/impact-strategies.d.ts +0 -41
- package/dist/diff/impact-strategies.js +0 -212
- package/dist/diff/index.d.ts +0 -8
- package/dist/diff/index.js +0 -11
- package/dist/diff/metrics-calculator.d.ts +0 -23
- package/dist/diff/metrics-calculator.js +0 -65
- package/dist/diff/risk-calculator.d.ts +0 -23
- package/dist/diff/risk-calculator.js +0 -55
- package/dist/diff/suggestion-generator.d.ts +0 -18
- package/dist/diff/suggestion-generator.js +0 -74
- package/dist/diff/types.d.ts +0 -24
- package/dist/diff/types.js +0 -8
- package/dist/errors/base-error.d.ts +0 -20
- package/dist/errors/base-error.js +0 -29
- package/dist/errors/config-error.d.ts +0 -4
- package/dist/errors/config-error.js +0 -7
- package/dist/errors/error-factory.d.ts +0 -22
- package/dist/errors/error-factory.js +0 -45
- package/dist/errors/index.d.ts +0 -8
- package/dist/errors/index.js +0 -8
- package/dist/errors/loader-error.d.ts +0 -4
- package/dist/errors/loader-error.js +0 -7
- package/dist/errors/reference-error.d.ts +0 -4
- package/dist/errors/reference-error.js +0 -7
- package/dist/errors/schema-error.d.ts +0 -4
- package/dist/errors/schema-error.js +0 -7
- package/dist/errors/security-error.d.ts +0 -4
- package/dist/errors/security-error.js +0 -7
- package/dist/errors/semantic-error.d.ts +0 -4
- package/dist/errors/semantic-error.js +0 -7
- package/dist/generated-schemas.d.ts +0 -2073
- package/dist/generated-schemas.js +0 -2097
- package/dist/index.cjs +0 -59
- package/dist/index.d.ts +0 -13
- package/dist/index.js +0 -43
- package/dist/loader/index.d.ts +0 -5
- package/dist/loader/index.js +0 -5
- package/dist/loader/security-validator.d.ts +0 -5
- package/dist/loader/security-validator.js +0 -50
- package/dist/loader/types.d.ts +0 -30
- package/dist/loader/types.js +0 -8
- package/dist/loader/unispec-loader.d.ts +0 -10
- package/dist/loader/unispec-loader.js +0 -81
- package/dist/loader/yaml-loader.d.ts +0 -10
- package/dist/loader/yaml-loader.js +0 -39
- package/dist/normalizer/core.d.ts +0 -24
- package/dist/normalizer/core.js +0 -29
- package/dist/normalizer/graphql-normalizer.d.ts +0 -8
- package/dist/normalizer/graphql-normalizer.js +0 -64
- package/dist/normalizer/index.d.ts +0 -2
- package/dist/normalizer/index.js +0 -3
- package/dist/normalizer/rest-normalizer.d.ts +0 -8
- package/dist/normalizer/rest-normalizer.js +0 -48
- package/dist/normalizer/types.d.ts +0 -7
- package/dist/normalizer/types.js +0 -1
- package/dist/normalizer/utils.d.ts +0 -14
- package/dist/normalizer/utils.js +0 -29
- package/dist/normalizer/websocket-normalizer.d.ts +0 -8
- package/dist/normalizer/websocket-normalizer.js +0 -78
- package/dist/optimizer/core.d.ts +0 -17
- package/dist/optimizer/core.js +0 -111
- package/dist/optimizer/index.d.ts +0 -4
- package/dist/optimizer/index.js +0 -7
- package/dist/optimizer/optimization-functions.d.ts +0 -32
- package/dist/optimizer/optimization-functions.js +0 -179
- package/dist/optimizer/types.d.ts +0 -28
- package/dist/optimizer/types.js +0 -1
- package/dist/optimizer/utils.d.ts +0 -7
- package/dist/optimizer/utils.js +0 -29
- package/dist/schemas/dedupe.d.ts +0 -9
- package/dist/schemas/dedupe.js +0 -97
- package/dist/schemas/index.d.ts +0 -3
- package/dist/schemas/index.js +0 -6
- package/dist/schemas/resolver.d.ts +0 -19
- package/dist/schemas/resolver.js +0 -37
- package/dist/schemas/utils.d.ts +0 -20
- package/dist/schemas/utils.js +0 -49
- package/dist/types/index.d.ts +0 -433
- package/dist/types/index.js +0 -1
- package/dist/validator/ajv-validator.d.ts +0 -15
- package/dist/validator/ajv-validator.js +0 -75
- package/dist/validator/config-validator-main.d.ts +0 -10
- package/dist/validator/config-validator-main.js +0 -31
- package/dist/validator/config-validator.d.ts +0 -5
- package/dist/validator/config-validator.js +0 -14
- package/dist/validator/index.d.ts +0 -10
- package/dist/validator/index.js +0 -11
- package/dist/validator/object-traversal.d.ts +0 -52
- package/dist/validator/object-traversal.js +0 -104
- package/dist/validator/reference-validator.d.ts +0 -31
- package/dist/validator/reference-validator.js +0 -230
- package/dist/validator/schema-references.d.ts +0 -23
- package/dist/validator/schema-references.js +0 -111
- package/dist/validator/semantic-validator.d.ts +0 -26
- package/dist/validator/semantic-validator.js +0 -325
- package/dist/validator/tests-validator.d.ts +0 -9
- package/dist/validator/tests-validator.js +0 -13
- package/dist/validator/types.d.ts +0 -29
- package/dist/validator/types.js +0 -1
- package/dist/validator/unispec-validator.d.ts +0 -15
- package/dist/validator/unispec-validator.js +0 -81
- package/dist/validator/validator-factory.d.ts +0 -10
- package/dist/validator/validator-factory.js +0 -73
- package/dist/versions.d.ts +0 -10
- package/dist/versions.js +0 -143
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { clearValidatorCache, getValidator } from "./ajv-validator.js";
|
|
2
|
-
export { validateUniSpecConfig } from "./config-validator-main.js";
|
|
3
|
-
export type { ReferenceValidationOptions, ReferenceValidationResult, } from "./reference-validator.js";
|
|
4
|
-
export { validateReferences } from "./reference-validator.js";
|
|
5
|
-
export type { SemanticValidationOptions, SemanticValidationResult, } from "./semantic-validator.js";
|
|
6
|
-
export { validateSemantic } from "./semantic-validator.js";
|
|
7
|
-
export { validateUniSpecTests } from "./tests-validator.js";
|
|
8
|
-
export type { Ajv2020, AjvValidateFn, ExtendedValidationResult, SchemaProvider, ValidateOptions, ValidatorSchemas, } from "./types.js";
|
|
9
|
-
export { validateUniSpec } from "./unispec-validator.js";
|
|
10
|
-
export { createValidator, mapAjvErrors } from "./validator-factory.js";
|
package/dist/validator/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// Export all validation functions and types
|
|
2
|
-
// Export AJV utilities
|
|
3
|
-
export { clearValidatorCache, getValidator } from "./ajv-validator.js";
|
|
4
|
-
export { validateUniSpecConfig } from "./config-validator-main.js";
|
|
5
|
-
export { validateReferences } from "./reference-validator.js";
|
|
6
|
-
// Re-export semantic and reference validators
|
|
7
|
-
export { validateSemantic } from "./semantic-validator.js";
|
|
8
|
-
export { validateUniSpecTests } from "./tests-validator.js";
|
|
9
|
-
export { validateUniSpec } from "./unispec-validator.js";
|
|
10
|
-
// Export validator factory for advanced usage
|
|
11
|
-
export { createValidator, mapAjvErrors } from "./validator-factory.js";
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility functions for traversing and manipulating objects.
|
|
3
|
-
*/
|
|
4
|
-
export interface TraversalOptions {
|
|
5
|
-
maxDepth?: number;
|
|
6
|
-
includeArrays?: boolean;
|
|
7
|
-
pathSeparator?: string;
|
|
8
|
-
}
|
|
9
|
-
export interface TraversalContext {
|
|
10
|
-
path: string;
|
|
11
|
-
depth: number;
|
|
12
|
-
parent?: unknown;
|
|
13
|
-
key?: string;
|
|
14
|
-
}
|
|
15
|
-
export type TraversalCallback = (value: unknown, context: TraversalContext) => void;
|
|
16
|
-
/**
|
|
17
|
-
* Traverse an object recursively and call a callback for each value.
|
|
18
|
-
*/
|
|
19
|
-
export declare function traverseObject(obj: unknown, callback: TraversalCallback, options?: TraversalOptions, context?: Partial<TraversalContext>): void;
|
|
20
|
-
/**
|
|
21
|
-
* Extract all values matching a predicate from an object.
|
|
22
|
-
*/
|
|
23
|
-
export declare function extractValues(obj: unknown, predicate: (value: unknown, context: TraversalContext) => boolean, options?: TraversalOptions): Array<{
|
|
24
|
-
value: unknown;
|
|
25
|
-
context: TraversalContext;
|
|
26
|
-
}>;
|
|
27
|
-
/**
|
|
28
|
-
* Find all paths to values matching a predicate.
|
|
29
|
-
*/
|
|
30
|
-
export declare function findPaths(obj: unknown, predicate: (value: unknown, context: TraversalContext) => boolean, options?: TraversalOptions): string[];
|
|
31
|
-
/**
|
|
32
|
-
* Extract all string values from an object.
|
|
33
|
-
*/
|
|
34
|
-
export declare function extractStrings(obj: unknown, options?: TraversalOptions): Array<{
|
|
35
|
-
value: string;
|
|
36
|
-
context: TraversalContext;
|
|
37
|
-
}>;
|
|
38
|
-
/**
|
|
39
|
-
* Extract all object references (schemaRef, $ref) from an object.
|
|
40
|
-
*/
|
|
41
|
-
export declare function extractReferences(obj: unknown, refKeys?: string[], options?: TraversalOptions): Array<{
|
|
42
|
-
value: string;
|
|
43
|
-
context: TraversalContext;
|
|
44
|
-
}>;
|
|
45
|
-
/**
|
|
46
|
-
* Count keys and depth in an object for security validation.
|
|
47
|
-
*/
|
|
48
|
-
export declare function analyzeObjectStructure(obj: unknown, options?: TraversalOptions): {
|
|
49
|
-
keyCount: number;
|
|
50
|
-
maxDepth: number;
|
|
51
|
-
paths: string[];
|
|
52
|
-
};
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility functions for traversing and manipulating objects.
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Traverse an object recursively and call a callback for each value.
|
|
6
|
-
*/
|
|
7
|
-
export function traverseObject(obj, callback, options = {}, context = {}) {
|
|
8
|
-
const { maxDepth = 100, includeArrays = true, pathSeparator = "." } = options;
|
|
9
|
-
const currentDepth = context.depth || 0;
|
|
10
|
-
const currentPath = context.path || "";
|
|
11
|
-
// Check depth limit
|
|
12
|
-
if (currentDepth > maxDepth) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
// Call callback for current value
|
|
16
|
-
callback(obj, {
|
|
17
|
-
path: currentPath,
|
|
18
|
-
depth: currentDepth,
|
|
19
|
-
parent: context.parent,
|
|
20
|
-
key: context.key,
|
|
21
|
-
});
|
|
22
|
-
// Handle arrays
|
|
23
|
-
if (Array.isArray(obj) && includeArrays) {
|
|
24
|
-
obj.forEach((item, index) => {
|
|
25
|
-
traverseObject(item, callback, options, {
|
|
26
|
-
path: currentPath ? `${currentPath}[${index}]` : `[${index}]`,
|
|
27
|
-
depth: currentDepth + 1,
|
|
28
|
-
parent: obj,
|
|
29
|
-
key: index.toString(),
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
// Handle objects
|
|
35
|
-
if (obj && typeof obj === "object") {
|
|
36
|
-
Object.entries(obj).forEach(([key, value]) => {
|
|
37
|
-
const newPath = currentPath
|
|
38
|
-
? `${currentPath}${pathSeparator}${key}`
|
|
39
|
-
: key;
|
|
40
|
-
traverseObject(value, callback, options, {
|
|
41
|
-
path: newPath,
|
|
42
|
-
depth: currentDepth + 1,
|
|
43
|
-
parent: obj,
|
|
44
|
-
key,
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Extract all values matching a predicate from an object.
|
|
51
|
-
*/
|
|
52
|
-
export function extractValues(obj, predicate, options) {
|
|
53
|
-
const results = [];
|
|
54
|
-
traverseObject(obj, (value, context) => {
|
|
55
|
-
if (predicate(value, context)) {
|
|
56
|
-
results.push({ value, context });
|
|
57
|
-
}
|
|
58
|
-
}, options);
|
|
59
|
-
return results;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Find all paths to values matching a predicate.
|
|
63
|
-
*/
|
|
64
|
-
export function findPaths(obj, predicate, options) {
|
|
65
|
-
const paths = [];
|
|
66
|
-
traverseObject(obj, (value, context) => {
|
|
67
|
-
if (predicate(value, context)) {
|
|
68
|
-
paths.push(context.path);
|
|
69
|
-
}
|
|
70
|
-
}, options);
|
|
71
|
-
return paths;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Extract all string values from an object.
|
|
75
|
-
*/
|
|
76
|
-
export function extractStrings(obj, options) {
|
|
77
|
-
return extractValues(obj, (value) => typeof value === "string", options);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Extract all object references (schemaRef, $ref) from an object.
|
|
81
|
-
*/
|
|
82
|
-
export function extractReferences(obj, refKeys = ["schemaRef", "$ref"], options) {
|
|
83
|
-
return extractValues(obj, (value, context) => {
|
|
84
|
-
return refKeys.includes(context.key || "") && typeof value === "string";
|
|
85
|
-
}, options);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Count keys and depth in an object for security validation.
|
|
89
|
-
*/
|
|
90
|
-
export function analyzeObjectStructure(obj, options = {}) {
|
|
91
|
-
let keyCount = 0;
|
|
92
|
-
let maxDepth = 0;
|
|
93
|
-
const paths = [];
|
|
94
|
-
traverseObject(obj, (_value, context) => {
|
|
95
|
-
if (context.key) {
|
|
96
|
-
keyCount++;
|
|
97
|
-
}
|
|
98
|
-
maxDepth = Math.max(maxDepth, context.depth);
|
|
99
|
-
if (context.path) {
|
|
100
|
-
paths.push(context.path);
|
|
101
|
-
}
|
|
102
|
-
}, options);
|
|
103
|
-
return { keyCount, maxDepth, paths };
|
|
104
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { UniSpecDocument, ValidationError } from "../types/index.js";
|
|
2
|
-
export interface ReferenceValidationOptions {
|
|
3
|
-
checkSchemaReferences?: boolean;
|
|
4
|
-
checkSecuritySchemeReferences?: boolean;
|
|
5
|
-
strictMode?: boolean;
|
|
6
|
-
}
|
|
7
|
-
export interface ReferenceValidationResult {
|
|
8
|
-
valid: boolean;
|
|
9
|
-
errors: ValidationError[];
|
|
10
|
-
warnings: ValidationError[];
|
|
11
|
-
referenceMap: Map<string, ReferenceInfo>;
|
|
12
|
-
}
|
|
13
|
-
export interface ReferenceInfo {
|
|
14
|
-
type: "schema" | "securityScheme";
|
|
15
|
-
source: string;
|
|
16
|
-
target: string;
|
|
17
|
-
exists: boolean;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Perform comprehensive reference validation on a UniSpec document.
|
|
21
|
-
*
|
|
22
|
-
* This function validates:
|
|
23
|
-
* - Schema references (schemaRef, $ref)
|
|
24
|
-
* - Security scheme references
|
|
25
|
-
* - Unused definitions (in strict mode)
|
|
26
|
-
*
|
|
27
|
-
* @param doc - The UniSpec document to validate
|
|
28
|
-
* @param options - Validation options
|
|
29
|
-
* @returns Reference validation result with detailed reference map
|
|
30
|
-
*/
|
|
31
|
-
export declare function validateReferences(doc: UniSpecDocument, options?: ReferenceValidationOptions): ReferenceValidationResult;
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import { extractReferences } from "./object-traversal.js";
|
|
2
|
-
/**
|
|
3
|
-
* Extract all schema references from a UniSpec document.
|
|
4
|
-
*/
|
|
5
|
-
function extractSchemaReferences(doc) {
|
|
6
|
-
const references = new Map();
|
|
7
|
-
const schemaRefs = extractReferences(doc, ["schemaRef", "$ref"]);
|
|
8
|
-
for (const { value, context } of schemaRefs) {
|
|
9
|
-
const schemaName = normalizeSchemaRef(value);
|
|
10
|
-
if (schemaName) {
|
|
11
|
-
const existing = references.get(schemaName) || [];
|
|
12
|
-
existing.push(context.path);
|
|
13
|
-
references.set(schemaName, existing);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return references;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Extract all security scheme references from a UniSpec document.
|
|
20
|
-
*/
|
|
21
|
-
function extractSecuritySchemeReferences(doc) {
|
|
22
|
-
const references = new Map();
|
|
23
|
-
const securityRefs = extractValues(doc, (value, context) => {
|
|
24
|
-
return context.key === "security" && Array.isArray(value);
|
|
25
|
-
});
|
|
26
|
-
for (const { value: securityArray, context } of securityRefs) {
|
|
27
|
-
if (!Array.isArray(securityArray))
|
|
28
|
-
continue;
|
|
29
|
-
securityArray.forEach((securityRequirement, index) => {
|
|
30
|
-
if (Array.isArray(securityRequirement)) {
|
|
31
|
-
securityRequirement.forEach((schemeName) => {
|
|
32
|
-
if (typeof schemeName === "string") {
|
|
33
|
-
const existing = references.get(schemeName) || [];
|
|
34
|
-
existing.push(`${context.path}[${index}]`);
|
|
35
|
-
references.set(schemeName, existing);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
return references;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Extract values using object traversal utility.
|
|
45
|
-
*/
|
|
46
|
-
function extractValues(obj, predicate) {
|
|
47
|
-
const results = [];
|
|
48
|
-
function traverse(current, path, depth) {
|
|
49
|
-
if (depth > 100)
|
|
50
|
-
return; // Prevent infinite recursion
|
|
51
|
-
if (predicate(current, { path, depth, key: path.split(".").pop() })) {
|
|
52
|
-
results.push({
|
|
53
|
-
value: current,
|
|
54
|
-
context: { path, depth, key: path.split(".").pop() },
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
if (Array.isArray(current)) {
|
|
58
|
-
current.forEach((item, index) => {
|
|
59
|
-
traverse(item, `${path}[${index}]`, depth + 1);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
else if (current && typeof current === "object") {
|
|
63
|
-
Object.entries(current).forEach(([key, value]) => {
|
|
64
|
-
traverse(value, path ? `${path}.${key}` : key, depth + 1);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
traverse(obj, "", 0);
|
|
69
|
-
return results;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Normalize schema reference to extract the schema name.
|
|
73
|
-
*/
|
|
74
|
-
function normalizeSchemaRef(ref) {
|
|
75
|
-
const trimmed = ref.trim();
|
|
76
|
-
if (trimmed.length === 0)
|
|
77
|
-
return null;
|
|
78
|
-
// Handle JSON Pointer format: #/service/schemas/SchemaName
|
|
79
|
-
if (trimmed.startsWith("#/service/schemas/")) {
|
|
80
|
-
const parts = trimmed.split("/");
|
|
81
|
-
return parts[parts.length - 1];
|
|
82
|
-
}
|
|
83
|
-
// Handle simple name format: SchemaName
|
|
84
|
-
if (!trimmed.startsWith("#") && !trimmed.includes("/")) {
|
|
85
|
-
return trimmed;
|
|
86
|
-
}
|
|
87
|
-
// Handle hash format: #SchemaName
|
|
88
|
-
if (trimmed.startsWith("#")) {
|
|
89
|
-
const withoutHash = trimmed.slice(1);
|
|
90
|
-
const parts = withoutHash.split("/").filter(Boolean);
|
|
91
|
-
return parts.length > 0 ? parts[parts.length - 1] : withoutHash;
|
|
92
|
-
}
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Validate schema references.
|
|
97
|
-
*/
|
|
98
|
-
function validateSchemaReferences(doc, options, referenceMap) {
|
|
99
|
-
const errors = [];
|
|
100
|
-
if (!options.checkSchemaReferences)
|
|
101
|
-
return errors;
|
|
102
|
-
const schemaReferences = extractSchemaReferences(doc);
|
|
103
|
-
const availableSchemas = new Set(Object.keys(doc.service?.schemas || {}));
|
|
104
|
-
for (const [schemaName, locations] of schemaReferences.entries()) {
|
|
105
|
-
const exists = availableSchemas.has(schemaName);
|
|
106
|
-
// Store reference info
|
|
107
|
-
for (const location of locations) {
|
|
108
|
-
referenceMap.set(location, {
|
|
109
|
-
type: "schema",
|
|
110
|
-
source: location,
|
|
111
|
-
target: schemaName,
|
|
112
|
-
exists,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
if (!exists) {
|
|
116
|
-
errors.push({
|
|
117
|
-
message: `Schema '${schemaName}' is referenced but not defined`,
|
|
118
|
-
path: locations[0], // First occurrence
|
|
119
|
-
code: "undefined_schema",
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return errors;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Validate security scheme references.
|
|
127
|
-
*/
|
|
128
|
-
function validateSecuritySchemeReferences(doc, options, referenceMap) {
|
|
129
|
-
const errors = [];
|
|
130
|
-
if (!options.checkSecuritySchemeReferences)
|
|
131
|
-
return errors;
|
|
132
|
-
const securityReferences = extractSecuritySchemeReferences(doc);
|
|
133
|
-
const availableSchemes = new Set(Object.keys(doc.service?.securitySchemes || {}));
|
|
134
|
-
for (const [schemeName, locations] of securityReferences.entries()) {
|
|
135
|
-
const exists = availableSchemes.has(schemeName);
|
|
136
|
-
// Store reference info
|
|
137
|
-
for (const location of locations) {
|
|
138
|
-
referenceMap.set(location, {
|
|
139
|
-
type: "securityScheme",
|
|
140
|
-
source: location,
|
|
141
|
-
target: schemeName,
|
|
142
|
-
exists,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
if (!exists) {
|
|
146
|
-
errors.push({
|
|
147
|
-
message: `Security scheme '${schemeName}' is referenced but not defined`,
|
|
148
|
-
path: locations[0], // First occurrence
|
|
149
|
-
code: "undefined_security_scheme",
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return errors;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Check for unused schemas and security schemes.
|
|
157
|
-
*/
|
|
158
|
-
function validateUnusedReferences(doc, options, referenceMap) {
|
|
159
|
-
const warnings = [];
|
|
160
|
-
if (!options.strictMode)
|
|
161
|
-
return warnings;
|
|
162
|
-
// Find all referenced schemas
|
|
163
|
-
const referencedSchemas = new Set();
|
|
164
|
-
const referencedSecuritySchemes = new Set();
|
|
165
|
-
for (const info of referenceMap.values()) {
|
|
166
|
-
if (info.type === "schema" && info.exists) {
|
|
167
|
-
referencedSchemas.add(info.target);
|
|
168
|
-
}
|
|
169
|
-
else if (info.type === "securityScheme" && info.exists) {
|
|
170
|
-
referencedSecuritySchemes.add(info.target);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
// Check for unused schemas
|
|
174
|
-
const allSchemas = Object.keys(doc.service?.schemas || {});
|
|
175
|
-
for (const schemaName of allSchemas) {
|
|
176
|
-
if (!referencedSchemas.has(schemaName)) {
|
|
177
|
-
warnings.push({
|
|
178
|
-
message: `Schema '${schemaName}' is defined but never referenced`,
|
|
179
|
-
path: `/service/schemas/${schemaName}`,
|
|
180
|
-
code: "unused_schema",
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
// Check for unused security schemes
|
|
185
|
-
const allSecuritySchemes = Object.keys(doc.service?.securitySchemes || {});
|
|
186
|
-
for (const schemeName of allSecuritySchemes) {
|
|
187
|
-
if (!referencedSecuritySchemes.has(schemeName)) {
|
|
188
|
-
warnings.push({
|
|
189
|
-
message: `Security scheme '${schemeName}' is defined but never referenced`,
|
|
190
|
-
path: `/service/securitySchemes/${schemeName}`,
|
|
191
|
-
code: "unused_security_scheme",
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return warnings;
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Perform comprehensive reference validation on a UniSpec document.
|
|
199
|
-
*
|
|
200
|
-
* This function validates:
|
|
201
|
-
* - Schema references (schemaRef, $ref)
|
|
202
|
-
* - Security scheme references
|
|
203
|
-
* - Unused definitions (in strict mode)
|
|
204
|
-
*
|
|
205
|
-
* @param doc - The UniSpec document to validate
|
|
206
|
-
* @param options - Validation options
|
|
207
|
-
* @returns Reference validation result with detailed reference map
|
|
208
|
-
*/
|
|
209
|
-
export function validateReferences(doc, options = {}) {
|
|
210
|
-
const errors = [];
|
|
211
|
-
const warnings = [];
|
|
212
|
-
const referenceMap = new Map();
|
|
213
|
-
// Default options
|
|
214
|
-
const opts = {
|
|
215
|
-
checkSchemaReferences: true,
|
|
216
|
-
checkSecuritySchemeReferences: true,
|
|
217
|
-
strictMode: false,
|
|
218
|
-
...options,
|
|
219
|
-
};
|
|
220
|
-
// Validate all reference types
|
|
221
|
-
errors.push(...validateSchemaReferences(doc, opts, referenceMap));
|
|
222
|
-
errors.push(...validateSecuritySchemeReferences(doc, opts, referenceMap));
|
|
223
|
-
warnings.push(...validateUnusedReferences(doc, opts, referenceMap));
|
|
224
|
-
return {
|
|
225
|
-
valid: errors.length === 0,
|
|
226
|
-
errors,
|
|
227
|
-
warnings,
|
|
228
|
-
referenceMap,
|
|
229
|
-
};
|
|
230
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { UniSpecDocument, ValidationResult } from "../types/index.js";
|
|
2
|
-
export interface SchemaReference {
|
|
3
|
-
path: string;
|
|
4
|
-
schemaName: string;
|
|
5
|
-
context: string;
|
|
6
|
-
}
|
|
7
|
-
export interface SchemaValidationResult extends ValidationResult {
|
|
8
|
-
references: {
|
|
9
|
-
valid: SchemaReference[];
|
|
10
|
-
invalid: SchemaReference[];
|
|
11
|
-
orphaned: string[];
|
|
12
|
-
circular: string[][];
|
|
13
|
-
};
|
|
14
|
-
statistics: {
|
|
15
|
-
totalSchemas: number;
|
|
16
|
-
totalReferences: number;
|
|
17
|
-
orphanedSchemas: number;
|
|
18
|
-
circularDependencies: number;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
export declare function extractSchemaReferences(doc: UniSpecDocument): SchemaReference[];
|
|
22
|
-
export declare function findOrphanedSchemas(doc: UniSpecDocument): string[];
|
|
23
|
-
export declare function validateSchemaReferences(doc: UniSpecDocument): SchemaValidationResult;
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
export function extractSchemaReferences(doc) {
|
|
2
|
-
const references = [];
|
|
3
|
-
function extractFromPath(obj, path) {
|
|
4
|
-
if (!obj || typeof obj !== "object")
|
|
5
|
-
return;
|
|
6
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
7
|
-
const currentPath = path ? `${path}.${key}` : key;
|
|
8
|
-
if (key === "schemaRef" && typeof value === "string") {
|
|
9
|
-
references.push({
|
|
10
|
-
path: currentPath,
|
|
11
|
-
schemaName: normalizeSchemaRef(value),
|
|
12
|
-
context: getContextFromPath(currentPath),
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
else if (typeof value === "object" && value !== null) {
|
|
16
|
-
extractFromPath(value, currentPath);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
extractFromPath(doc, "");
|
|
21
|
-
return references;
|
|
22
|
-
}
|
|
23
|
-
function normalizeSchemaRef(ref) {
|
|
24
|
-
const trimmed = ref.trim();
|
|
25
|
-
if (trimmed.length === 0)
|
|
26
|
-
return "";
|
|
27
|
-
if (trimmed.startsWith("#/service/schemas/")) {
|
|
28
|
-
const parts = trimmed.split("/");
|
|
29
|
-
return parts[parts.length - 1];
|
|
30
|
-
}
|
|
31
|
-
const withoutHash = trimmed.startsWith("#") ? trimmed.slice(1) : trimmed;
|
|
32
|
-
const parts = withoutHash.split("/").filter(Boolean);
|
|
33
|
-
return parts.length > 0 ? parts[parts.length - 1] : withoutHash;
|
|
34
|
-
}
|
|
35
|
-
function getContextFromPath(path) {
|
|
36
|
-
if (path.includes("routes"))
|
|
37
|
-
return "REST route";
|
|
38
|
-
if (path.includes("queries"))
|
|
39
|
-
return "GraphQL query";
|
|
40
|
-
if (path.includes("mutations"))
|
|
41
|
-
return "GraphQL mutation";
|
|
42
|
-
if (path.includes("subscriptions"))
|
|
43
|
-
return "GraphQL subscription";
|
|
44
|
-
if (path.includes("channels"))
|
|
45
|
-
return "WebSocket channel";
|
|
46
|
-
if (path.includes("messages"))
|
|
47
|
-
return "WebSocket message";
|
|
48
|
-
if (path.includes("pathParams"))
|
|
49
|
-
return "REST path parameter";
|
|
50
|
-
if (path.includes("queryParams"))
|
|
51
|
-
return "REST query parameter";
|
|
52
|
-
if (path.includes("headers"))
|
|
53
|
-
return "Header parameter";
|
|
54
|
-
if (path.includes("requestBody"))
|
|
55
|
-
return "Request body";
|
|
56
|
-
if (path.includes("responses"))
|
|
57
|
-
return "Response body";
|
|
58
|
-
return "Unknown context";
|
|
59
|
-
}
|
|
60
|
-
export function findOrphanedSchemas(doc) {
|
|
61
|
-
const references = extractSchemaReferences(doc);
|
|
62
|
-
const referencedSchemas = new Set(references.map((ref) => ref.schemaName).filter(Boolean));
|
|
63
|
-
const allSchemas = new Set(Object.keys(doc.service?.schemas || {}));
|
|
64
|
-
const orphaned = Array.from(allSchemas).filter((schema) => !referencedSchemas.has(schema));
|
|
65
|
-
return orphaned;
|
|
66
|
-
}
|
|
67
|
-
export function validateSchemaReferences(doc) {
|
|
68
|
-
const errors = [];
|
|
69
|
-
const references = extractSchemaReferences(doc);
|
|
70
|
-
const allSchemas = new Set(Object.keys(doc.service?.schemas || {}));
|
|
71
|
-
const valid = [];
|
|
72
|
-
const invalid = [];
|
|
73
|
-
for (const ref of references) {
|
|
74
|
-
if (allSchemas.has(ref.schemaName)) {
|
|
75
|
-
valid.push(ref);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
invalid.push(ref);
|
|
79
|
-
errors.push({
|
|
80
|
-
message: `Schema reference "${ref.schemaName}" not found at ${ref.path}`,
|
|
81
|
-
path: ref.path,
|
|
82
|
-
code: "schema_not_found",
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
const orphaned = findOrphanedSchemas(doc);
|
|
87
|
-
for (const orphan of orphaned) {
|
|
88
|
-
errors.push({
|
|
89
|
-
message: `Schema "${orphan}" is defined but never referenced`,
|
|
90
|
-
path: `/service/schemas/${orphan}`,
|
|
91
|
-
code: "orphaned_schema",
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
const isValid = errors.length === 0;
|
|
95
|
-
return {
|
|
96
|
-
valid: isValid,
|
|
97
|
-
errors,
|
|
98
|
-
references: {
|
|
99
|
-
valid,
|
|
100
|
-
invalid,
|
|
101
|
-
orphaned,
|
|
102
|
-
circular: [],
|
|
103
|
-
},
|
|
104
|
-
statistics: {
|
|
105
|
-
totalSchemas: allSchemas.size,
|
|
106
|
-
totalReferences: references.length,
|
|
107
|
-
orphanedSchemas: orphaned.length,
|
|
108
|
-
circularDependencies: 0,
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { UniSpecDocument, ValidationError } from "../types/index.js";
|
|
2
|
-
export interface SemanticValidationOptions {
|
|
3
|
-
strictNaming?: boolean;
|
|
4
|
-
checkUrlPatterns?: boolean;
|
|
5
|
-
checkNameConflicts?: boolean;
|
|
6
|
-
checkCircularDependencies?: boolean;
|
|
7
|
-
}
|
|
8
|
-
export interface SemanticValidationResult {
|
|
9
|
-
valid: boolean;
|
|
10
|
-
errors: ValidationError[];
|
|
11
|
-
warnings: ValidationError[];
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Perform semantic validation on a UniSpec document.
|
|
15
|
-
*
|
|
16
|
-
* This function goes beyond JSON Schema validation to check:
|
|
17
|
-
* - Naming conventions
|
|
18
|
-
* - URL patterns
|
|
19
|
-
* - Name conflicts
|
|
20
|
-
* - Circular dependencies
|
|
21
|
-
*
|
|
22
|
-
* @param doc - The UniSpec document to validate
|
|
23
|
-
* @param options - Validation options
|
|
24
|
-
* @returns Semantic validation result
|
|
25
|
-
*/
|
|
26
|
-
export declare function validateSemantic(doc: UniSpecDocument, options?: SemanticValidationOptions): SemanticValidationResult;
|