@unispechq/unispec-core 0.2.13 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -160
- package/dist/cache/cache-factory.d.ts +31 -0
- package/dist/cache/cache-factory.js +65 -0
- package/dist/cache/cache-manager.d.ts +62 -0
- package/dist/cache/cache-manager.js +122 -0
- package/dist/cache/constants.d.ts +21 -0
- package/dist/cache/constants.js +22 -0
- package/dist/cache/hash-utils.d.ts +21 -0
- package/dist/cache/hash-utils.js +35 -0
- package/dist/cache/hashing.d.ts +19 -0
- package/dist/cache/hashing.js +197 -0
- package/dist/cache/index.d.ts +6 -0
- package/dist/cache/index.js +10 -0
- package/dist/cache/lru-cache.d.ts +56 -0
- package/dist/cache/lru-cache.js +161 -0
- package/dist/cache/types.d.ts +24 -0
- package/dist/cache/types.js +4 -0
- package/dist/cjs/cache/cache-factory.js +72 -0
- package/dist/cjs/cache/cache-manager.js +126 -0
- package/dist/cjs/cache/constants.js +25 -0
- package/dist/cjs/cache/hash-utils.js +41 -0
- package/dist/cjs/cache/hashing.js +236 -0
- package/dist/cjs/cache/index.js +26 -0
- package/dist/cjs/cache/lru-cache.js +165 -0
- package/dist/cjs/cache/types.js +5 -0
- package/dist/cjs/diff/annotators.js +132 -0
- package/dist/cjs/diff/change-reports.js +369 -0
- package/dist/cjs/diff/core.js +158 -0
- package/dist/cjs/diff/enhanced-diff.js +79 -0
- package/dist/cjs/diff/impact-strategies-refactored.js +230 -0
- package/dist/cjs/diff/impact-strategies.js +219 -0
- package/dist/cjs/diff/index.js +25 -247
- package/dist/cjs/diff/metrics-calculator.js +69 -0
- package/dist/cjs/diff/risk-calculator.js +58 -0
- package/dist/cjs/diff/suggestion-generator.js +78 -0
- package/dist/cjs/diff/types.js +11 -0
- package/dist/cjs/errors/base-error.js +33 -0
- package/dist/cjs/errors/config-error.js +11 -0
- package/dist/cjs/errors/error-factory.js +48 -0
- package/dist/cjs/errors/index.js +19 -0
- package/dist/cjs/errors/loader-error.js +11 -0
- package/dist/cjs/errors/reference-error.js +11 -0
- package/dist/cjs/errors/schema-error.js +11 -0
- package/dist/cjs/errors/security-error.js +11 -0
- package/dist/cjs/errors/semantic-error.js +11 -0
- package/dist/cjs/generated-schemas.js +2100 -0
- package/dist/cjs/index.js +41 -5
- package/dist/cjs/loader/index.js +11 -75
- package/dist/cjs/loader/security-validator.js +53 -0
- package/dist/cjs/loader/types.js +11 -0
- package/dist/cjs/loader/unispec-loader.js +84 -0
- package/dist/cjs/loader/yaml-loader.js +76 -0
- package/dist/cjs/normalizer/core.js +32 -0
- package/dist/cjs/normalizer/graphql-normalizer.js +67 -0
- package/dist/cjs/normalizer/index.js +5 -119
- package/dist/cjs/normalizer/rest-normalizer.js +51 -0
- package/dist/cjs/normalizer/types.js +2 -0
- package/dist/cjs/normalizer/utils.js +33 -0
- package/dist/cjs/normalizer/websocket-normalizer.js +81 -0
- package/dist/cjs/optimizer/core.js +115 -0
- package/dist/cjs/optimizer/index.js +17 -0
- package/dist/cjs/optimizer/optimization-functions.js +185 -0
- package/dist/cjs/optimizer/types.js +2 -0
- package/dist/cjs/optimizer/utils.js +32 -0
- package/dist/cjs/schemas/dedupe.js +100 -0
- package/dist/cjs/schemas/index.js +12 -132
- package/dist/cjs/schemas/resolver.js +41 -0
- package/dist/cjs/schemas/utils.js +53 -0
- package/dist/cjs/types/index.js +0 -1
- package/dist/cjs/validator/ajv-validator.js +82 -0
- package/dist/cjs/validator/config-validator-main.js +34 -0
- package/dist/cjs/validator/config-validator.js +17 -0
- package/dist/cjs/validator/index.js +21 -108
- package/dist/cjs/validator/object-traversal.js +112 -0
- package/dist/cjs/validator/reference-validator.js +233 -0
- package/dist/cjs/validator/schema-references.js +116 -0
- package/dist/cjs/validator/semantic-validator.js +328 -0
- package/dist/cjs/validator/tests-validator.js +16 -0
- package/dist/cjs/validator/types.js +2 -0
- package/dist/cjs/validator/unispec-validator.js +84 -0
- package/dist/cjs/validator/validator-factory.js +77 -0
- package/dist/cjs/versions.js +147 -0
- package/dist/diff/annotators.d.ts +4 -0
- package/dist/diff/annotators.js +127 -0
- package/dist/diff/change-reports.d.ts +37 -0
- package/dist/diff/change-reports.js +366 -0
- package/dist/diff/core.d.ts +26 -0
- package/dist/diff/core.js +155 -0
- package/dist/diff/enhanced-diff.d.ts +51 -0
- package/dist/diff/enhanced-diff.js +76 -0
- package/dist/diff/impact-strategies-refactored.d.ts +69 -0
- package/dist/diff/impact-strategies-refactored.js +223 -0
- package/dist/diff/impact-strategies.d.ts +41 -0
- package/dist/diff/impact-strategies.js +212 -0
- package/dist/diff/index.d.ts +8 -34
- package/dist/diff/index.js +11 -246
- package/dist/diff/metrics-calculator.d.ts +23 -0
- package/dist/diff/metrics-calculator.js +65 -0
- package/dist/diff/risk-calculator.d.ts +23 -0
- package/dist/diff/risk-calculator.js +55 -0
- package/dist/diff/suggestion-generator.d.ts +18 -0
- package/dist/diff/suggestion-generator.js +74 -0
- package/dist/diff/types.d.ts +24 -0
- package/dist/diff/types.js +8 -0
- package/dist/errors/base-error.d.ts +20 -0
- package/dist/errors/base-error.js +29 -0
- package/dist/errors/config-error.d.ts +4 -0
- package/dist/errors/config-error.js +7 -0
- package/dist/errors/error-factory.d.ts +22 -0
- package/dist/errors/error-factory.js +45 -0
- package/dist/errors/index.d.ts +8 -0
- package/dist/errors/index.js +8 -0
- package/dist/errors/loader-error.d.ts +4 -0
- package/dist/errors/loader-error.js +7 -0
- package/dist/errors/reference-error.d.ts +4 -0
- package/dist/errors/reference-error.js +7 -0
- package/dist/errors/schema-error.d.ts +4 -0
- package/dist/errors/schema-error.js +7 -0
- package/dist/errors/security-error.d.ts +4 -0
- package/dist/errors/security-error.js +7 -0
- package/dist/errors/semantic-error.d.ts +4 -0
- package/dist/errors/semantic-error.js +7 -0
- package/dist/generated-schemas.d.ts +2073 -0
- package/dist/generated-schemas.js +2097 -0
- package/dist/index.cjs +41 -5
- package/dist/index.d.ts +11 -5
- package/dist/index.js +41 -5
- package/dist/loader/index.d.ts +5 -12
- package/dist/loader/index.js +5 -41
- package/dist/loader/security-validator.d.ts +5 -0
- package/dist/loader/security-validator.js +50 -0
- package/dist/loader/types.d.ts +30 -0
- package/dist/loader/types.js +8 -0
- package/dist/loader/unispec-loader.d.ts +10 -0
- package/dist/loader/unispec-loader.js +81 -0
- package/dist/loader/yaml-loader.d.ts +10 -0
- package/dist/loader/yaml-loader.js +39 -0
- package/dist/normalizer/core.d.ts +24 -0
- package/dist/normalizer/core.js +29 -0
- package/dist/normalizer/graphql-normalizer.d.ts +8 -0
- package/dist/normalizer/graphql-normalizer.js +64 -0
- package/dist/normalizer/index.d.ts +2 -25
- package/dist/normalizer/index.js +3 -118
- package/dist/normalizer/rest-normalizer.d.ts +8 -0
- package/dist/normalizer/rest-normalizer.js +48 -0
- package/dist/normalizer/types.d.ts +7 -0
- package/dist/normalizer/types.js +1 -0
- package/dist/normalizer/utils.d.ts +14 -0
- package/dist/normalizer/utils.js +29 -0
- package/dist/normalizer/websocket-normalizer.d.ts +8 -0
- package/dist/normalizer/websocket-normalizer.js +78 -0
- package/dist/optimizer/core.d.ts +17 -0
- package/dist/optimizer/core.js +111 -0
- package/dist/optimizer/index.d.ts +4 -0
- package/dist/optimizer/index.js +7 -0
- package/dist/optimizer/optimization-functions.d.ts +32 -0
- package/dist/optimizer/optimization-functions.js +179 -0
- package/dist/optimizer/types.d.ts +28 -0
- package/dist/optimizer/types.js +1 -0
- package/dist/optimizer/utils.d.ts +7 -0
- package/dist/optimizer/utils.js +29 -0
- package/dist/schemas/dedupe.d.ts +9 -0
- package/dist/schemas/dedupe.js +97 -0
- package/dist/schemas/index.d.ts +3 -4
- package/dist/schemas/index.js +6 -129
- package/dist/schemas/resolver.d.ts +19 -0
- package/dist/schemas/resolver.js +37 -0
- package/dist/schemas/utils.d.ts +20 -0
- package/dist/schemas/utils.js +49 -0
- package/dist/types/index.d.ts +279 -41
- package/dist/types/index.js +0 -1
- package/dist/validator/ajv-validator.d.ts +15 -0
- package/dist/validator/ajv-validator.js +75 -0
- package/dist/validator/config-validator-main.d.ts +10 -0
- package/dist/validator/config-validator-main.js +31 -0
- package/dist/validator/config-validator.d.ts +5 -0
- package/dist/validator/config-validator.js +14 -0
- package/dist/validator/index.d.ts +10 -23
- package/dist/validator/index.js +11 -103
- package/dist/validator/object-traversal.d.ts +52 -0
- package/dist/validator/object-traversal.js +104 -0
- package/dist/validator/reference-validator.d.ts +31 -0
- package/dist/validator/reference-validator.js +230 -0
- package/dist/validator/schema-references.d.ts +23 -0
- package/dist/validator/schema-references.js +111 -0
- package/dist/validator/semantic-validator.d.ts +26 -0
- package/dist/validator/semantic-validator.js +325 -0
- package/dist/validator/tests-validator.d.ts +9 -0
- package/dist/validator/tests-validator.js +13 -0
- package/dist/validator/types.d.ts +29 -0
- package/dist/validator/types.js +1 -0
- package/dist/validator/unispec-validator.d.ts +15 -0
- package/dist/validator/unispec-validator.js +81 -0
- package/dist/validator/validator-factory.d.ts +10 -0
- package/dist/validator/validator-factory.js +73 -0
- package/dist/versions.d.ts +10 -0
- package/dist/versions.js +143 -0
- package/package.json +11 -9
- package/dist/cjs/converters/index.js +0 -204
- package/dist/cjs/validator/generated-schemas.js +0 -827
- package/dist/converters/index.d.ts +0 -14
- package/dist/converters/index.js +0 -199
- package/dist/validator/generated-schemas.d.ts +0 -842
- package/dist/validator/generated-schemas.js +0 -824
package/dist/types/index.d.ts
CHANGED
|
@@ -1,40 +1,108 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface UniSpecNamedItem {
|
|
2
2
|
name: string;
|
|
3
3
|
description?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface UniSpecDeprecatedItem {
|
|
4
6
|
deprecated?: boolean;
|
|
5
7
|
deprecationReason?: string;
|
|
6
8
|
}
|
|
7
|
-
export interface
|
|
9
|
+
export interface UniSpecTaggedItem {
|
|
10
|
+
tags?: string[];
|
|
11
|
+
}
|
|
12
|
+
export interface UniSpecProtocolBase {
|
|
8
13
|
url?: string;
|
|
9
|
-
|
|
10
|
-
queries?: UniSpecGraphQLOperation[];
|
|
11
|
-
mutations?: UniSpecGraphQLOperation[];
|
|
12
|
-
subscriptions?: UniSpecGraphQLOperation[];
|
|
14
|
+
securitySchemes?: Record<string, UniSpecSecurityScheme>;
|
|
13
15
|
}
|
|
14
16
|
export interface UniSpecSecurityRequirement extends Array<string> {
|
|
15
17
|
}
|
|
16
|
-
export interface
|
|
18
|
+
export interface UniSpecBaseHeader {
|
|
17
19
|
name: string;
|
|
18
20
|
description?: string;
|
|
21
|
+
required?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface UniSpecHeader extends UniSpecBaseHeader {
|
|
24
|
+
defaultValue?: string;
|
|
19
25
|
schemaRef?: string;
|
|
20
26
|
}
|
|
21
|
-
export interface
|
|
27
|
+
export interface UniSpecApiKeyScheme {
|
|
28
|
+
type: "apiKey";
|
|
22
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;
|
|
23
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 {
|
|
24
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[];
|
|
25
98
|
messages?: UniSpecWebSocketMessage[];
|
|
26
99
|
security?: UniSpecSecurityRequirement[];
|
|
27
|
-
extensions?: Record<string, unknown>;
|
|
28
100
|
}
|
|
29
|
-
export interface UniSpecWebSocketProtocol {
|
|
30
|
-
|
|
101
|
+
export interface UniSpecWebSocketProtocol extends UniSpecProtocolBase {
|
|
102
|
+
headers?: UniSpecWebSocketHeader[];
|
|
31
103
|
channels?: UniSpecWebSocketChannel[];
|
|
32
|
-
securitySchemes?: Record<string, Record<string, unknown>>;
|
|
33
104
|
}
|
|
34
|
-
export interface UniSpecRestParameter {
|
|
35
|
-
name: string;
|
|
36
|
-
description?: string;
|
|
37
|
-
required?: boolean;
|
|
105
|
+
export interface UniSpecRestParameter extends UniSpecBaseHeader {
|
|
38
106
|
schemaRef?: string;
|
|
39
107
|
}
|
|
40
108
|
export interface UniSpecRestMediaType {
|
|
@@ -48,14 +116,15 @@ export interface UniSpecRestRequestBody {
|
|
|
48
116
|
required?: boolean;
|
|
49
117
|
content?: UniSpecRestContent;
|
|
50
118
|
}
|
|
119
|
+
export interface UniSpecRestResponseHeader extends UniSpecHeader {
|
|
120
|
+
}
|
|
51
121
|
export interface UniSpecRestResponse {
|
|
52
122
|
description?: string;
|
|
123
|
+
headers?: UniSpecRestResponseHeader[];
|
|
53
124
|
content?: UniSpecRestContent;
|
|
54
125
|
}
|
|
55
|
-
export interface UniSpecRestRoute {
|
|
56
|
-
name?: string;
|
|
126
|
+
export interface UniSpecRestRoute extends UniSpecNamedItem, UniSpecDeprecatedItem, UniSpecTaggedItem {
|
|
57
127
|
summary?: string;
|
|
58
|
-
description?: string;
|
|
59
128
|
path: string;
|
|
60
129
|
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
61
130
|
pathParams?: UniSpecRestParameter[];
|
|
@@ -65,12 +134,23 @@ export interface UniSpecRestRoute {
|
|
|
65
134
|
responses?: Record<string, UniSpecRestResponse>;
|
|
66
135
|
security?: UniSpecSecurityRequirement[];
|
|
67
136
|
}
|
|
68
|
-
export interface UniSpecRestProtocol {
|
|
137
|
+
export interface UniSpecRestProtocol extends UniSpecProtocolBase {
|
|
69
138
|
routes?: UniSpecRestRoute[];
|
|
70
|
-
securitySchemes?: Record<string, Record<string, unknown>>;
|
|
71
139
|
}
|
|
72
|
-
export interface
|
|
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[];
|
|
73
152
|
jsonSchema: Record<string, unknown>;
|
|
153
|
+
validation?: UniSpecSchemaValidation;
|
|
74
154
|
}
|
|
75
155
|
export interface UniSpecSchemas {
|
|
76
156
|
[name: string]: UniSpecSchemaDefinition;
|
|
@@ -82,6 +162,30 @@ export interface UniSpecEnvironment {
|
|
|
82
162
|
labels?: Record<string, string>;
|
|
83
163
|
isDefault?: boolean;
|
|
84
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";
|
|
85
189
|
export interface UniSpecServiceProtocols {
|
|
86
190
|
rest?: UniSpecRestProtocol;
|
|
87
191
|
graphql?: UniSpecGraphQLProtocol;
|
|
@@ -90,14 +194,19 @@ export interface UniSpecServiceProtocols {
|
|
|
90
194
|
export interface UniSpecDocument {
|
|
91
195
|
unispecVersion: string;
|
|
92
196
|
service: UniSpecService;
|
|
93
|
-
extensions?: Record<string, unknown>;
|
|
94
197
|
}
|
|
95
|
-
export interface UniSpecService {
|
|
96
|
-
name: string;
|
|
97
|
-
description?: string;
|
|
198
|
+
export interface UniSpecService extends UniSpecNamedItem, UniSpecTaggedItem {
|
|
98
199
|
version?: string;
|
|
200
|
+
baseUrl?: string;
|
|
201
|
+
contact?: UniSpecContact;
|
|
202
|
+
license?: UniSpecLicense;
|
|
203
|
+
servers?: UniSpecServer[];
|
|
99
204
|
protocols?: UniSpecServiceProtocols;
|
|
100
205
|
schemas?: UniSpecSchemas;
|
|
206
|
+
securitySchemes?: Record<string, UniSpecSecurityScheme>;
|
|
207
|
+
rateLimit?: UniSpecRateLimit;
|
|
208
|
+
compliance?: UniSpecCompliance[];
|
|
209
|
+
dataClassification?: UniSpecDataClassification;
|
|
101
210
|
}
|
|
102
211
|
export interface ValidationError {
|
|
103
212
|
message: string;
|
|
@@ -108,6 +217,10 @@ export interface ValidationResult {
|
|
|
108
217
|
valid: boolean;
|
|
109
218
|
errors: ValidationError[];
|
|
110
219
|
}
|
|
220
|
+
export interface UniSpecTestRequestBase {
|
|
221
|
+
headers?: Record<string, unknown>;
|
|
222
|
+
authProfile?: string;
|
|
223
|
+
}
|
|
111
224
|
export type UniSpecTestProtocol = "rest" | "graphql" | "websocket";
|
|
112
225
|
export interface UniSpecTestTarget {
|
|
113
226
|
protocol: UniSpecTestProtocol;
|
|
@@ -118,16 +231,13 @@ export interface UniSpecRestTestParams {
|
|
|
118
231
|
path?: Record<string, unknown>;
|
|
119
232
|
query?: Record<string, unknown>;
|
|
120
233
|
}
|
|
121
|
-
export interface UniSpecRestTestRequest {
|
|
234
|
+
export interface UniSpecRestTestRequest extends UniSpecTestRequestBase {
|
|
122
235
|
params?: UniSpecRestTestParams;
|
|
123
|
-
headers?: Record<string, unknown>;
|
|
124
236
|
body?: unknown;
|
|
125
|
-
authProfile?: string;
|
|
126
237
|
}
|
|
127
238
|
export type UniSpecRestExpectedStatus = number | number[];
|
|
128
|
-
export type UniSpecRestBodyExpectationMode = "exact" | "contains" | "schemaOnly" | "snapshot";
|
|
129
239
|
export interface UniSpecRestBodyExpectation {
|
|
130
|
-
mode?:
|
|
240
|
+
mode?: "exact" | "contains" | "schemaOnly" | "snapshot";
|
|
131
241
|
json?: unknown;
|
|
132
242
|
schemaRef?: string;
|
|
133
243
|
}
|
|
@@ -136,12 +246,10 @@ export interface UniSpecRestTestExpect {
|
|
|
136
246
|
headers?: Record<string, unknown>;
|
|
137
247
|
body?: UniSpecRestBodyExpectation;
|
|
138
248
|
}
|
|
139
|
-
export interface UniSpecGraphQLTestRequest {
|
|
249
|
+
export interface UniSpecGraphQLTestRequest extends UniSpecTestRequestBase {
|
|
140
250
|
operationName?: string;
|
|
141
251
|
query: string;
|
|
142
252
|
variables?: Record<string, unknown>;
|
|
143
|
-
headers?: Record<string, unknown>;
|
|
144
|
-
authProfile?: string;
|
|
145
253
|
}
|
|
146
254
|
export interface UniSpecGraphQLTestExpect {
|
|
147
255
|
data?: unknown;
|
|
@@ -154,11 +262,10 @@ export interface UniSpecWebSocketTestMessageAction {
|
|
|
154
262
|
messageName: string;
|
|
155
263
|
payload?: unknown;
|
|
156
264
|
}
|
|
157
|
-
export interface UniSpecWebSocketTestRequest {
|
|
265
|
+
export interface UniSpecWebSocketTestRequest extends UniSpecTestRequestBase {
|
|
158
266
|
channel: string;
|
|
159
267
|
direction?: "publish" | "subscribe" | "both";
|
|
160
268
|
messages?: UniSpecWebSocketTestMessageAction[];
|
|
161
|
-
authProfile?: string;
|
|
162
269
|
}
|
|
163
270
|
export interface UniSpecWebSocketTestExpect {
|
|
164
271
|
messages?: UniSpecWebSocketTestMessageAction[];
|
|
@@ -174,14 +281,11 @@ export interface UniSpecTestExpect {
|
|
|
174
281
|
graphql?: UniSpecGraphQLTestExpect;
|
|
175
282
|
websocket?: UniSpecWebSocketTestExpect;
|
|
176
283
|
}
|
|
177
|
-
export interface UniSpecTestCase {
|
|
178
|
-
name: string;
|
|
179
|
-
description?: string;
|
|
284
|
+
export interface UniSpecTestCase extends UniSpecNamedItem {
|
|
180
285
|
target: UniSpecTestTarget;
|
|
181
286
|
request: UniSpecTestRequest;
|
|
182
287
|
expect: UniSpecTestExpect;
|
|
183
288
|
tags?: string[];
|
|
184
|
-
extensions?: Record<string, unknown>;
|
|
185
289
|
}
|
|
186
290
|
export interface UniSpecTestsDocument {
|
|
187
291
|
uniSpecTestsVersion: string;
|
|
@@ -191,5 +295,139 @@ export interface UniSpecTestsDocument {
|
|
|
191
295
|
environment?: string;
|
|
192
296
|
};
|
|
193
297
|
tests: UniSpecTestCase[];
|
|
194
|
-
|
|
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
|
+
};
|
|
195
433
|
}
|
package/dist/types/index.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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>;
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
}
|
|
@@ -1,23 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
export interface ValidateOptions {
|
|
12
|
-
schemas?: ValidatorSchemas;
|
|
13
|
-
schemaProvider?: SchemaProvider;
|
|
14
|
-
ajvOptions?: ConstructorParameters<typeof Ajv2020>[0];
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Validate a UniSpec document against the UniSpec JSON Schema.
|
|
18
|
-
*/
|
|
19
|
-
export declare function validateUniSpec(doc: UniSpecDocument, options?: ValidateOptions): Promise<ValidationResult>;
|
|
20
|
-
/**
|
|
21
|
-
* Validate a UniSpec Tests document against the UniSpec Tests JSON Schema.
|
|
22
|
-
*/
|
|
23
|
-
export declare function validateUniSpecTests(doc: UniSpecTestsDocument, options?: ValidateOptions): Promise<ValidationResult>;
|
|
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";
|