@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,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateUniSpecConfig = validateUniSpecConfig;
|
|
4
|
-
const errors_1 = require("../errors/index.js");
|
|
5
|
-
const ajv_validator_1 = require("./ajv-validator.js");
|
|
6
|
-
const config_validator_1 = require("./config-validator.js");
|
|
7
|
-
const validator_factory_1 = require("./validator-factory.js");
|
|
8
|
-
/**
|
|
9
|
-
* Validate a UniSpec Config document against the UniSpec Config JSON Schema.
|
|
10
|
-
*
|
|
11
|
-
* @param doc - The UniSpec Config document to validate
|
|
12
|
-
* @param options - Validation options including custom schemas
|
|
13
|
-
* @returns Validation result with success status and error details
|
|
14
|
-
*/
|
|
15
|
-
async function validateUniSpecConfig(doc, options = {}) {
|
|
16
|
-
// Handle null input
|
|
17
|
-
if (doc === null || doc === undefined) {
|
|
18
|
-
const error = errors_1.ErrorFactory.fromError(new Error("Config validation error: input must be an object"), "validation_error");
|
|
19
|
-
return {
|
|
20
|
-
valid: false,
|
|
21
|
-
errors: [error.toJSON()],
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
// Use factory for the rest of validation
|
|
25
|
-
const factoryValidator = (0, validator_factory_1.createValidator)("unispecConfig", async (options) => {
|
|
26
|
-
// If custom schemas are provided but unispecConfig is missing, return undefined
|
|
27
|
-
if (options.schemas && !options.schemas.unispecConfig) {
|
|
28
|
-
return undefined; // Will trigger schema missing error
|
|
29
|
-
}
|
|
30
|
-
const { validateUniSpecConfigFn } = await (0, ajv_validator_1.getValidator)(options);
|
|
31
|
-
return validateUniSpecConfigFn;
|
|
32
|
-
}, config_validator_1.validateConfigCustomRules);
|
|
33
|
-
return await factoryValidator(doc, options);
|
|
34
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateConfigCustomRules = validateConfigCustomRules;
|
|
4
|
-
const errors_1 = require("../errors/index.js");
|
|
5
|
-
/**
|
|
6
|
-
* Custom validation for UniSpec Config documents.
|
|
7
|
-
*/
|
|
8
|
-
function validateConfigCustomRules(doc) {
|
|
9
|
-
const customErrors = [];
|
|
10
|
-
// Check for empty services array
|
|
11
|
-
if (doc.services &&
|
|
12
|
-
Array.isArray(doc.services) &&
|
|
13
|
-
doc.services.length === 0) {
|
|
14
|
-
customErrors.push(errors_1.ErrorFactory.createConfigError("services array must contain at least one service", "/services", { code: "minItems" }).toJSON());
|
|
15
|
-
}
|
|
16
|
-
return customErrors;
|
|
17
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Export all validation functions and types
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.mapAjvErrors = exports.createValidator = exports.validateUniSpec = exports.validateUniSpecTests = exports.validateSemantic = exports.validateReferences = exports.validateUniSpecConfig = exports.getValidator = exports.clearValidatorCache = void 0;
|
|
5
|
-
// Export AJV utilities
|
|
6
|
-
var ajv_validator_1 = require("./ajv-validator.js");
|
|
7
|
-
Object.defineProperty(exports, "clearValidatorCache", { enumerable: true, get: function () { return ajv_validator_1.clearValidatorCache; } });
|
|
8
|
-
Object.defineProperty(exports, "getValidator", { enumerable: true, get: function () { return ajv_validator_1.getValidator; } });
|
|
9
|
-
var config_validator_main_1 = require("./config-validator-main.js");
|
|
10
|
-
Object.defineProperty(exports, "validateUniSpecConfig", { enumerable: true, get: function () { return config_validator_main_1.validateUniSpecConfig; } });
|
|
11
|
-
var reference_validator_1 = require("./reference-validator.js");
|
|
12
|
-
Object.defineProperty(exports, "validateReferences", { enumerable: true, get: function () { return reference_validator_1.validateReferences; } });
|
|
13
|
-
// Re-export semantic and reference validators
|
|
14
|
-
var semantic_validator_1 = require("./semantic-validator.js");
|
|
15
|
-
Object.defineProperty(exports, "validateSemantic", { enumerable: true, get: function () { return semantic_validator_1.validateSemantic; } });
|
|
16
|
-
var tests_validator_1 = require("./tests-validator.js");
|
|
17
|
-
Object.defineProperty(exports, "validateUniSpecTests", { enumerable: true, get: function () { return tests_validator_1.validateUniSpecTests; } });
|
|
18
|
-
var unispec_validator_1 = require("./unispec-validator.js");
|
|
19
|
-
Object.defineProperty(exports, "validateUniSpec", { enumerable: true, get: function () { return unispec_validator_1.validateUniSpec; } });
|
|
20
|
-
// Export validator factory for advanced usage
|
|
21
|
-
var validator_factory_1 = require("./validator-factory.js");
|
|
22
|
-
Object.defineProperty(exports, "createValidator", { enumerable: true, get: function () { return validator_factory_1.createValidator; } });
|
|
23
|
-
Object.defineProperty(exports, "mapAjvErrors", { enumerable: true, get: function () { return validator_factory_1.mapAjvErrors; } });
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Utility functions for traversing and manipulating objects.
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.traverseObject = traverseObject;
|
|
7
|
-
exports.extractValues = extractValues;
|
|
8
|
-
exports.findPaths = findPaths;
|
|
9
|
-
exports.extractStrings = extractStrings;
|
|
10
|
-
exports.extractReferences = extractReferences;
|
|
11
|
-
exports.analyzeObjectStructure = analyzeObjectStructure;
|
|
12
|
-
/**
|
|
13
|
-
* Traverse an object recursively and call a callback for each value.
|
|
14
|
-
*/
|
|
15
|
-
function traverseObject(obj, callback, options = {}, context = {}) {
|
|
16
|
-
const { maxDepth = 100, includeArrays = true, pathSeparator = "." } = options;
|
|
17
|
-
const currentDepth = context.depth || 0;
|
|
18
|
-
const currentPath = context.path || "";
|
|
19
|
-
// Check depth limit
|
|
20
|
-
if (currentDepth > maxDepth) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
// Call callback for current value
|
|
24
|
-
callback(obj, {
|
|
25
|
-
path: currentPath,
|
|
26
|
-
depth: currentDepth,
|
|
27
|
-
parent: context.parent,
|
|
28
|
-
key: context.key,
|
|
29
|
-
});
|
|
30
|
-
// Handle arrays
|
|
31
|
-
if (Array.isArray(obj) && includeArrays) {
|
|
32
|
-
obj.forEach((item, index) => {
|
|
33
|
-
traverseObject(item, callback, options, {
|
|
34
|
-
path: currentPath ? `${currentPath}[${index}]` : `[${index}]`,
|
|
35
|
-
depth: currentDepth + 1,
|
|
36
|
-
parent: obj,
|
|
37
|
-
key: index.toString(),
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
// Handle objects
|
|
43
|
-
if (obj && typeof obj === "object") {
|
|
44
|
-
Object.entries(obj).forEach(([key, value]) => {
|
|
45
|
-
const newPath = currentPath
|
|
46
|
-
? `${currentPath}${pathSeparator}${key}`
|
|
47
|
-
: key;
|
|
48
|
-
traverseObject(value, callback, options, {
|
|
49
|
-
path: newPath,
|
|
50
|
-
depth: currentDepth + 1,
|
|
51
|
-
parent: obj,
|
|
52
|
-
key,
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Extract all values matching a predicate from an object.
|
|
59
|
-
*/
|
|
60
|
-
function extractValues(obj, predicate, options) {
|
|
61
|
-
const results = [];
|
|
62
|
-
traverseObject(obj, (value, context) => {
|
|
63
|
-
if (predicate(value, context)) {
|
|
64
|
-
results.push({ value, context });
|
|
65
|
-
}
|
|
66
|
-
}, options);
|
|
67
|
-
return results;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Find all paths to values matching a predicate.
|
|
71
|
-
*/
|
|
72
|
-
function findPaths(obj, predicate, options) {
|
|
73
|
-
const paths = [];
|
|
74
|
-
traverseObject(obj, (value, context) => {
|
|
75
|
-
if (predicate(value, context)) {
|
|
76
|
-
paths.push(context.path);
|
|
77
|
-
}
|
|
78
|
-
}, options);
|
|
79
|
-
return paths;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Extract all string values from an object.
|
|
83
|
-
*/
|
|
84
|
-
function extractStrings(obj, options) {
|
|
85
|
-
return extractValues(obj, (value) => typeof value === "string", options);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Extract all object references (schemaRef, $ref) from an object.
|
|
89
|
-
*/
|
|
90
|
-
function extractReferences(obj, refKeys = ["schemaRef", "$ref"], options) {
|
|
91
|
-
return extractValues(obj, (value, context) => {
|
|
92
|
-
return refKeys.includes(context.key || "") && typeof value === "string";
|
|
93
|
-
}, options);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Count keys and depth in an object for security validation.
|
|
97
|
-
*/
|
|
98
|
-
function analyzeObjectStructure(obj, options = {}) {
|
|
99
|
-
let keyCount = 0;
|
|
100
|
-
let maxDepth = 0;
|
|
101
|
-
const paths = [];
|
|
102
|
-
traverseObject(obj, (_value, context) => {
|
|
103
|
-
if (context.key) {
|
|
104
|
-
keyCount++;
|
|
105
|
-
}
|
|
106
|
-
maxDepth = Math.max(maxDepth, context.depth);
|
|
107
|
-
if (context.path) {
|
|
108
|
-
paths.push(context.path);
|
|
109
|
-
}
|
|
110
|
-
}, options);
|
|
111
|
-
return { keyCount, maxDepth, paths };
|
|
112
|
-
}
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateReferences = validateReferences;
|
|
4
|
-
const object_traversal_1 = require("./object-traversal.js");
|
|
5
|
-
/**
|
|
6
|
-
* Extract all schema references from a UniSpec document.
|
|
7
|
-
*/
|
|
8
|
-
function extractSchemaReferences(doc) {
|
|
9
|
-
const references = new Map();
|
|
10
|
-
const schemaRefs = (0, object_traversal_1.extractReferences)(doc, ["schemaRef", "$ref"]);
|
|
11
|
-
for (const { value, context } of schemaRefs) {
|
|
12
|
-
const schemaName = normalizeSchemaRef(value);
|
|
13
|
-
if (schemaName) {
|
|
14
|
-
const existing = references.get(schemaName) || [];
|
|
15
|
-
existing.push(context.path);
|
|
16
|
-
references.set(schemaName, existing);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return references;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Extract all security scheme references from a UniSpec document.
|
|
23
|
-
*/
|
|
24
|
-
function extractSecuritySchemeReferences(doc) {
|
|
25
|
-
const references = new Map();
|
|
26
|
-
const securityRefs = extractValues(doc, (value, context) => {
|
|
27
|
-
return context.key === "security" && Array.isArray(value);
|
|
28
|
-
});
|
|
29
|
-
for (const { value: securityArray, context } of securityRefs) {
|
|
30
|
-
if (!Array.isArray(securityArray))
|
|
31
|
-
continue;
|
|
32
|
-
securityArray.forEach((securityRequirement, index) => {
|
|
33
|
-
if (Array.isArray(securityRequirement)) {
|
|
34
|
-
securityRequirement.forEach((schemeName) => {
|
|
35
|
-
if (typeof schemeName === "string") {
|
|
36
|
-
const existing = references.get(schemeName) || [];
|
|
37
|
-
existing.push(`${context.path}[${index}]`);
|
|
38
|
-
references.set(schemeName, existing);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
return references;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Extract values using object traversal utility.
|
|
48
|
-
*/
|
|
49
|
-
function extractValues(obj, predicate) {
|
|
50
|
-
const results = [];
|
|
51
|
-
function traverse(current, path, depth) {
|
|
52
|
-
if (depth > 100)
|
|
53
|
-
return; // Prevent infinite recursion
|
|
54
|
-
if (predicate(current, { path, depth, key: path.split(".").pop() })) {
|
|
55
|
-
results.push({
|
|
56
|
-
value: current,
|
|
57
|
-
context: { path, depth, key: path.split(".").pop() },
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
if (Array.isArray(current)) {
|
|
61
|
-
current.forEach((item, index) => {
|
|
62
|
-
traverse(item, `${path}[${index}]`, depth + 1);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
else if (current && typeof current === "object") {
|
|
66
|
-
Object.entries(current).forEach(([key, value]) => {
|
|
67
|
-
traverse(value, path ? `${path}.${key}` : key, depth + 1);
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
traverse(obj, "", 0);
|
|
72
|
-
return results;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Normalize schema reference to extract the schema name.
|
|
76
|
-
*/
|
|
77
|
-
function normalizeSchemaRef(ref) {
|
|
78
|
-
const trimmed = ref.trim();
|
|
79
|
-
if (trimmed.length === 0)
|
|
80
|
-
return null;
|
|
81
|
-
// Handle JSON Pointer format: #/service/schemas/SchemaName
|
|
82
|
-
if (trimmed.startsWith("#/service/schemas/")) {
|
|
83
|
-
const parts = trimmed.split("/");
|
|
84
|
-
return parts[parts.length - 1];
|
|
85
|
-
}
|
|
86
|
-
// Handle simple name format: SchemaName
|
|
87
|
-
if (!trimmed.startsWith("#") && !trimmed.includes("/")) {
|
|
88
|
-
return trimmed;
|
|
89
|
-
}
|
|
90
|
-
// Handle hash format: #SchemaName
|
|
91
|
-
if (trimmed.startsWith("#")) {
|
|
92
|
-
const withoutHash = trimmed.slice(1);
|
|
93
|
-
const parts = withoutHash.split("/").filter(Boolean);
|
|
94
|
-
return parts.length > 0 ? parts[parts.length - 1] : withoutHash;
|
|
95
|
-
}
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Validate schema references.
|
|
100
|
-
*/
|
|
101
|
-
function validateSchemaReferences(doc, options, referenceMap) {
|
|
102
|
-
const errors = [];
|
|
103
|
-
if (!options.checkSchemaReferences)
|
|
104
|
-
return errors;
|
|
105
|
-
const schemaReferences = extractSchemaReferences(doc);
|
|
106
|
-
const availableSchemas = new Set(Object.keys(doc.service?.schemas || {}));
|
|
107
|
-
for (const [schemaName, locations] of schemaReferences.entries()) {
|
|
108
|
-
const exists = availableSchemas.has(schemaName);
|
|
109
|
-
// Store reference info
|
|
110
|
-
for (const location of locations) {
|
|
111
|
-
referenceMap.set(location, {
|
|
112
|
-
type: "schema",
|
|
113
|
-
source: location,
|
|
114
|
-
target: schemaName,
|
|
115
|
-
exists,
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
if (!exists) {
|
|
119
|
-
errors.push({
|
|
120
|
-
message: `Schema '${schemaName}' is referenced but not defined`,
|
|
121
|
-
path: locations[0], // First occurrence
|
|
122
|
-
code: "undefined_schema",
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return errors;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Validate security scheme references.
|
|
130
|
-
*/
|
|
131
|
-
function validateSecuritySchemeReferences(doc, options, referenceMap) {
|
|
132
|
-
const errors = [];
|
|
133
|
-
if (!options.checkSecuritySchemeReferences)
|
|
134
|
-
return errors;
|
|
135
|
-
const securityReferences = extractSecuritySchemeReferences(doc);
|
|
136
|
-
const availableSchemes = new Set(Object.keys(doc.service?.securitySchemes || {}));
|
|
137
|
-
for (const [schemeName, locations] of securityReferences.entries()) {
|
|
138
|
-
const exists = availableSchemes.has(schemeName);
|
|
139
|
-
// Store reference info
|
|
140
|
-
for (const location of locations) {
|
|
141
|
-
referenceMap.set(location, {
|
|
142
|
-
type: "securityScheme",
|
|
143
|
-
source: location,
|
|
144
|
-
target: schemeName,
|
|
145
|
-
exists,
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
if (!exists) {
|
|
149
|
-
errors.push({
|
|
150
|
-
message: `Security scheme '${schemeName}' is referenced but not defined`,
|
|
151
|
-
path: locations[0], // First occurrence
|
|
152
|
-
code: "undefined_security_scheme",
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return errors;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Check for unused schemas and security schemes.
|
|
160
|
-
*/
|
|
161
|
-
function validateUnusedReferences(doc, options, referenceMap) {
|
|
162
|
-
const warnings = [];
|
|
163
|
-
if (!options.strictMode)
|
|
164
|
-
return warnings;
|
|
165
|
-
// Find all referenced schemas
|
|
166
|
-
const referencedSchemas = new Set();
|
|
167
|
-
const referencedSecuritySchemes = new Set();
|
|
168
|
-
for (const info of referenceMap.values()) {
|
|
169
|
-
if (info.type === "schema" && info.exists) {
|
|
170
|
-
referencedSchemas.add(info.target);
|
|
171
|
-
}
|
|
172
|
-
else if (info.type === "securityScheme" && info.exists) {
|
|
173
|
-
referencedSecuritySchemes.add(info.target);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
// Check for unused schemas
|
|
177
|
-
const allSchemas = Object.keys(doc.service?.schemas || {});
|
|
178
|
-
for (const schemaName of allSchemas) {
|
|
179
|
-
if (!referencedSchemas.has(schemaName)) {
|
|
180
|
-
warnings.push({
|
|
181
|
-
message: `Schema '${schemaName}' is defined but never referenced`,
|
|
182
|
-
path: `/service/schemas/${schemaName}`,
|
|
183
|
-
code: "unused_schema",
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
// Check for unused security schemes
|
|
188
|
-
const allSecuritySchemes = Object.keys(doc.service?.securitySchemes || {});
|
|
189
|
-
for (const schemeName of allSecuritySchemes) {
|
|
190
|
-
if (!referencedSecuritySchemes.has(schemeName)) {
|
|
191
|
-
warnings.push({
|
|
192
|
-
message: `Security scheme '${schemeName}' is defined but never referenced`,
|
|
193
|
-
path: `/service/securitySchemes/${schemeName}`,
|
|
194
|
-
code: "unused_security_scheme",
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return warnings;
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Perform comprehensive reference validation on a UniSpec document.
|
|
202
|
-
*
|
|
203
|
-
* This function validates:
|
|
204
|
-
* - Schema references (schemaRef, $ref)
|
|
205
|
-
* - Security scheme references
|
|
206
|
-
* - Unused definitions (in strict mode)
|
|
207
|
-
*
|
|
208
|
-
* @param doc - The UniSpec document to validate
|
|
209
|
-
* @param options - Validation options
|
|
210
|
-
* @returns Reference validation result with detailed reference map
|
|
211
|
-
*/
|
|
212
|
-
function validateReferences(doc, options = {}) {
|
|
213
|
-
const errors = [];
|
|
214
|
-
const warnings = [];
|
|
215
|
-
const referenceMap = new Map();
|
|
216
|
-
// Default options
|
|
217
|
-
const opts = {
|
|
218
|
-
checkSchemaReferences: true,
|
|
219
|
-
checkSecuritySchemeReferences: true,
|
|
220
|
-
strictMode: false,
|
|
221
|
-
...options,
|
|
222
|
-
};
|
|
223
|
-
// Validate all reference types
|
|
224
|
-
errors.push(...validateSchemaReferences(doc, opts, referenceMap));
|
|
225
|
-
errors.push(...validateSecuritySchemeReferences(doc, opts, referenceMap));
|
|
226
|
-
warnings.push(...validateUnusedReferences(doc, opts, referenceMap));
|
|
227
|
-
return {
|
|
228
|
-
valid: errors.length === 0,
|
|
229
|
-
errors,
|
|
230
|
-
warnings,
|
|
231
|
-
referenceMap,
|
|
232
|
-
};
|
|
233
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractSchemaReferences = extractSchemaReferences;
|
|
4
|
-
exports.findOrphanedSchemas = findOrphanedSchemas;
|
|
5
|
-
exports.validateSchemaReferences = validateSchemaReferences;
|
|
6
|
-
function extractSchemaReferences(doc) {
|
|
7
|
-
const references = [];
|
|
8
|
-
function extractFromPath(obj, path) {
|
|
9
|
-
if (!obj || typeof obj !== "object")
|
|
10
|
-
return;
|
|
11
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
12
|
-
const currentPath = path ? `${path}.${key}` : key;
|
|
13
|
-
if (key === "schemaRef" && typeof value === "string") {
|
|
14
|
-
references.push({
|
|
15
|
-
path: currentPath,
|
|
16
|
-
schemaName: normalizeSchemaRef(value),
|
|
17
|
-
context: getContextFromPath(currentPath),
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
else if (typeof value === "object" && value !== null) {
|
|
21
|
-
extractFromPath(value, currentPath);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
extractFromPath(doc, "");
|
|
26
|
-
return references;
|
|
27
|
-
}
|
|
28
|
-
function normalizeSchemaRef(ref) {
|
|
29
|
-
const trimmed = ref.trim();
|
|
30
|
-
if (trimmed.length === 0)
|
|
31
|
-
return "";
|
|
32
|
-
if (trimmed.startsWith("#/service/schemas/")) {
|
|
33
|
-
const parts = trimmed.split("/");
|
|
34
|
-
return parts[parts.length - 1];
|
|
35
|
-
}
|
|
36
|
-
const withoutHash = trimmed.startsWith("#") ? trimmed.slice(1) : trimmed;
|
|
37
|
-
const parts = withoutHash.split("/").filter(Boolean);
|
|
38
|
-
return parts.length > 0 ? parts[parts.length - 1] : withoutHash;
|
|
39
|
-
}
|
|
40
|
-
function getContextFromPath(path) {
|
|
41
|
-
if (path.includes("routes"))
|
|
42
|
-
return "REST route";
|
|
43
|
-
if (path.includes("queries"))
|
|
44
|
-
return "GraphQL query";
|
|
45
|
-
if (path.includes("mutations"))
|
|
46
|
-
return "GraphQL mutation";
|
|
47
|
-
if (path.includes("subscriptions"))
|
|
48
|
-
return "GraphQL subscription";
|
|
49
|
-
if (path.includes("channels"))
|
|
50
|
-
return "WebSocket channel";
|
|
51
|
-
if (path.includes("messages"))
|
|
52
|
-
return "WebSocket message";
|
|
53
|
-
if (path.includes("pathParams"))
|
|
54
|
-
return "REST path parameter";
|
|
55
|
-
if (path.includes("queryParams"))
|
|
56
|
-
return "REST query parameter";
|
|
57
|
-
if (path.includes("headers"))
|
|
58
|
-
return "Header parameter";
|
|
59
|
-
if (path.includes("requestBody"))
|
|
60
|
-
return "Request body";
|
|
61
|
-
if (path.includes("responses"))
|
|
62
|
-
return "Response body";
|
|
63
|
-
return "Unknown context";
|
|
64
|
-
}
|
|
65
|
-
function findOrphanedSchemas(doc) {
|
|
66
|
-
const references = extractSchemaReferences(doc);
|
|
67
|
-
const referencedSchemas = new Set(references.map((ref) => ref.schemaName).filter(Boolean));
|
|
68
|
-
const allSchemas = new Set(Object.keys(doc.service?.schemas || {}));
|
|
69
|
-
const orphaned = Array.from(allSchemas).filter((schema) => !referencedSchemas.has(schema));
|
|
70
|
-
return orphaned;
|
|
71
|
-
}
|
|
72
|
-
function validateSchemaReferences(doc) {
|
|
73
|
-
const errors = [];
|
|
74
|
-
const references = extractSchemaReferences(doc);
|
|
75
|
-
const allSchemas = new Set(Object.keys(doc.service?.schemas || {}));
|
|
76
|
-
const valid = [];
|
|
77
|
-
const invalid = [];
|
|
78
|
-
for (const ref of references) {
|
|
79
|
-
if (allSchemas.has(ref.schemaName)) {
|
|
80
|
-
valid.push(ref);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
invalid.push(ref);
|
|
84
|
-
errors.push({
|
|
85
|
-
message: `Schema reference "${ref.schemaName}" not found at ${ref.path}`,
|
|
86
|
-
path: ref.path,
|
|
87
|
-
code: "schema_not_found",
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
const orphaned = findOrphanedSchemas(doc);
|
|
92
|
-
for (const orphan of orphaned) {
|
|
93
|
-
errors.push({
|
|
94
|
-
message: `Schema "${orphan}" is defined but never referenced`,
|
|
95
|
-
path: `/service/schemas/${orphan}`,
|
|
96
|
-
code: "orphaned_schema",
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
const isValid = errors.length === 0;
|
|
100
|
-
return {
|
|
101
|
-
valid: isValid,
|
|
102
|
-
errors,
|
|
103
|
-
references: {
|
|
104
|
-
valid,
|
|
105
|
-
invalid,
|
|
106
|
-
orphaned,
|
|
107
|
-
circular: [],
|
|
108
|
-
},
|
|
109
|
-
statistics: {
|
|
110
|
-
totalSchemas: allSchemas.size,
|
|
111
|
-
totalReferences: references.length,
|
|
112
|
-
orphanedSchemas: orphaned.length,
|
|
113
|
-
circularDependencies: 0,
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
}
|