@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
package/dist/schemas/resolver.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { normalizeSchemaRef } from "./utils.js";
|
|
2
|
-
/**
|
|
3
|
-
* Resolve a schema reference to its definition in a UniSpec document.
|
|
4
|
-
*
|
|
5
|
-
* @param doc - The UniSpec document containing schemas
|
|
6
|
-
* @param ref - The schema reference to resolve
|
|
7
|
-
* @returns The schema definition or undefined if not found
|
|
8
|
-
*/
|
|
9
|
-
export function resolveSchemaRef(doc, ref) {
|
|
10
|
-
const name = normalizeSchemaRef(ref);
|
|
11
|
-
if (!name)
|
|
12
|
-
return undefined;
|
|
13
|
-
return doc.service?.schemas?.[name];
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Register a new schema definition in a UniSpec document.
|
|
17
|
-
* Creates the schemas container if it doesn't exist.
|
|
18
|
-
*
|
|
19
|
-
* @param doc - The UniSpec document to modify
|
|
20
|
-
* @param name - The schema name
|
|
21
|
-
* @param jsonSchema - The JSON Schema definition
|
|
22
|
-
* @returns The created schema definition
|
|
23
|
-
*/
|
|
24
|
-
export function registerSchema(doc, name, jsonSchema) {
|
|
25
|
-
if (!doc.service) {
|
|
26
|
-
doc.service = { name: "" };
|
|
27
|
-
}
|
|
28
|
-
if (!doc.service.schemas) {
|
|
29
|
-
doc.service.schemas = {};
|
|
30
|
-
}
|
|
31
|
-
const definition = {
|
|
32
|
-
name,
|
|
33
|
-
jsonSchema,
|
|
34
|
-
};
|
|
35
|
-
doc.service.schemas[name] = definition;
|
|
36
|
-
return definition;
|
|
37
|
-
}
|
package/dist/schemas/utils.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Normalize a schema reference to extract the schema name.
|
|
3
|
-
* Supports multiple formats:
|
|
4
|
-
* - Simple name: "User"
|
|
5
|
-
* - JSON Pointer: "#/service/schemas/User"
|
|
6
|
-
* - Hash format: "#User"
|
|
7
|
-
* - Path format: "path/to/User"
|
|
8
|
-
*
|
|
9
|
-
* @param ref - The schema reference to normalize
|
|
10
|
-
* @returns The normalized schema name
|
|
11
|
-
*/
|
|
12
|
-
export declare function normalizeSchemaRef(ref: string): string;
|
|
13
|
-
/**
|
|
14
|
-
* Create a stable string representation of a value for comparison.
|
|
15
|
-
* Used for schema deduplication by creating consistent JSON strings.
|
|
16
|
-
*
|
|
17
|
-
* @param value - The value to stringify
|
|
18
|
-
* @returns A stable JSON string representation
|
|
19
|
-
*/
|
|
20
|
-
export declare function stableStringify(value: unknown): string;
|
package/dist/schemas/utils.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Normalize a schema reference to extract the schema name.
|
|
3
|
-
* Supports multiple formats:
|
|
4
|
-
* - Simple name: "User"
|
|
5
|
-
* - JSON Pointer: "#/service/schemas/User"
|
|
6
|
-
* - Hash format: "#User"
|
|
7
|
-
* - Path format: "path/to/User"
|
|
8
|
-
*
|
|
9
|
-
* @param ref - The schema reference to normalize
|
|
10
|
-
* @returns The normalized schema name
|
|
11
|
-
*/
|
|
12
|
-
export function normalizeSchemaRef(ref) {
|
|
13
|
-
const trimmed = ref.trim();
|
|
14
|
-
if (trimmed.length === 0)
|
|
15
|
-
return "";
|
|
16
|
-
// Handle JSON Pointer format: #/service/schemas/SchemaName
|
|
17
|
-
if (trimmed.startsWith("#/service/schemas/")) {
|
|
18
|
-
const parts = trimmed.split("/");
|
|
19
|
-
return parts[parts.length - 1];
|
|
20
|
-
}
|
|
21
|
-
// Handle simple name format: SchemaName
|
|
22
|
-
const withoutHash = trimmed.startsWith("#") ? trimmed.slice(1) : trimmed;
|
|
23
|
-
const parts = withoutHash.split("/").filter(Boolean);
|
|
24
|
-
return parts.length > 0 ? parts[parts.length - 1] : withoutHash;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Create a stable string representation of a value for comparison.
|
|
28
|
-
* Used for schema deduplication by creating consistent JSON strings.
|
|
29
|
-
*
|
|
30
|
-
* @param value - The value to stringify
|
|
31
|
-
* @returns A stable JSON string representation
|
|
32
|
-
*/
|
|
33
|
-
export function stableStringify(value) {
|
|
34
|
-
if (value === null)
|
|
35
|
-
return "null";
|
|
36
|
-
const t = typeof value;
|
|
37
|
-
if (t === "number" || t === "boolean")
|
|
38
|
-
return JSON.stringify(value);
|
|
39
|
-
if (t === "string")
|
|
40
|
-
return JSON.stringify(value);
|
|
41
|
-
if (Array.isArray(value))
|
|
42
|
-
return `[${value.map(stableStringify).join(",")}]`;
|
|
43
|
-
if (t !== "object")
|
|
44
|
-
return JSON.stringify(value);
|
|
45
|
-
const obj = value;
|
|
46
|
-
const keys = Object.keys(obj).sort();
|
|
47
|
-
const entries = keys.map((k) => `${JSON.stringify(k)}:${stableStringify(obj[k])}`);
|
|
48
|
-
return `{${entries.join(",")}}`;
|
|
49
|
-
}
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,433 +0,0 @@
|
|
|
1
|
-
export interface UniSpecNamedItem {
|
|
2
|
-
name: string;
|
|
3
|
-
description?: string;
|
|
4
|
-
}
|
|
5
|
-
export interface UniSpecDeprecatedItem {
|
|
6
|
-
deprecated?: boolean;
|
|
7
|
-
deprecationReason?: string;
|
|
8
|
-
}
|
|
9
|
-
export interface UniSpecTaggedItem {
|
|
10
|
-
tags?: string[];
|
|
11
|
-
}
|
|
12
|
-
export interface UniSpecProtocolBase {
|
|
13
|
-
url?: string;
|
|
14
|
-
securitySchemes?: Record<string, UniSpecSecurityScheme>;
|
|
15
|
-
}
|
|
16
|
-
export interface UniSpecSecurityRequirement extends Array<string> {
|
|
17
|
-
}
|
|
18
|
-
export interface UniSpecBaseHeader {
|
|
19
|
-
name: string;
|
|
20
|
-
description?: string;
|
|
21
|
-
required?: boolean;
|
|
22
|
-
}
|
|
23
|
-
export interface UniSpecHeader extends UniSpecBaseHeader {
|
|
24
|
-
defaultValue?: string;
|
|
25
|
-
schemaRef?: string;
|
|
26
|
-
}
|
|
27
|
-
export interface UniSpecApiKeyScheme {
|
|
28
|
-
type: "apiKey";
|
|
29
|
-
name: string;
|
|
30
|
-
in: "header" | "query" | "cookie";
|
|
31
|
-
description?: string;
|
|
32
|
-
}
|
|
33
|
-
export interface UniSpecHttpScheme {
|
|
34
|
-
type: "http";
|
|
35
|
-
scheme: "basic" | "bearer" | "digest";
|
|
36
|
-
bearerFormat?: string;
|
|
37
|
-
description?: string;
|
|
38
|
-
}
|
|
39
|
-
export interface UniSpecOAuth2Flow {
|
|
40
|
-
authorizationUrl: string;
|
|
41
|
-
tokenUrl: string;
|
|
42
|
-
refreshUrl?: string;
|
|
43
|
-
scopes: Record<string, string>;
|
|
44
|
-
}
|
|
45
|
-
export interface UniSpecOAuth2Scheme {
|
|
46
|
-
type: "oauth2";
|
|
47
|
-
flows: {
|
|
48
|
-
authorizationCode?: UniSpecOAuth2Flow;
|
|
49
|
-
clientCredentials?: UniSpecOAuth2Flow;
|
|
50
|
-
implicit?: UniSpecOAuth2Flow;
|
|
51
|
-
};
|
|
52
|
-
description?: string;
|
|
53
|
-
}
|
|
54
|
-
export interface UniSpecJwtScheme {
|
|
55
|
-
type: "jwt";
|
|
56
|
-
issuer?: string;
|
|
57
|
-
audience?: string[];
|
|
58
|
-
algorithms?: string[];
|
|
59
|
-
description?: string;
|
|
60
|
-
}
|
|
61
|
-
export type UniSpecSecurityScheme = UniSpecApiKeyScheme | UniSpecHttpScheme | UniSpecOAuth2Scheme | UniSpecJwtScheme;
|
|
62
|
-
export interface UniSpecGraphQLArgument extends UniSpecNamedItem, UniSpecDeprecatedItem {
|
|
63
|
-
type: string;
|
|
64
|
-
defaultValue?: unknown;
|
|
65
|
-
}
|
|
66
|
-
export interface UniSpecGraphQLOperation extends UniSpecNamedItem, UniSpecDeprecatedItem, UniSpecTaggedItem {
|
|
67
|
-
args?: UniSpecGraphQLArgument[];
|
|
68
|
-
returnType?: string;
|
|
69
|
-
headers?: UniSpecGraphQLHeader[];
|
|
70
|
-
security?: UniSpecSecurityRequirement[];
|
|
71
|
-
}
|
|
72
|
-
export interface UniSpecGraphQLHeader extends UniSpecBaseHeader {
|
|
73
|
-
}
|
|
74
|
-
export interface UniSpecGraphQLProtocol extends UniSpecProtocolBase {
|
|
75
|
-
schema?: string;
|
|
76
|
-
headers?: UniSpecGraphQLHeader[];
|
|
77
|
-
queries?: UniSpecGraphQLOperation[];
|
|
78
|
-
mutations?: UniSpecGraphQLOperation[];
|
|
79
|
-
subscriptions?: UniSpecGraphQLOperation[];
|
|
80
|
-
}
|
|
81
|
-
export interface UniSpecWebSocketMessage extends UniSpecNamedItem, UniSpecDeprecatedItem {
|
|
82
|
-
direction?: "publish" | "subscribe" | "both";
|
|
83
|
-
schemaRef?: string;
|
|
84
|
-
}
|
|
85
|
-
export interface UniSpecWebSocketHeader extends UniSpecBaseHeader {
|
|
86
|
-
}
|
|
87
|
-
export interface UniSpecWebSocketReconnectStrategy {
|
|
88
|
-
maxAttempts?: number;
|
|
89
|
-
delay?: number;
|
|
90
|
-
backoffMultiplier?: number;
|
|
91
|
-
}
|
|
92
|
-
export interface UniSpecWebSocketChannel extends UniSpecNamedItem, UniSpecDeprecatedItem, UniSpecTaggedItem {
|
|
93
|
-
namespace?: string;
|
|
94
|
-
direction?: "publish" | "subscribe" | "both";
|
|
95
|
-
connectionParams?: Record<string, string>;
|
|
96
|
-
reconnectStrategy?: UniSpecWebSocketReconnectStrategy;
|
|
97
|
-
headers?: UniSpecWebSocketHeader[];
|
|
98
|
-
messages?: UniSpecWebSocketMessage[];
|
|
99
|
-
security?: UniSpecSecurityRequirement[];
|
|
100
|
-
}
|
|
101
|
-
export interface UniSpecWebSocketProtocol extends UniSpecProtocolBase {
|
|
102
|
-
headers?: UniSpecWebSocketHeader[];
|
|
103
|
-
channels?: UniSpecWebSocketChannel[];
|
|
104
|
-
}
|
|
105
|
-
export interface UniSpecRestParameter extends UniSpecBaseHeader {
|
|
106
|
-
schemaRef?: string;
|
|
107
|
-
}
|
|
108
|
-
export interface UniSpecRestMediaType {
|
|
109
|
-
schemaRef?: string;
|
|
110
|
-
}
|
|
111
|
-
export interface UniSpecRestContent {
|
|
112
|
-
[mediaType: string]: UniSpecRestMediaType;
|
|
113
|
-
}
|
|
114
|
-
export interface UniSpecRestRequestBody {
|
|
115
|
-
description?: string;
|
|
116
|
-
required?: boolean;
|
|
117
|
-
content?: UniSpecRestContent;
|
|
118
|
-
}
|
|
119
|
-
export interface UniSpecRestResponseHeader extends UniSpecHeader {
|
|
120
|
-
}
|
|
121
|
-
export interface UniSpecRestResponse {
|
|
122
|
-
description?: string;
|
|
123
|
-
headers?: UniSpecRestResponseHeader[];
|
|
124
|
-
content?: UniSpecRestContent;
|
|
125
|
-
}
|
|
126
|
-
export interface UniSpecRestRoute extends UniSpecNamedItem, UniSpecDeprecatedItem, UniSpecTaggedItem {
|
|
127
|
-
summary?: string;
|
|
128
|
-
path: string;
|
|
129
|
-
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
130
|
-
pathParams?: UniSpecRestParameter[];
|
|
131
|
-
queryParams?: UniSpecRestParameter[];
|
|
132
|
-
headers?: UniSpecRestParameter[];
|
|
133
|
-
requestBody?: UniSpecRestRequestBody;
|
|
134
|
-
responses?: Record<string, UniSpecRestResponse>;
|
|
135
|
-
security?: UniSpecSecurityRequirement[];
|
|
136
|
-
}
|
|
137
|
-
export interface UniSpecRestProtocol extends UniSpecProtocolBase {
|
|
138
|
-
routes?: UniSpecRestRoute[];
|
|
139
|
-
}
|
|
140
|
-
export interface UniSpecSchemaValidation {
|
|
141
|
-
strict?: boolean;
|
|
142
|
-
additionalProperties?: boolean;
|
|
143
|
-
customValidators?: UniSpecCustomValidator[];
|
|
144
|
-
}
|
|
145
|
-
export interface UniSpecCustomValidator {
|
|
146
|
-
name: string;
|
|
147
|
-
rule: string;
|
|
148
|
-
message: string;
|
|
149
|
-
}
|
|
150
|
-
export interface UniSpecSchemaDefinition extends UniSpecNamedItem, UniSpecDeprecatedItem {
|
|
151
|
-
examples?: unknown[];
|
|
152
|
-
jsonSchema: Record<string, unknown>;
|
|
153
|
-
validation?: UniSpecSchemaValidation;
|
|
154
|
-
}
|
|
155
|
-
export interface UniSpecSchemas {
|
|
156
|
-
[name: string]: UniSpecSchemaDefinition;
|
|
157
|
-
}
|
|
158
|
-
export interface UniSpecEnvironment {
|
|
159
|
-
name: string;
|
|
160
|
-
baseUrl: string;
|
|
161
|
-
region?: string;
|
|
162
|
-
labels?: Record<string, string>;
|
|
163
|
-
isDefault?: boolean;
|
|
164
|
-
}
|
|
165
|
-
export interface UniSpecServer {
|
|
166
|
-
url: string;
|
|
167
|
-
description?: string;
|
|
168
|
-
}
|
|
169
|
-
export interface UniSpecContact {
|
|
170
|
-
name?: string;
|
|
171
|
-
email?: string;
|
|
172
|
-
url?: string;
|
|
173
|
-
}
|
|
174
|
-
export interface UniSpecLicense {
|
|
175
|
-
name?: string;
|
|
176
|
-
url?: string;
|
|
177
|
-
}
|
|
178
|
-
export interface UniSpecRateLimit {
|
|
179
|
-
requestsPerMinute?: number;
|
|
180
|
-
requestsPerHour?: number;
|
|
181
|
-
requestsPerDay?: number;
|
|
182
|
-
burstLimit?: number;
|
|
183
|
-
perUser?: boolean;
|
|
184
|
-
perApiKey?: boolean;
|
|
185
|
-
customKey?: string;
|
|
186
|
-
}
|
|
187
|
-
export type UniSpecCompliance = "GDPR" | "SOC2" | "HIPAA" | "PCI-DSS" | "ISO27001" | "CCPA";
|
|
188
|
-
export type UniSpecDataClassification = "public" | "internal" | "confidential" | "restricted";
|
|
189
|
-
export interface UniSpecServiceProtocols {
|
|
190
|
-
rest?: UniSpecRestProtocol;
|
|
191
|
-
graphql?: UniSpecGraphQLProtocol;
|
|
192
|
-
websocket?: UniSpecWebSocketProtocol;
|
|
193
|
-
}
|
|
194
|
-
export interface UniSpecDocument {
|
|
195
|
-
unispecVersion: string;
|
|
196
|
-
service: UniSpecService;
|
|
197
|
-
}
|
|
198
|
-
export interface UniSpecService extends UniSpecNamedItem, UniSpecTaggedItem {
|
|
199
|
-
version?: string;
|
|
200
|
-
baseUrl?: string;
|
|
201
|
-
contact?: UniSpecContact;
|
|
202
|
-
license?: UniSpecLicense;
|
|
203
|
-
servers?: UniSpecServer[];
|
|
204
|
-
protocols?: UniSpecServiceProtocols;
|
|
205
|
-
schemas?: UniSpecSchemas;
|
|
206
|
-
securitySchemes?: Record<string, UniSpecSecurityScheme>;
|
|
207
|
-
rateLimit?: UniSpecRateLimit;
|
|
208
|
-
compliance?: UniSpecCompliance[];
|
|
209
|
-
dataClassification?: UniSpecDataClassification;
|
|
210
|
-
}
|
|
211
|
-
export interface ValidationError {
|
|
212
|
-
message: string;
|
|
213
|
-
path?: string;
|
|
214
|
-
code?: string;
|
|
215
|
-
}
|
|
216
|
-
export interface ValidationResult {
|
|
217
|
-
valid: boolean;
|
|
218
|
-
errors: ValidationError[];
|
|
219
|
-
}
|
|
220
|
-
export interface UniSpecTestRequestBase {
|
|
221
|
-
headers?: Record<string, unknown>;
|
|
222
|
-
authProfile?: string;
|
|
223
|
-
}
|
|
224
|
-
export type UniSpecTestProtocol = "rest" | "graphql" | "websocket";
|
|
225
|
-
export interface UniSpecTestTarget {
|
|
226
|
-
protocol: UniSpecTestProtocol;
|
|
227
|
-
operationId: string;
|
|
228
|
-
environment?: string;
|
|
229
|
-
}
|
|
230
|
-
export interface UniSpecRestTestParams {
|
|
231
|
-
path?: Record<string, unknown>;
|
|
232
|
-
query?: Record<string, unknown>;
|
|
233
|
-
}
|
|
234
|
-
export interface UniSpecRestTestRequest extends UniSpecTestRequestBase {
|
|
235
|
-
params?: UniSpecRestTestParams;
|
|
236
|
-
body?: unknown;
|
|
237
|
-
}
|
|
238
|
-
export type UniSpecRestExpectedStatus = number | number[];
|
|
239
|
-
export interface UniSpecRestBodyExpectation {
|
|
240
|
-
mode?: "exact" | "contains" | "schemaOnly" | "snapshot";
|
|
241
|
-
json?: unknown;
|
|
242
|
-
schemaRef?: string;
|
|
243
|
-
}
|
|
244
|
-
export interface UniSpecRestTestExpect {
|
|
245
|
-
status: UniSpecRestExpectedStatus;
|
|
246
|
-
headers?: Record<string, unknown>;
|
|
247
|
-
body?: UniSpecRestBodyExpectation;
|
|
248
|
-
}
|
|
249
|
-
export interface UniSpecGraphQLTestRequest extends UniSpecTestRequestBase {
|
|
250
|
-
operationName?: string;
|
|
251
|
-
query: string;
|
|
252
|
-
variables?: Record<string, unknown>;
|
|
253
|
-
}
|
|
254
|
-
export interface UniSpecGraphQLTestExpect {
|
|
255
|
-
data?: unknown;
|
|
256
|
-
errors?: unknown;
|
|
257
|
-
bodyMode?: string;
|
|
258
|
-
}
|
|
259
|
-
export type UniSpecWebSocketTestMessageActionType = "send" | "expect";
|
|
260
|
-
export interface UniSpecWebSocketTestMessageAction {
|
|
261
|
-
type: UniSpecWebSocketTestMessageActionType;
|
|
262
|
-
messageName: string;
|
|
263
|
-
payload?: unknown;
|
|
264
|
-
}
|
|
265
|
-
export interface UniSpecWebSocketTestRequest extends UniSpecTestRequestBase {
|
|
266
|
-
channel: string;
|
|
267
|
-
direction?: "publish" | "subscribe" | "both";
|
|
268
|
-
messages?: UniSpecWebSocketTestMessageAction[];
|
|
269
|
-
}
|
|
270
|
-
export interface UniSpecWebSocketTestExpect {
|
|
271
|
-
messages?: UniSpecWebSocketTestMessageAction[];
|
|
272
|
-
timeoutMs?: number;
|
|
273
|
-
}
|
|
274
|
-
export interface UniSpecTestRequest {
|
|
275
|
-
rest?: UniSpecRestTestRequest;
|
|
276
|
-
graphql?: UniSpecGraphQLTestRequest;
|
|
277
|
-
websocket?: UniSpecWebSocketTestRequest;
|
|
278
|
-
}
|
|
279
|
-
export interface UniSpecTestExpect {
|
|
280
|
-
rest?: UniSpecRestTestExpect;
|
|
281
|
-
graphql?: UniSpecGraphQLTestExpect;
|
|
282
|
-
websocket?: UniSpecWebSocketTestExpect;
|
|
283
|
-
}
|
|
284
|
-
export interface UniSpecTestCase extends UniSpecNamedItem {
|
|
285
|
-
target: UniSpecTestTarget;
|
|
286
|
-
request: UniSpecTestRequest;
|
|
287
|
-
expect: UniSpecTestExpect;
|
|
288
|
-
tags?: string[];
|
|
289
|
-
}
|
|
290
|
-
export interface UniSpecTestsDocument {
|
|
291
|
-
uniSpecTestsVersion: string;
|
|
292
|
-
target: {
|
|
293
|
-
serviceName: string;
|
|
294
|
-
serviceVersion?: string;
|
|
295
|
-
environment?: string;
|
|
296
|
-
};
|
|
297
|
-
tests: UniSpecTestCase[];
|
|
298
|
-
loadTesting?: {
|
|
299
|
-
concurrentUsers?: number;
|
|
300
|
-
duration?: string;
|
|
301
|
-
rampUp?: string;
|
|
302
|
-
thresholds?: {
|
|
303
|
-
responseTime?: string;
|
|
304
|
-
errorRate?: number;
|
|
305
|
-
throughput?: string;
|
|
306
|
-
};
|
|
307
|
-
scenario?: {
|
|
308
|
-
weight?: Record<string, number>;
|
|
309
|
-
thinkTime?: string;
|
|
310
|
-
};
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
export interface UniSpecConfigDocument {
|
|
314
|
-
version: number;
|
|
315
|
-
services: UniSpecConfigServiceEntry[];
|
|
316
|
-
discovery?: UniSpecConfigDiscovery;
|
|
317
|
-
environments?: UniSpecConfigEnvironment[];
|
|
318
|
-
}
|
|
319
|
-
export interface UniSpecConfigServiceEntry {
|
|
320
|
-
name: string;
|
|
321
|
-
baseUrl?: string;
|
|
322
|
-
spec: UniSpecConfigSpecReference;
|
|
323
|
-
health?: UniSpecConfigHealth;
|
|
324
|
-
discovery?: UniSpecConfigDiscovery;
|
|
325
|
-
headers?: UniSpecConfigHeader[];
|
|
326
|
-
security?: UniSpecConfigSecurityRequirement[];
|
|
327
|
-
}
|
|
328
|
-
export type UniSpecConfigSpecReference = string | UniSpecConfigHttpSpecReference | UniSpecConfigFileSpecReference | UniSpecConfigRegistrySpecReference;
|
|
329
|
-
export interface UniSpecConfigHttpSpecReference {
|
|
330
|
-
type: "http";
|
|
331
|
-
url?: string;
|
|
332
|
-
path?: string;
|
|
333
|
-
}
|
|
334
|
-
export interface UniSpecConfigFileSpecReference {
|
|
335
|
-
type: "file";
|
|
336
|
-
path: string;
|
|
337
|
-
}
|
|
338
|
-
export interface UniSpecConfigRegistrySpecReference {
|
|
339
|
-
type: "registry";
|
|
340
|
-
ref: string;
|
|
341
|
-
}
|
|
342
|
-
export interface UniSpecConfigHealth {
|
|
343
|
-
path: string;
|
|
344
|
-
}
|
|
345
|
-
export interface UniSpecConfigDiscovery {
|
|
346
|
-
dnsTemplate?: string;
|
|
347
|
-
}
|
|
348
|
-
export interface UniSpecConfigEnvironment {
|
|
349
|
-
name: string;
|
|
350
|
-
overrides?: UniSpecConfigEnvironmentOverrides;
|
|
351
|
-
observability?: UniSpecConfigObservability;
|
|
352
|
-
deployment?: UniSpecConfigDeployment;
|
|
353
|
-
dataResidency?: string;
|
|
354
|
-
audit?: UniSpecConfigAudit;
|
|
355
|
-
}
|
|
356
|
-
export interface UniSpecConfigEnvironmentOverrides {
|
|
357
|
-
services?: Record<string, UniSpecConfigServiceOverride>;
|
|
358
|
-
}
|
|
359
|
-
export interface UniSpecConfigServiceOverride {
|
|
360
|
-
baseUrl?: string;
|
|
361
|
-
spec?: UniSpecConfigSpecReference;
|
|
362
|
-
health?: UniSpecConfigHealth;
|
|
363
|
-
discovery?: UniSpecConfigDiscovery;
|
|
364
|
-
headers?: UniSpecConfigHeader[];
|
|
365
|
-
security?: UniSpecConfigSecurityRequirement[];
|
|
366
|
-
}
|
|
367
|
-
export interface UniSpecConfigHeader {
|
|
368
|
-
name: string;
|
|
369
|
-
description?: string;
|
|
370
|
-
required?: boolean;
|
|
371
|
-
defaultValue?: string;
|
|
372
|
-
}
|
|
373
|
-
export type UniSpecConfigSecurityRequirement = string[];
|
|
374
|
-
export interface UniSpecConfigObservability {
|
|
375
|
-
logging?: {
|
|
376
|
-
level?: "debug" | "info" | "warn" | "error";
|
|
377
|
-
format?: "json" | "text";
|
|
378
|
-
fields?: string[];
|
|
379
|
-
};
|
|
380
|
-
metrics?: {
|
|
381
|
-
enabled?: boolean;
|
|
382
|
-
endpoints?: string[];
|
|
383
|
-
customMetrics?: UniSpecConfigCustomMetric[];
|
|
384
|
-
};
|
|
385
|
-
tracing?: {
|
|
386
|
-
enabled?: boolean;
|
|
387
|
-
samplingRate?: number;
|
|
388
|
-
exporter?: string;
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
export interface UniSpecConfigCustomMetric {
|
|
392
|
-
name: string;
|
|
393
|
-
type: "counter" | "gauge" | "histogram" | "summary";
|
|
394
|
-
description?: string;
|
|
395
|
-
labels?: string[];
|
|
396
|
-
}
|
|
397
|
-
export interface UniSpecConfigDeployment {
|
|
398
|
-
kubernetes?: UniSpecConfigKubernetesConfig;
|
|
399
|
-
docker?: UniSpecConfigDockerConfig;
|
|
400
|
-
replicas?: number;
|
|
401
|
-
resources?: UniSpecConfigResources;
|
|
402
|
-
}
|
|
403
|
-
export interface UniSpecConfigKubernetesConfig {
|
|
404
|
-
namespace?: string;
|
|
405
|
-
image?: string;
|
|
406
|
-
port?: number;
|
|
407
|
-
serviceType?: "ClusterIP" | "NodePort" | "LoadBalancer";
|
|
408
|
-
ingress?: {
|
|
409
|
-
host?: string;
|
|
410
|
-
path?: string;
|
|
411
|
-
tls?: boolean;
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
export interface UniSpecConfigDockerConfig {
|
|
415
|
-
image?: string;
|
|
416
|
-
port?: number;
|
|
417
|
-
environment?: Record<string, string>;
|
|
418
|
-
volumes?: string[];
|
|
419
|
-
}
|
|
420
|
-
export interface UniSpecConfigResources {
|
|
421
|
-
cpu?: string;
|
|
422
|
-
memory?: string;
|
|
423
|
-
storage?: string;
|
|
424
|
-
}
|
|
425
|
-
export interface UniSpecConfigAudit {
|
|
426
|
-
enabled?: boolean;
|
|
427
|
-
retention?: string;
|
|
428
|
-
fields?: string[];
|
|
429
|
-
export?: {
|
|
430
|
-
format?: "json" | "csv";
|
|
431
|
-
destination?: string;
|
|
432
|
-
};
|
|
433
|
-
}
|
package/dist/types/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { AjvValidateFn, ValidateOptions } from "./types.js";
|
|
2
|
-
declare let cached: {
|
|
3
|
-
validateUniSpecFn: AjvValidateFn;
|
|
4
|
-
validateUniSpecTestsFn?: AjvValidateFn;
|
|
5
|
-
validateUniSpecConfigFn?: AjvValidateFn;
|
|
6
|
-
} | null;
|
|
7
|
-
/**
|
|
8
|
-
* Get compiled AJV validators for different document types.
|
|
9
|
-
*/
|
|
10
|
-
export declare function getValidator(options?: ValidateOptions): Promise<NonNullable<typeof cached>>;
|
|
11
|
-
/**
|
|
12
|
-
* Clear cached validators (useful for testing or when schemas change).
|
|
13
|
-
*/
|
|
14
|
-
export declare function clearValidatorCache(): void;
|
|
15
|
-
export {};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import Ajv2020 from "ajv/dist/2020.js";
|
|
2
|
-
import { GENERATED_SCHEMAS } from "../generated-schemas.js";
|
|
3
|
-
let cached = null;
|
|
4
|
-
/**
|
|
5
|
-
* Load default schemas from generated schemas.
|
|
6
|
-
*/
|
|
7
|
-
async function loadDefaultSchemas() {
|
|
8
|
-
// Always use generated schemas - they work in all environments
|
|
9
|
-
return {
|
|
10
|
-
unispec: GENERATED_SCHEMAS.unispec,
|
|
11
|
-
unispecTests: GENERATED_SCHEMAS.unispecTests,
|
|
12
|
-
unispecConfig: GENERATED_SCHEMAS.unispecConfig,
|
|
13
|
-
subschemas: GENERATED_SCHEMAS.subschemas,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Create AJV instance with custom formats and options.
|
|
18
|
-
*/
|
|
19
|
-
function createAjv(options) {
|
|
20
|
-
const ajv = new Ajv2020({
|
|
21
|
-
allErrors: true,
|
|
22
|
-
strict: false, // Disabled to support discriminator keyword in new schema
|
|
23
|
-
...(options.ajvOptions ?? {}),
|
|
24
|
-
});
|
|
25
|
-
// Add format validators
|
|
26
|
-
ajv.addFormat("uri", true);
|
|
27
|
-
ajv.addFormat("email", {
|
|
28
|
-
type: "string",
|
|
29
|
-
validate: (data) => {
|
|
30
|
-
// Basic email validation regex
|
|
31
|
-
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
|
32
|
-
return typeof data === "string" && emailRegex.test(data);
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
return ajv;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Get compiled AJV validators for different document types.
|
|
39
|
-
*/
|
|
40
|
-
export async function getValidator(options = {}) {
|
|
41
|
-
if (cached &&
|
|
42
|
-
!options.schemas &&
|
|
43
|
-
!options.schemaProvider &&
|
|
44
|
-
!options.ajvOptions)
|
|
45
|
-
return cached;
|
|
46
|
-
const schemas = options.schemas ?? (await loadDefaultSchemas());
|
|
47
|
-
const ajv = createAjv(options);
|
|
48
|
-
if (schemas.subschemas?.length) {
|
|
49
|
-
ajv.addSchema(schemas.subschemas);
|
|
50
|
-
}
|
|
51
|
-
const validateUniSpecFn = ajv.compile(schemas.unispec);
|
|
52
|
-
let validateUniSpecTestsFn;
|
|
53
|
-
if (schemas.unispecTests) {
|
|
54
|
-
validateUniSpecTestsFn = ajv.compile(schemas.unispecTests);
|
|
55
|
-
}
|
|
56
|
-
let validateUniSpecConfigFn;
|
|
57
|
-
if (schemas.unispecConfig) {
|
|
58
|
-
validateUniSpecConfigFn = ajv.compile(schemas.unispecConfig);
|
|
59
|
-
}
|
|
60
|
-
const result = {
|
|
61
|
-
validateUniSpecFn,
|
|
62
|
-
validateUniSpecTestsFn,
|
|
63
|
-
validateUniSpecConfigFn,
|
|
64
|
-
};
|
|
65
|
-
if (!options.schemas && !options.schemaProvider && !options.ajvOptions) {
|
|
66
|
-
cached = result;
|
|
67
|
-
}
|
|
68
|
-
return result;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Clear cached validators (useful for testing or when schemas change).
|
|
72
|
-
*/
|
|
73
|
-
export function clearValidatorCache() {
|
|
74
|
-
cached = null;
|
|
75
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { UniSpecConfigDocument, ValidationResult } from "../types/index.js";
|
|
2
|
-
import type { ValidateOptions } from "./types.js";
|
|
3
|
-
/**
|
|
4
|
-
* Validate a UniSpec Config document against the UniSpec Config JSON Schema.
|
|
5
|
-
*
|
|
6
|
-
* @param doc - The UniSpec Config document to validate
|
|
7
|
-
* @param options - Validation options including custom schemas
|
|
8
|
-
* @returns Validation result with success status and error details
|
|
9
|
-
*/
|
|
10
|
-
export declare function validateUniSpecConfig(doc: UniSpecConfigDocument, options?: ValidateOptions): Promise<ValidationResult>;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { ErrorFactory } from "../errors/index.js";
|
|
2
|
-
import { getValidator } from "./ajv-validator.js";
|
|
3
|
-
import { validateConfigCustomRules } from "./config-validator.js";
|
|
4
|
-
import { createValidator } from "./validator-factory.js";
|
|
5
|
-
/**
|
|
6
|
-
* Validate a UniSpec Config document against the UniSpec Config JSON Schema.
|
|
7
|
-
*
|
|
8
|
-
* @param doc - The UniSpec Config document to validate
|
|
9
|
-
* @param options - Validation options including custom schemas
|
|
10
|
-
* @returns Validation result with success status and error details
|
|
11
|
-
*/
|
|
12
|
-
export async function validateUniSpecConfig(doc, options = {}) {
|
|
13
|
-
// Handle null input
|
|
14
|
-
if (doc === null || doc === undefined) {
|
|
15
|
-
const error = ErrorFactory.fromError(new Error("Config validation error: input must be an object"), "validation_error");
|
|
16
|
-
return {
|
|
17
|
-
valid: false,
|
|
18
|
-
errors: [error.toJSON()],
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
// Use factory for the rest of validation
|
|
22
|
-
const factoryValidator = createValidator("unispecConfig", async (options) => {
|
|
23
|
-
// If custom schemas are provided but unispecConfig is missing, return undefined
|
|
24
|
-
if (options.schemas && !options.schemas.unispecConfig) {
|
|
25
|
-
return undefined; // Will trigger schema missing error
|
|
26
|
-
}
|
|
27
|
-
const { validateUniSpecConfigFn } = await getValidator(options);
|
|
28
|
-
return validateUniSpecConfigFn;
|
|
29
|
-
}, validateConfigCustomRules);
|
|
30
|
-
return await factoryValidator(doc, options);
|
|
31
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ErrorFactory } from "../errors/index.js";
|
|
2
|
-
/**
|
|
3
|
-
* Custom validation for UniSpec Config documents.
|
|
4
|
-
*/
|
|
5
|
-
export function validateConfigCustomRules(doc) {
|
|
6
|
-
const customErrors = [];
|
|
7
|
-
// Check for empty services array
|
|
8
|
-
if (doc.services &&
|
|
9
|
-
Array.isArray(doc.services) &&
|
|
10
|
-
doc.services.length === 0) {
|
|
11
|
-
customErrors.push(ErrorFactory.createConfigError("services array must contain at least one service", "/services", { code: "minItems" }).toJSON());
|
|
12
|
-
}
|
|
13
|
-
return customErrors;
|
|
14
|
-
}
|