@e22m4u/js-openapi 0.0.5
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/.c8rc +9 -0
- package/.commitlintrc +5 -0
- package/.editorconfig +13 -0
- package/.husky/commit-msg +1 -0
- package/.husky/pre-commit +6 -0
- package/.mocharc.json +4 -0
- package/.prettierrc +7 -0
- package/LICENSE +21 -0
- package/README.md +510 -0
- package/build-cjs.js +16 -0
- package/dist/cjs/index.cjs +2695 -0
- package/eslint.config.js +41 -0
- package/package.json +64 -0
- package/src/data-type/index.d.ts +1 -0
- package/src/data-type/index.js +1 -0
- package/src/data-type/infer-openapi-data-type.d.ts +30 -0
- package/src/data-type/infer-openapi-data-type.js +38 -0
- package/src/data-validation/data-format-validator-map.d.ts +13 -0
- package/src/data-validation/data-format-validator-map.js +36 -0
- package/src/data-validation/data-format-validator-map.spec.js +39 -0
- package/src/data-validation/data-format-validators.d.ts +84 -0
- package/src/data-validation/data-format-validators.js +217 -0
- package/src/data-validation/index.d.ts +3 -0
- package/src/data-validation/index.js +3 -0
- package/src/data-validation/validate-data-with-openapi-schema.d.ts +46 -0
- package/src/data-validation/validate-data-with-openapi-schema.js +1913 -0
- package/src/data-validation/validate-data-with-openapi-schema.spec.js +6953 -0
- package/src/errors/index.d.ts +1 -0
- package/src/errors/index.js +1 -0
- package/src/errors/oa-data-validation-error.d.ts +6 -0
- package/src/errors/oa-data-validation-error.js +6 -0
- package/src/errors/oa-data-validation-error.spec.js +17 -0
- package/src/index.d.ts +9 -0
- package/src/index.js +9 -0
- package/src/json-pointer/escape-json-pointer.d.ts +7 -0
- package/src/json-pointer/escape-json-pointer.js +18 -0
- package/src/json-pointer/escape-json-pointer.spec.js +36 -0
- package/src/json-pointer/index.d.ts +3 -0
- package/src/json-pointer/index.js +3 -0
- package/src/json-pointer/resolve-json-pointer.d.ts +10 -0
- package/src/json-pointer/resolve-json-pointer.js +83 -0
- package/src/json-pointer/resolve-json-pointer.spec.js +103 -0
- package/src/json-pointer/unescape-json-pointer.d.ts +8 -0
- package/src/json-pointer/unescape-json-pointer.js +18 -0
- package/src/json-pointer/unescape-json-pointer.spec.js +32 -0
- package/src/oa-document-builder.d.ts +312 -0
- package/src/oa-document-builder.js +450 -0
- package/src/oa-document-object/index.d.ts +1 -0
- package/src/oa-document-object/index.js +1 -0
- package/src/oa-document-object/validate-shallow-oa-document.d.ts +10 -0
- package/src/oa-document-object/validate-shallow-oa-document.js +209 -0
- package/src/oa-document-object/validate-shallow-oa-document.spec.js +362 -0
- package/src/oa-document-scope.d.ts +52 -0
- package/src/oa-document-scope.js +228 -0
- package/src/oa-reference-object/index.d.ts +3 -0
- package/src/oa-reference-object/index.js +3 -0
- package/src/oa-reference-object/is-oa-reference-object.d.ts +9 -0
- package/src/oa-reference-object/is-oa-reference-object.js +14 -0
- package/src/oa-reference-object/is-oa-reference-object.spec.js +19 -0
- package/src/oa-reference-object/oa-ref.d.ts +11 -0
- package/src/oa-reference-object/oa-ref.js +31 -0
- package/src/oa-reference-object/oa-ref.spec.js +56 -0
- package/src/oa-reference-object/resolve-oa-reference-object.d.ts +18 -0
- package/src/oa-reference-object/resolve-oa-reference-object.js +113 -0
- package/src/oa-reference-object/resolve-oa-reference-object.spec.js +233 -0
- package/src/oa-specification.d.ts +767 -0
- package/src/oa-specification.js +153 -0
- package/src/types.d.ts +4 -0
- package/src/utils/count-unicode.d.ts +11 -0
- package/src/utils/count-unicode.js +15 -0
- package/src/utils/index.d.ts +5 -0
- package/src/utils/index.js +5 -0
- package/src/utils/join-path.d.ts +6 -0
- package/src/utils/join-path.js +36 -0
- package/src/utils/join-path.spec.js +104 -0
- package/src/utils/normalize-path.d.ts +12 -0
- package/src/utils/normalize-path.js +22 -0
- package/src/utils/normalize-path.spec.js +56 -0
- package/src/utils/to-pascal-case.d.ts +6 -0
- package/src/utils/to-pascal-case.js +26 -0
- package/src/utils/to-pascal-case.spec.js +15 -0
- package/src/utils/to-spaced-json.d.ts +17 -0
- package/src/utils/to-spaced-json.js +27 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,2695 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.js
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
ACCESS_MODE_LIST: () => ACCESS_MODE_LIST,
|
|
25
|
+
JSON_INTEGER_REGEXP: () => JSON_INTEGER_REGEXP,
|
|
26
|
+
JSON_NUMBER_REGEXP: () => JSON_NUMBER_REGEXP,
|
|
27
|
+
OAAccessMode: () => OAAccessMode,
|
|
28
|
+
OAApiKeyLocation: () => OAApiKeyLocation,
|
|
29
|
+
OAComponentType: () => OAComponentType,
|
|
30
|
+
OADataFormat: () => OADataFormat,
|
|
31
|
+
OADataType: () => OADataType,
|
|
32
|
+
OADataValidationError: () => OADataValidationError,
|
|
33
|
+
OADocumentBuilder: () => OADocumentBuilder,
|
|
34
|
+
OADocumentScope: () => OADocumentScope,
|
|
35
|
+
OAMediaType: () => OAMediaType,
|
|
36
|
+
OAOperationMethod: () => OAOperationMethod,
|
|
37
|
+
OAParameterLocation: () => OAParameterLocation,
|
|
38
|
+
OAParameterStyle: () => OAParameterStyle,
|
|
39
|
+
OASecuritySchemeType: () => OASecuritySchemeType,
|
|
40
|
+
OA_BUILT_IN_DATA_FORMAT_VALIDATOR_MAP: () => OA_BUILT_IN_DATA_FORMAT_VALIDATOR_MAP,
|
|
41
|
+
OA_COMPONENT_TYPES: () => OA_COMPONENT_TYPES,
|
|
42
|
+
OA_COMPONENT_TYPE_TO_COMPONENTS_KEY_MAP: () => OA_COMPONENT_TYPE_TO_COMPONENTS_KEY_MAP,
|
|
43
|
+
OA_DATA_TYPE_LIST: () => OA_DATA_TYPE_LIST,
|
|
44
|
+
OPENAPI_VERSION: () => OPENAPI_VERSION,
|
|
45
|
+
escapeJsonPointer: () => escapeJsonPointer,
|
|
46
|
+
inferOpenApiDataType: () => inferOpenApiDataType,
|
|
47
|
+
isOAReferenceObject: () => isOAReferenceObject,
|
|
48
|
+
oaCallbackRef: () => oaCallbackRef,
|
|
49
|
+
oaExampleRef: () => oaExampleRef,
|
|
50
|
+
oaLinkRef: () => oaLinkRef,
|
|
51
|
+
oaParameterRef: () => oaParameterRef,
|
|
52
|
+
oaPathItemRef: () => oaPathItemRef,
|
|
53
|
+
oaRequestBodyRef: () => oaRequestBodyRef,
|
|
54
|
+
oaResponseRef: () => oaResponseRef,
|
|
55
|
+
oaSchemaRef: () => oaSchemaRef,
|
|
56
|
+
oaSecuritySchemeRef: () => oaSecuritySchemeRef,
|
|
57
|
+
resolveJsonPointer: () => resolveJsonPointer,
|
|
58
|
+
resolveOAReferenceObject: () => resolveOAReferenceObject,
|
|
59
|
+
unescapeJsonPointer: () => unescapeJsonPointer,
|
|
60
|
+
validateByteFormat: () => validateByteFormat,
|
|
61
|
+
validateDataWithOpenApiSchema: () => validateDataWithOpenApiSchema,
|
|
62
|
+
validateDateFormat: () => validateDateFormat,
|
|
63
|
+
validateDateTimeFormat: () => validateDateTimeFormat,
|
|
64
|
+
validateDoubleFormat: () => validateDoubleFormat,
|
|
65
|
+
validateEmailFormat: () => validateEmailFormat,
|
|
66
|
+
validateFloatFormat: () => validateFloatFormat,
|
|
67
|
+
validateHostnameFormat: () => validateHostnameFormat,
|
|
68
|
+
validateInt32Format: () => validateInt32Format,
|
|
69
|
+
validateInt64Format: () => validateInt64Format,
|
|
70
|
+
validateIpv4Format: () => validateIpv4Format,
|
|
71
|
+
validateIpv6Format: () => validateIpv6Format,
|
|
72
|
+
validateShallowOADocument: () => validateShallowOADocument,
|
|
73
|
+
validateUriFormat: () => validateUriFormat,
|
|
74
|
+
validateUuidFormat: () => validateUuidFormat
|
|
75
|
+
});
|
|
76
|
+
module.exports = __toCommonJS(index_exports);
|
|
77
|
+
|
|
78
|
+
// src/errors/oa-data-validation-error.js
|
|
79
|
+
var import_js_format = require("@e22m4u/js-format");
|
|
80
|
+
var OADataValidationError = class extends import_js_format.Errorf {
|
|
81
|
+
static {
|
|
82
|
+
__name(this, "OADataValidationError");
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// src/data-type/infer-openapi-data-type.js
|
|
87
|
+
var import_js_format2 = require("@e22m4u/js-format");
|
|
88
|
+
|
|
89
|
+
// src/oa-specification.js
|
|
90
|
+
var OPENAPI_VERSION = "3.1.0";
|
|
91
|
+
var OAOperationMethod = {
|
|
92
|
+
GET: "get",
|
|
93
|
+
PUT: "put",
|
|
94
|
+
POST: "post",
|
|
95
|
+
DELETE: "delete",
|
|
96
|
+
OPTIONS: "options",
|
|
97
|
+
HEAD: "head",
|
|
98
|
+
PATCH: "patch",
|
|
99
|
+
TRACE: "trace"
|
|
100
|
+
};
|
|
101
|
+
var OAParameterLocation = {
|
|
102
|
+
QUERY: "query",
|
|
103
|
+
HEADER: "header",
|
|
104
|
+
PATH: "path",
|
|
105
|
+
COOKIE: "cookie"
|
|
106
|
+
};
|
|
107
|
+
var OAParameterStyle = {
|
|
108
|
+
MATRIX: "matrix",
|
|
109
|
+
LABEL: "label",
|
|
110
|
+
FORM: "form",
|
|
111
|
+
SIMPLE: "simple",
|
|
112
|
+
SPACE_DELIMITED: "spaceDelimited",
|
|
113
|
+
PIPE_DELIMITED: "pipeDelimited",
|
|
114
|
+
DEEP_OBJECT: "deepObject"
|
|
115
|
+
};
|
|
116
|
+
var OADataType = {
|
|
117
|
+
STRING: "string",
|
|
118
|
+
NUMBER: "number",
|
|
119
|
+
INTEGER: "integer",
|
|
120
|
+
BOOLEAN: "boolean",
|
|
121
|
+
OBJECT: "object",
|
|
122
|
+
ARRAY: "array",
|
|
123
|
+
NULL: "null"
|
|
124
|
+
};
|
|
125
|
+
var OA_DATA_TYPE_LIST = Object.values(OADataType);
|
|
126
|
+
var OADataFormat = {
|
|
127
|
+
// number
|
|
128
|
+
INT32: "int32",
|
|
129
|
+
INT64: "int64",
|
|
130
|
+
FLOAT: "float",
|
|
131
|
+
DOUBLE: "double",
|
|
132
|
+
// date and time
|
|
133
|
+
DATE: "date",
|
|
134
|
+
DATE_TIME: "date-time",
|
|
135
|
+
TIME: "time",
|
|
136
|
+
DURATION: "duration",
|
|
137
|
+
// binary
|
|
138
|
+
BYTE: "byte",
|
|
139
|
+
BINARY: "binary",
|
|
140
|
+
// identifiers and network
|
|
141
|
+
EMAIL: "email",
|
|
142
|
+
IDN_EMAIL: "idn-email",
|
|
143
|
+
UUID: "uuid",
|
|
144
|
+
HOSTNAME: "hostname",
|
|
145
|
+
IDN_HOSTNAME: "idn-hostname",
|
|
146
|
+
IPV4: "ipv4",
|
|
147
|
+
IPV6: "ipv6",
|
|
148
|
+
URI: "uri",
|
|
149
|
+
URI_REFERENCE: "uri-reference",
|
|
150
|
+
IRI: "iri",
|
|
151
|
+
IRI_REFERENCE: "iri-reference",
|
|
152
|
+
// extra
|
|
153
|
+
PASSWORD: "password",
|
|
154
|
+
REGEX: "regex",
|
|
155
|
+
JSON_POINTER: "json-pointer",
|
|
156
|
+
RELATIVE_JSON_POINTER: "relative-json-pointer"
|
|
157
|
+
};
|
|
158
|
+
var OAMediaType = {
|
|
159
|
+
TEXT_PLAIN: "text/plain",
|
|
160
|
+
TEXT_HTML: "text/html",
|
|
161
|
+
APPLICATION_XML: "application/xml",
|
|
162
|
+
APPLICATION_JSON: "application/json",
|
|
163
|
+
MULTIPART_FORM_DATA: "multipart/form-data"
|
|
164
|
+
};
|
|
165
|
+
var OASecuritySchemeType = {
|
|
166
|
+
API_KEY: "apiKey",
|
|
167
|
+
HTTP: "http",
|
|
168
|
+
MUTUAL_TLS: "mutualTLS",
|
|
169
|
+
OAUTH_2: "oauth2",
|
|
170
|
+
OPEN_ID_CONNECT: "openIdConnect"
|
|
171
|
+
};
|
|
172
|
+
var OAApiKeyLocation = {
|
|
173
|
+
QUERY: "query",
|
|
174
|
+
HEADER: "header",
|
|
175
|
+
COOKIE: "cookie"
|
|
176
|
+
};
|
|
177
|
+
var OAAccessMode = {
|
|
178
|
+
READ: "read",
|
|
179
|
+
WRITE: "write"
|
|
180
|
+
};
|
|
181
|
+
var ACCESS_MODE_LIST = Object.values(OAAccessMode);
|
|
182
|
+
|
|
183
|
+
// src/data-type/infer-openapi-data-type.js
|
|
184
|
+
function inferOpenApiDataType(data, returnJsTypeOnFail = false) {
|
|
185
|
+
if (data === null) {
|
|
186
|
+
return OADataType.NULL;
|
|
187
|
+
}
|
|
188
|
+
if (Array.isArray(data)) {
|
|
189
|
+
return OADataType.ARRAY;
|
|
190
|
+
}
|
|
191
|
+
const jsType = typeof data;
|
|
192
|
+
switch (jsType) {
|
|
193
|
+
case "string":
|
|
194
|
+
return OADataType.STRING;
|
|
195
|
+
case "boolean":
|
|
196
|
+
return OADataType.BOOLEAN;
|
|
197
|
+
case "number":
|
|
198
|
+
return Number.isInteger(data) ? OADataType.INTEGER : OADataType.NUMBER;
|
|
199
|
+
case "bigint":
|
|
200
|
+
return OADataType.INTEGER;
|
|
201
|
+
case "object":
|
|
202
|
+
return OADataType.OBJECT;
|
|
203
|
+
}
|
|
204
|
+
if (returnJsTypeOnFail === true) {
|
|
205
|
+
return jsType;
|
|
206
|
+
}
|
|
207
|
+
throw new import_js_format2.InvalidArgumentError(
|
|
208
|
+
"Unable to infer the data type from %v value.",
|
|
209
|
+
data
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
__name(inferOpenApiDataType, "inferOpenApiDataType");
|
|
213
|
+
|
|
214
|
+
// src/oa-document-scope.js
|
|
215
|
+
var import_js_format5 = require("@e22m4u/js-format");
|
|
216
|
+
|
|
217
|
+
// src/utils/join-path.js
|
|
218
|
+
function joinPath(...segments) {
|
|
219
|
+
const parts = segments.filter((seg) => seg != void 0 && String(seg) !== "");
|
|
220
|
+
if (parts.length === 0) {
|
|
221
|
+
return "/";
|
|
222
|
+
}
|
|
223
|
+
let joined = parts.join("/").replace(/\/+/g, "/");
|
|
224
|
+
const protocolRegex = /^([a-z][a-z0-9+.-]*):\//i;
|
|
225
|
+
const protocolMatch = joined.match(protocolRegex);
|
|
226
|
+
if (protocolMatch) {
|
|
227
|
+
joined = joined.replace(protocolRegex, "$1://");
|
|
228
|
+
} else {
|
|
229
|
+
if (!joined.startsWith("/")) {
|
|
230
|
+
joined = "/" + joined;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (joined.length > 1 && joined.endsWith("/")) {
|
|
234
|
+
joined = joined.slice(0, -1);
|
|
235
|
+
}
|
|
236
|
+
return joined;
|
|
237
|
+
}
|
|
238
|
+
__name(joinPath, "joinPath");
|
|
239
|
+
|
|
240
|
+
// src/utils/count-unicode.js
|
|
241
|
+
function countUnicode(data) {
|
|
242
|
+
const matchedChars = String(data).match(/[\s\S]/gu);
|
|
243
|
+
return Array.isArray(matchedChars) ? matchedChars.length : 0;
|
|
244
|
+
}
|
|
245
|
+
__name(countUnicode, "countUnicode");
|
|
246
|
+
|
|
247
|
+
// src/utils/normalize-path.js
|
|
248
|
+
function normalizePath(value, noStartingSlash = false) {
|
|
249
|
+
if (typeof value !== "string") {
|
|
250
|
+
return "/";
|
|
251
|
+
}
|
|
252
|
+
const res = value.trim().replace(/\/+/g, "/").replace(/(^\/|\/$)/g, "");
|
|
253
|
+
return noStartingSlash ? res : "/" + res;
|
|
254
|
+
}
|
|
255
|
+
__name(normalizePath, "normalizePath");
|
|
256
|
+
|
|
257
|
+
// src/utils/to-spaced-json.js
|
|
258
|
+
function toSpacedJson(value, options = {}) {
|
|
259
|
+
const stringified = JSON.stringify(value, null, 1);
|
|
260
|
+
const res = stringified ? stringified.replace(/\n\s*/g, " ").replace(/\[\s/g, "[").replace(/\s\]/g, "]").replace(/\{\s/g, "{").replace(/\s\}/g, "}") : "undefined";
|
|
261
|
+
if (options.truncate && typeof options.truncate === "number" && res.length > options.truncate) {
|
|
262
|
+
return res.slice(0, options.truncate) + "...";
|
|
263
|
+
}
|
|
264
|
+
return res;
|
|
265
|
+
}
|
|
266
|
+
__name(toSpacedJson, "toSpacedJson");
|
|
267
|
+
|
|
268
|
+
// src/utils/to-pascal-case.js
|
|
269
|
+
function toPascalCase(input) {
|
|
270
|
+
if (!input) {
|
|
271
|
+
return "";
|
|
272
|
+
}
|
|
273
|
+
return input.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/([0-9])([a-zA-Z])/g, "$1 $2").replace(/[-_]+|[^\p{L}\p{N}]/gu, " ").toLowerCase().replace(new RegExp("(?:^|\\s)(\\p{L})", "gu"), (_, letter) => letter.toUpperCase()).replace(/\s+/g, "");
|
|
274
|
+
}
|
|
275
|
+
__name(toPascalCase, "toPascalCase");
|
|
276
|
+
|
|
277
|
+
// src/oa-document-builder.js
|
|
278
|
+
var import_js_format4 = require("@e22m4u/js-format");
|
|
279
|
+
var import_js_service = require("@e22m4u/js-service");
|
|
280
|
+
|
|
281
|
+
// src/oa-document-object/validate-shallow-oa-document.js
|
|
282
|
+
var import_js_format3 = require("@e22m4u/js-format");
|
|
283
|
+
function validateShallowOADocument(documentObject) {
|
|
284
|
+
if (!documentObject || typeof documentObject !== "object" || Array.isArray(documentObject)) {
|
|
285
|
+
throw new import_js_format3.InvalidArgumentError(
|
|
286
|
+
"OpenAPI Document Object must be an Object, but %v was given.",
|
|
287
|
+
documentObject
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
if (!documentObject.openapi || typeof documentObject.openapi !== "string") {
|
|
291
|
+
throw new import_js_format3.InvalidArgumentError(
|
|
292
|
+
'Property "openapi" must be a non-empty String, but %v was given.',
|
|
293
|
+
documentObject.openapi
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
if (!documentObject.info || typeof documentObject.info !== "object" || Array.isArray(documentObject.info)) {
|
|
297
|
+
throw new import_js_format3.InvalidArgumentError(
|
|
298
|
+
'Property "info" must be an Object, but %v was given.',
|
|
299
|
+
documentObject.info
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
if (!documentObject.info.title || typeof documentObject.info.title !== "string") {
|
|
303
|
+
throw new import_js_format3.InvalidArgumentError(
|
|
304
|
+
'Property "info.title" must be a non-empty String, but %v was given.',
|
|
305
|
+
documentObject.info.title
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
if (!documentObject.info.version || typeof documentObject.info.version !== "string") {
|
|
309
|
+
throw new import_js_format3.InvalidArgumentError(
|
|
310
|
+
'Property "info.version" must be a non-empty String, but %v was given.',
|
|
311
|
+
documentObject.info.version
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
if (documentObject.jsonSchemaDialect !== void 0) {
|
|
315
|
+
if (!documentObject.jsonSchemaDialect || typeof documentObject.jsonSchemaDialect !== "string") {
|
|
316
|
+
throw new import_js_format3.InvalidArgumentError(
|
|
317
|
+
'Property "jsonSchemaDialect" must be a non-empty String, but %v was given.',
|
|
318
|
+
documentObject.jsonSchemaDialect
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (documentObject.servers !== void 0) {
|
|
323
|
+
if (!Array.isArray(documentObject.servers)) {
|
|
324
|
+
throw new import_js_format3.InvalidArgumentError(
|
|
325
|
+
'Property "servers" must be an Array, but %v was given.',
|
|
326
|
+
documentObject.servers
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
documentObject.servers.forEach((serverObject, index) => {
|
|
330
|
+
if (!serverObject || typeof serverObject !== "object" || Array.isArray(serverObject)) {
|
|
331
|
+
throw new import_js_format3.InvalidArgumentError(
|
|
332
|
+
'Element "servers[%d]" must be an Object, but %v was given.',
|
|
333
|
+
index,
|
|
334
|
+
serverObject
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
if (!serverObject.url || typeof serverObject.url !== "string") {
|
|
338
|
+
throw new import_js_format3.InvalidArgumentError(
|
|
339
|
+
'Property "servers[%d].url" must be a non-empty String, but %v was given.',
|
|
340
|
+
index,
|
|
341
|
+
serverObject.url
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
if (documentObject.paths !== void 0) {
|
|
347
|
+
if (!documentObject.paths || typeof documentObject.paths !== "object" || Array.isArray(documentObject.paths)) {
|
|
348
|
+
throw new import_js_format3.InvalidArgumentError(
|
|
349
|
+
'Property "paths" must be an Object, but %v was given.',
|
|
350
|
+
documentObject.paths
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
if (documentObject.webhooks !== void 0) {
|
|
355
|
+
if (!documentObject.webhooks || typeof documentObject.webhooks !== "object" || Array.isArray(documentObject.webhooks)) {
|
|
356
|
+
throw new import_js_format3.InvalidArgumentError(
|
|
357
|
+
'Property "webhooks" must be an Object, but %v was given.',
|
|
358
|
+
documentObject.webhooks
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (documentObject.components !== void 0) {
|
|
363
|
+
if (!documentObject.components || typeof documentObject.components !== "object" || Array.isArray(documentObject.components)) {
|
|
364
|
+
throw new import_js_format3.InvalidArgumentError(
|
|
365
|
+
'Property "components" must be an Object, but %v was given.',
|
|
366
|
+
documentObject.components
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (documentObject.security !== void 0) {
|
|
371
|
+
if (!Array.isArray(documentObject.security)) {
|
|
372
|
+
throw new import_js_format3.InvalidArgumentError(
|
|
373
|
+
'Property "security" must be an Array, but %v was given.',
|
|
374
|
+
documentObject.security
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
documentObject.security.forEach((securityRequirementObject, index) => {
|
|
378
|
+
if (!securityRequirementObject || typeof securityRequirementObject !== "object" || Array.isArray(securityRequirementObject)) {
|
|
379
|
+
throw new import_js_format3.InvalidArgumentError(
|
|
380
|
+
'Element "security[%d]" must be an Object, but %v was given.',
|
|
381
|
+
index,
|
|
382
|
+
securityRequirementObject
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
if (documentObject.tags !== void 0) {
|
|
388
|
+
if (!Array.isArray(documentObject.tags)) {
|
|
389
|
+
throw new import_js_format3.InvalidArgumentError(
|
|
390
|
+
'Property "tags" must be an Array, but %v was given.',
|
|
391
|
+
documentObject.tags
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
documentObject.tags.forEach((tagObject, index) => {
|
|
395
|
+
if (!tagObject || typeof tagObject !== "object" || Array.isArray(tagObject)) {
|
|
396
|
+
throw new import_js_format3.InvalidArgumentError(
|
|
397
|
+
'Element "tags[%d]" must be an Object, but %v was given.',
|
|
398
|
+
index,
|
|
399
|
+
tagObject
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
if (!tagObject.name || typeof tagObject.name !== "string") {
|
|
403
|
+
throw new import_js_format3.InvalidArgumentError(
|
|
404
|
+
'Property "tags[%d].name" must be a non-empty String, but %v was given.',
|
|
405
|
+
index,
|
|
406
|
+
tagObject.name
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
if (documentObject.externalDocs !== void 0) {
|
|
412
|
+
if (!documentObject.externalDocs || typeof documentObject.externalDocs !== "object" || Array.isArray(documentObject.externalDocs)) {
|
|
413
|
+
throw new import_js_format3.InvalidArgumentError(
|
|
414
|
+
'Property "externalDocs" must be an Object, but %v was given.',
|
|
415
|
+
documentObject.externalDocs
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
__name(validateShallowOADocument, "validateShallowOADocument");
|
|
421
|
+
|
|
422
|
+
// src/oa-document-builder.js
|
|
423
|
+
var OAComponentType = {
|
|
424
|
+
SCHEMA: "schema",
|
|
425
|
+
RESPONSE: "response",
|
|
426
|
+
PARAMETER: "parameter",
|
|
427
|
+
EXAMPLE: "example",
|
|
428
|
+
REQUEST_BODY: "requestBody",
|
|
429
|
+
HEADER: "header",
|
|
430
|
+
SECURITY_SCHEME: "securityScheme",
|
|
431
|
+
LINK: "link",
|
|
432
|
+
CALLBACK: "callback",
|
|
433
|
+
PATH_ITEM: "pathItem"
|
|
434
|
+
};
|
|
435
|
+
var OA_COMPONENT_TYPES = Object.values(OAComponentType);
|
|
436
|
+
var OA_COMPONENT_TYPE_TO_COMPONENTS_KEY_MAP = {
|
|
437
|
+
[OAComponentType.SCHEMA]: "schemas",
|
|
438
|
+
[OAComponentType.RESPONSE]: "responses",
|
|
439
|
+
[OAComponentType.PARAMETER]: "parameters",
|
|
440
|
+
[OAComponentType.EXAMPLE]: "examples",
|
|
441
|
+
[OAComponentType.REQUEST_BODY]: "requestBodies",
|
|
442
|
+
[OAComponentType.HEADER]: "headers",
|
|
443
|
+
[OAComponentType.SECURITY_SCHEME]: "securitySchemes",
|
|
444
|
+
[OAComponentType.LINK]: "links",
|
|
445
|
+
[OAComponentType.CALLBACK]: "callbacks",
|
|
446
|
+
[OAComponentType.PATH_ITEM]: "pathItems"
|
|
447
|
+
};
|
|
448
|
+
var OADocumentBuilder = class extends import_js_service.Service {
|
|
449
|
+
static {
|
|
450
|
+
__name(this, "OADocumentBuilder");
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Document.
|
|
454
|
+
*
|
|
455
|
+
* @private
|
|
456
|
+
* @type {object}
|
|
457
|
+
*/
|
|
458
|
+
_document = {
|
|
459
|
+
openapi: OPENAPI_VERSION,
|
|
460
|
+
info: {
|
|
461
|
+
title: "API Documentation",
|
|
462
|
+
version: "0.0.1"
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
/**
|
|
466
|
+
* Constructor.
|
|
467
|
+
*
|
|
468
|
+
* @param {object} [containerOrDocument]
|
|
469
|
+
* @param {object} [document]
|
|
470
|
+
*/
|
|
471
|
+
constructor(containerOrDocument, document) {
|
|
472
|
+
if ((0, import_js_service.isServiceContainer)(containerOrDocument)) {
|
|
473
|
+
super(containerOrDocument);
|
|
474
|
+
} else {
|
|
475
|
+
super();
|
|
476
|
+
document = containerOrDocument;
|
|
477
|
+
}
|
|
478
|
+
if (document !== void 0) {
|
|
479
|
+
if (!document || typeof document !== "object" || Array.isArray(document)) {
|
|
480
|
+
throw new import_js_format4.InvalidArgumentError(
|
|
481
|
+
"OpenAPI Document Object must be an Object, but %v was given.",
|
|
482
|
+
document
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
document = structuredClone(document);
|
|
486
|
+
if (!document.openapi) {
|
|
487
|
+
document.openapi = this._document.openapi;
|
|
488
|
+
}
|
|
489
|
+
if (!document.info) {
|
|
490
|
+
document.info = this._document.info;
|
|
491
|
+
}
|
|
492
|
+
if (!document.info || typeof document.info !== "object" || Array.isArray(document.info)) {
|
|
493
|
+
throw new import_js_format4.InvalidArgumentError(
|
|
494
|
+
'Property "info" must be an Object, but %v was given.',
|
|
495
|
+
document.info
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
if (!document.info.title) {
|
|
499
|
+
document.info.title = this._document.info.title;
|
|
500
|
+
}
|
|
501
|
+
if (!document.info.version) {
|
|
502
|
+
document.info.version = this._document.info.version;
|
|
503
|
+
}
|
|
504
|
+
validateShallowOADocument(document);
|
|
505
|
+
this._document = document;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Define component.
|
|
510
|
+
*
|
|
511
|
+
* @param {string} type
|
|
512
|
+
* @param {object} definition
|
|
513
|
+
* @returns {this}
|
|
514
|
+
*/
|
|
515
|
+
defineComponent(type, definition) {
|
|
516
|
+
if (!OA_COMPONENT_TYPES.includes(type)) {
|
|
517
|
+
throw new import_js_format4.InvalidArgumentError(
|
|
518
|
+
"Components type %v is not supported.",
|
|
519
|
+
type
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
if (!definition || typeof definition !== "object" || Array.isArray(definition)) {
|
|
523
|
+
throw new import_js_format4.InvalidArgumentError(
|
|
524
|
+
"Component definition must be an Object, but %v was given.",
|
|
525
|
+
definition
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
if (!definition.name || typeof definition.name !== "string") {
|
|
529
|
+
throw new import_js_format4.InvalidArgumentError(
|
|
530
|
+
'Property "name" must be a non-empty String, but %v was given.',
|
|
531
|
+
definition.name
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
const component = definition[type];
|
|
535
|
+
if (!component || typeof component !== "object" || Array.isArray(component)) {
|
|
536
|
+
throw new import_js_format4.InvalidArgumentError(
|
|
537
|
+
"Property %v must be an Object, but %v was given.",
|
|
538
|
+
type,
|
|
539
|
+
component
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
const key = OA_COMPONENT_TYPE_TO_COMPONENTS_KEY_MAP[type];
|
|
543
|
+
if (!key) {
|
|
544
|
+
throw new import_js_format4.InvalidArgumentError(
|
|
545
|
+
"Component type %v does not have a reference to the components key.",
|
|
546
|
+
type
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
this._document.components = this._document.components || {};
|
|
550
|
+
this._document.components[key] = this._document.components[key] || {};
|
|
551
|
+
this._document.components[key][definition.name] = structuredClone(component);
|
|
552
|
+
return this;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Has component.
|
|
556
|
+
*
|
|
557
|
+
* @param {string} type
|
|
558
|
+
* @param {string} name
|
|
559
|
+
* @returns {boolean}
|
|
560
|
+
*/
|
|
561
|
+
hasComponent(type, name) {
|
|
562
|
+
if (!name || typeof name !== "string") {
|
|
563
|
+
throw new import_js_format4.InvalidArgumentError(
|
|
564
|
+
'Parameter "name" must be a non-empty String, but %v was given.',
|
|
565
|
+
name
|
|
566
|
+
);
|
|
567
|
+
}
|
|
568
|
+
const key = OA_COMPONENT_TYPE_TO_COMPONENTS_KEY_MAP[type];
|
|
569
|
+
if (!key) {
|
|
570
|
+
throw new import_js_format4.InvalidArgumentError(
|
|
571
|
+
"Component type %v does not have a reference to the components key.",
|
|
572
|
+
type
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
return Boolean(
|
|
576
|
+
this._document.components && this._document.components[key] && this._document.components[key][name]
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Get component.
|
|
581
|
+
*
|
|
582
|
+
* @param {string} type
|
|
583
|
+
* @param {string} name
|
|
584
|
+
* @returns {object}
|
|
585
|
+
*/
|
|
586
|
+
getComponent(type, name) {
|
|
587
|
+
if (!name || typeof name !== "string") {
|
|
588
|
+
throw new import_js_format4.InvalidArgumentError(
|
|
589
|
+
'Parameter "name" must be a non-empty String, but %v was given.',
|
|
590
|
+
name
|
|
591
|
+
);
|
|
592
|
+
}
|
|
593
|
+
const key = OA_COMPONENT_TYPE_TO_COMPONENTS_KEY_MAP[type];
|
|
594
|
+
if (!key) {
|
|
595
|
+
throw new import_js_format4.InvalidArgumentError(
|
|
596
|
+
"Component type %v does not have a reference to the components key.",
|
|
597
|
+
type
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
const component = this._document && this._document.components && this._document.components[key] && this._document.components[key][name];
|
|
601
|
+
if (!component) {
|
|
602
|
+
throw new import_js_format4.InvalidArgumentError(
|
|
603
|
+
'Component "#/components/%s/%s" does not exist.',
|
|
604
|
+
key,
|
|
605
|
+
name
|
|
606
|
+
);
|
|
607
|
+
}
|
|
608
|
+
return component;
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Define schema component.
|
|
612
|
+
*
|
|
613
|
+
* @param {object} schemaDef
|
|
614
|
+
* @returns {this}
|
|
615
|
+
*/
|
|
616
|
+
defineSchemaComponent(schemaDef) {
|
|
617
|
+
return this.defineComponent(OAComponentType.SCHEMA, schemaDef);
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Define response component.
|
|
621
|
+
*
|
|
622
|
+
* @param {object} responseDef
|
|
623
|
+
* @returns {this}
|
|
624
|
+
*/
|
|
625
|
+
defineResponseComponent(responseDef) {
|
|
626
|
+
return this.defineComponent(OAComponentType.RESPONSE, responseDef);
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Define parameter component.
|
|
630
|
+
*
|
|
631
|
+
* @param {object} parameterDef
|
|
632
|
+
* @returns {this}
|
|
633
|
+
*/
|
|
634
|
+
defineParameterComponent(parameterDef) {
|
|
635
|
+
return this.defineComponent(OAComponentType.PARAMETER, parameterDef);
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Define example component.
|
|
639
|
+
*
|
|
640
|
+
* @param {object} exampleDef
|
|
641
|
+
* @returns {this}
|
|
642
|
+
*/
|
|
643
|
+
defineExampleComponent(exampleDef) {
|
|
644
|
+
return this.defineComponent(OAComponentType.EXAMPLE, exampleDef);
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Define request body component.
|
|
648
|
+
*
|
|
649
|
+
* @param {object} requestBodyDef
|
|
650
|
+
* @returns {this}
|
|
651
|
+
*/
|
|
652
|
+
defineRequestBodyComponent(requestBodyDef) {
|
|
653
|
+
return this.defineComponent(OAComponentType.REQUEST_BODY, requestBodyDef);
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Define header component.
|
|
657
|
+
*
|
|
658
|
+
* @param {object} headerDef
|
|
659
|
+
* @returns {this}
|
|
660
|
+
*/
|
|
661
|
+
defineHeaderComponent(headerDef) {
|
|
662
|
+
return this.defineComponent(OAComponentType.HEADER, headerDef);
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Define security scheme component.
|
|
666
|
+
*
|
|
667
|
+
* @param {object} securitySchemeDef
|
|
668
|
+
* @returns {this}
|
|
669
|
+
*/
|
|
670
|
+
defineSecuritySchemeComponent(securitySchemeDef) {
|
|
671
|
+
return this.defineComponent(
|
|
672
|
+
OAComponentType.SECURITY_SCHEME,
|
|
673
|
+
securitySchemeDef
|
|
674
|
+
);
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Define link component.
|
|
678
|
+
*
|
|
679
|
+
* @param {object} linkDef
|
|
680
|
+
* @returns {this}
|
|
681
|
+
*/
|
|
682
|
+
defineLinkComponent(linkDef) {
|
|
683
|
+
return this.defineComponent(OAComponentType.LINK, linkDef);
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* Define callback component.
|
|
687
|
+
*
|
|
688
|
+
* @param {object} callbackDef
|
|
689
|
+
* @returns {this}
|
|
690
|
+
*/
|
|
691
|
+
defineCallbackComponent(callbackDef) {
|
|
692
|
+
return this.defineComponent(OAComponentType.CALLBACK, callbackDef);
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Define path item component.
|
|
696
|
+
*
|
|
697
|
+
* @param {object} pathItemDef
|
|
698
|
+
* @returns {this}
|
|
699
|
+
*/
|
|
700
|
+
definePathItemComponent(pathItemDef) {
|
|
701
|
+
return this.defineComponent(OAComponentType.PATH_ITEM, pathItemDef);
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Define operation.
|
|
705
|
+
*
|
|
706
|
+
* @param {object} operationDef
|
|
707
|
+
*/
|
|
708
|
+
defineOperation(operationDef) {
|
|
709
|
+
if (!operationDef || typeof operationDef !== "object" || Array.isArray(operationDef)) {
|
|
710
|
+
throw new import_js_format4.InvalidArgumentError(
|
|
711
|
+
"Operation Definition must be an Object, but %v was given.",
|
|
712
|
+
operationDef
|
|
713
|
+
);
|
|
714
|
+
}
|
|
715
|
+
if (!operationDef.path || typeof operationDef.path !== "string") {
|
|
716
|
+
throw new import_js_format4.InvalidArgumentError(
|
|
717
|
+
'Property "path" must be a non-empty String, but %v was given.',
|
|
718
|
+
operationDef.path
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
if (!operationDef.method || typeof operationDef.method !== "string") {
|
|
722
|
+
throw new import_js_format4.InvalidArgumentError(
|
|
723
|
+
'Property "method" must be a non-empty String, but %v was given.',
|
|
724
|
+
operationDef.method
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
if (!Object.values(OAOperationMethod).includes(operationDef.method)) {
|
|
728
|
+
throw new import_js_format4.InvalidArgumentError(
|
|
729
|
+
'Property "method" must be one of values: %l, but %v was given.',
|
|
730
|
+
Object.values(OAOperationMethod)
|
|
731
|
+
);
|
|
732
|
+
}
|
|
733
|
+
if (!operationDef.operation || typeof operationDef.operation !== "object" || Array.isArray(operationDef.operation)) {
|
|
734
|
+
throw new import_js_format4.InvalidArgumentError(
|
|
735
|
+
'Property "operation" must be an Object, but %v was given.',
|
|
736
|
+
operationDef.operation
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
const normalizedPath = normalizePath(operationDef.path);
|
|
740
|
+
if (!this._document.paths) {
|
|
741
|
+
this._document.paths = {};
|
|
742
|
+
}
|
|
743
|
+
if (!this._document.paths[normalizedPath]) {
|
|
744
|
+
this._document.paths[normalizedPath] = {};
|
|
745
|
+
}
|
|
746
|
+
this._document.paths[normalizedPath][operationDef.method] = structuredClone(
|
|
747
|
+
operationDef.operation
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Create scope.
|
|
752
|
+
*
|
|
753
|
+
* @param {object} [options]
|
|
754
|
+
* @returns {OADocumentScope}
|
|
755
|
+
*/
|
|
756
|
+
createScope(options) {
|
|
757
|
+
return new OADocumentScope(this, options);
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Build.
|
|
761
|
+
*
|
|
762
|
+
* @returns {object}
|
|
763
|
+
*/
|
|
764
|
+
build() {
|
|
765
|
+
return structuredClone(this._document);
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* Build JSON.
|
|
769
|
+
*
|
|
770
|
+
* @param {string|number} [space]
|
|
771
|
+
* @returns {string}
|
|
772
|
+
*/
|
|
773
|
+
buildJson(space = 0) {
|
|
774
|
+
return JSON.stringify(this.build(), null, space);
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
// src/oa-document-scope.js
|
|
779
|
+
var OADocumentScope = class _OADocumentScope {
|
|
780
|
+
static {
|
|
781
|
+
__name(this, "OADocumentScope");
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* Builder.
|
|
785
|
+
*
|
|
786
|
+
* @type {OADocumentBuilder}
|
|
787
|
+
*/
|
|
788
|
+
_builder;
|
|
789
|
+
/**
|
|
790
|
+
* Path prefix.
|
|
791
|
+
*
|
|
792
|
+
* @type {string}
|
|
793
|
+
*/
|
|
794
|
+
_pathPrefix;
|
|
795
|
+
/**
|
|
796
|
+
* Tags.
|
|
797
|
+
*
|
|
798
|
+
* @type {string[]}
|
|
799
|
+
*/
|
|
800
|
+
_tags;
|
|
801
|
+
/**
|
|
802
|
+
* @param {object} builder
|
|
803
|
+
* @param {object} [options]
|
|
804
|
+
*/
|
|
805
|
+
constructor(builder, options = {}) {
|
|
806
|
+
if (!(builder instanceof OADocumentBuilder)) {
|
|
807
|
+
throw new import_js_format5.InvalidArgumentError(
|
|
808
|
+
'Parameter "builder" must be an instance of OADocumentBuilder, but %v was given.',
|
|
809
|
+
builder
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
if (!options || typeof options !== "object" || Array.isArray(options)) {
|
|
813
|
+
throw new import_js_format5.InvalidArgumentError(
|
|
814
|
+
'Parameter "options" must be an Object, but %v was given.',
|
|
815
|
+
options
|
|
816
|
+
);
|
|
817
|
+
}
|
|
818
|
+
if (options.pathPrefix !== void 0) {
|
|
819
|
+
if (!options.pathPrefix || typeof options.pathPrefix !== "string") {
|
|
820
|
+
throw new import_js_format5.InvalidArgumentError(
|
|
821
|
+
'Property "pathPrefix" must be a non-empty String, but %v was given.',
|
|
822
|
+
options.pathPrefix
|
|
823
|
+
);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
if (options.tags !== void 0) {
|
|
827
|
+
if (!Array.isArray(options.tags)) {
|
|
828
|
+
throw new import_js_format5.InvalidArgumentError(
|
|
829
|
+
'Property "tags" must be an Array, but %v was given.',
|
|
830
|
+
options.tags
|
|
831
|
+
);
|
|
832
|
+
}
|
|
833
|
+
options.tags.forEach((tag, index) => {
|
|
834
|
+
if (!tag || typeof tag !== "string") {
|
|
835
|
+
throw new import_js_format5.InvalidArgumentError(
|
|
836
|
+
'Element "tags[%d]" must be a non-empty String, but %v was given.',
|
|
837
|
+
index,
|
|
838
|
+
tag
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
this._builder = builder;
|
|
844
|
+
this._pathPrefix = normalizePath(options.pathPrefix || "/");
|
|
845
|
+
this._tags = options.tags || [];
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* Get builder.
|
|
849
|
+
*
|
|
850
|
+
* @returns {OADocumentBuilder}
|
|
851
|
+
*/
|
|
852
|
+
getBuilder() {
|
|
853
|
+
return this._builder;
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Get path prefix.
|
|
857
|
+
*
|
|
858
|
+
* @returns {string}
|
|
859
|
+
*/
|
|
860
|
+
getPathPrefix() {
|
|
861
|
+
return this._pathPrefix;
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Get tags.
|
|
865
|
+
*
|
|
866
|
+
* @returns {string[]}
|
|
867
|
+
*/
|
|
868
|
+
getTags() {
|
|
869
|
+
return [...this._tags];
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* Define operation.
|
|
873
|
+
*
|
|
874
|
+
* @param {object} operationDef
|
|
875
|
+
* @returns {this}
|
|
876
|
+
*/
|
|
877
|
+
defineOperation(operationDef) {
|
|
878
|
+
if (!operationDef || typeof operationDef !== "object" || Array.isArray(operationDef)) {
|
|
879
|
+
throw new import_js_format5.InvalidArgumentError(
|
|
880
|
+
"Operation Definition must be an Object, but %v was given.",
|
|
881
|
+
operationDef
|
|
882
|
+
);
|
|
883
|
+
}
|
|
884
|
+
if (!operationDef.path || typeof operationDef.path !== "string") {
|
|
885
|
+
throw new import_js_format5.InvalidArgumentError(
|
|
886
|
+
'Property "path" must be a non-empty String, but %v was given.',
|
|
887
|
+
operationDef.path
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
if (!operationDef.method || typeof operationDef.method !== "string") {
|
|
891
|
+
throw new import_js_format5.InvalidArgumentError(
|
|
892
|
+
'Property "method" must be a non-empty String, but %v was given.',
|
|
893
|
+
operationDef.method
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
if (!Object.values(OAOperationMethod).includes(operationDef.method)) {
|
|
897
|
+
throw new import_js_format5.InvalidArgumentError(
|
|
898
|
+
'Property "method" must be one of values: %l, but %v was given.',
|
|
899
|
+
Object.values(OAOperationMethod)
|
|
900
|
+
);
|
|
901
|
+
}
|
|
902
|
+
if (!operationDef.operation || typeof operationDef.operation !== "object" || Array.isArray(operationDef.operation)) {
|
|
903
|
+
throw new import_js_format5.InvalidArgumentError(
|
|
904
|
+
'Property "operation" must be an Object, but %v was given.',
|
|
905
|
+
operationDef.operation
|
|
906
|
+
);
|
|
907
|
+
}
|
|
908
|
+
const fullPath = joinPath(this._pathPrefix, operationDef.path);
|
|
909
|
+
const operation = structuredClone(operationDef.operation);
|
|
910
|
+
if (this._tags.length > 0) {
|
|
911
|
+
operation.tags = [...this._tags, ...operation.tags || []];
|
|
912
|
+
operation.tags = [...new Set(operation.tags)];
|
|
913
|
+
}
|
|
914
|
+
this._builder.defineOperation({
|
|
915
|
+
...operationDef,
|
|
916
|
+
path: fullPath,
|
|
917
|
+
operation
|
|
918
|
+
});
|
|
919
|
+
return this;
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* Create scope.
|
|
923
|
+
*
|
|
924
|
+
* @param {object} [options]
|
|
925
|
+
* @returns {OADocumentScope}
|
|
926
|
+
*/
|
|
927
|
+
createScope(options = {}) {
|
|
928
|
+
if (!options || typeof options !== "object" || Array.isArray(options)) {
|
|
929
|
+
throw new import_js_format5.InvalidArgumentError(
|
|
930
|
+
'Parameter "options" must be an Object, but %v was given.',
|
|
931
|
+
options
|
|
932
|
+
);
|
|
933
|
+
}
|
|
934
|
+
if (options.pathPrefix !== void 0) {
|
|
935
|
+
if (!options.pathPrefix || typeof options.pathPrefix !== "string") {
|
|
936
|
+
throw new import_js_format5.InvalidArgumentError(
|
|
937
|
+
'Property "pathPrefix" must be a non-empty String, but %v was given.',
|
|
938
|
+
options.pathPrefix
|
|
939
|
+
);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
if (options.tags !== void 0) {
|
|
943
|
+
if (!Array.isArray(options.tags)) {
|
|
944
|
+
throw new import_js_format5.InvalidArgumentError(
|
|
945
|
+
'Property "tags" must be an Array, but %v was given.',
|
|
946
|
+
options.tags
|
|
947
|
+
);
|
|
948
|
+
}
|
|
949
|
+
options.tags.forEach((tag, index) => {
|
|
950
|
+
if (!tag || typeof tag !== "string") {
|
|
951
|
+
throw new import_js_format5.InvalidArgumentError(
|
|
952
|
+
'Element "tags[%d]" must be a non-empty String, but %v was given.',
|
|
953
|
+
index,
|
|
954
|
+
tag
|
|
955
|
+
);
|
|
956
|
+
}
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
return new _OADocumentScope(this._builder, {
|
|
960
|
+
pathPrefix: joinPath(this._pathPrefix, options.pathPrefix),
|
|
961
|
+
tags: [...this._tags, ...options.tags || []]
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
};
|
|
965
|
+
|
|
966
|
+
// src/json-pointer/escape-json-pointer.js
|
|
967
|
+
var import_js_format6 = require("@e22m4u/js-format");
|
|
968
|
+
function escapeJsonPointer(jsonPointer) {
|
|
969
|
+
if (typeof jsonPointer !== "string") {
|
|
970
|
+
throw new import_js_format6.InvalidArgumentError(
|
|
971
|
+
'Parameter "jsonPointer" must be a String, but %v was given.',
|
|
972
|
+
jsonPointer
|
|
973
|
+
);
|
|
974
|
+
}
|
|
975
|
+
return jsonPointer.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
976
|
+
}
|
|
977
|
+
__name(escapeJsonPointer, "escapeJsonPointer");
|
|
978
|
+
|
|
979
|
+
// src/json-pointer/resolve-json-pointer.js
|
|
980
|
+
var import_js_format7 = require("@e22m4u/js-format");
|
|
981
|
+
var ARRAY_INDEX_PATTERN = /^(0|[1-9][0-9]*)$/;
|
|
982
|
+
function resolveJsonPointer(document, pointer) {
|
|
983
|
+
if (!document || typeof document !== "object") {
|
|
984
|
+
throw new import_js_format7.InvalidArgumentError(
|
|
985
|
+
'Parameter "document" must be an Object or an Array, but %v was given.',
|
|
986
|
+
document
|
|
987
|
+
);
|
|
988
|
+
}
|
|
989
|
+
if (typeof pointer !== "string") {
|
|
990
|
+
throw new import_js_format7.InvalidArgumentError(
|
|
991
|
+
"JSON pointer must be a String, but %v was given.",
|
|
992
|
+
pointer
|
|
993
|
+
);
|
|
994
|
+
}
|
|
995
|
+
if (pointer === "") {
|
|
996
|
+
return document;
|
|
997
|
+
}
|
|
998
|
+
if (!pointer.startsWith("/")) {
|
|
999
|
+
throw new import_js_format7.InvalidArgumentError(
|
|
1000
|
+
'JSON pointer must start with a forward slash "/", but %v was given.',
|
|
1001
|
+
pointer
|
|
1002
|
+
);
|
|
1003
|
+
}
|
|
1004
|
+
const pathParts = pointer.substring(1).split("/");
|
|
1005
|
+
let current = document;
|
|
1006
|
+
for (let i = 0, l = pathParts.length; i < l; i++) {
|
|
1007
|
+
const part = pathParts[i];
|
|
1008
|
+
const segment = unescapeJsonPointer(part);
|
|
1009
|
+
if (current && typeof current === "object" && !Array.isArray(current) && Object.hasOwn(current, segment) && current[segment] !== void 0) {
|
|
1010
|
+
current = current[segment];
|
|
1011
|
+
} else if (Array.isArray(current) && ARRAY_INDEX_PATTERN.test(segment) && current[segment] !== void 0) {
|
|
1012
|
+
current = current[segment];
|
|
1013
|
+
} else {
|
|
1014
|
+
const currentPointer = "/" + pathParts.slice(0, i + 1).join("/");
|
|
1015
|
+
throw new import_js_format7.InvalidArgumentError(
|
|
1016
|
+
"Unable to resolve %v in the given document.",
|
|
1017
|
+
currentPointer
|
|
1018
|
+
);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
return current;
|
|
1022
|
+
}
|
|
1023
|
+
__name(resolveJsonPointer, "resolveJsonPointer");
|
|
1024
|
+
|
|
1025
|
+
// src/json-pointer/unescape-json-pointer.js
|
|
1026
|
+
var import_js_format8 = require("@e22m4u/js-format");
|
|
1027
|
+
function unescapeJsonPointer(jsonPointer) {
|
|
1028
|
+
if (typeof jsonPointer !== "string") {
|
|
1029
|
+
throw new import_js_format8.InvalidArgumentError(
|
|
1030
|
+
'Parameter "jsonPointer" must be a String, but %v was given.',
|
|
1031
|
+
jsonPointer
|
|
1032
|
+
);
|
|
1033
|
+
}
|
|
1034
|
+
return jsonPointer.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
1035
|
+
}
|
|
1036
|
+
__name(unescapeJsonPointer, "unescapeJsonPointer");
|
|
1037
|
+
|
|
1038
|
+
// src/data-validation/data-format-validators.js
|
|
1039
|
+
var RX_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
1040
|
+
var RX_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
1041
|
+
var RX_DATE_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|([+-]\d{2}:?\d{2}))$/i;
|
|
1042
|
+
var RX_IPV4 = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
1043
|
+
var RX_IPV6 = /^((([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])))$/;
|
|
1044
|
+
var RX_HOSTNAME = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/;
|
|
1045
|
+
var RX_EMAIL = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
1046
|
+
var RX_BASE64 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
1047
|
+
var validateInt32Format = /* @__PURE__ */ __name((v) => {
|
|
1048
|
+
if (typeof v !== "number") {
|
|
1049
|
+
return true;
|
|
1050
|
+
}
|
|
1051
|
+
return Number.isInteger(v) && v >= -2147483648 && v <= 2147483647;
|
|
1052
|
+
}, "validateInt32Format");
|
|
1053
|
+
var validateInt64Format = /* @__PURE__ */ __name((v) => {
|
|
1054
|
+
if (typeof v !== "number") {
|
|
1055
|
+
return true;
|
|
1056
|
+
}
|
|
1057
|
+
return Number.isSafeInteger(v);
|
|
1058
|
+
}, "validateInt64Format");
|
|
1059
|
+
var validateFloatFormat = /* @__PURE__ */ __name((v) => {
|
|
1060
|
+
if (typeof v !== "number") {
|
|
1061
|
+
return true;
|
|
1062
|
+
}
|
|
1063
|
+
return !Number.isNaN(v) && Number.isFinite(v) && // Math.fround приводит число к 32-битному float,
|
|
1064
|
+
// если результат бесконечен, значит число не влазит в float
|
|
1065
|
+
Number.isFinite(Math.fround(v));
|
|
1066
|
+
}, "validateFloatFormat");
|
|
1067
|
+
var validateDoubleFormat = /* @__PURE__ */ __name((v) => {
|
|
1068
|
+
if (typeof v !== "number") {
|
|
1069
|
+
return true;
|
|
1070
|
+
}
|
|
1071
|
+
return !Number.isNaN(v) && Number.isFinite(v);
|
|
1072
|
+
}, "validateDoubleFormat");
|
|
1073
|
+
var validateByteFormat = /* @__PURE__ */ __name((v) => {
|
|
1074
|
+
if (typeof v !== "string") {
|
|
1075
|
+
return true;
|
|
1076
|
+
}
|
|
1077
|
+
return v.length % 4 === 0 && RX_BASE64.test(v);
|
|
1078
|
+
}, "validateByteFormat");
|
|
1079
|
+
var validateDateFormat = /* @__PURE__ */ __name((v) => {
|
|
1080
|
+
if (typeof v !== "string") {
|
|
1081
|
+
return true;
|
|
1082
|
+
}
|
|
1083
|
+
if (!RX_DATE.test(v)) {
|
|
1084
|
+
return false;
|
|
1085
|
+
}
|
|
1086
|
+
const [y, m, d] = v.split("-").map(Number);
|
|
1087
|
+
const date = new Date(Date.UTC(y, m - 1, d));
|
|
1088
|
+
return date.getUTCFullYear() === y && date.getUTCMonth() === m - 1 && date.getUTCDate() === d;
|
|
1089
|
+
}, "validateDateFormat");
|
|
1090
|
+
var validateDateTimeFormat = /* @__PURE__ */ __name((v) => {
|
|
1091
|
+
if (typeof v !== "string") {
|
|
1092
|
+
return true;
|
|
1093
|
+
}
|
|
1094
|
+
return RX_DATE_TIME.test(v) && !isNaN(Date.parse(v));
|
|
1095
|
+
}, "validateDateTimeFormat");
|
|
1096
|
+
var validateEmailFormat = /* @__PURE__ */ __name((v) => {
|
|
1097
|
+
if (typeof v !== "string") {
|
|
1098
|
+
return true;
|
|
1099
|
+
}
|
|
1100
|
+
return RX_EMAIL.test(v);
|
|
1101
|
+
}, "validateEmailFormat");
|
|
1102
|
+
var validateUuidFormat = /* @__PURE__ */ __name((v) => {
|
|
1103
|
+
if (typeof v !== "string") {
|
|
1104
|
+
return true;
|
|
1105
|
+
}
|
|
1106
|
+
return RX_UUID.test(v);
|
|
1107
|
+
}, "validateUuidFormat");
|
|
1108
|
+
var validateIpv4Format = /* @__PURE__ */ __name((v) => {
|
|
1109
|
+
if (typeof v !== "string") {
|
|
1110
|
+
return true;
|
|
1111
|
+
}
|
|
1112
|
+
return RX_IPV4.test(v);
|
|
1113
|
+
}, "validateIpv4Format");
|
|
1114
|
+
var validateIpv6Format = /* @__PURE__ */ __name((v) => {
|
|
1115
|
+
if (typeof v !== "string") {
|
|
1116
|
+
return true;
|
|
1117
|
+
}
|
|
1118
|
+
return RX_IPV6.test(v);
|
|
1119
|
+
}, "validateIpv6Format");
|
|
1120
|
+
var validateHostnameFormat = /* @__PURE__ */ __name((v) => {
|
|
1121
|
+
if (typeof v !== "string") {
|
|
1122
|
+
return true;
|
|
1123
|
+
}
|
|
1124
|
+
return v.length <= 255 && RX_HOSTNAME.test(v);
|
|
1125
|
+
}, "validateHostnameFormat");
|
|
1126
|
+
var validateUriFormat = /* @__PURE__ */ __name((v) => {
|
|
1127
|
+
if (typeof v !== "string") {
|
|
1128
|
+
return true;
|
|
1129
|
+
}
|
|
1130
|
+
try {
|
|
1131
|
+
new URL(v);
|
|
1132
|
+
return true;
|
|
1133
|
+
} catch {
|
|
1134
|
+
return false;
|
|
1135
|
+
}
|
|
1136
|
+
}, "validateUriFormat");
|
|
1137
|
+
|
|
1138
|
+
// src/data-validation/data-format-validator-map.js
|
|
1139
|
+
var OA_BUILT_IN_DATA_FORMAT_VALIDATOR_MAP = {
|
|
1140
|
+
[OADataFormat.INT32]: validateInt32Format,
|
|
1141
|
+
[OADataFormat.INT64]: validateInt64Format,
|
|
1142
|
+
[OADataFormat.FLOAT]: validateFloatFormat,
|
|
1143
|
+
[OADataFormat.DOUBLE]: validateDoubleFormat,
|
|
1144
|
+
[OADataFormat.DATE]: validateDateFormat,
|
|
1145
|
+
[OADataFormat.DATE_TIME]: validateDateTimeFormat,
|
|
1146
|
+
[OADataFormat.BYTE]: validateByteFormat,
|
|
1147
|
+
[OADataFormat.EMAIL]: validateEmailFormat,
|
|
1148
|
+
[OADataFormat.UUID]: validateUuidFormat,
|
|
1149
|
+
[OADataFormat.HOSTNAME]: validateHostnameFormat,
|
|
1150
|
+
[OADataFormat.IPV4]: validateIpv4Format,
|
|
1151
|
+
[OADataFormat.IPV6]: validateIpv6Format,
|
|
1152
|
+
[OADataFormat.URI]: validateUriFormat
|
|
1153
|
+
};
|
|
1154
|
+
|
|
1155
|
+
// src/data-validation/validate-data-with-openapi-schema.js
|
|
1156
|
+
var import_js_format11 = require("@e22m4u/js-format");
|
|
1157
|
+
|
|
1158
|
+
// src/oa-reference-object/oa-ref.js
|
|
1159
|
+
var import_js_format9 = require("@e22m4u/js-format");
|
|
1160
|
+
function oaRef(name, segment) {
|
|
1161
|
+
if (!name || typeof name !== "string") {
|
|
1162
|
+
throw new import_js_format9.InvalidArgumentError(
|
|
1163
|
+
'Parameter "name" must be a non-empty String, but %v was given.',
|
|
1164
|
+
name
|
|
1165
|
+
);
|
|
1166
|
+
}
|
|
1167
|
+
const escapedName = escapeJsonPointer(name);
|
|
1168
|
+
return { $ref: `#/components/${segment}/${escapedName}` };
|
|
1169
|
+
}
|
|
1170
|
+
__name(oaRef, "oaRef");
|
|
1171
|
+
var oaSchemaRef = /* @__PURE__ */ __name((name) => oaRef(name, "schemas"), "oaSchemaRef");
|
|
1172
|
+
var oaResponseRef = /* @__PURE__ */ __name((name) => oaRef(name, "responses"), "oaResponseRef");
|
|
1173
|
+
var oaParameterRef = /* @__PURE__ */ __name((name) => oaRef(name, "parameters"), "oaParameterRef");
|
|
1174
|
+
var oaExampleRef = /* @__PURE__ */ __name((name) => oaRef(name, "examples"), "oaExampleRef");
|
|
1175
|
+
var oaRequestBodyRef = /* @__PURE__ */ __name((name) => oaRef(name, "requestBodies"), "oaRequestBodyRef");
|
|
1176
|
+
var oaSecuritySchemeRef = /* @__PURE__ */ __name((name) => oaRef(name, "securitySchemes"), "oaSecuritySchemeRef");
|
|
1177
|
+
var oaLinkRef = /* @__PURE__ */ __name((name) => oaRef(name, "links"), "oaLinkRef");
|
|
1178
|
+
var oaCallbackRef = /* @__PURE__ */ __name((name) => oaRef(name, "callbacks"), "oaCallbackRef");
|
|
1179
|
+
var oaPathItemRef = /* @__PURE__ */ __name((name) => oaRef(name, "pathItems"), "oaPathItemRef");
|
|
1180
|
+
|
|
1181
|
+
// src/oa-reference-object/is-oa-reference-object.js
|
|
1182
|
+
function isOAReferenceObject(value) {
|
|
1183
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
1184
|
+
if (value.$ref !== void 0 || value.$dynamicRef !== void 0) {
|
|
1185
|
+
return true;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
return false;
|
|
1189
|
+
}
|
|
1190
|
+
__name(isOAReferenceObject, "isOAReferenceObject");
|
|
1191
|
+
|
|
1192
|
+
// src/oa-reference-object/resolve-oa-reference-object.js
|
|
1193
|
+
var import_js_format10 = require("@e22m4u/js-format");
|
|
1194
|
+
function resolveOAReferenceObject(referenceObj, options = {}) {
|
|
1195
|
+
if (!referenceObj || typeof referenceObj !== "object" || Array.isArray(referenceObj)) {
|
|
1196
|
+
throw new import_js_format10.InvalidArgumentError(
|
|
1197
|
+
'Parameter "referenceObj" must be an Object, but %v was given.',
|
|
1198
|
+
referenceObj
|
|
1199
|
+
);
|
|
1200
|
+
}
|
|
1201
|
+
if (!options || typeof options !== "object" || Array.isArray(options)) {
|
|
1202
|
+
throw new import_js_format10.InvalidArgumentError(
|
|
1203
|
+
'Parameter "options" must be an Object, but %v was given.',
|
|
1204
|
+
options
|
|
1205
|
+
);
|
|
1206
|
+
}
|
|
1207
|
+
if (options.rootDocument !== void 0) {
|
|
1208
|
+
if (!options.rootDocument || typeof options.rootDocument !== "object") {
|
|
1209
|
+
throw new import_js_format10.InvalidArgumentError(
|
|
1210
|
+
'Option "rootDocument" must be an Object or an Array, but %v was given.',
|
|
1211
|
+
options.rootDocument
|
|
1212
|
+
);
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
if (referenceObj.$ref !== void 0) {
|
|
1216
|
+
if (!referenceObj.$ref || typeof referenceObj.$ref !== "string") {
|
|
1217
|
+
throw new import_js_format10.InvalidArgumentError(
|
|
1218
|
+
'Schema keyword "$ref" must be a non-empty String, but %v was given.',
|
|
1219
|
+
referenceObj.$ref
|
|
1220
|
+
);
|
|
1221
|
+
}
|
|
1222
|
+
const refUri = referenceObj.$ref;
|
|
1223
|
+
if (refUri.startsWith("#")) {
|
|
1224
|
+
if (!options.rootDocument) {
|
|
1225
|
+
throw new import_js_format10.InvalidArgumentError(
|
|
1226
|
+
'Option "rootDocument" is required to resolve the same-document reference (URI starts with "#").'
|
|
1227
|
+
);
|
|
1228
|
+
}
|
|
1229
|
+
if (refUri === "#") {
|
|
1230
|
+
return options.rootDocument;
|
|
1231
|
+
} else if (refUri.startsWith("#/")) {
|
|
1232
|
+
return resolveJsonPointer(options.rootDocument, refUri.substring(1));
|
|
1233
|
+
}
|
|
1234
|
+
throw new import_js_format10.InvalidArgumentError(
|
|
1235
|
+
"Anchor reference is not supported, but %v was given.",
|
|
1236
|
+
refUri
|
|
1237
|
+
);
|
|
1238
|
+
}
|
|
1239
|
+
if (refUri.startsWith("http://") || refUri.startsWith("https://")) {
|
|
1240
|
+
throw new import_js_format10.InvalidArgumentError(
|
|
1241
|
+
"External resource is not supported, but %v was given.",
|
|
1242
|
+
refUri
|
|
1243
|
+
);
|
|
1244
|
+
}
|
|
1245
|
+
throw new import_js_format10.InvalidArgumentError(
|
|
1246
|
+
"Relative reference is not supported, but %v was given.",
|
|
1247
|
+
refUri
|
|
1248
|
+
);
|
|
1249
|
+
}
|
|
1250
|
+
if (referenceObj.$dynamicRef) {
|
|
1251
|
+
throw new import_js_format10.InvalidArgumentError(
|
|
1252
|
+
'Schema keyword "$dynamicRef" is not supported.'
|
|
1253
|
+
);
|
|
1254
|
+
}
|
|
1255
|
+
throw new import_js_format10.InvalidArgumentError(
|
|
1256
|
+
"Reference object does not have reference properties."
|
|
1257
|
+
);
|
|
1258
|
+
}
|
|
1259
|
+
__name(resolveOAReferenceObject, "resolveOAReferenceObject");
|
|
1260
|
+
|
|
1261
|
+
// src/data-validation/validate-data-with-openapi-schema.js
|
|
1262
|
+
var JSON_INTEGER_REGEXP = /^-?\d+$/;
|
|
1263
|
+
var JSON_NUMBER_REGEXP = /^-?\d+(\.\d+)?([eE][+-]?\d+)?$/;
|
|
1264
|
+
var UNSUPPORTED_SCHEMA_KEYWORDS = [
|
|
1265
|
+
"nullable",
|
|
1266
|
+
// удалено в 3.1.0
|
|
1267
|
+
"contentEncoding",
|
|
1268
|
+
"contentMediaType",
|
|
1269
|
+
"contentSchema",
|
|
1270
|
+
"discriminator"
|
|
1271
|
+
];
|
|
1272
|
+
function validateDataWithOpenApiSchema(data, schema, options = {}) {
|
|
1273
|
+
if (schema === null || typeof schema !== "boolean" && typeof schema !== "object" || Array.isArray(schema)) {
|
|
1274
|
+
throw new import_js_format11.InvalidArgumentError(
|
|
1275
|
+
'Parameter "schema" must be a Boolean or an Object, but %v was given.',
|
|
1276
|
+
schema
|
|
1277
|
+
);
|
|
1278
|
+
}
|
|
1279
|
+
if (!options || typeof options !== "object" || Array.isArray(options)) {
|
|
1280
|
+
throw new import_js_format11.InvalidArgumentError(
|
|
1281
|
+
'Parameter "options" must be an Object, but %v was given.',
|
|
1282
|
+
options
|
|
1283
|
+
);
|
|
1284
|
+
}
|
|
1285
|
+
if (options.rootDocument !== void 0) {
|
|
1286
|
+
if (!options.rootDocument || typeof options.rootDocument !== "object" || Array.isArray(options.rootDocument)) {
|
|
1287
|
+
throw new import_js_format11.InvalidArgumentError(
|
|
1288
|
+
'Option "rootDocument" must be an Object, but %v was given.',
|
|
1289
|
+
options.rootDocument
|
|
1290
|
+
);
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
if (options.required !== void 0) {
|
|
1294
|
+
if (typeof options.required !== "boolean") {
|
|
1295
|
+
throw new import_js_format11.InvalidArgumentError(
|
|
1296
|
+
'Option "required" must be a Boolean, but %v was given.',
|
|
1297
|
+
options.required
|
|
1298
|
+
);
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
if (options.coerceTypes !== void 0) {
|
|
1302
|
+
if (typeof options.coerceTypes !== "boolean") {
|
|
1303
|
+
throw new import_js_format11.InvalidArgumentError(
|
|
1304
|
+
'Option "coerceTypes" must be a Boolean, but %v was given.',
|
|
1305
|
+
options.coerceTypes
|
|
1306
|
+
);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
if (options.applyDefaults !== void 0) {
|
|
1310
|
+
if (typeof options.applyDefaults !== "boolean") {
|
|
1311
|
+
throw new import_js_format11.InvalidArgumentError(
|
|
1312
|
+
'Option "applyDefaults" must be a Boolean, but %v was given.',
|
|
1313
|
+
options.applyDefaults
|
|
1314
|
+
);
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
if (options.stripUnknown !== void 0) {
|
|
1318
|
+
if (typeof options.stripUnknown !== "boolean") {
|
|
1319
|
+
throw new import_js_format11.InvalidArgumentError(
|
|
1320
|
+
'Option "stripUnknown" must be a Boolean, but %v was given.',
|
|
1321
|
+
options.stripUnknown
|
|
1322
|
+
);
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
if (options.dataSourceUri !== void 0) {
|
|
1326
|
+
if (!options.dataSourceUri || typeof options.dataSourceUri !== "string") {
|
|
1327
|
+
throw new import_js_format11.InvalidArgumentError(
|
|
1328
|
+
'Option "dataSourceUri" must be a non-empty String, but %v was given.',
|
|
1329
|
+
options.dataSourceUri
|
|
1330
|
+
);
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
if (options.schemaSourceUri !== void 0) {
|
|
1334
|
+
if (!options.schemaSourceUri || typeof options.schemaSourceUri !== "string") {
|
|
1335
|
+
throw new import_js_format11.InvalidArgumentError(
|
|
1336
|
+
'Option "schemaSourceUri" must be a non-empty String, but %v was given.',
|
|
1337
|
+
options.schemaSourceUri
|
|
1338
|
+
);
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
if (options.silent !== void 0) {
|
|
1342
|
+
if (typeof options.silent !== "boolean") {
|
|
1343
|
+
throw new import_js_format11.InvalidArgumentError(
|
|
1344
|
+
'Option "silent" must be a Boolean, but %v was given.',
|
|
1345
|
+
options.silent
|
|
1346
|
+
);
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
if (options.accessMode !== void 0) {
|
|
1350
|
+
if (!ACCESS_MODE_LIST.includes(options.accessMode)) {
|
|
1351
|
+
throw new import_js_format11.InvalidArgumentError(
|
|
1352
|
+
"Access mode %v is not supported.",
|
|
1353
|
+
options.accessMode
|
|
1354
|
+
);
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
if (options.formatValidators !== void 0) {
|
|
1358
|
+
if (!options.formatValidators || typeof options.formatValidators !== "object" || Array.isArray(options.formatValidators)) {
|
|
1359
|
+
throw new import_js_format11.InvalidArgumentError(
|
|
1360
|
+
'Option "formatValidators" must be an Object, but %v was given.',
|
|
1361
|
+
options.formatValidators
|
|
1362
|
+
);
|
|
1363
|
+
}
|
|
1364
|
+
Object.keys(options.formatValidators).forEach((formatName) => {
|
|
1365
|
+
const formatValidator = options.formatValidators[formatName];
|
|
1366
|
+
if (formatValidator !== void 0 && typeof formatValidator !== "function") {
|
|
1367
|
+
throw new import_js_format11.InvalidArgumentError(
|
|
1368
|
+
"Format validator %v must be a Function, but %v was given.",
|
|
1369
|
+
formatName,
|
|
1370
|
+
formatValidator
|
|
1371
|
+
);
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
1374
|
+
}
|
|
1375
|
+
if (options.parseJson !== void 0) {
|
|
1376
|
+
if (typeof options.parseJson !== "boolean") {
|
|
1377
|
+
throw new import_js_format11.InvalidArgumentError(
|
|
1378
|
+
'Option "parseJson" must be a Boolean, but %v was given.',
|
|
1379
|
+
options.parseJson
|
|
1380
|
+
);
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
if (options.required === true && data === void 0) {
|
|
1384
|
+
const result2 = {
|
|
1385
|
+
isValid: false,
|
|
1386
|
+
value: data,
|
|
1387
|
+
valueUri: options.dataSourceUri || "",
|
|
1388
|
+
schemaUri: options.schemaSourceUri || "",
|
|
1389
|
+
reason: (0, import_js_format11.format)(
|
|
1390
|
+
"Value at %v is required, but %v was given.",
|
|
1391
|
+
options.dataSourceUri || "",
|
|
1392
|
+
data
|
|
1393
|
+
)
|
|
1394
|
+
};
|
|
1395
|
+
if (!options.silent) {
|
|
1396
|
+
throw new OADataValidationError(result2.reason);
|
|
1397
|
+
} else {
|
|
1398
|
+
return result2;
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
const subResult = _validate(data, schema, {
|
|
1402
|
+
...options,
|
|
1403
|
+
dataSourceUri: options.dataSourceUri || "",
|
|
1404
|
+
schemaSourceUri: options.schemaSourceUri || ""
|
|
1405
|
+
});
|
|
1406
|
+
if (!subResult.isValid && !options.silent) {
|
|
1407
|
+
throw new OADataValidationError(subResult.reason);
|
|
1408
|
+
}
|
|
1409
|
+
const result = {
|
|
1410
|
+
isValid: subResult.isValid,
|
|
1411
|
+
reason: subResult.reason,
|
|
1412
|
+
value: subResult.value,
|
|
1413
|
+
valueUri: subResult.valueUri,
|
|
1414
|
+
schemaUri: subResult.schemaUri
|
|
1415
|
+
};
|
|
1416
|
+
if (result.isValid) {
|
|
1417
|
+
delete result.reason;
|
|
1418
|
+
}
|
|
1419
|
+
return result;
|
|
1420
|
+
}
|
|
1421
|
+
__name(validateDataWithOpenApiSchema, "validateDataWithOpenApiSchema");
|
|
1422
|
+
function _validate(data, schema, options) {
|
|
1423
|
+
if (schema === null || typeof schema !== "boolean" && typeof schema !== "object" || Array.isArray(schema)) {
|
|
1424
|
+
throw new import_js_format11.InvalidArgumentError(
|
|
1425
|
+
"Schema at %v must be a Boolean or an Object, but %v was given.",
|
|
1426
|
+
options.schemaSourceUri,
|
|
1427
|
+
schema
|
|
1428
|
+
);
|
|
1429
|
+
}
|
|
1430
|
+
if (typeof schema === "boolean") {
|
|
1431
|
+
if (schema === true) {
|
|
1432
|
+
return {
|
|
1433
|
+
isValid: true,
|
|
1434
|
+
value: data,
|
|
1435
|
+
valueUri: options.dataSourceUri,
|
|
1436
|
+
schemaUri: options.schemaSourceUri
|
|
1437
|
+
};
|
|
1438
|
+
} else if (data !== void 0) {
|
|
1439
|
+
return {
|
|
1440
|
+
isValid: false,
|
|
1441
|
+
value: data,
|
|
1442
|
+
valueUri: options.dataSourceUri,
|
|
1443
|
+
schemaUri: options.schemaSourceUri,
|
|
1444
|
+
reason: (0, import_js_format11.format)(
|
|
1445
|
+
"Value at %v is rejected by the boolean schema at %v.",
|
|
1446
|
+
options.dataSourceUri,
|
|
1447
|
+
options.schemaSourceUri
|
|
1448
|
+
)
|
|
1449
|
+
};
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
let evaluatedIndexes = /* @__PURE__ */ new Set();
|
|
1453
|
+
let evaluatedProperties = /* @__PURE__ */ new Set();
|
|
1454
|
+
if (schema.default !== void 0 && data === void 0 && options.applyDefaults === true) {
|
|
1455
|
+
data = schema.default;
|
|
1456
|
+
}
|
|
1457
|
+
if (options.parseJson === true && schema.type !== void 0 && typeof data === "string") {
|
|
1458
|
+
data = _parseJson(data, schema.type);
|
|
1459
|
+
}
|
|
1460
|
+
if (options.coerceTypes === true && schema.type !== void 0 && data !== void 0) {
|
|
1461
|
+
data = _coerceType(data, schema.type);
|
|
1462
|
+
}
|
|
1463
|
+
if (schema.$ref !== void 0 || schema.$dynamicRef !== void 0) {
|
|
1464
|
+
const resSchema = resolveOAReferenceObject(schema, {
|
|
1465
|
+
rootDocument: options.rootDocument
|
|
1466
|
+
});
|
|
1467
|
+
const result = _validate(data, resSchema, {
|
|
1468
|
+
...options,
|
|
1469
|
+
schemaSourceUri: schema.$ref || schema.$dynamicRef
|
|
1470
|
+
});
|
|
1471
|
+
if (!result.isValid) {
|
|
1472
|
+
return result;
|
|
1473
|
+
}
|
|
1474
|
+
data = result.value;
|
|
1475
|
+
if (result.evaluatedIndexes) {
|
|
1476
|
+
evaluatedIndexes = /* @__PURE__ */ new Set([
|
|
1477
|
+
...evaluatedIndexes,
|
|
1478
|
+
...result.evaluatedIndexes
|
|
1479
|
+
]);
|
|
1480
|
+
}
|
|
1481
|
+
if (result.evaluatedProperties) {
|
|
1482
|
+
evaluatedProperties = /* @__PURE__ */ new Set([
|
|
1483
|
+
...evaluatedProperties,
|
|
1484
|
+
...result.evaluatedProperties
|
|
1485
|
+
]);
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
UNSUPPORTED_SCHEMA_KEYWORDS.forEach((keyword) => {
|
|
1489
|
+
if (schema[keyword] !== void 0) {
|
|
1490
|
+
throw new import_js_format11.InvalidArgumentError(
|
|
1491
|
+
"Schema keyword %v is not supported.",
|
|
1492
|
+
keyword
|
|
1493
|
+
);
|
|
1494
|
+
}
|
|
1495
|
+
});
|
|
1496
|
+
if (options.accessMode === OAAccessMode.WRITE && schema.readOnly === true && data !== void 0) {
|
|
1497
|
+
return {
|
|
1498
|
+
isValid: false,
|
|
1499
|
+
value: data,
|
|
1500
|
+
valueUri: options.dataSourceUri,
|
|
1501
|
+
schemaUri: options.schemaSourceUri,
|
|
1502
|
+
reason: (0, import_js_format11.format)(
|
|
1503
|
+
"Value at %v is read-only and cannot be sent in a write context.",
|
|
1504
|
+
options.dataSourceUri
|
|
1505
|
+
)
|
|
1506
|
+
};
|
|
1507
|
+
}
|
|
1508
|
+
if (options.accessMode === OAAccessMode.READ && schema.writeOnly === true && data !== void 0) {
|
|
1509
|
+
return {
|
|
1510
|
+
isValid: false,
|
|
1511
|
+
value: data,
|
|
1512
|
+
valueUri: options.dataSourceUri,
|
|
1513
|
+
schemaUri: options.schemaSourceUri,
|
|
1514
|
+
reason: (0, import_js_format11.format)(
|
|
1515
|
+
"Value at %v is write-only and cannot be present in a read context.",
|
|
1516
|
+
options.dataSourceUri
|
|
1517
|
+
)
|
|
1518
|
+
};
|
|
1519
|
+
}
|
|
1520
|
+
if (schema.allOf && Array.isArray(schema.allOf)) {
|
|
1521
|
+
for (const index in schema.allOf) {
|
|
1522
|
+
const subSchema = schema.allOf[index];
|
|
1523
|
+
const result = _validate(data, subSchema, {
|
|
1524
|
+
...options,
|
|
1525
|
+
schemaSourceUri: options.schemaSourceUri + "/allOf/" + index
|
|
1526
|
+
});
|
|
1527
|
+
if (!result.isValid) {
|
|
1528
|
+
return result;
|
|
1529
|
+
}
|
|
1530
|
+
data = result.value;
|
|
1531
|
+
if (result.evaluatedIndexes) {
|
|
1532
|
+
evaluatedIndexes = /* @__PURE__ */ new Set([
|
|
1533
|
+
...evaluatedIndexes,
|
|
1534
|
+
...result.evaluatedIndexes
|
|
1535
|
+
]);
|
|
1536
|
+
}
|
|
1537
|
+
if (result.evaluatedProperties) {
|
|
1538
|
+
evaluatedProperties = /* @__PURE__ */ new Set([
|
|
1539
|
+
...evaluatedProperties,
|
|
1540
|
+
...result.evaluatedProperties
|
|
1541
|
+
]);
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
if (schema.oneOf && Array.isArray(schema.oneOf)) {
|
|
1546
|
+
let matches = 0;
|
|
1547
|
+
let matchedResultValue = data;
|
|
1548
|
+
let matchedEvaluatedIndexes = void 0;
|
|
1549
|
+
let matchedEvaluatedProperties = void 0;
|
|
1550
|
+
for (const index in schema.oneOf) {
|
|
1551
|
+
const subSchema = schema.oneOf[index];
|
|
1552
|
+
const result = _validate(data, subSchema, {
|
|
1553
|
+
...options,
|
|
1554
|
+
schemaSourceUri: options.schemaSourceUri + "/oneOf/" + index
|
|
1555
|
+
});
|
|
1556
|
+
if (result.isValid) {
|
|
1557
|
+
matches++;
|
|
1558
|
+
matchedResultValue = result.value;
|
|
1559
|
+
matchedEvaluatedIndexes = result.evaluatedIndexes;
|
|
1560
|
+
matchedEvaluatedProperties = result.evaluatedProperties;
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
if (matches !== 1) {
|
|
1564
|
+
const schemaUri = options.schemaSourceUri + "/oneOf";
|
|
1565
|
+
return {
|
|
1566
|
+
isValid: false,
|
|
1567
|
+
value: data,
|
|
1568
|
+
valueUri: options.dataSourceUri,
|
|
1569
|
+
schemaUri,
|
|
1570
|
+
reason: (0, import_js_format11.format)(
|
|
1571
|
+
"Value at %v must match exactly one of schemas at %v, but %d matched.",
|
|
1572
|
+
options.dataSourceUri,
|
|
1573
|
+
schemaUri,
|
|
1574
|
+
matches
|
|
1575
|
+
)
|
|
1576
|
+
};
|
|
1577
|
+
}
|
|
1578
|
+
data = matchedResultValue;
|
|
1579
|
+
if (matchedEvaluatedIndexes) {
|
|
1580
|
+
evaluatedIndexes = /* @__PURE__ */ new Set([
|
|
1581
|
+
...evaluatedIndexes,
|
|
1582
|
+
...matchedEvaluatedIndexes
|
|
1583
|
+
]);
|
|
1584
|
+
}
|
|
1585
|
+
if (matchedEvaluatedProperties) {
|
|
1586
|
+
evaluatedProperties = /* @__PURE__ */ new Set([
|
|
1587
|
+
...evaluatedProperties,
|
|
1588
|
+
...matchedEvaluatedProperties
|
|
1589
|
+
]);
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
if (schema.anyOf && Array.isArray(schema.anyOf)) {
|
|
1593
|
+
let matchFound = false;
|
|
1594
|
+
for (const index in schema.anyOf) {
|
|
1595
|
+
const subSchema = schema.anyOf[index];
|
|
1596
|
+
const result = _validate(data, subSchema, {
|
|
1597
|
+
...options,
|
|
1598
|
+
schemaSourceUri: options.schemaSourceUri + "/anyOf/" + index
|
|
1599
|
+
});
|
|
1600
|
+
if (result.isValid) {
|
|
1601
|
+
if (!matchFound) {
|
|
1602
|
+
data = result.value;
|
|
1603
|
+
}
|
|
1604
|
+
if (result.evaluatedIndexes) {
|
|
1605
|
+
evaluatedIndexes = /* @__PURE__ */ new Set([
|
|
1606
|
+
...evaluatedIndexes,
|
|
1607
|
+
...result.evaluatedIndexes
|
|
1608
|
+
]);
|
|
1609
|
+
}
|
|
1610
|
+
if (result.evaluatedProperties) {
|
|
1611
|
+
evaluatedProperties = /* @__PURE__ */ new Set([
|
|
1612
|
+
...evaluatedProperties,
|
|
1613
|
+
...result.evaluatedProperties
|
|
1614
|
+
]);
|
|
1615
|
+
}
|
|
1616
|
+
matchFound = true;
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
if (!matchFound) {
|
|
1620
|
+
const schemaUri = options.schemaSourceUri + "/anyOf";
|
|
1621
|
+
return {
|
|
1622
|
+
isValid: false,
|
|
1623
|
+
value: data,
|
|
1624
|
+
valueUri: options.dataSourceUri,
|
|
1625
|
+
schemaUri,
|
|
1626
|
+
reason: (0, import_js_format11.format)(
|
|
1627
|
+
"Value at %v must match at least one of schemas at %v, but 0 matched.",
|
|
1628
|
+
options.dataSourceUri,
|
|
1629
|
+
schemaUri
|
|
1630
|
+
)
|
|
1631
|
+
};
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
if (schema.not) {
|
|
1635
|
+
const { isValid } = _validate(data, schema.not, {
|
|
1636
|
+
...options,
|
|
1637
|
+
schemaSourceUri: options.schemaSourceUri + "/not"
|
|
1638
|
+
});
|
|
1639
|
+
if (isValid) {
|
|
1640
|
+
return {
|
|
1641
|
+
isValid: false,
|
|
1642
|
+
value: data,
|
|
1643
|
+
valueUri: options.dataSourceUri,
|
|
1644
|
+
schemaUri: options.schemaSourceUri + "/not",
|
|
1645
|
+
reason: (0, import_js_format11.format)(
|
|
1646
|
+
'Value at %v must not match the "not" schema.',
|
|
1647
|
+
options.dataSourceUri
|
|
1648
|
+
)
|
|
1649
|
+
};
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
if (schema.if) {
|
|
1653
|
+
const ifResult = _validate(data, schema.if, {
|
|
1654
|
+
...options,
|
|
1655
|
+
schemaSourceUri: options.schemaSourceUri + "/if"
|
|
1656
|
+
});
|
|
1657
|
+
if (ifResult.isValid) {
|
|
1658
|
+
data = ifResult.value;
|
|
1659
|
+
if (ifResult.evaluatedIndexes) {
|
|
1660
|
+
evaluatedIndexes = /* @__PURE__ */ new Set([
|
|
1661
|
+
...evaluatedIndexes,
|
|
1662
|
+
...ifResult.evaluatedIndexes
|
|
1663
|
+
]);
|
|
1664
|
+
}
|
|
1665
|
+
if (ifResult.evaluatedProperties) {
|
|
1666
|
+
evaluatedProperties = /* @__PURE__ */ new Set([
|
|
1667
|
+
...evaluatedProperties,
|
|
1668
|
+
...ifResult.evaluatedProperties
|
|
1669
|
+
]);
|
|
1670
|
+
}
|
|
1671
|
+
if (schema.then) {
|
|
1672
|
+
const result = _validate(data, schema.then, {
|
|
1673
|
+
...options,
|
|
1674
|
+
schemaSourceUri: options.schemaSourceUri + "/then"
|
|
1675
|
+
});
|
|
1676
|
+
if (!result.isValid) {
|
|
1677
|
+
return result;
|
|
1678
|
+
}
|
|
1679
|
+
data = result.value;
|
|
1680
|
+
if (result.evaluatedIndexes) {
|
|
1681
|
+
evaluatedIndexes = /* @__PURE__ */ new Set([
|
|
1682
|
+
...evaluatedIndexes,
|
|
1683
|
+
...result.evaluatedIndexes
|
|
1684
|
+
]);
|
|
1685
|
+
}
|
|
1686
|
+
if (result.evaluatedProperties) {
|
|
1687
|
+
evaluatedProperties = /* @__PURE__ */ new Set([
|
|
1688
|
+
...evaluatedProperties,
|
|
1689
|
+
...result.evaluatedProperties
|
|
1690
|
+
]);
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
} else {
|
|
1694
|
+
if (schema.else) {
|
|
1695
|
+
const result = _validate(data, schema.else, {
|
|
1696
|
+
...options,
|
|
1697
|
+
schemaSourceUri: options.schemaSourceUri + "/else"
|
|
1698
|
+
});
|
|
1699
|
+
if (!result.isValid) {
|
|
1700
|
+
return result;
|
|
1701
|
+
}
|
|
1702
|
+
data = result.value;
|
|
1703
|
+
if (result.evaluatedIndexes) {
|
|
1704
|
+
evaluatedIndexes = /* @__PURE__ */ new Set([
|
|
1705
|
+
...evaluatedIndexes,
|
|
1706
|
+
...result.evaluatedIndexes
|
|
1707
|
+
]);
|
|
1708
|
+
}
|
|
1709
|
+
if (result.evaluatedProperties) {
|
|
1710
|
+
evaluatedProperties = /* @__PURE__ */ new Set([
|
|
1711
|
+
...evaluatedProperties,
|
|
1712
|
+
...result.evaluatedProperties
|
|
1713
|
+
]);
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
if (schema.type !== void 0 && data !== void 0) {
|
|
1719
|
+
const result = _validateType(data, schema.type, options);
|
|
1720
|
+
if (!result.isValid) {
|
|
1721
|
+
return result;
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
if (schema.format) {
|
|
1725
|
+
const result = _validateFormat(
|
|
1726
|
+
data,
|
|
1727
|
+
schema.format,
|
|
1728
|
+
{ ...OA_BUILT_IN_DATA_FORMAT_VALIDATOR_MAP, ...options.formatValidators },
|
|
1729
|
+
options
|
|
1730
|
+
);
|
|
1731
|
+
if (!result.isValid) {
|
|
1732
|
+
return result;
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
if (schema.const !== void 0) {
|
|
1736
|
+
if (!_areValuesEqual(schema.const, data)) {
|
|
1737
|
+
return {
|
|
1738
|
+
isValid: false,
|
|
1739
|
+
value: data,
|
|
1740
|
+
valueUri: options.dataSourceUri,
|
|
1741
|
+
schemaUri: options.schemaSourceUri,
|
|
1742
|
+
reason: (0, import_js_format11.format)(
|
|
1743
|
+
"Value at %v must be equal to constant %s, but %s was given.",
|
|
1744
|
+
options.dataSourceUri,
|
|
1745
|
+
toSpacedJson(schema.const, { truncate: 50 }),
|
|
1746
|
+
toSpacedJson(data, { truncate: 50 })
|
|
1747
|
+
)
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
if (schema.enum && Array.isArray(schema.enum)) {
|
|
1752
|
+
const isFoundInEnum = schema.enum.some((el) => _areValuesEqual(el, data));
|
|
1753
|
+
if (!isFoundInEnum) {
|
|
1754
|
+
return {
|
|
1755
|
+
isValid: false,
|
|
1756
|
+
value: data,
|
|
1757
|
+
valueUri: options.dataSourceUri,
|
|
1758
|
+
schemaUri: options.schemaSourceUri,
|
|
1759
|
+
reason: (0, import_js_format11.format)(
|
|
1760
|
+
"Value at %v must be one of %s, but %s was given.",
|
|
1761
|
+
options.dataSourceUri,
|
|
1762
|
+
toSpacedJson(schema.enum, { truncate: 50 }),
|
|
1763
|
+
toSpacedJson(data, { truncate: 50 })
|
|
1764
|
+
)
|
|
1765
|
+
};
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
const currentType = inferOpenApiDataType(data, true);
|
|
1769
|
+
if (currentType === OADataType.STRING) {
|
|
1770
|
+
const result = _validateString(data, schema, options);
|
|
1771
|
+
if (!result.isValid) {
|
|
1772
|
+
return result;
|
|
1773
|
+
}
|
|
1774
|
+
} else if (currentType === OADataType.NUMBER || currentType === OADataType.INTEGER) {
|
|
1775
|
+
const result = _validateNumber(data, schema, options);
|
|
1776
|
+
if (!result.isValid) {
|
|
1777
|
+
return result;
|
|
1778
|
+
}
|
|
1779
|
+
} else if (currentType === OADataType.ARRAY) {
|
|
1780
|
+
const result = _validateArray(data, schema, evaluatedIndexes, options);
|
|
1781
|
+
if (!result.isValid) {
|
|
1782
|
+
return result;
|
|
1783
|
+
}
|
|
1784
|
+
data = result.value;
|
|
1785
|
+
if (result.evaluatedIndexes) {
|
|
1786
|
+
evaluatedIndexes = /* @__PURE__ */ new Set([
|
|
1787
|
+
...evaluatedIndexes,
|
|
1788
|
+
...result.evaluatedIndexes
|
|
1789
|
+
]);
|
|
1790
|
+
}
|
|
1791
|
+
} else if (currentType === OADataType.OBJECT) {
|
|
1792
|
+
const result = _validateObject(data, schema, evaluatedProperties, options);
|
|
1793
|
+
if (!result.isValid) {
|
|
1794
|
+
return result;
|
|
1795
|
+
}
|
|
1796
|
+
data = result.value;
|
|
1797
|
+
if (result.evaluatedProperties) {
|
|
1798
|
+
evaluatedProperties = /* @__PURE__ */ new Set([
|
|
1799
|
+
...evaluatedProperties,
|
|
1800
|
+
...result.evaluatedProperties
|
|
1801
|
+
]);
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
return {
|
|
1805
|
+
isValid: true,
|
|
1806
|
+
value: data,
|
|
1807
|
+
valueUri: options.dataSourceUri,
|
|
1808
|
+
schemaUri: options.schemaSourceUri,
|
|
1809
|
+
evaluatedIndexes,
|
|
1810
|
+
evaluatedProperties
|
|
1811
|
+
};
|
|
1812
|
+
}
|
|
1813
|
+
__name(_validate, "_validate");
|
|
1814
|
+
function _parseJson(data, expectedType) {
|
|
1815
|
+
if (typeof data !== "string") {
|
|
1816
|
+
return data;
|
|
1817
|
+
}
|
|
1818
|
+
const types = Array.isArray(expectedType) ? expectedType : [expectedType];
|
|
1819
|
+
const trimmedData = data.trim();
|
|
1820
|
+
if (types.includes(OADataType.ARRAY) && trimmedData[0] === "[" || types.includes(OADataType.OBJECT) && trimmedData[0] === "{" || types.includes(OADataType.INTEGER) && JSON_INTEGER_REGEXP.test(trimmedData) || types.includes(OADataType.NUMBER) && JSON_NUMBER_REGEXP.test(trimmedData) || types.includes(OADataType.BOOLEAN) && (trimmedData === "true" || trimmedData === "false") || types.includes(OADataType.NULL) && trimmedData === "null") {
|
|
1821
|
+
try {
|
|
1822
|
+
return JSON.parse(trimmedData);
|
|
1823
|
+
} catch {
|
|
1824
|
+
return data;
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
return data;
|
|
1828
|
+
}
|
|
1829
|
+
__name(_parseJson, "_parseJson");
|
|
1830
|
+
function _coerceType(data, expectedType) {
|
|
1831
|
+
const types = Array.isArray(expectedType) ? expectedType : [expectedType];
|
|
1832
|
+
const actualType = inferOpenApiDataType(data, true);
|
|
1833
|
+
if (types.includes(actualType)) {
|
|
1834
|
+
return data;
|
|
1835
|
+
}
|
|
1836
|
+
if (actualType === OADataType.INTEGER && types.includes(OADataType.NUMBER)) {
|
|
1837
|
+
return data;
|
|
1838
|
+
}
|
|
1839
|
+
for (const type of types) {
|
|
1840
|
+
switch (type) {
|
|
1841
|
+
case OADataType.STRING: {
|
|
1842
|
+
if (typeof data === "number" || typeof data === "boolean") {
|
|
1843
|
+
return String(data);
|
|
1844
|
+
}
|
|
1845
|
+
break;
|
|
1846
|
+
}
|
|
1847
|
+
case OADataType.NUMBER:
|
|
1848
|
+
case OADataType.INTEGER: {
|
|
1849
|
+
if (typeof data === "string" && data.trim() !== "") {
|
|
1850
|
+
const num = Number(data);
|
|
1851
|
+
if (!Number.isNaN(num)) {
|
|
1852
|
+
if (type === OADataType.INTEGER && Number.isInteger(num)) {
|
|
1853
|
+
return num;
|
|
1854
|
+
}
|
|
1855
|
+
if (type === OADataType.NUMBER) {
|
|
1856
|
+
return num;
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
break;
|
|
1861
|
+
}
|
|
1862
|
+
case OADataType.BOOLEAN: {
|
|
1863
|
+
if (data === "true") {
|
|
1864
|
+
return true;
|
|
1865
|
+
}
|
|
1866
|
+
if (data === "false") {
|
|
1867
|
+
return false;
|
|
1868
|
+
}
|
|
1869
|
+
break;
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
return data;
|
|
1874
|
+
}
|
|
1875
|
+
__name(_coerceType, "_coerceType");
|
|
1876
|
+
function _validateType(data, expectedType, options) {
|
|
1877
|
+
const allowedTypes = [expectedType].flat();
|
|
1878
|
+
const actualType = inferOpenApiDataType(data, true);
|
|
1879
|
+
const isMatch = allowedTypes.some((allowedType) => {
|
|
1880
|
+
if (allowedType === actualType) {
|
|
1881
|
+
return true;
|
|
1882
|
+
}
|
|
1883
|
+
if (allowedType === OADataType.NUMBER && actualType === OADataType.INTEGER) {
|
|
1884
|
+
return true;
|
|
1885
|
+
}
|
|
1886
|
+
return false;
|
|
1887
|
+
});
|
|
1888
|
+
if (allowedTypes.length && !isMatch) {
|
|
1889
|
+
return {
|
|
1890
|
+
isValid: false,
|
|
1891
|
+
value: data,
|
|
1892
|
+
valueUri: options.dataSourceUri,
|
|
1893
|
+
schemaUri: options.schemaSourceUri,
|
|
1894
|
+
reason: (0, import_js_format11.format)(
|
|
1895
|
+
"Value at %v must be %s, but %s was given.",
|
|
1896
|
+
options.dataSourceUri,
|
|
1897
|
+
allowedTypes.map((v) => toPascalCase(v)).join(" or "),
|
|
1898
|
+
toPascalCase(actualType)
|
|
1899
|
+
)
|
|
1900
|
+
};
|
|
1901
|
+
}
|
|
1902
|
+
return {
|
|
1903
|
+
isValid: true,
|
|
1904
|
+
value: data,
|
|
1905
|
+
valueUri: options.dataSourceUri,
|
|
1906
|
+
schemaUri: options.schemaSourceUri
|
|
1907
|
+
};
|
|
1908
|
+
}
|
|
1909
|
+
__name(_validateType, "_validateType");
|
|
1910
|
+
function _validateFormat(data, expectedFormat, validatorsMap, options) {
|
|
1911
|
+
const validator = validatorsMap[expectedFormat];
|
|
1912
|
+
if (validator) {
|
|
1913
|
+
const isValid = validator(data);
|
|
1914
|
+
if (!isValid) {
|
|
1915
|
+
return {
|
|
1916
|
+
isValid: false,
|
|
1917
|
+
value: data,
|
|
1918
|
+
valueUri: options.dataSourceUri,
|
|
1919
|
+
schemaUri: options.schemaSourceUri,
|
|
1920
|
+
reason: (0, import_js_format11.format)(
|
|
1921
|
+
"Value at %v must match format %v, but %s was given.",
|
|
1922
|
+
options.dataSourceUri,
|
|
1923
|
+
expectedFormat,
|
|
1924
|
+
toSpacedJson(data, { truncate: 50 })
|
|
1925
|
+
)
|
|
1926
|
+
};
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
return {
|
|
1930
|
+
isValid: true,
|
|
1931
|
+
value: data,
|
|
1932
|
+
valueUri: options.dataSourceUri,
|
|
1933
|
+
schemaUri: options.schemaSourceUri
|
|
1934
|
+
};
|
|
1935
|
+
}
|
|
1936
|
+
__name(_validateFormat, "_validateFormat");
|
|
1937
|
+
function _areValuesEqual(a, b) {
|
|
1938
|
+
if (a === b) {
|
|
1939
|
+
return true;
|
|
1940
|
+
}
|
|
1941
|
+
if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) {
|
|
1942
|
+
return false;
|
|
1943
|
+
}
|
|
1944
|
+
if (a instanceof Date && b instanceof Date) {
|
|
1945
|
+
return a.getTime() === b.getTime();
|
|
1946
|
+
}
|
|
1947
|
+
if (a instanceof RegExp && b instanceof RegExp) {
|
|
1948
|
+
return a.toString() === b.toString();
|
|
1949
|
+
}
|
|
1950
|
+
if (Array.isArray(a) !== Array.isArray(b)) {
|
|
1951
|
+
return false;
|
|
1952
|
+
}
|
|
1953
|
+
if (Array.isArray(a)) {
|
|
1954
|
+
if (a.length !== b.length) {
|
|
1955
|
+
return false;
|
|
1956
|
+
}
|
|
1957
|
+
for (let i = 0; i < a.length; i++) {
|
|
1958
|
+
if (!_areValuesEqual(a[i], b[i])) {
|
|
1959
|
+
return false;
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
return true;
|
|
1963
|
+
}
|
|
1964
|
+
const keysA = Object.keys(a);
|
|
1965
|
+
const keysB = Object.keys(b);
|
|
1966
|
+
if (keysA.length !== keysB.length) {
|
|
1967
|
+
return false;
|
|
1968
|
+
}
|
|
1969
|
+
for (const key of keysA) {
|
|
1970
|
+
if (!Object.prototype.hasOwnProperty.call(b, key)) {
|
|
1971
|
+
return false;
|
|
1972
|
+
}
|
|
1973
|
+
if (!_areValuesEqual(a[key], b[key])) {
|
|
1974
|
+
return false;
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
return true;
|
|
1978
|
+
}
|
|
1979
|
+
__name(_areValuesEqual, "_areValuesEqual");
|
|
1980
|
+
function _validateString(data, schema, options) {
|
|
1981
|
+
if (typeof schema.minLength === "number") {
|
|
1982
|
+
const dataLength = countUnicode(data);
|
|
1983
|
+
if (dataLength < schema.minLength) {
|
|
1984
|
+
return {
|
|
1985
|
+
isValid: false,
|
|
1986
|
+
value: data,
|
|
1987
|
+
valueUri: options.dataSourceUri,
|
|
1988
|
+
schemaUri: options.schemaSourceUri,
|
|
1989
|
+
reason: (0, import_js_format11.format)(
|
|
1990
|
+
"String at %v must be at least %d characters long, but %d was given.",
|
|
1991
|
+
options.dataSourceUri,
|
|
1992
|
+
schema.minLength,
|
|
1993
|
+
dataLength
|
|
1994
|
+
)
|
|
1995
|
+
};
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
if (typeof schema.maxLength === "number") {
|
|
1999
|
+
const dataLength = countUnicode(data);
|
|
2000
|
+
if (dataLength > schema.maxLength) {
|
|
2001
|
+
return {
|
|
2002
|
+
isValid: false,
|
|
2003
|
+
value: data,
|
|
2004
|
+
valueUri: options.dataSourceUri,
|
|
2005
|
+
schemaUri: options.schemaSourceUri,
|
|
2006
|
+
reason: (0, import_js_format11.format)(
|
|
2007
|
+
"String at %v must be at most %d characters long, but %d was given.",
|
|
2008
|
+
options.dataSourceUri,
|
|
2009
|
+
schema.maxLength,
|
|
2010
|
+
dataLength
|
|
2011
|
+
)
|
|
2012
|
+
};
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
if (schema.pattern) {
|
|
2016
|
+
let regex;
|
|
2017
|
+
try {
|
|
2018
|
+
regex = new RegExp(schema.pattern, "u");
|
|
2019
|
+
} catch {
|
|
2020
|
+
throw new import_js_format11.InvalidArgumentError(
|
|
2021
|
+
"Schema pattern %v at %v has an invalid expression.",
|
|
2022
|
+
schema.pattern,
|
|
2023
|
+
options.schemaSourceUri
|
|
2024
|
+
);
|
|
2025
|
+
}
|
|
2026
|
+
if (!regex.test(data)) {
|
|
2027
|
+
const reString = schema.pattern instanceof RegExp ? String(schema.pattern) : schema.pattern;
|
|
2028
|
+
return {
|
|
2029
|
+
isValid: false,
|
|
2030
|
+
value: data,
|
|
2031
|
+
valueUri: options.dataSourceUri,
|
|
2032
|
+
schemaUri: options.schemaSourceUri,
|
|
2033
|
+
reason: (0, import_js_format11.format)(
|
|
2034
|
+
"String at %v must match pattern %v, but %s was given.",
|
|
2035
|
+
options.dataSourceUri,
|
|
2036
|
+
reString,
|
|
2037
|
+
toSpacedJson(data, { truncate: 50 })
|
|
2038
|
+
)
|
|
2039
|
+
};
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
return {
|
|
2043
|
+
isValid: true,
|
|
2044
|
+
value: data,
|
|
2045
|
+
valueUri: options.dataSourceUri,
|
|
2046
|
+
schemaUri: options.schemaSourceUri
|
|
2047
|
+
};
|
|
2048
|
+
}
|
|
2049
|
+
__name(_validateString, "_validateString");
|
|
2050
|
+
function _validateNumber(data, schema, options) {
|
|
2051
|
+
if (typeof schema.minimum === "number") {
|
|
2052
|
+
if (data < schema.minimum) {
|
|
2053
|
+
return {
|
|
2054
|
+
isValid: false,
|
|
2055
|
+
value: data,
|
|
2056
|
+
valueUri: options.dataSourceUri,
|
|
2057
|
+
schemaUri: options.schemaSourceUri,
|
|
2058
|
+
reason: (0, import_js_format11.format)(
|
|
2059
|
+
"Value at %v must be greater than or equal to %d, but %v was given.",
|
|
2060
|
+
options.dataSourceUri,
|
|
2061
|
+
schema.minimum,
|
|
2062
|
+
data
|
|
2063
|
+
)
|
|
2064
|
+
};
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
if (typeof schema.maximum === "number") {
|
|
2068
|
+
if (data > schema.maximum) {
|
|
2069
|
+
return {
|
|
2070
|
+
isValid: false,
|
|
2071
|
+
value: data,
|
|
2072
|
+
valueUri: options.dataSourceUri,
|
|
2073
|
+
schemaUri: options.schemaSourceUri,
|
|
2074
|
+
reason: (0, import_js_format11.format)(
|
|
2075
|
+
"Value at %v must be less than or equal to %d, but %v was given.",
|
|
2076
|
+
options.dataSourceUri,
|
|
2077
|
+
schema.maximum,
|
|
2078
|
+
data
|
|
2079
|
+
)
|
|
2080
|
+
};
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
if (typeof schema.exclusiveMinimum === "number") {
|
|
2084
|
+
if (data <= schema.exclusiveMinimum) {
|
|
2085
|
+
return {
|
|
2086
|
+
isValid: false,
|
|
2087
|
+
value: data,
|
|
2088
|
+
valueUri: options.dataSourceUri,
|
|
2089
|
+
schemaUri: options.schemaSourceUri,
|
|
2090
|
+
reason: (0, import_js_format11.format)(
|
|
2091
|
+
"Value at %v must be greater than %d, but %v was given.",
|
|
2092
|
+
options.dataSourceUri,
|
|
2093
|
+
schema.exclusiveMinimum,
|
|
2094
|
+
data
|
|
2095
|
+
)
|
|
2096
|
+
};
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
if (typeof schema.exclusiveMaximum === "number") {
|
|
2100
|
+
if (data >= schema.exclusiveMaximum) {
|
|
2101
|
+
return {
|
|
2102
|
+
isValid: false,
|
|
2103
|
+
value: data,
|
|
2104
|
+
valueUri: options.dataSourceUri,
|
|
2105
|
+
schemaUri: options.schemaSourceUri,
|
|
2106
|
+
reason: (0, import_js_format11.format)(
|
|
2107
|
+
"Value at %v must be less than %d, but %v was given.",
|
|
2108
|
+
options.dataSourceUri,
|
|
2109
|
+
schema.exclusiveMaximum,
|
|
2110
|
+
data
|
|
2111
|
+
)
|
|
2112
|
+
};
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
if (typeof schema.multipleOf === "number") {
|
|
2116
|
+
if (schema.multipleOf <= 0) {
|
|
2117
|
+
throw new import_js_format11.InvalidArgumentError(
|
|
2118
|
+
'Schema keyword "multipleOf" must be a Number strictly greater than 0, but %v was given.',
|
|
2119
|
+
schema.multipleOf
|
|
2120
|
+
);
|
|
2121
|
+
}
|
|
2122
|
+
const quotient = data / schema.multipleOf;
|
|
2123
|
+
const isInteger = Math.abs(quotient - Math.round(quotient)) < 1e-9;
|
|
2124
|
+
if (!isInteger) {
|
|
2125
|
+
return {
|
|
2126
|
+
isValid: false,
|
|
2127
|
+
value: data,
|
|
2128
|
+
valueUri: options.dataSourceUri,
|
|
2129
|
+
schemaUri: options.schemaSourceUri,
|
|
2130
|
+
reason: (0, import_js_format11.format)(
|
|
2131
|
+
"Value at %v must be a multiple of %v, but %v was given.",
|
|
2132
|
+
options.dataSourceUri,
|
|
2133
|
+
schema.multipleOf,
|
|
2134
|
+
data
|
|
2135
|
+
)
|
|
2136
|
+
};
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
return {
|
|
2140
|
+
isValid: true,
|
|
2141
|
+
value: data,
|
|
2142
|
+
valueUri: options.dataSourceUri,
|
|
2143
|
+
schemaUri: options.schemaSourceUri
|
|
2144
|
+
};
|
|
2145
|
+
}
|
|
2146
|
+
__name(_validateNumber, "_validateNumber");
|
|
2147
|
+
function _validateArray(data, schema, evaluatedIndexes, options) {
|
|
2148
|
+
evaluatedIndexes = new Set(evaluatedIndexes);
|
|
2149
|
+
const originalData = data;
|
|
2150
|
+
let validationStartIndex = 0;
|
|
2151
|
+
if (Array.isArray(schema.prefixItems)) {
|
|
2152
|
+
const loopLimit = Math.min(schema.prefixItems.length, data.length);
|
|
2153
|
+
for (let i = 0; i < loopLimit; i++) {
|
|
2154
|
+
const item = data[i];
|
|
2155
|
+
const subSchema = schema.prefixItems[i];
|
|
2156
|
+
const result = _validate(item, subSchema, {
|
|
2157
|
+
...options,
|
|
2158
|
+
dataSourceUri: `${options.dataSourceUri}/${i}`,
|
|
2159
|
+
schemaSourceUri: `${options.schemaSourceUri}/prefixItems/${i}`
|
|
2160
|
+
});
|
|
2161
|
+
if (!result.isValid) {
|
|
2162
|
+
return result;
|
|
2163
|
+
}
|
|
2164
|
+
if (item !== result.value) {
|
|
2165
|
+
if (data === originalData) {
|
|
2166
|
+
data = [...originalData];
|
|
2167
|
+
}
|
|
2168
|
+
data[i] = result.value;
|
|
2169
|
+
}
|
|
2170
|
+
evaluatedIndexes.add(i);
|
|
2171
|
+
}
|
|
2172
|
+
validationStartIndex = schema.prefixItems.length;
|
|
2173
|
+
}
|
|
2174
|
+
if (schema.items !== void 0) {
|
|
2175
|
+
for (let i = validationStartIndex; i < data.length; i++) {
|
|
2176
|
+
const item = data[i];
|
|
2177
|
+
const result = _validate(item, schema.items, {
|
|
2178
|
+
...options,
|
|
2179
|
+
dataSourceUri: `${options.dataSourceUri}/${i}`,
|
|
2180
|
+
schemaSourceUri: `${options.schemaSourceUri}/items`
|
|
2181
|
+
});
|
|
2182
|
+
if (!result.isValid) {
|
|
2183
|
+
return result;
|
|
2184
|
+
}
|
|
2185
|
+
if (item !== result.value) {
|
|
2186
|
+
if (data === originalData) {
|
|
2187
|
+
data = [...originalData];
|
|
2188
|
+
}
|
|
2189
|
+
data[i] = result.value;
|
|
2190
|
+
}
|
|
2191
|
+
evaluatedIndexes.add(i);
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
if (typeof schema.minItems === "number") {
|
|
2195
|
+
if (data.length < schema.minItems) {
|
|
2196
|
+
return {
|
|
2197
|
+
isValid: false,
|
|
2198
|
+
value: data,
|
|
2199
|
+
valueUri: options.dataSourceUri,
|
|
2200
|
+
schemaUri: options.schemaSourceUri,
|
|
2201
|
+
reason: (0, import_js_format11.format)(
|
|
2202
|
+
"Array at %v must contain at least %d items, but %d was given.",
|
|
2203
|
+
options.dataSourceUri,
|
|
2204
|
+
schema.minItems,
|
|
2205
|
+
data.length
|
|
2206
|
+
)
|
|
2207
|
+
};
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2210
|
+
if (typeof schema.maxItems === "number") {
|
|
2211
|
+
if (data.length > schema.maxItems) {
|
|
2212
|
+
return {
|
|
2213
|
+
isValid: false,
|
|
2214
|
+
value: data,
|
|
2215
|
+
valueUri: options.dataSourceUri,
|
|
2216
|
+
schemaUri: options.schemaSourceUri,
|
|
2217
|
+
reason: (0, import_js_format11.format)(
|
|
2218
|
+
"Array at %v must contain at most %d items, but %d was given.",
|
|
2219
|
+
options.dataSourceUri,
|
|
2220
|
+
schema.maxItems,
|
|
2221
|
+
data.length
|
|
2222
|
+
)
|
|
2223
|
+
};
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
if (schema.uniqueItems === true) {
|
|
2227
|
+
for (let i = 0; i < data.length; i++) {
|
|
2228
|
+
for (let j = i + 1; j < data.length; j++) {
|
|
2229
|
+
if (_areValuesEqual(data[i], data[j])) {
|
|
2230
|
+
return {
|
|
2231
|
+
isValid: false,
|
|
2232
|
+
value: data,
|
|
2233
|
+
valueUri: options.dataSourceUri,
|
|
2234
|
+
schemaUri: options.schemaSourceUri,
|
|
2235
|
+
reason: (0, import_js_format11.format)(
|
|
2236
|
+
"Array at %v must contain unique items, but items at index %d and %d are identical.",
|
|
2237
|
+
options.dataSourceUri,
|
|
2238
|
+
i,
|
|
2239
|
+
j
|
|
2240
|
+
)
|
|
2241
|
+
};
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
if (schema.contains) {
|
|
2247
|
+
let matches = 0;
|
|
2248
|
+
for (let i = 0, l = data.length; i < l; i++) {
|
|
2249
|
+
const item = data[i];
|
|
2250
|
+
const { isValid } = _validate(item, schema.contains, {
|
|
2251
|
+
...options,
|
|
2252
|
+
silent: true,
|
|
2253
|
+
schemaSourceUri: options.schemaSourceUri + "/contains"
|
|
2254
|
+
});
|
|
2255
|
+
if (isValid) {
|
|
2256
|
+
matches++;
|
|
2257
|
+
evaluatedIndexes.add(i);
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
const minContains = typeof schema.minContains === "number" ? schema.minContains : 1;
|
|
2261
|
+
if (matches < minContains) {
|
|
2262
|
+
return {
|
|
2263
|
+
isValid: false,
|
|
2264
|
+
value: data,
|
|
2265
|
+
valueUri: options.dataSourceUri,
|
|
2266
|
+
schemaUri: options.schemaSourceUri + "/contains",
|
|
2267
|
+
reason: (0, import_js_format11.format)(
|
|
2268
|
+
'Array at %v must contain at least %d item(s) matching the "contains" schema, but %d was found.',
|
|
2269
|
+
options.dataSourceUri,
|
|
2270
|
+
minContains,
|
|
2271
|
+
matches
|
|
2272
|
+
)
|
|
2273
|
+
};
|
|
2274
|
+
}
|
|
2275
|
+
if (typeof schema.maxContains === "number") {
|
|
2276
|
+
if (matches > schema.maxContains) {
|
|
2277
|
+
return {
|
|
2278
|
+
isValid: false,
|
|
2279
|
+
value: data,
|
|
2280
|
+
valueUri: options.dataSourceUri,
|
|
2281
|
+
schemaUri: options.schemaSourceUri + "/contains",
|
|
2282
|
+
reason: (0, import_js_format11.format)(
|
|
2283
|
+
'Array at %v must contain at most %d item(s) matching the "contains" schema, but %d was found.',
|
|
2284
|
+
options.dataSourceUri,
|
|
2285
|
+
schema.maxContains,
|
|
2286
|
+
matches
|
|
2287
|
+
)
|
|
2288
|
+
};
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
if (schema.unevaluatedItems !== void 0) {
|
|
2293
|
+
for (let i = 0, l = data.length; i < l; i++) {
|
|
2294
|
+
if (evaluatedIndexes.has(i)) {
|
|
2295
|
+
continue;
|
|
2296
|
+
}
|
|
2297
|
+
const result = _validate(data[i], schema.unevaluatedItems, {
|
|
2298
|
+
...options,
|
|
2299
|
+
dataSourceUri: `${options.dataSourceUri}/${i}`,
|
|
2300
|
+
schemaSourceUri: `${options.schemaSourceUri}/unevaluatedItems`
|
|
2301
|
+
});
|
|
2302
|
+
if (!result.isValid) {
|
|
2303
|
+
if (schema.unevaluatedItems === false) {
|
|
2304
|
+
return {
|
|
2305
|
+
isValid: false,
|
|
2306
|
+
value: data[i],
|
|
2307
|
+
valueUri: `${options.dataSourceUri}/${i}`,
|
|
2308
|
+
schemaUri: `${options.schemaSourceUri}/unevaluatedItems`,
|
|
2309
|
+
reason: (0, import_js_format11.format)(
|
|
2310
|
+
"Array at %v has unevaluated item at index %d, which is not allowed.",
|
|
2311
|
+
options.dataSourceUri,
|
|
2312
|
+
i
|
|
2313
|
+
)
|
|
2314
|
+
};
|
|
2315
|
+
}
|
|
2316
|
+
return result;
|
|
2317
|
+
}
|
|
2318
|
+
if (data[i] !== result.value) {
|
|
2319
|
+
if (data === originalData) {
|
|
2320
|
+
data = [...originalData];
|
|
2321
|
+
}
|
|
2322
|
+
data[i] = result.value;
|
|
2323
|
+
}
|
|
2324
|
+
evaluatedIndexes.add(i);
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
if (options.stripUnknown === true) {
|
|
2328
|
+
if (evaluatedIndexes.size > 0) {
|
|
2329
|
+
for (let i = 0, l = data.length; i < l; i++) {
|
|
2330
|
+
if (evaluatedIndexes.has(i)) {
|
|
2331
|
+
continue;
|
|
2332
|
+
}
|
|
2333
|
+
if (data === originalData) {
|
|
2334
|
+
data = [...originalData];
|
|
2335
|
+
}
|
|
2336
|
+
data.splice(i, 1);
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
return {
|
|
2341
|
+
isValid: true,
|
|
2342
|
+
value: data,
|
|
2343
|
+
valueUri: options.dataSourceUri,
|
|
2344
|
+
schemaUri: options.schemaSourceUri,
|
|
2345
|
+
evaluatedIndexes
|
|
2346
|
+
};
|
|
2347
|
+
}
|
|
2348
|
+
__name(_validateArray, "_validateArray");
|
|
2349
|
+
function _validateObject(data, schema, evaluatedProperties, options) {
|
|
2350
|
+
evaluatedProperties = new Set(evaluatedProperties);
|
|
2351
|
+
const originalData = data;
|
|
2352
|
+
if (typeof schema.maxProperties === "number") {
|
|
2353
|
+
const propsNumber = Object.keys(data).length;
|
|
2354
|
+
if (propsNumber > schema.maxProperties) {
|
|
2355
|
+
return {
|
|
2356
|
+
isValid: false,
|
|
2357
|
+
value: data,
|
|
2358
|
+
valueUri: options.dataSourceUri,
|
|
2359
|
+
schemaUri: options.schemaSourceUri,
|
|
2360
|
+
reason: (0, import_js_format11.format)(
|
|
2361
|
+
"Object at %v must contain at most %d properties, but %d was given.",
|
|
2362
|
+
options.dataSourceUri,
|
|
2363
|
+
schema.maxProperties,
|
|
2364
|
+
propsNumber
|
|
2365
|
+
)
|
|
2366
|
+
};
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
if (typeof schema.minProperties === "number") {
|
|
2370
|
+
const propsNumber = Object.keys(data).length;
|
|
2371
|
+
if (propsNumber < schema.minProperties) {
|
|
2372
|
+
return {
|
|
2373
|
+
isValid: false,
|
|
2374
|
+
value: data,
|
|
2375
|
+
valueUri: options.dataSourceUri,
|
|
2376
|
+
schemaUri: options.schemaSourceUri,
|
|
2377
|
+
reason: (0, import_js_format11.format)(
|
|
2378
|
+
"Object at %v must contain at least %d properties, but %d was given.",
|
|
2379
|
+
options.dataSourceUri,
|
|
2380
|
+
schema.minProperties,
|
|
2381
|
+
propsNumber
|
|
2382
|
+
)
|
|
2383
|
+
};
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
if (Array.isArray(schema.required)) {
|
|
2387
|
+
for (const propName of schema.required) {
|
|
2388
|
+
if (data[propName] === void 0) {
|
|
2389
|
+
if (options.accessMode) {
|
|
2390
|
+
const propSchema = schema.properties !== null && typeof schema.properties === "object" && schema.properties[propName] !== null && typeof schema.properties[propName] === "object" && schema.properties[propName];
|
|
2391
|
+
if (propSchema) {
|
|
2392
|
+
if (options.accessMode === OAAccessMode.WRITE && propSchema.readOnly === true || options.accessMode === OAAccessMode.READ && propSchema.writeOnly === true) {
|
|
2393
|
+
continue;
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
const propValue = data[propName];
|
|
2398
|
+
return {
|
|
2399
|
+
isValid: false,
|
|
2400
|
+
value: propValue,
|
|
2401
|
+
valueUri: `${options.dataSourceUri}/${propName}`,
|
|
2402
|
+
schemaUri: options.schemaSourceUri,
|
|
2403
|
+
reason: (0, import_js_format11.format)(
|
|
2404
|
+
"Property %v at %v is required, but %v was given.",
|
|
2405
|
+
propName,
|
|
2406
|
+
options.dataSourceUri,
|
|
2407
|
+
propValue
|
|
2408
|
+
)
|
|
2409
|
+
};
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
if (schema.dependentRequired && typeof schema.dependentRequired === "object" && !Array.isArray(schema.dependentRequired)) {
|
|
2414
|
+
for (const triggerProp of Object.keys(schema.dependentRequired)) {
|
|
2415
|
+
const requiredProps = schema.dependentRequired[triggerProp];
|
|
2416
|
+
if (data[triggerProp] !== void 0) {
|
|
2417
|
+
if (Array.isArray(requiredProps)) {
|
|
2418
|
+
for (const requiredProp of requiredProps) {
|
|
2419
|
+
if (data[requiredProp] === void 0) {
|
|
2420
|
+
if (options.accessMode) {
|
|
2421
|
+
const requiredPropSchema = schema.properties !== null && typeof schema.properties === "object" && schema.properties[requiredProp] !== null && typeof schema.properties[requiredProp] === "object" && schema.properties[requiredProp];
|
|
2422
|
+
if (requiredPropSchema) {
|
|
2423
|
+
if (options.accessMode === OAAccessMode.WRITE && requiredPropSchema.readOnly === true || options.accessMode === OAAccessMode.READ && requiredPropSchema.writeOnly === true) {
|
|
2424
|
+
continue;
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
return {
|
|
2429
|
+
isValid: false,
|
|
2430
|
+
value: data[requiredProp],
|
|
2431
|
+
valueUri: `${options.dataSourceUri}/${requiredProp}`,
|
|
2432
|
+
schemaUri: options.schemaSourceUri,
|
|
2433
|
+
reason: (0, import_js_format11.format)(
|
|
2434
|
+
"Property %v at %v is required because the property %v is present.",
|
|
2435
|
+
requiredProp,
|
|
2436
|
+
options.dataSourceUri,
|
|
2437
|
+
triggerProp
|
|
2438
|
+
)
|
|
2439
|
+
};
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
}
|
|
2446
|
+
if (schema.dependentSchemas && typeof schema.dependentSchemas === "object" && !Array.isArray(schema.dependentSchemas)) {
|
|
2447
|
+
for (const triggerProp of Object.keys(schema.dependentSchemas)) {
|
|
2448
|
+
const subSchema = schema.dependentSchemas[triggerProp];
|
|
2449
|
+
if (data[triggerProp] !== void 0) {
|
|
2450
|
+
const result = _validate(data, subSchema, {
|
|
2451
|
+
...options,
|
|
2452
|
+
schemaSourceUri: `${options.schemaSourceUri}/dependentSchemas/${triggerProp}`
|
|
2453
|
+
});
|
|
2454
|
+
if (!result.isValid) {
|
|
2455
|
+
return result;
|
|
2456
|
+
}
|
|
2457
|
+
data = result.value;
|
|
2458
|
+
if (result.evaluatedProperties) {
|
|
2459
|
+
evaluatedProperties = /* @__PURE__ */ new Set([
|
|
2460
|
+
...evaluatedProperties,
|
|
2461
|
+
...result.evaluatedProperties
|
|
2462
|
+
]);
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
if (schema.propertyNames && typeof schema.propertyNames === "object" && !Array.isArray(schema.propertyNames)) {
|
|
2468
|
+
for (const propName of Object.keys(data)) {
|
|
2469
|
+
const result = _validate(propName, schema.propertyNames, {
|
|
2470
|
+
...options,
|
|
2471
|
+
dataSourceUri: `${options.dataSourceUri}`,
|
|
2472
|
+
schemaSourceUri: `${options.schemaSourceUri}/propertyNames`
|
|
2473
|
+
});
|
|
2474
|
+
if (!result.isValid) {
|
|
2475
|
+
return result;
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
if (schema.properties && typeof schema.properties === "object") {
|
|
2480
|
+
for (const propName of Object.keys(schema.properties)) {
|
|
2481
|
+
const propSchema = schema.properties[propName];
|
|
2482
|
+
const isPropValuePresent = data[propName] !== void 0;
|
|
2483
|
+
const shouldApplyDefault = options.applyDefaults === true && propSchema !== null && typeof propSchema === "object" && propSchema.default !== void 0;
|
|
2484
|
+
if (isPropValuePresent || shouldApplyDefault) {
|
|
2485
|
+
const propValue = data[propName];
|
|
2486
|
+
const result = _validate(propValue, propSchema, {
|
|
2487
|
+
...options,
|
|
2488
|
+
dataSourceUri: `${options.dataSourceUri}/${propName}`,
|
|
2489
|
+
schemaSourceUri: `${options.schemaSourceUri}/properties/${propName}`
|
|
2490
|
+
});
|
|
2491
|
+
if (!result.isValid) {
|
|
2492
|
+
return result;
|
|
2493
|
+
}
|
|
2494
|
+
if (data[propName] !== result.value) {
|
|
2495
|
+
if (data === originalData) {
|
|
2496
|
+
data = { ...originalData };
|
|
2497
|
+
}
|
|
2498
|
+
data[propName] = result.value;
|
|
2499
|
+
}
|
|
2500
|
+
evaluatedProperties.add(propName);
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
const passedPatternProperties = [];
|
|
2505
|
+
if (schema.patternProperties && typeof schema.patternProperties === "object") {
|
|
2506
|
+
for (const pattern of Object.keys(schema.patternProperties)) {
|
|
2507
|
+
const patternSchema = schema.patternProperties[pattern];
|
|
2508
|
+
let regex;
|
|
2509
|
+
try {
|
|
2510
|
+
regex = new RegExp(pattern, "u");
|
|
2511
|
+
} catch {
|
|
2512
|
+
throw new import_js_format11.InvalidArgumentError(
|
|
2513
|
+
"Property pattern %v at %v has an invalid expression.",
|
|
2514
|
+
pattern,
|
|
2515
|
+
options.schemaSourceUri
|
|
2516
|
+
);
|
|
2517
|
+
}
|
|
2518
|
+
for (const propName of Object.keys(data)) {
|
|
2519
|
+
if (regex.test(propName)) {
|
|
2520
|
+
const propValue = data[propName];
|
|
2521
|
+
const result = _validate(propValue, patternSchema, {
|
|
2522
|
+
...options,
|
|
2523
|
+
dataSourceUri: `${options.dataSourceUri}/${propName}`,
|
|
2524
|
+
schemaSourceUri: `${options.schemaSourceUri}/patternProperties/${pattern}`
|
|
2525
|
+
});
|
|
2526
|
+
if (!result.isValid) {
|
|
2527
|
+
return result;
|
|
2528
|
+
}
|
|
2529
|
+
if (data[propName] !== result.value) {
|
|
2530
|
+
if (data === originalData) {
|
|
2531
|
+
data = { ...originalData };
|
|
2532
|
+
}
|
|
2533
|
+
data[propName] = result.value;
|
|
2534
|
+
}
|
|
2535
|
+
evaluatedProperties.add(propName);
|
|
2536
|
+
passedPatternProperties.push(propName);
|
|
2537
|
+
}
|
|
2538
|
+
}
|
|
2539
|
+
}
|
|
2540
|
+
}
|
|
2541
|
+
if (schema.additionalProperties !== void 0) {
|
|
2542
|
+
const definedProps = schema.properties ? Object.keys(schema.properties) : [];
|
|
2543
|
+
for (const propName of Object.keys(data)) {
|
|
2544
|
+
if (definedProps.includes(propName)) {
|
|
2545
|
+
continue;
|
|
2546
|
+
}
|
|
2547
|
+
if (passedPatternProperties.includes(propName)) {
|
|
2548
|
+
continue;
|
|
2549
|
+
}
|
|
2550
|
+
if (schema.additionalProperties === false) {
|
|
2551
|
+
return {
|
|
2552
|
+
isValid: false,
|
|
2553
|
+
value: data[propName],
|
|
2554
|
+
valueUri: `${options.dataSourceUri}/${propName}`,
|
|
2555
|
+
schemaUri: `${options.schemaSourceUri}/additionalProperties`,
|
|
2556
|
+
reason: (0, import_js_format11.format)(
|
|
2557
|
+
"Property %v at %v is not allowed.",
|
|
2558
|
+
propName,
|
|
2559
|
+
options.dataSourceUri
|
|
2560
|
+
)
|
|
2561
|
+
};
|
|
2562
|
+
}
|
|
2563
|
+
if (schema.additionalProperties !== null && typeof schema.additionalProperties === "object" && !Array.isArray(schema.additionalProperties)) {
|
|
2564
|
+
const propValue = data[propName];
|
|
2565
|
+
const result = _validate(propValue, schema.additionalProperties, {
|
|
2566
|
+
...options,
|
|
2567
|
+
dataSourceUri: `${options.dataSourceUri}/${propName}`,
|
|
2568
|
+
schemaSourceUri: `${options.schemaSourceUri}/additionalProperties`
|
|
2569
|
+
});
|
|
2570
|
+
if (!result.isValid) {
|
|
2571
|
+
return result;
|
|
2572
|
+
}
|
|
2573
|
+
if (data[propName] !== result.value) {
|
|
2574
|
+
if (data === originalData) {
|
|
2575
|
+
data = { ...originalData };
|
|
2576
|
+
}
|
|
2577
|
+
data[propName] = result.value;
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
evaluatedProperties.add(propName);
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
if (schema.unevaluatedProperties !== void 0) {
|
|
2584
|
+
for (const propName of Object.keys(data)) {
|
|
2585
|
+
if (evaluatedProperties.has(propName)) {
|
|
2586
|
+
continue;
|
|
2587
|
+
}
|
|
2588
|
+
if (schema.unevaluatedProperties === false) {
|
|
2589
|
+
return {
|
|
2590
|
+
isValid: false,
|
|
2591
|
+
value: data[propName],
|
|
2592
|
+
valueUri: `${options.dataSourceUri}/${propName}`,
|
|
2593
|
+
schemaUri: `${options.schemaSourceUri}/unevaluatedProperties`,
|
|
2594
|
+
reason: (0, import_js_format11.format)(
|
|
2595
|
+
"Property %v at %v is not evaluated and not allowed.",
|
|
2596
|
+
propName,
|
|
2597
|
+
options.dataSourceUri
|
|
2598
|
+
)
|
|
2599
|
+
};
|
|
2600
|
+
} else if (schema.unevaluatedProperties && typeof schema.unevaluatedProperties === "object" && !Array.isArray(schema.unevaluatedProperties)) {
|
|
2601
|
+
const propValue = data[propName];
|
|
2602
|
+
const result = _validate(propValue, schema.unevaluatedProperties, {
|
|
2603
|
+
...options,
|
|
2604
|
+
dataSourceUri: `${options.dataSourceUri}/${propName}`,
|
|
2605
|
+
schemaSourceUri: `${options.schemaSourceUri}/unevaluatedProperties`
|
|
2606
|
+
});
|
|
2607
|
+
if (!result.isValid) {
|
|
2608
|
+
return result;
|
|
2609
|
+
}
|
|
2610
|
+
if (data[propName] !== result.value) {
|
|
2611
|
+
if (data === originalData) {
|
|
2612
|
+
data = { ...originalData };
|
|
2613
|
+
}
|
|
2614
|
+
data[propName] = result.value;
|
|
2615
|
+
}
|
|
2616
|
+
evaluatedProperties.add(propName);
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
}
|
|
2620
|
+
if (options.stripUnknown === true) {
|
|
2621
|
+
if (evaluatedProperties.size > 0) {
|
|
2622
|
+
for (const propName of Object.keys(data)) {
|
|
2623
|
+
if (evaluatedProperties.has(propName)) {
|
|
2624
|
+
continue;
|
|
2625
|
+
}
|
|
2626
|
+
if (data === originalData) {
|
|
2627
|
+
data = { ...originalData };
|
|
2628
|
+
}
|
|
2629
|
+
delete data[propName];
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
return {
|
|
2634
|
+
isValid: true,
|
|
2635
|
+
value: data,
|
|
2636
|
+
valueUri: options.dataSourceUri,
|
|
2637
|
+
schemaUri: options.schemaSourceUri,
|
|
2638
|
+
evaluatedProperties
|
|
2639
|
+
};
|
|
2640
|
+
}
|
|
2641
|
+
__name(_validateObject, "_validateObject");
|
|
2642
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2643
|
+
0 && (module.exports = {
|
|
2644
|
+
ACCESS_MODE_LIST,
|
|
2645
|
+
JSON_INTEGER_REGEXP,
|
|
2646
|
+
JSON_NUMBER_REGEXP,
|
|
2647
|
+
OAAccessMode,
|
|
2648
|
+
OAApiKeyLocation,
|
|
2649
|
+
OAComponentType,
|
|
2650
|
+
OADataFormat,
|
|
2651
|
+
OADataType,
|
|
2652
|
+
OADataValidationError,
|
|
2653
|
+
OADocumentBuilder,
|
|
2654
|
+
OADocumentScope,
|
|
2655
|
+
OAMediaType,
|
|
2656
|
+
OAOperationMethod,
|
|
2657
|
+
OAParameterLocation,
|
|
2658
|
+
OAParameterStyle,
|
|
2659
|
+
OASecuritySchemeType,
|
|
2660
|
+
OA_BUILT_IN_DATA_FORMAT_VALIDATOR_MAP,
|
|
2661
|
+
OA_COMPONENT_TYPES,
|
|
2662
|
+
OA_COMPONENT_TYPE_TO_COMPONENTS_KEY_MAP,
|
|
2663
|
+
OA_DATA_TYPE_LIST,
|
|
2664
|
+
OPENAPI_VERSION,
|
|
2665
|
+
escapeJsonPointer,
|
|
2666
|
+
inferOpenApiDataType,
|
|
2667
|
+
isOAReferenceObject,
|
|
2668
|
+
oaCallbackRef,
|
|
2669
|
+
oaExampleRef,
|
|
2670
|
+
oaLinkRef,
|
|
2671
|
+
oaParameterRef,
|
|
2672
|
+
oaPathItemRef,
|
|
2673
|
+
oaRequestBodyRef,
|
|
2674
|
+
oaResponseRef,
|
|
2675
|
+
oaSchemaRef,
|
|
2676
|
+
oaSecuritySchemeRef,
|
|
2677
|
+
resolveJsonPointer,
|
|
2678
|
+
resolveOAReferenceObject,
|
|
2679
|
+
unescapeJsonPointer,
|
|
2680
|
+
validateByteFormat,
|
|
2681
|
+
validateDataWithOpenApiSchema,
|
|
2682
|
+
validateDateFormat,
|
|
2683
|
+
validateDateTimeFormat,
|
|
2684
|
+
validateDoubleFormat,
|
|
2685
|
+
validateEmailFormat,
|
|
2686
|
+
validateFloatFormat,
|
|
2687
|
+
validateHostnameFormat,
|
|
2688
|
+
validateInt32Format,
|
|
2689
|
+
validateInt64Format,
|
|
2690
|
+
validateIpv4Format,
|
|
2691
|
+
validateIpv6Format,
|
|
2692
|
+
validateShallowOADocument,
|
|
2693
|
+
validateUriFormat,
|
|
2694
|
+
validateUuidFormat
|
|
2695
|
+
});
|