@schmock/cli 1.8.0 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/index.js +1535 -1494
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -5478,6 +5478,46 @@ Too many redirects:
|
|
|
5478
5478
|
})();
|
|
5479
5479
|
});
|
|
5480
5480
|
|
|
5481
|
+
// ../../node_modules/@apidevtools/swagger-parser/lib/util.js
|
|
5482
|
+
var require_util2 = __commonJS((exports) => {
|
|
5483
|
+
var util = __require("util");
|
|
5484
|
+
exports.format = util.format;
|
|
5485
|
+
exports.inherits = util.inherits;
|
|
5486
|
+
var parse = (u2) => new URL(u2);
|
|
5487
|
+
exports.swaggerParamRegExp = /\{([^/}]+)}/g;
|
|
5488
|
+
var operationsList = ["get", "post", "put", "delete", "patch", "options", "head", "trace"];
|
|
5489
|
+
function fixServers(server, path) {
|
|
5490
|
+
if (server.url && server.url.startsWith("/")) {
|
|
5491
|
+
const inUrl = parse(path);
|
|
5492
|
+
const finalUrl = inUrl.protocol + "//" + inUrl.hostname + server.url;
|
|
5493
|
+
server.url = finalUrl;
|
|
5494
|
+
return server;
|
|
5495
|
+
}
|
|
5496
|
+
}
|
|
5497
|
+
function fixOasRelativeServers(schema, filePath) {
|
|
5498
|
+
if (schema.openapi && filePath && (filePath.startsWith("http:") || filePath.startsWith("https:"))) {
|
|
5499
|
+
if (schema.servers) {
|
|
5500
|
+
schema.servers.map((server) => fixServers(server, filePath));
|
|
5501
|
+
}
|
|
5502
|
+
["paths", "webhooks"].forEach((component) => {
|
|
5503
|
+
Object.keys(schema[component] || []).forEach((path) => {
|
|
5504
|
+
const pathItem = schema[component][path];
|
|
5505
|
+
Object.keys(pathItem).forEach((opItem) => {
|
|
5506
|
+
if (opItem === "servers") {
|
|
5507
|
+
pathItem[opItem].map((server) => fixServers(server, filePath));
|
|
5508
|
+
} else if (operationsList.includes(opItem)) {
|
|
5509
|
+
if (pathItem[opItem].servers) {
|
|
5510
|
+
pathItem[opItem].servers.map((server) => fixServers(server, filePath));
|
|
5511
|
+
}
|
|
5512
|
+
}
|
|
5513
|
+
});
|
|
5514
|
+
});
|
|
5515
|
+
});
|
|
5516
|
+
} else {}
|
|
5517
|
+
}
|
|
5518
|
+
exports.fixOasRelativeServers = fixOasRelativeServers;
|
|
5519
|
+
});
|
|
5520
|
+
|
|
5481
5521
|
// ../../node_modules/ajv/dist/compile/codegen/code.js
|
|
5482
5522
|
var require_code = __commonJS((exports) => {
|
|
5483
5523
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -6489,7 +6529,7 @@ var require_codegen = __commonJS((exports) => {
|
|
|
6489
6529
|
});
|
|
6490
6530
|
|
|
6491
6531
|
// ../../node_modules/ajv/dist/compile/util.js
|
|
6492
|
-
var
|
|
6532
|
+
var require_util3 = __commonJS((exports) => {
|
|
6493
6533
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6494
6534
|
exports.checkStrictMode = exports.getErrorPath = exports.Type = exports.useFunc = exports.setEvaluated = exports.evaluatedPropsToName = exports.mergeEvaluated = exports.eachItem = exports.unescapeJsonPointer = exports.escapeJsonPointer = exports.escapeFragment = exports.unescapeFragment = exports.schemaRefOrVal = exports.schemaHasRulesButRef = exports.schemaHasRules = exports.checkUnknownRules = exports.alwaysValidSchema = exports.toHash = undefined;
|
|
6495
6535
|
var codegen_1 = require_codegen();
|
|
@@ -6682,7 +6722,7 @@ var require_errors = __commonJS((exports) => {
|
|
|
6682
6722
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6683
6723
|
exports.extendErrors = exports.resetErrorsCount = exports.reportExtraError = exports.reportError = exports.keyword$DataError = exports.keywordError = undefined;
|
|
6684
6724
|
var codegen_1 = require_codegen();
|
|
6685
|
-
var util_1 =
|
|
6725
|
+
var util_1 = require_util3();
|
|
6686
6726
|
var names_1 = require_names();
|
|
6687
6727
|
exports.keywordError = {
|
|
6688
6728
|
message: ({ keyword }) => (0, codegen_1.str)`must pass "${keyword}" keyword validation`
|
|
@@ -6899,7 +6939,7 @@ var require_dataType = __commonJS((exports) => {
|
|
|
6899
6939
|
var applicability_1 = require_applicability();
|
|
6900
6940
|
var errors_1 = require_errors();
|
|
6901
6941
|
var codegen_1 = require_codegen();
|
|
6902
|
-
var util_1 =
|
|
6942
|
+
var util_1 = require_util3();
|
|
6903
6943
|
var DataType;
|
|
6904
6944
|
(function(DataType2) {
|
|
6905
6945
|
DataType2[DataType2["Correct"] = 0] = "Correct";
|
|
@@ -7077,7 +7117,7 @@ var require_defaults = __commonJS((exports) => {
|
|
|
7077
7117
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7078
7118
|
exports.assignDefaults = undefined;
|
|
7079
7119
|
var codegen_1 = require_codegen();
|
|
7080
|
-
var util_1 =
|
|
7120
|
+
var util_1 = require_util3();
|
|
7081
7121
|
function assignDefaults(it, ty) {
|
|
7082
7122
|
const { properties, items } = it.schema;
|
|
7083
7123
|
if (ty === "object" && properties) {
|
|
@@ -7111,9 +7151,9 @@ var require_code2 = __commonJS((exports) => {
|
|
|
7111
7151
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7112
7152
|
exports.validateUnion = exports.validateArray = exports.usePattern = exports.callValidateCode = exports.schemaProperties = exports.allSchemaProperties = exports.noPropertyInData = exports.propertyInData = exports.isOwnProperty = exports.hasPropFunc = exports.reportMissingProp = exports.checkMissingProp = exports.checkReportMissingProp = undefined;
|
|
7113
7153
|
var codegen_1 = require_codegen();
|
|
7114
|
-
var util_1 =
|
|
7154
|
+
var util_1 = require_util3();
|
|
7115
7155
|
var names_1 = require_names();
|
|
7116
|
-
var util_2 =
|
|
7156
|
+
var util_2 = require_util3();
|
|
7117
7157
|
function checkReportMissingProp(cxt, prop) {
|
|
7118
7158
|
const { gen, data, it } = cxt;
|
|
7119
7159
|
gen.if(noPropertyInData(gen, data, prop, it.opts.ownProperties), () => {
|
|
@@ -7355,7 +7395,7 @@ var require_subschema = __commonJS((exports) => {
|
|
|
7355
7395
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7356
7396
|
exports.extendSubschemaMode = exports.extendSubschemaData = exports.getSubschema = undefined;
|
|
7357
7397
|
var codegen_1 = require_codegen();
|
|
7358
|
-
var util_1 =
|
|
7398
|
+
var util_1 = require_util3();
|
|
7359
7399
|
function getSubschema(it, { keyword, schemaProp, schema, schemaPath, errSchemaPath, topSchemaRef }) {
|
|
7360
7400
|
if (keyword !== undefined && schema !== undefined) {
|
|
7361
7401
|
throw new Error('both "keyword" and "schema" passed, only one allowed');
|
|
@@ -7559,7 +7599,7 @@ var require_json_schema_traverse = __commonJS((exports, module) => {
|
|
|
7559
7599
|
var require_resolve = __commonJS((exports) => {
|
|
7560
7600
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7561
7601
|
exports.getSchemaRefs = exports.resolveUrl = exports.normalizeId = exports._getFullPath = exports.getFullPath = exports.inlineRef = undefined;
|
|
7562
|
-
var util_1 =
|
|
7602
|
+
var util_1 = require_util3();
|
|
7563
7603
|
var equal = require_fast_deep_equal();
|
|
7564
7604
|
var traverse2 = require_json_schema_traverse();
|
|
7565
7605
|
var SIMPLE_INLINED = new Set([
|
|
@@ -7722,7 +7762,7 @@ var require_validate = __commonJS((exports) => {
|
|
|
7722
7762
|
var codegen_1 = require_codegen();
|
|
7723
7763
|
var names_1 = require_names();
|
|
7724
7764
|
var resolve_1 = require_resolve();
|
|
7725
|
-
var util_1 =
|
|
7765
|
+
var util_1 = require_util3();
|
|
7726
7766
|
var errors_1 = require_errors();
|
|
7727
7767
|
function validateFunctionCode(it) {
|
|
7728
7768
|
if (isSchemaObj(it)) {
|
|
@@ -8250,7 +8290,7 @@ var require_compile = __commonJS((exports) => {
|
|
|
8250
8290
|
var validation_error_1 = require_validation_error();
|
|
8251
8291
|
var names_1 = require_names();
|
|
8252
8292
|
var resolve_1 = require_resolve();
|
|
8253
|
-
var util_1 =
|
|
8293
|
+
var util_1 = require_util3();
|
|
8254
8294
|
var validate_1 = require_validate();
|
|
8255
8295
|
|
|
8256
8296
|
class SchemaEnv {
|
|
@@ -9202,7 +9242,7 @@ var require_core = __commonJS((exports) => {
|
|
|
9202
9242
|
var codegen_2 = require_codegen();
|
|
9203
9243
|
var resolve_1 = require_resolve();
|
|
9204
9244
|
var dataType_1 = require_dataType();
|
|
9205
|
-
var util_1 =
|
|
9245
|
+
var util_1 = require_util3();
|
|
9206
9246
|
var $dataRefSchema = require_data();
|
|
9207
9247
|
var uri_1 = require_uri();
|
|
9208
9248
|
var defaultRegExp = (str, flags) => new RegExp(str, flags);
|
|
@@ -9782,7 +9822,7 @@ var require_ref = __commonJS((exports) => {
|
|
|
9782
9822
|
var codegen_1 = require_codegen();
|
|
9783
9823
|
var names_1 = require_names();
|
|
9784
9824
|
var compile_1 = require_compile();
|
|
9785
|
-
var util_1 =
|
|
9825
|
+
var util_1 = require_util3();
|
|
9786
9826
|
var def = {
|
|
9787
9827
|
keyword: "$ref",
|
|
9788
9828
|
schemaType: "string",
|
|
@@ -9991,7 +10031,7 @@ var require_ucs2length = __commonJS((exports) => {
|
|
|
9991
10031
|
var require_limitLength = __commonJS((exports) => {
|
|
9992
10032
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9993
10033
|
var codegen_1 = require_codegen();
|
|
9994
|
-
var util_1 =
|
|
10034
|
+
var util_1 = require_util3();
|
|
9995
10035
|
var ucs2length_1 = require_ucs2length();
|
|
9996
10036
|
var error = {
|
|
9997
10037
|
message({ keyword, schemaCode }) {
|
|
@@ -10072,7 +10112,7 @@ var require_required = __commonJS((exports) => {
|
|
|
10072
10112
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10073
10113
|
var code_1 = require_code2();
|
|
10074
10114
|
var codegen_1 = require_codegen();
|
|
10075
|
-
var util_1 =
|
|
10115
|
+
var util_1 = require_util3();
|
|
10076
10116
|
var error = {
|
|
10077
10117
|
message: ({ params: { missingProperty } }) => (0, codegen_1.str)`must have required property '${missingProperty}'`,
|
|
10078
10118
|
params: ({ params: { missingProperty } }) => (0, codegen_1._)`{missingProperty: ${missingProperty}}`
|
|
@@ -10185,7 +10225,7 @@ var require_uniqueItems = __commonJS((exports) => {
|
|
|
10185
10225
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10186
10226
|
var dataType_1 = require_dataType();
|
|
10187
10227
|
var codegen_1 = require_codegen();
|
|
10188
|
-
var util_1 =
|
|
10228
|
+
var util_1 = require_util3();
|
|
10189
10229
|
var equal_1 = require_equal();
|
|
10190
10230
|
var error = {
|
|
10191
10231
|
message: ({ params: { i: i2, j: j3 } }) => (0, codegen_1.str)`must NOT have duplicate items (items ## ${j3} and ${i2} are identical)`,
|
|
@@ -10248,7 +10288,7 @@ var require_uniqueItems = __commonJS((exports) => {
|
|
|
10248
10288
|
var require_const = __commonJS((exports) => {
|
|
10249
10289
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10250
10290
|
var codegen_1 = require_codegen();
|
|
10251
|
-
var util_1 =
|
|
10291
|
+
var util_1 = require_util3();
|
|
10252
10292
|
var equal_1 = require_equal();
|
|
10253
10293
|
var error = {
|
|
10254
10294
|
message: "must be equal to constant",
|
|
@@ -10274,7 +10314,7 @@ var require_const = __commonJS((exports) => {
|
|
|
10274
10314
|
var require_enum = __commonJS((exports) => {
|
|
10275
10315
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10276
10316
|
var codegen_1 = require_codegen();
|
|
10277
|
-
var util_1 =
|
|
10317
|
+
var util_1 = require_util3();
|
|
10278
10318
|
var equal_1 = require_equal();
|
|
10279
10319
|
var error = {
|
|
10280
10320
|
message: "must be equal to one of the allowed values",
|
|
@@ -10351,7 +10391,7 @@ var require_additionalItems = __commonJS((exports) => {
|
|
|
10351
10391
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10352
10392
|
exports.validateAdditionalItems = undefined;
|
|
10353
10393
|
var codegen_1 = require_codegen();
|
|
10354
|
-
var util_1 =
|
|
10394
|
+
var util_1 = require_util3();
|
|
10355
10395
|
var error = {
|
|
10356
10396
|
message: ({ params: { len } }) => (0, codegen_1.str)`must NOT have more than ${len} items`,
|
|
10357
10397
|
params: ({ params: { len } }) => (0, codegen_1._)`{limit: ${len}}`
|
|
@@ -10401,7 +10441,7 @@ var require_items = __commonJS((exports) => {
|
|
|
10401
10441
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10402
10442
|
exports.validateTuple = undefined;
|
|
10403
10443
|
var codegen_1 = require_codegen();
|
|
10404
|
-
var util_1 =
|
|
10444
|
+
var util_1 = require_util3();
|
|
10405
10445
|
var code_1 = require_code2();
|
|
10406
10446
|
var def = {
|
|
10407
10447
|
keyword: "items",
|
|
@@ -10468,7 +10508,7 @@ var require_prefixItems = __commonJS((exports) => {
|
|
|
10468
10508
|
var require_items2020 = __commonJS((exports) => {
|
|
10469
10509
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10470
10510
|
var codegen_1 = require_codegen();
|
|
10471
|
-
var util_1 =
|
|
10511
|
+
var util_1 = require_util3();
|
|
10472
10512
|
var code_1 = require_code2();
|
|
10473
10513
|
var additionalItems_1 = require_additionalItems();
|
|
10474
10514
|
var error = {
|
|
@@ -10500,7 +10540,7 @@ var require_items2020 = __commonJS((exports) => {
|
|
|
10500
10540
|
var require_contains = __commonJS((exports) => {
|
|
10501
10541
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10502
10542
|
var codegen_1 = require_codegen();
|
|
10503
|
-
var util_1 =
|
|
10543
|
+
var util_1 = require_util3();
|
|
10504
10544
|
var error = {
|
|
10505
10545
|
message: ({ params: { min, max } }) => max === undefined ? (0, codegen_1.str)`must contain at least ${min} valid item(s)` : (0, codegen_1.str)`must contain at least ${min} and no more than ${max} valid item(s)`,
|
|
10506
10546
|
params: ({ params: { min, max } }) => max === undefined ? (0, codegen_1._)`{minContains: ${min}}` : (0, codegen_1._)`{minContains: ${min}, maxContains: ${max}}`
|
|
@@ -10592,7 +10632,7 @@ var require_dependencies = __commonJS((exports) => {
|
|
|
10592
10632
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10593
10633
|
exports.validateSchemaDeps = exports.validatePropertyDeps = exports.error = undefined;
|
|
10594
10634
|
var codegen_1 = require_codegen();
|
|
10595
|
-
var util_1 =
|
|
10635
|
+
var util_1 = require_util3();
|
|
10596
10636
|
var code_1 = require_code2();
|
|
10597
10637
|
exports.error = {
|
|
10598
10638
|
message: ({ params: { property, depsCount, deps } }) => {
|
|
@@ -10676,7 +10716,7 @@ var require_dependencies = __commonJS((exports) => {
|
|
|
10676
10716
|
var require_propertyNames = __commonJS((exports) => {
|
|
10677
10717
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10678
10718
|
var codegen_1 = require_codegen();
|
|
10679
|
-
var util_1 =
|
|
10719
|
+
var util_1 = require_util3();
|
|
10680
10720
|
var error = {
|
|
10681
10721
|
message: "property name must be valid",
|
|
10682
10722
|
params: ({ params }) => (0, codegen_1._)`{propertyName: ${params.propertyName}}`
|
|
@@ -10718,7 +10758,7 @@ var require_additionalProperties = __commonJS((exports) => {
|
|
|
10718
10758
|
var code_1 = require_code2();
|
|
10719
10759
|
var codegen_1 = require_codegen();
|
|
10720
10760
|
var names_1 = require_names();
|
|
10721
|
-
var util_1 =
|
|
10761
|
+
var util_1 = require_util3();
|
|
10722
10762
|
var error = {
|
|
10723
10763
|
message: "must NOT have additional properties",
|
|
10724
10764
|
params: ({ params }) => (0, codegen_1._)`{additionalProperty: ${params.additionalProperty}}`
|
|
@@ -10820,7 +10860,7 @@ var require_properties = __commonJS((exports) => {
|
|
|
10820
10860
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10821
10861
|
var validate_1 = require_validate();
|
|
10822
10862
|
var code_1 = require_code2();
|
|
10823
|
-
var util_1 =
|
|
10863
|
+
var util_1 = require_util3();
|
|
10824
10864
|
var additionalProperties_1 = require_additionalProperties();
|
|
10825
10865
|
var def = {
|
|
10826
10866
|
keyword: "properties",
|
|
@@ -10875,8 +10915,8 @@ var require_patternProperties = __commonJS((exports) => {
|
|
|
10875
10915
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10876
10916
|
var code_1 = require_code2();
|
|
10877
10917
|
var codegen_1 = require_codegen();
|
|
10878
|
-
var util_1 =
|
|
10879
|
-
var util_2 =
|
|
10918
|
+
var util_1 = require_util3();
|
|
10919
|
+
var util_2 = require_util3();
|
|
10880
10920
|
var def = {
|
|
10881
10921
|
keyword: "patternProperties",
|
|
10882
10922
|
type: "object",
|
|
@@ -10944,7 +10984,7 @@ var require_patternProperties = __commonJS((exports) => {
|
|
|
10944
10984
|
// ../../node_modules/ajv/dist/vocabularies/applicator/not.js
|
|
10945
10985
|
var require_not = __commonJS((exports) => {
|
|
10946
10986
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10947
|
-
var util_1 =
|
|
10987
|
+
var util_1 = require_util3();
|
|
10948
10988
|
var def = {
|
|
10949
10989
|
keyword: "not",
|
|
10950
10990
|
schemaType: ["object", "boolean"],
|
|
@@ -10987,7 +11027,7 @@ var require_anyOf = __commonJS((exports) => {
|
|
|
10987
11027
|
var require_oneOf = __commonJS((exports) => {
|
|
10988
11028
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10989
11029
|
var codegen_1 = require_codegen();
|
|
10990
|
-
var util_1 =
|
|
11030
|
+
var util_1 = require_util3();
|
|
10991
11031
|
var error = {
|
|
10992
11032
|
message: "must match exactly one schema in oneOf",
|
|
10993
11033
|
params: ({ params }) => (0, codegen_1._)`{passingSchemas: ${params.passing}}`
|
|
@@ -11041,7 +11081,7 @@ var require_oneOf = __commonJS((exports) => {
|
|
|
11041
11081
|
// ../../node_modules/ajv/dist/vocabularies/applicator/allOf.js
|
|
11042
11082
|
var require_allOf = __commonJS((exports) => {
|
|
11043
11083
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11044
|
-
var util_1 =
|
|
11084
|
+
var util_1 = require_util3();
|
|
11045
11085
|
var def = {
|
|
11046
11086
|
keyword: "allOf",
|
|
11047
11087
|
schemaType: "array",
|
|
@@ -11066,7 +11106,7 @@ var require_allOf = __commonJS((exports) => {
|
|
|
11066
11106
|
var require_if = __commonJS((exports) => {
|
|
11067
11107
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11068
11108
|
var codegen_1 = require_codegen();
|
|
11069
|
-
var util_1 =
|
|
11109
|
+
var util_1 = require_util3();
|
|
11070
11110
|
var error = {
|
|
11071
11111
|
message: ({ params }) => (0, codegen_1.str)`must match "${params.ifClause}" schema`,
|
|
11072
11112
|
params: ({ params }) => (0, codegen_1._)`{failingKeyword: ${params.ifClause}}`
|
|
@@ -11131,7 +11171,7 @@ var require_if = __commonJS((exports) => {
|
|
|
11131
11171
|
// ../../node_modules/ajv/dist/vocabularies/applicator/thenElse.js
|
|
11132
11172
|
var require_thenElse = __commonJS((exports) => {
|
|
11133
11173
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11134
|
-
var util_1 =
|
|
11174
|
+
var util_1 = require_util3();
|
|
11135
11175
|
var def = {
|
|
11136
11176
|
keyword: ["then", "else"],
|
|
11137
11177
|
schemaType: ["object", "boolean"],
|
|
@@ -11186,797 +11226,402 @@ var require_applicator = __commonJS((exports) => {
|
|
|
11186
11226
|
exports.default = getApplicator;
|
|
11187
11227
|
});
|
|
11188
11228
|
|
|
11189
|
-
// ../../node_modules/ajv/dist/vocabularies/
|
|
11190
|
-
var
|
|
11229
|
+
// ../../node_modules/ajv/dist/vocabularies/dynamic/dynamicAnchor.js
|
|
11230
|
+
var require_dynamicAnchor = __commonJS((exports) => {
|
|
11191
11231
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11232
|
+
exports.dynamicAnchor = undefined;
|
|
11192
11233
|
var codegen_1 = require_codegen();
|
|
11193
|
-
var
|
|
11194
|
-
|
|
11195
|
-
|
|
11234
|
+
var names_1 = require_names();
|
|
11235
|
+
var compile_1 = require_compile();
|
|
11236
|
+
var ref_1 = require_ref();
|
|
11237
|
+
var def = {
|
|
11238
|
+
keyword: "$dynamicAnchor",
|
|
11239
|
+
schemaType: "string",
|
|
11240
|
+
code: (cxt) => dynamicAnchor(cxt, cxt.schema)
|
|
11196
11241
|
};
|
|
11242
|
+
function dynamicAnchor(cxt, anchor) {
|
|
11243
|
+
const { gen, it } = cxt;
|
|
11244
|
+
it.schemaEnv.root.dynamicAnchors[anchor] = true;
|
|
11245
|
+
const v3 = (0, codegen_1._)`${names_1.default.dynamicAnchors}${(0, codegen_1.getProperty)(anchor)}`;
|
|
11246
|
+
const validate2 = it.errSchemaPath === "#" ? it.validateName : _getValidate(cxt);
|
|
11247
|
+
gen.if((0, codegen_1._)`!${v3}`, () => gen.assign(v3, validate2));
|
|
11248
|
+
}
|
|
11249
|
+
exports.dynamicAnchor = dynamicAnchor;
|
|
11250
|
+
function _getValidate(cxt) {
|
|
11251
|
+
const { schemaEnv, schema, self: self2 } = cxt.it;
|
|
11252
|
+
const { root, baseId, localRefs, meta } = schemaEnv.root;
|
|
11253
|
+
const { schemaId } = self2.opts;
|
|
11254
|
+
const sch = new compile_1.SchemaEnv({ schema, schemaId, root, baseId, localRefs, meta });
|
|
11255
|
+
compile_1.compileSchema.call(self2, sch);
|
|
11256
|
+
return (0, ref_1.getValidate)(cxt, sch);
|
|
11257
|
+
}
|
|
11258
|
+
exports.default = def;
|
|
11259
|
+
});
|
|
11260
|
+
|
|
11261
|
+
// ../../node_modules/ajv/dist/vocabularies/dynamic/dynamicRef.js
|
|
11262
|
+
var require_dynamicRef = __commonJS((exports) => {
|
|
11263
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11264
|
+
exports.dynamicRef = undefined;
|
|
11265
|
+
var codegen_1 = require_codegen();
|
|
11266
|
+
var names_1 = require_names();
|
|
11267
|
+
var ref_1 = require_ref();
|
|
11197
11268
|
var def = {
|
|
11198
|
-
keyword: "
|
|
11199
|
-
type: ["number", "string"],
|
|
11269
|
+
keyword: "$dynamicRef",
|
|
11200
11270
|
schemaType: "string",
|
|
11201
|
-
|
|
11202
|
-
|
|
11203
|
-
|
|
11204
|
-
|
|
11205
|
-
|
|
11206
|
-
|
|
11207
|
-
|
|
11208
|
-
|
|
11209
|
-
|
|
11210
|
-
|
|
11211
|
-
|
|
11212
|
-
|
|
11213
|
-
|
|
11214
|
-
|
|
11215
|
-
|
|
11216
|
-
|
|
11217
|
-
const
|
|
11218
|
-
|
|
11219
|
-
|
|
11220
|
-
|
|
11221
|
-
cxt.fail$data((0, codegen_1.or)(unknownFmt(), invalidFmt()));
|
|
11222
|
-
function unknownFmt() {
|
|
11223
|
-
if (opts.strictSchema === false)
|
|
11224
|
-
return codegen_1.nil;
|
|
11225
|
-
return (0, codegen_1._)`${schemaCode} && !${format}`;
|
|
11226
|
-
}
|
|
11227
|
-
function invalidFmt() {
|
|
11228
|
-
const callFormat = schemaEnv.$async ? (0, codegen_1._)`(${fDef}.async ? await ${format}(${data}) : ${format}(${data}))` : (0, codegen_1._)`${format}(${data})`;
|
|
11229
|
-
const validData = (0, codegen_1._)`(typeof ${format} == "function" ? ${callFormat} : ${format}.test(${data}))`;
|
|
11230
|
-
return (0, codegen_1._)`${format} && ${format} !== true && ${fType} === ${ruleType} && !${validData}`;
|
|
11231
|
-
}
|
|
11232
|
-
}
|
|
11233
|
-
function validateFormat() {
|
|
11234
|
-
const formatDef = self2.formats[schema];
|
|
11235
|
-
if (!formatDef) {
|
|
11236
|
-
unknownFormat();
|
|
11237
|
-
return;
|
|
11238
|
-
}
|
|
11239
|
-
if (formatDef === true)
|
|
11240
|
-
return;
|
|
11241
|
-
const [fmtType, format, fmtRef] = getFormat(formatDef);
|
|
11242
|
-
if (fmtType === ruleType)
|
|
11243
|
-
cxt.pass(validCondition());
|
|
11244
|
-
function unknownFormat() {
|
|
11245
|
-
if (opts.strictSchema === false) {
|
|
11246
|
-
self2.logger.warn(unknownMsg());
|
|
11247
|
-
return;
|
|
11248
|
-
}
|
|
11249
|
-
throw new Error(unknownMsg());
|
|
11250
|
-
function unknownMsg() {
|
|
11251
|
-
return `unknown format "${schema}" ignored in schema at path "${errSchemaPath}"`;
|
|
11252
|
-
}
|
|
11253
|
-
}
|
|
11254
|
-
function getFormat(fmtDef) {
|
|
11255
|
-
const code = fmtDef instanceof RegExp ? (0, codegen_1.regexpCode)(fmtDef) : opts.code.formats ? (0, codegen_1._)`${opts.code.formats}${(0, codegen_1.getProperty)(schema)}` : undefined;
|
|
11256
|
-
const fmt = gen.scopeValue("formats", { key: schema, ref: fmtDef, code });
|
|
11257
|
-
if (typeof fmtDef == "object" && !(fmtDef instanceof RegExp)) {
|
|
11258
|
-
return [fmtDef.type || "string", fmtDef.validate, (0, codegen_1._)`${fmt}.validate`];
|
|
11259
|
-
}
|
|
11260
|
-
return ["string", fmtDef, fmt];
|
|
11261
|
-
}
|
|
11262
|
-
function validCondition() {
|
|
11263
|
-
if (typeof formatDef == "object" && !(formatDef instanceof RegExp) && formatDef.async) {
|
|
11264
|
-
if (!schemaEnv.$async)
|
|
11265
|
-
throw new Error("async format in sync schema");
|
|
11266
|
-
return (0, codegen_1._)`await ${fmtRef}(${data})`;
|
|
11267
|
-
}
|
|
11268
|
-
return typeof format == "function" ? (0, codegen_1._)`${fmtRef}(${data})` : (0, codegen_1._)`${fmtRef}.test(${data})`;
|
|
11269
|
-
}
|
|
11271
|
+
code: (cxt) => dynamicRef(cxt, cxt.schema)
|
|
11272
|
+
};
|
|
11273
|
+
function dynamicRef(cxt, ref) {
|
|
11274
|
+
const { gen, keyword, it } = cxt;
|
|
11275
|
+
if (ref[0] !== "#")
|
|
11276
|
+
throw new Error(`"${keyword}" only supports hash fragment reference`);
|
|
11277
|
+
const anchor = ref.slice(1);
|
|
11278
|
+
if (it.allErrors) {
|
|
11279
|
+
_dynamicRef();
|
|
11280
|
+
} else {
|
|
11281
|
+
const valid = gen.let("valid", false);
|
|
11282
|
+
_dynamicRef(valid);
|
|
11283
|
+
cxt.ok(valid);
|
|
11284
|
+
}
|
|
11285
|
+
function _dynamicRef(valid) {
|
|
11286
|
+
if (it.schemaEnv.root.dynamicAnchors[anchor]) {
|
|
11287
|
+
const v3 = gen.let("_v", (0, codegen_1._)`${names_1.default.dynamicAnchors}${(0, codegen_1.getProperty)(anchor)}`);
|
|
11288
|
+
gen.if(v3, _callRef(v3, valid), _callRef(it.validateName, valid));
|
|
11289
|
+
} else {
|
|
11290
|
+
_callRef(it.validateName, valid)();
|
|
11270
11291
|
}
|
|
11271
11292
|
}
|
|
11272
|
-
|
|
11293
|
+
function _callRef(validate2, valid) {
|
|
11294
|
+
return valid ? () => gen.block(() => {
|
|
11295
|
+
(0, ref_1.callRef)(cxt, validate2);
|
|
11296
|
+
gen.let(valid, true);
|
|
11297
|
+
}) : () => (0, ref_1.callRef)(cxt, validate2);
|
|
11298
|
+
}
|
|
11299
|
+
}
|
|
11300
|
+
exports.dynamicRef = dynamicRef;
|
|
11273
11301
|
exports.default = def;
|
|
11274
11302
|
});
|
|
11275
11303
|
|
|
11276
|
-
// ../../node_modules/ajv/dist/vocabularies/
|
|
11277
|
-
var
|
|
11304
|
+
// ../../node_modules/ajv/dist/vocabularies/dynamic/recursiveAnchor.js
|
|
11305
|
+
var require_recursiveAnchor = __commonJS((exports) => {
|
|
11278
11306
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11279
|
-
var
|
|
11280
|
-
var
|
|
11281
|
-
|
|
11307
|
+
var dynamicAnchor_1 = require_dynamicAnchor();
|
|
11308
|
+
var util_1 = require_util3();
|
|
11309
|
+
var def = {
|
|
11310
|
+
keyword: "$recursiveAnchor",
|
|
11311
|
+
schemaType: "boolean",
|
|
11312
|
+
code(cxt) {
|
|
11313
|
+
if (cxt.schema)
|
|
11314
|
+
(0, dynamicAnchor_1.dynamicAnchor)(cxt, "");
|
|
11315
|
+
else
|
|
11316
|
+
(0, util_1.checkStrictMode)(cxt.it, "$recursiveAnchor: false is ignored");
|
|
11317
|
+
}
|
|
11318
|
+
};
|
|
11319
|
+
exports.default = def;
|
|
11282
11320
|
});
|
|
11283
11321
|
|
|
11284
|
-
// ../../node_modules/ajv/dist/vocabularies/
|
|
11285
|
-
var
|
|
11322
|
+
// ../../node_modules/ajv/dist/vocabularies/dynamic/recursiveRef.js
|
|
11323
|
+
var require_recursiveRef = __commonJS((exports) => {
|
|
11286
11324
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11287
|
-
|
|
11288
|
-
|
|
11289
|
-
"
|
|
11290
|
-
"
|
|
11291
|
-
|
|
11292
|
-
|
|
11293
|
-
|
|
11294
|
-
"writeOnly",
|
|
11295
|
-
"examples"
|
|
11296
|
-
];
|
|
11297
|
-
exports.contentVocabulary = [
|
|
11298
|
-
"contentMediaType",
|
|
11299
|
-
"contentEncoding",
|
|
11300
|
-
"contentSchema"
|
|
11301
|
-
];
|
|
11325
|
+
var dynamicRef_1 = require_dynamicRef();
|
|
11326
|
+
var def = {
|
|
11327
|
+
keyword: "$recursiveRef",
|
|
11328
|
+
schemaType: "string",
|
|
11329
|
+
code: (cxt) => (0, dynamicRef_1.dynamicRef)(cxt, cxt.schema)
|
|
11330
|
+
};
|
|
11331
|
+
exports.default = def;
|
|
11302
11332
|
});
|
|
11303
11333
|
|
|
11304
|
-
// ../../node_modules/ajv/dist/vocabularies/
|
|
11305
|
-
var
|
|
11334
|
+
// ../../node_modules/ajv/dist/vocabularies/dynamic/index.js
|
|
11335
|
+
var require_dynamic = __commonJS((exports) => {
|
|
11306
11336
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11307
|
-
var
|
|
11308
|
-
var
|
|
11309
|
-
var
|
|
11310
|
-
var
|
|
11311
|
-
var
|
|
11312
|
-
|
|
11313
|
-
core_1.default,
|
|
11314
|
-
validation_1.default,
|
|
11315
|
-
(0, applicator_1.default)(),
|
|
11316
|
-
format_1.default,
|
|
11317
|
-
metadata_1.metadataVocabulary,
|
|
11318
|
-
metadata_1.contentVocabulary
|
|
11319
|
-
];
|
|
11320
|
-
exports.default = draft7Vocabularies;
|
|
11337
|
+
var dynamicAnchor_1 = require_dynamicAnchor();
|
|
11338
|
+
var dynamicRef_1 = require_dynamicRef();
|
|
11339
|
+
var recursiveAnchor_1 = require_recursiveAnchor();
|
|
11340
|
+
var recursiveRef_1 = require_recursiveRef();
|
|
11341
|
+
var dynamic = [dynamicAnchor_1.default, dynamicRef_1.default, recursiveAnchor_1.default, recursiveRef_1.default];
|
|
11342
|
+
exports.default = dynamic;
|
|
11321
11343
|
});
|
|
11322
11344
|
|
|
11323
|
-
// ../../node_modules/ajv/dist/vocabularies/
|
|
11324
|
-
var
|
|
11325
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11326
|
-
|
|
11327
|
-
var
|
|
11328
|
-
|
|
11329
|
-
|
|
11330
|
-
|
|
11331
|
-
|
|
11345
|
+
// ../../node_modules/ajv/dist/vocabularies/validation/dependentRequired.js
|
|
11346
|
+
var require_dependentRequired = __commonJS((exports) => {
|
|
11347
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11348
|
+
var dependencies_1 = require_dependencies();
|
|
11349
|
+
var def = {
|
|
11350
|
+
keyword: "dependentRequired",
|
|
11351
|
+
type: "object",
|
|
11352
|
+
schemaType: "object",
|
|
11353
|
+
error: dependencies_1.error,
|
|
11354
|
+
code: (cxt) => (0, dependencies_1.validatePropertyDeps)(cxt)
|
|
11355
|
+
};
|
|
11356
|
+
exports.default = def;
|
|
11332
11357
|
});
|
|
11333
11358
|
|
|
11334
|
-
// ../../node_modules/ajv/dist/vocabularies/
|
|
11335
|
-
var
|
|
11359
|
+
// ../../node_modules/ajv/dist/vocabularies/applicator/dependentSchemas.js
|
|
11360
|
+
var require_dependentSchemas = __commonJS((exports) => {
|
|
11361
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11362
|
+
var dependencies_1 = require_dependencies();
|
|
11363
|
+
var def = {
|
|
11364
|
+
keyword: "dependentSchemas",
|
|
11365
|
+
type: "object",
|
|
11366
|
+
schemaType: "object",
|
|
11367
|
+
code: (cxt) => (0, dependencies_1.validateSchemaDeps)(cxt)
|
|
11368
|
+
};
|
|
11369
|
+
exports.default = def;
|
|
11370
|
+
});
|
|
11371
|
+
|
|
11372
|
+
// ../../node_modules/ajv/dist/vocabularies/validation/limitContains.js
|
|
11373
|
+
var require_limitContains = __commonJS((exports) => {
|
|
11374
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11375
|
+
var util_1 = require_util3();
|
|
11376
|
+
var def = {
|
|
11377
|
+
keyword: ["maxContains", "minContains"],
|
|
11378
|
+
type: "array",
|
|
11379
|
+
schemaType: "number",
|
|
11380
|
+
code({ keyword, parentSchema, it }) {
|
|
11381
|
+
if (parentSchema.contains === undefined) {
|
|
11382
|
+
(0, util_1.checkStrictMode)(it, `"${keyword}" without "contains" is ignored`);
|
|
11383
|
+
}
|
|
11384
|
+
}
|
|
11385
|
+
};
|
|
11386
|
+
exports.default = def;
|
|
11387
|
+
});
|
|
11388
|
+
|
|
11389
|
+
// ../../node_modules/ajv/dist/vocabularies/next.js
|
|
11390
|
+
var require_next = __commonJS((exports) => {
|
|
11391
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11392
|
+
var dependentRequired_1 = require_dependentRequired();
|
|
11393
|
+
var dependentSchemas_1 = require_dependentSchemas();
|
|
11394
|
+
var limitContains_1 = require_limitContains();
|
|
11395
|
+
var next = [dependentRequired_1.default, dependentSchemas_1.default, limitContains_1.default];
|
|
11396
|
+
exports.default = next;
|
|
11397
|
+
});
|
|
11398
|
+
|
|
11399
|
+
// ../../node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedProperties.js
|
|
11400
|
+
var require_unevaluatedProperties = __commonJS((exports) => {
|
|
11336
11401
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11337
11402
|
var codegen_1 = require_codegen();
|
|
11338
|
-
var
|
|
11339
|
-
var
|
|
11340
|
-
var ref_error_1 = require_ref_error();
|
|
11341
|
-
var util_1 = require_util2();
|
|
11403
|
+
var util_1 = require_util3();
|
|
11404
|
+
var names_1 = require_names();
|
|
11342
11405
|
var error = {
|
|
11343
|
-
message:
|
|
11344
|
-
params: ({ params
|
|
11406
|
+
message: "must NOT have unevaluated properties",
|
|
11407
|
+
params: ({ params }) => (0, codegen_1._)`{unevaluatedProperty: ${params.unevaluatedProperty}}`
|
|
11345
11408
|
};
|
|
11346
11409
|
var def = {
|
|
11347
|
-
keyword: "
|
|
11410
|
+
keyword: "unevaluatedProperties",
|
|
11348
11411
|
type: "object",
|
|
11349
|
-
schemaType: "object",
|
|
11412
|
+
schemaType: ["boolean", "object"],
|
|
11413
|
+
trackErrors: true,
|
|
11350
11414
|
error,
|
|
11351
11415
|
code(cxt) {
|
|
11352
|
-
const { gen,
|
|
11353
|
-
|
|
11354
|
-
|
|
11355
|
-
|
|
11416
|
+
const { gen, schema, data, errsCount, it } = cxt;
|
|
11417
|
+
if (!errsCount)
|
|
11418
|
+
throw new Error("ajv implementation error");
|
|
11419
|
+
const { allErrors, props } = it;
|
|
11420
|
+
if (props instanceof codegen_1.Name) {
|
|
11421
|
+
gen.if((0, codegen_1._)`${props} !== true`, () => gen.forIn("key", data, (key) => gen.if(unevaluatedDynamic(props, key), () => unevaluatedPropCode(key))));
|
|
11422
|
+
} else if (props !== true) {
|
|
11423
|
+
gen.forIn("key", data, (key) => props === undefined ? unevaluatedPropCode(key) : gen.if(unevaluatedStatic(props, key), () => unevaluatedPropCode(key)));
|
|
11356
11424
|
}
|
|
11357
|
-
|
|
11358
|
-
|
|
11359
|
-
|
|
11360
|
-
|
|
11361
|
-
|
|
11362
|
-
|
|
11363
|
-
|
|
11364
|
-
|
|
11365
|
-
|
|
11366
|
-
|
|
11367
|
-
|
|
11368
|
-
|
|
11369
|
-
|
|
11370
|
-
|
|
11371
|
-
|
|
11372
|
-
|
|
11373
|
-
|
|
11425
|
+
it.props = true;
|
|
11426
|
+
cxt.ok((0, codegen_1._)`${errsCount} === ${names_1.default.errors}`);
|
|
11427
|
+
function unevaluatedPropCode(key) {
|
|
11428
|
+
if (schema === false) {
|
|
11429
|
+
cxt.setParams({ unevaluatedProperty: key });
|
|
11430
|
+
cxt.error();
|
|
11431
|
+
if (!allErrors)
|
|
11432
|
+
gen.break();
|
|
11433
|
+
return;
|
|
11434
|
+
}
|
|
11435
|
+
if (!(0, util_1.alwaysValidSchema)(it, schema)) {
|
|
11436
|
+
const valid = gen.name("valid");
|
|
11437
|
+
cxt.subschema({
|
|
11438
|
+
keyword: "unevaluatedProperties",
|
|
11439
|
+
dataProp: key,
|
|
11440
|
+
dataPropType: util_1.Type.Str
|
|
11441
|
+
}, valid);
|
|
11442
|
+
if (!allErrors)
|
|
11443
|
+
gen.if((0, codegen_1.not)(valid), () => gen.break());
|
|
11374
11444
|
}
|
|
11375
|
-
gen.else();
|
|
11376
|
-
cxt.error(false, { discrError: types_1.DiscrError.Mapping, tag, tagName });
|
|
11377
|
-
gen.endIf();
|
|
11378
11445
|
}
|
|
11379
|
-
function
|
|
11380
|
-
|
|
11381
|
-
const schCxt = cxt.subschema({ keyword: "oneOf", schemaProp }, _valid);
|
|
11382
|
-
cxt.mergeEvaluated(schCxt, codegen_1.Name);
|
|
11383
|
-
return _valid;
|
|
11446
|
+
function unevaluatedDynamic(evaluatedProps, key) {
|
|
11447
|
+
return (0, codegen_1._)`!${evaluatedProps} || !${evaluatedProps}[${key}]`;
|
|
11384
11448
|
}
|
|
11385
|
-
function
|
|
11386
|
-
|
|
11387
|
-
const
|
|
11388
|
-
|
|
11389
|
-
|
|
11390
|
-
for (let i2 = 0;i2 < oneOf.length; i2++) {
|
|
11391
|
-
let sch = oneOf[i2];
|
|
11392
|
-
if ((sch === null || sch === undefined ? undefined : sch.$ref) && !(0, util_1.schemaHasRulesButRef)(sch, it.self.RULES)) {
|
|
11393
|
-
const ref = sch.$ref;
|
|
11394
|
-
sch = compile_1.resolveRef.call(it.self, it.schemaEnv.root, it.baseId, ref);
|
|
11395
|
-
if (sch instanceof compile_1.SchemaEnv)
|
|
11396
|
-
sch = sch.schema;
|
|
11397
|
-
if (sch === undefined)
|
|
11398
|
-
throw new ref_error_1.default(it.opts.uriResolver, it.baseId, ref);
|
|
11399
|
-
}
|
|
11400
|
-
const propSch = (_a2 = sch === null || sch === undefined ? undefined : sch.properties) === null || _a2 === undefined ? undefined : _a2[tagName];
|
|
11401
|
-
if (typeof propSch != "object") {
|
|
11402
|
-
throw new Error(`discriminator: oneOf subschemas (or referenced schemas) must have "properties/${tagName}"`);
|
|
11403
|
-
}
|
|
11404
|
-
tagRequired = tagRequired && (topRequired || hasRequired(sch));
|
|
11405
|
-
addMappings(propSch, i2);
|
|
11406
|
-
}
|
|
11407
|
-
if (!tagRequired)
|
|
11408
|
-
throw new Error(`discriminator: "${tagName}" must be required`);
|
|
11409
|
-
return oneOfMapping;
|
|
11410
|
-
function hasRequired({ required }) {
|
|
11411
|
-
return Array.isArray(required) && required.includes(tagName);
|
|
11412
|
-
}
|
|
11413
|
-
function addMappings(sch, i2) {
|
|
11414
|
-
if (sch.const) {
|
|
11415
|
-
addMapping(sch.const, i2);
|
|
11416
|
-
} else if (sch.enum) {
|
|
11417
|
-
for (const tagValue of sch.enum) {
|
|
11418
|
-
addMapping(tagValue, i2);
|
|
11419
|
-
}
|
|
11420
|
-
} else {
|
|
11421
|
-
throw new Error(`discriminator: "properties/${tagName}" must have "const" or "enum"`);
|
|
11422
|
-
}
|
|
11423
|
-
}
|
|
11424
|
-
function addMapping(tagValue, i2) {
|
|
11425
|
-
if (typeof tagValue != "string" || tagValue in oneOfMapping) {
|
|
11426
|
-
throw new Error(`discriminator: "${tagName}" values must be unique strings`);
|
|
11427
|
-
}
|
|
11428
|
-
oneOfMapping[tagValue] = i2;
|
|
11449
|
+
function unevaluatedStatic(evaluatedProps, key) {
|
|
11450
|
+
const ps = [];
|
|
11451
|
+
for (const p3 in evaluatedProps) {
|
|
11452
|
+
if (evaluatedProps[p3] === true)
|
|
11453
|
+
ps.push((0, codegen_1._)`${key} !== ${p3}`);
|
|
11429
11454
|
}
|
|
11455
|
+
return (0, codegen_1.and)(...ps);
|
|
11430
11456
|
}
|
|
11431
11457
|
}
|
|
11432
11458
|
};
|
|
11433
11459
|
exports.default = def;
|
|
11434
11460
|
});
|
|
11435
11461
|
|
|
11436
|
-
// ../../node_modules/ajv/dist/
|
|
11437
|
-
var
|
|
11438
|
-
|
|
11439
|
-
|
|
11440
|
-
|
|
11441
|
-
|
|
11442
|
-
|
|
11443
|
-
|
|
11444
|
-
|
|
11445
|
-
|
|
11446
|
-
|
|
11447
|
-
|
|
11448
|
-
|
|
11449
|
-
|
|
11450
|
-
|
|
11451
|
-
}
|
|
11452
|
-
|
|
11453
|
-
|
|
11454
|
-
|
|
11455
|
-
|
|
11456
|
-
|
|
11457
|
-
|
|
11458
|
-
|
|
11459
|
-
|
|
11460
|
-
|
|
11461
|
-
|
|
11462
|
-
|
|
11462
|
+
// ../../node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedItems.js
|
|
11463
|
+
var require_unevaluatedItems = __commonJS((exports) => {
|
|
11464
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11465
|
+
var codegen_1 = require_codegen();
|
|
11466
|
+
var util_1 = require_util3();
|
|
11467
|
+
var error = {
|
|
11468
|
+
message: ({ params: { len } }) => (0, codegen_1.str)`must NOT have more than ${len} items`,
|
|
11469
|
+
params: ({ params: { len } }) => (0, codegen_1._)`{limit: ${len}}`
|
|
11470
|
+
};
|
|
11471
|
+
var def = {
|
|
11472
|
+
keyword: "unevaluatedItems",
|
|
11473
|
+
type: "array",
|
|
11474
|
+
schemaType: ["boolean", "object"],
|
|
11475
|
+
error,
|
|
11476
|
+
code(cxt) {
|
|
11477
|
+
const { gen, schema, data, it } = cxt;
|
|
11478
|
+
const items = it.items || 0;
|
|
11479
|
+
if (items === true)
|
|
11480
|
+
return;
|
|
11481
|
+
const len = gen.const("len", (0, codegen_1._)`${data}.length`);
|
|
11482
|
+
if (schema === false) {
|
|
11483
|
+
cxt.setParams({ len: items });
|
|
11484
|
+
cxt.fail((0, codegen_1._)`${len} > ${items}`);
|
|
11485
|
+
} else if (typeof schema == "object" && !(0, util_1.alwaysValidSchema)(it, schema)) {
|
|
11486
|
+
const valid = gen.var("valid", (0, codegen_1._)`${len} <= ${items}`);
|
|
11487
|
+
gen.if((0, codegen_1.not)(valid), () => validateItems(valid, items));
|
|
11488
|
+
cxt.ok(valid);
|
|
11463
11489
|
}
|
|
11464
|
-
|
|
11465
|
-
|
|
11466
|
-
|
|
11467
|
-
|
|
11468
|
-
|
|
11469
|
-
format: "uri-reference"
|
|
11470
|
-
},
|
|
11471
|
-
$schema: {
|
|
11472
|
-
type: "string",
|
|
11473
|
-
format: "uri"
|
|
11474
|
-
},
|
|
11475
|
-
$ref: {
|
|
11476
|
-
type: "string",
|
|
11477
|
-
format: "uri-reference"
|
|
11478
|
-
},
|
|
11479
|
-
$comment: {
|
|
11480
|
-
type: "string"
|
|
11481
|
-
},
|
|
11482
|
-
title: {
|
|
11483
|
-
type: "string"
|
|
11484
|
-
},
|
|
11485
|
-
description: {
|
|
11486
|
-
type: "string"
|
|
11487
|
-
},
|
|
11488
|
-
default: true,
|
|
11489
|
-
readOnly: {
|
|
11490
|
-
type: "boolean",
|
|
11491
|
-
default: false
|
|
11492
|
-
},
|
|
11493
|
-
examples: {
|
|
11494
|
-
type: "array",
|
|
11495
|
-
items: true
|
|
11496
|
-
},
|
|
11497
|
-
multipleOf: {
|
|
11498
|
-
type: "number",
|
|
11499
|
-
exclusiveMinimum: 0
|
|
11500
|
-
},
|
|
11501
|
-
maximum: {
|
|
11502
|
-
type: "number"
|
|
11503
|
-
},
|
|
11504
|
-
exclusiveMaximum: {
|
|
11505
|
-
type: "number"
|
|
11506
|
-
},
|
|
11507
|
-
minimum: {
|
|
11508
|
-
type: "number"
|
|
11509
|
-
},
|
|
11510
|
-
exclusiveMinimum: {
|
|
11511
|
-
type: "number"
|
|
11512
|
-
},
|
|
11513
|
-
maxLength: { $ref: "#/definitions/nonNegativeInteger" },
|
|
11514
|
-
minLength: { $ref: "#/definitions/nonNegativeIntegerDefault0" },
|
|
11515
|
-
pattern: {
|
|
11516
|
-
type: "string",
|
|
11517
|
-
format: "regex"
|
|
11518
|
-
},
|
|
11519
|
-
additionalItems: { $ref: "#" },
|
|
11520
|
-
items: {
|
|
11521
|
-
anyOf: [{ $ref: "#" }, { $ref: "#/definitions/schemaArray" }],
|
|
11522
|
-
default: true
|
|
11523
|
-
},
|
|
11524
|
-
maxItems: { $ref: "#/definitions/nonNegativeInteger" },
|
|
11525
|
-
minItems: { $ref: "#/definitions/nonNegativeIntegerDefault0" },
|
|
11526
|
-
uniqueItems: {
|
|
11527
|
-
type: "boolean",
|
|
11528
|
-
default: false
|
|
11529
|
-
},
|
|
11530
|
-
contains: { $ref: "#" },
|
|
11531
|
-
maxProperties: { $ref: "#/definitions/nonNegativeInteger" },
|
|
11532
|
-
minProperties: { $ref: "#/definitions/nonNegativeIntegerDefault0" },
|
|
11533
|
-
required: { $ref: "#/definitions/stringArray" },
|
|
11534
|
-
additionalProperties: { $ref: "#" },
|
|
11535
|
-
definitions: {
|
|
11536
|
-
type: "object",
|
|
11537
|
-
additionalProperties: { $ref: "#" },
|
|
11538
|
-
default: {}
|
|
11539
|
-
},
|
|
11540
|
-
properties: {
|
|
11541
|
-
type: "object",
|
|
11542
|
-
additionalProperties: { $ref: "#" },
|
|
11543
|
-
default: {}
|
|
11544
|
-
},
|
|
11545
|
-
patternProperties: {
|
|
11546
|
-
type: "object",
|
|
11547
|
-
additionalProperties: { $ref: "#" },
|
|
11548
|
-
propertyNames: { format: "regex" },
|
|
11549
|
-
default: {}
|
|
11550
|
-
},
|
|
11551
|
-
dependencies: {
|
|
11552
|
-
type: "object",
|
|
11553
|
-
additionalProperties: {
|
|
11554
|
-
anyOf: [{ $ref: "#" }, { $ref: "#/definitions/stringArray" }]
|
|
11555
|
-
}
|
|
11556
|
-
},
|
|
11557
|
-
propertyNames: { $ref: "#" },
|
|
11558
|
-
const: true,
|
|
11559
|
-
enum: {
|
|
11560
|
-
type: "array",
|
|
11561
|
-
items: true,
|
|
11562
|
-
minItems: 1,
|
|
11563
|
-
uniqueItems: true
|
|
11564
|
-
},
|
|
11565
|
-
type: {
|
|
11566
|
-
anyOf: [
|
|
11567
|
-
{ $ref: "#/definitions/simpleTypes" },
|
|
11568
|
-
{
|
|
11569
|
-
type: "array",
|
|
11570
|
-
items: { $ref: "#/definitions/simpleTypes" },
|
|
11571
|
-
minItems: 1,
|
|
11572
|
-
uniqueItems: true
|
|
11573
|
-
}
|
|
11574
|
-
]
|
|
11575
|
-
},
|
|
11576
|
-
format: { type: "string" },
|
|
11577
|
-
contentMediaType: { type: "string" },
|
|
11578
|
-
contentEncoding: { type: "string" },
|
|
11579
|
-
if: { $ref: "#" },
|
|
11580
|
-
then: { $ref: "#" },
|
|
11581
|
-
else: { $ref: "#" },
|
|
11582
|
-
allOf: { $ref: "#/definitions/schemaArray" },
|
|
11583
|
-
anyOf: { $ref: "#/definitions/schemaArray" },
|
|
11584
|
-
oneOf: { $ref: "#/definitions/schemaArray" },
|
|
11585
|
-
not: { $ref: "#" }
|
|
11586
|
-
},
|
|
11587
|
-
default: true
|
|
11588
|
-
};
|
|
11589
|
-
});
|
|
11590
|
-
|
|
11591
|
-
// ../../node_modules/ajv/dist/ajv.js
|
|
11592
|
-
var require_ajv = __commonJS((exports, module) => {
|
|
11593
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11594
|
-
exports.MissingRefError = exports.ValidationError = exports.CodeGen = exports.Name = exports.nil = exports.stringify = exports.str = exports._ = exports.KeywordCxt = exports.Ajv = undefined;
|
|
11595
|
-
var core_1 = require_core();
|
|
11596
|
-
var draft7_1 = require_draft7();
|
|
11597
|
-
var discriminator_1 = require_discriminator();
|
|
11598
|
-
var draft7MetaSchema = require_json_schema_draft_07();
|
|
11599
|
-
var META_SUPPORT_DATA = ["/properties"];
|
|
11600
|
-
var META_SCHEMA_ID = "http://json-schema.org/draft-07/schema";
|
|
11601
|
-
|
|
11602
|
-
class Ajv extends core_1.default {
|
|
11603
|
-
_addVocabularies() {
|
|
11604
|
-
super._addVocabularies();
|
|
11605
|
-
draft7_1.default.forEach((v3) => this.addVocabulary(v3));
|
|
11606
|
-
if (this.opts.discriminator)
|
|
11607
|
-
this.addKeyword(discriminator_1.default);
|
|
11608
|
-
}
|
|
11609
|
-
_addDefaultMetaSchema() {
|
|
11610
|
-
super._addDefaultMetaSchema();
|
|
11611
|
-
if (!this.opts.meta)
|
|
11612
|
-
return;
|
|
11613
|
-
const metaSchema = this.opts.$data ? this.$dataMetaSchema(draft7MetaSchema, META_SUPPORT_DATA) : draft7MetaSchema;
|
|
11614
|
-
this.addMetaSchema(metaSchema, META_SCHEMA_ID, false);
|
|
11615
|
-
this.refs["http://json-schema.org/schema"] = META_SCHEMA_ID;
|
|
11616
|
-
}
|
|
11617
|
-
defaultMeta() {
|
|
11618
|
-
return this.opts.defaultMeta = super.defaultMeta() || (this.getSchema(META_SCHEMA_ID) ? META_SCHEMA_ID : undefined);
|
|
11619
|
-
}
|
|
11620
|
-
}
|
|
11621
|
-
exports.Ajv = Ajv;
|
|
11622
|
-
module.exports = exports = Ajv;
|
|
11623
|
-
module.exports.Ajv = Ajv;
|
|
11624
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11625
|
-
exports.default = Ajv;
|
|
11626
|
-
var validate_1 = require_validate();
|
|
11627
|
-
Object.defineProperty(exports, "KeywordCxt", { enumerable: true, get: function() {
|
|
11628
|
-
return validate_1.KeywordCxt;
|
|
11629
|
-
} });
|
|
11630
|
-
var codegen_1 = require_codegen();
|
|
11631
|
-
Object.defineProperty(exports, "_", { enumerable: true, get: function() {
|
|
11632
|
-
return codegen_1._;
|
|
11633
|
-
} });
|
|
11634
|
-
Object.defineProperty(exports, "str", { enumerable: true, get: function() {
|
|
11635
|
-
return codegen_1.str;
|
|
11636
|
-
} });
|
|
11637
|
-
Object.defineProperty(exports, "stringify", { enumerable: true, get: function() {
|
|
11638
|
-
return codegen_1.stringify;
|
|
11639
|
-
} });
|
|
11640
|
-
Object.defineProperty(exports, "nil", { enumerable: true, get: function() {
|
|
11641
|
-
return codegen_1.nil;
|
|
11642
|
-
} });
|
|
11643
|
-
Object.defineProperty(exports, "Name", { enumerable: true, get: function() {
|
|
11644
|
-
return codegen_1.Name;
|
|
11645
|
-
} });
|
|
11646
|
-
Object.defineProperty(exports, "CodeGen", { enumerable: true, get: function() {
|
|
11647
|
-
return codegen_1.CodeGen;
|
|
11648
|
-
} });
|
|
11649
|
-
var validation_error_1 = require_validation_error();
|
|
11650
|
-
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function() {
|
|
11651
|
-
return validation_error_1.default;
|
|
11652
|
-
} });
|
|
11653
|
-
var ref_error_1 = require_ref_error();
|
|
11654
|
-
Object.defineProperty(exports, "MissingRefError", { enumerable: true, get: function() {
|
|
11655
|
-
return ref_error_1.default;
|
|
11656
|
-
} });
|
|
11657
|
-
});
|
|
11658
|
-
|
|
11659
|
-
// ../../node_modules/@apidevtools/swagger-parser/lib/util.js
|
|
11660
|
-
var require_util3 = __commonJS((exports) => {
|
|
11661
|
-
var util = __require("util");
|
|
11662
|
-
exports.format = util.format;
|
|
11663
|
-
exports.inherits = util.inherits;
|
|
11664
|
-
var parse = (u2) => new URL(u2);
|
|
11665
|
-
exports.swaggerParamRegExp = /\{([^/}]+)}/g;
|
|
11666
|
-
var operationsList = ["get", "post", "put", "delete", "patch", "options", "head", "trace"];
|
|
11667
|
-
function fixServers(server, path) {
|
|
11668
|
-
if (server.url && server.url.startsWith("/")) {
|
|
11669
|
-
const inUrl = parse(path);
|
|
11670
|
-
const finalUrl = inUrl.protocol + "//" + inUrl.hostname + server.url;
|
|
11671
|
-
server.url = finalUrl;
|
|
11672
|
-
return server;
|
|
11673
|
-
}
|
|
11674
|
-
}
|
|
11675
|
-
function fixOasRelativeServers(schema, filePath) {
|
|
11676
|
-
if (schema.openapi && filePath && (filePath.startsWith("http:") || filePath.startsWith("https:"))) {
|
|
11677
|
-
if (schema.servers) {
|
|
11678
|
-
schema.servers.map((server) => fixServers(server, filePath));
|
|
11679
|
-
}
|
|
11680
|
-
["paths", "webhooks"].forEach((component) => {
|
|
11681
|
-
Object.keys(schema[component] || []).forEach((path) => {
|
|
11682
|
-
const pathItem = schema[component][path];
|
|
11683
|
-
Object.keys(pathItem).forEach((opItem) => {
|
|
11684
|
-
if (opItem === "servers") {
|
|
11685
|
-
pathItem[opItem].map((server) => fixServers(server, filePath));
|
|
11686
|
-
} else if (operationsList.includes(opItem)) {
|
|
11687
|
-
if (pathItem[opItem].servers) {
|
|
11688
|
-
pathItem[opItem].servers.map((server) => fixServers(server, filePath));
|
|
11689
|
-
}
|
|
11690
|
-
}
|
|
11691
|
-
});
|
|
11692
|
-
});
|
|
11693
|
-
});
|
|
11694
|
-
} else {}
|
|
11695
|
-
}
|
|
11696
|
-
exports.fixOasRelativeServers = fixOasRelativeServers;
|
|
11697
|
-
});
|
|
11698
|
-
|
|
11699
|
-
// ../../node_modules/ajv/dist/vocabularies/dynamic/dynamicAnchor.js
|
|
11700
|
-
var require_dynamicAnchor = __commonJS((exports) => {
|
|
11701
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11702
|
-
exports.dynamicAnchor = undefined;
|
|
11703
|
-
var codegen_1 = require_codegen();
|
|
11704
|
-
var names_1 = require_names();
|
|
11705
|
-
var compile_1 = require_compile();
|
|
11706
|
-
var ref_1 = require_ref();
|
|
11707
|
-
var def = {
|
|
11708
|
-
keyword: "$dynamicAnchor",
|
|
11709
|
-
schemaType: "string",
|
|
11710
|
-
code: (cxt) => dynamicAnchor(cxt, cxt.schema)
|
|
11711
|
-
};
|
|
11712
|
-
function dynamicAnchor(cxt, anchor) {
|
|
11713
|
-
const { gen, it } = cxt;
|
|
11714
|
-
it.schemaEnv.root.dynamicAnchors[anchor] = true;
|
|
11715
|
-
const v3 = (0, codegen_1._)`${names_1.default.dynamicAnchors}${(0, codegen_1.getProperty)(anchor)}`;
|
|
11716
|
-
const validate2 = it.errSchemaPath === "#" ? it.validateName : _getValidate(cxt);
|
|
11717
|
-
gen.if((0, codegen_1._)`!${v3}`, () => gen.assign(v3, validate2));
|
|
11718
|
-
}
|
|
11719
|
-
exports.dynamicAnchor = dynamicAnchor;
|
|
11720
|
-
function _getValidate(cxt) {
|
|
11721
|
-
const { schemaEnv, schema, self: self2 } = cxt.it;
|
|
11722
|
-
const { root, baseId, localRefs, meta } = schemaEnv.root;
|
|
11723
|
-
const { schemaId } = self2.opts;
|
|
11724
|
-
const sch = new compile_1.SchemaEnv({ schema, schemaId, root, baseId, localRefs, meta });
|
|
11725
|
-
compile_1.compileSchema.call(self2, sch);
|
|
11726
|
-
return (0, ref_1.getValidate)(cxt, sch);
|
|
11727
|
-
}
|
|
11728
|
-
exports.default = def;
|
|
11729
|
-
});
|
|
11730
|
-
|
|
11731
|
-
// ../../node_modules/ajv/dist/vocabularies/dynamic/dynamicRef.js
|
|
11732
|
-
var require_dynamicRef = __commonJS((exports) => {
|
|
11733
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11734
|
-
exports.dynamicRef = undefined;
|
|
11735
|
-
var codegen_1 = require_codegen();
|
|
11736
|
-
var names_1 = require_names();
|
|
11737
|
-
var ref_1 = require_ref();
|
|
11738
|
-
var def = {
|
|
11739
|
-
keyword: "$dynamicRef",
|
|
11740
|
-
schemaType: "string",
|
|
11741
|
-
code: (cxt) => dynamicRef(cxt, cxt.schema)
|
|
11742
|
-
};
|
|
11743
|
-
function dynamicRef(cxt, ref) {
|
|
11744
|
-
const { gen, keyword, it } = cxt;
|
|
11745
|
-
if (ref[0] !== "#")
|
|
11746
|
-
throw new Error(`"${keyword}" only supports hash fragment reference`);
|
|
11747
|
-
const anchor = ref.slice(1);
|
|
11748
|
-
if (it.allErrors) {
|
|
11749
|
-
_dynamicRef();
|
|
11750
|
-
} else {
|
|
11751
|
-
const valid = gen.let("valid", false);
|
|
11752
|
-
_dynamicRef(valid);
|
|
11753
|
-
cxt.ok(valid);
|
|
11754
|
-
}
|
|
11755
|
-
function _dynamicRef(valid) {
|
|
11756
|
-
if (it.schemaEnv.root.dynamicAnchors[anchor]) {
|
|
11757
|
-
const v3 = gen.let("_v", (0, codegen_1._)`${names_1.default.dynamicAnchors}${(0, codegen_1.getProperty)(anchor)}`);
|
|
11758
|
-
gen.if(v3, _callRef(v3, valid), _callRef(it.validateName, valid));
|
|
11759
|
-
} else {
|
|
11760
|
-
_callRef(it.validateName, valid)();
|
|
11761
|
-
}
|
|
11762
|
-
}
|
|
11763
|
-
function _callRef(validate2, valid) {
|
|
11764
|
-
return valid ? () => gen.block(() => {
|
|
11765
|
-
(0, ref_1.callRef)(cxt, validate2);
|
|
11766
|
-
gen.let(valid, true);
|
|
11767
|
-
}) : () => (0, ref_1.callRef)(cxt, validate2);
|
|
11768
|
-
}
|
|
11769
|
-
}
|
|
11770
|
-
exports.dynamicRef = dynamicRef;
|
|
11771
|
-
exports.default = def;
|
|
11772
|
-
});
|
|
11773
|
-
|
|
11774
|
-
// ../../node_modules/ajv/dist/vocabularies/dynamic/recursiveAnchor.js
|
|
11775
|
-
var require_recursiveAnchor = __commonJS((exports) => {
|
|
11776
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11777
|
-
var dynamicAnchor_1 = require_dynamicAnchor();
|
|
11778
|
-
var util_1 = require_util2();
|
|
11779
|
-
var def = {
|
|
11780
|
-
keyword: "$recursiveAnchor",
|
|
11781
|
-
schemaType: "boolean",
|
|
11782
|
-
code(cxt) {
|
|
11783
|
-
if (cxt.schema)
|
|
11784
|
-
(0, dynamicAnchor_1.dynamicAnchor)(cxt, "");
|
|
11785
|
-
else
|
|
11786
|
-
(0, util_1.checkStrictMode)(cxt.it, "$recursiveAnchor: false is ignored");
|
|
11787
|
-
}
|
|
11788
|
-
};
|
|
11789
|
-
exports.default = def;
|
|
11790
|
-
});
|
|
11791
|
-
|
|
11792
|
-
// ../../node_modules/ajv/dist/vocabularies/dynamic/recursiveRef.js
|
|
11793
|
-
var require_recursiveRef = __commonJS((exports) => {
|
|
11794
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11795
|
-
var dynamicRef_1 = require_dynamicRef();
|
|
11796
|
-
var def = {
|
|
11797
|
-
keyword: "$recursiveRef",
|
|
11798
|
-
schemaType: "string",
|
|
11799
|
-
code: (cxt) => (0, dynamicRef_1.dynamicRef)(cxt, cxt.schema)
|
|
11800
|
-
};
|
|
11801
|
-
exports.default = def;
|
|
11802
|
-
});
|
|
11803
|
-
|
|
11804
|
-
// ../../node_modules/ajv/dist/vocabularies/dynamic/index.js
|
|
11805
|
-
var require_dynamic = __commonJS((exports) => {
|
|
11806
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11807
|
-
var dynamicAnchor_1 = require_dynamicAnchor();
|
|
11808
|
-
var dynamicRef_1 = require_dynamicRef();
|
|
11809
|
-
var recursiveAnchor_1 = require_recursiveAnchor();
|
|
11810
|
-
var recursiveRef_1 = require_recursiveRef();
|
|
11811
|
-
var dynamic = [dynamicAnchor_1.default, dynamicRef_1.default, recursiveAnchor_1.default, recursiveRef_1.default];
|
|
11812
|
-
exports.default = dynamic;
|
|
11813
|
-
});
|
|
11814
|
-
|
|
11815
|
-
// ../../node_modules/ajv/dist/vocabularies/validation/dependentRequired.js
|
|
11816
|
-
var require_dependentRequired = __commonJS((exports) => {
|
|
11817
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11818
|
-
var dependencies_1 = require_dependencies();
|
|
11819
|
-
var def = {
|
|
11820
|
-
keyword: "dependentRequired",
|
|
11821
|
-
type: "object",
|
|
11822
|
-
schemaType: "object",
|
|
11823
|
-
error: dependencies_1.error,
|
|
11824
|
-
code: (cxt) => (0, dependencies_1.validatePropertyDeps)(cxt)
|
|
11825
|
-
};
|
|
11826
|
-
exports.default = def;
|
|
11827
|
-
});
|
|
11828
|
-
|
|
11829
|
-
// ../../node_modules/ajv/dist/vocabularies/applicator/dependentSchemas.js
|
|
11830
|
-
var require_dependentSchemas = __commonJS((exports) => {
|
|
11831
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11832
|
-
var dependencies_1 = require_dependencies();
|
|
11833
|
-
var def = {
|
|
11834
|
-
keyword: "dependentSchemas",
|
|
11835
|
-
type: "object",
|
|
11836
|
-
schemaType: "object",
|
|
11837
|
-
code: (cxt) => (0, dependencies_1.validateSchemaDeps)(cxt)
|
|
11838
|
-
};
|
|
11839
|
-
exports.default = def;
|
|
11840
|
-
});
|
|
11841
|
-
|
|
11842
|
-
// ../../node_modules/ajv/dist/vocabularies/validation/limitContains.js
|
|
11843
|
-
var require_limitContains = __commonJS((exports) => {
|
|
11844
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11845
|
-
var util_1 = require_util2();
|
|
11846
|
-
var def = {
|
|
11847
|
-
keyword: ["maxContains", "minContains"],
|
|
11848
|
-
type: "array",
|
|
11849
|
-
schemaType: "number",
|
|
11850
|
-
code({ keyword, parentSchema, it }) {
|
|
11851
|
-
if (parentSchema.contains === undefined) {
|
|
11852
|
-
(0, util_1.checkStrictMode)(it, `"${keyword}" without "contains" is ignored`);
|
|
11853
|
-
}
|
|
11854
|
-
}
|
|
11855
|
-
};
|
|
11856
|
-
exports.default = def;
|
|
11857
|
-
});
|
|
11858
|
-
|
|
11859
|
-
// ../../node_modules/ajv/dist/vocabularies/next.js
|
|
11860
|
-
var require_next = __commonJS((exports) => {
|
|
11861
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11862
|
-
var dependentRequired_1 = require_dependentRequired();
|
|
11863
|
-
var dependentSchemas_1 = require_dependentSchemas();
|
|
11864
|
-
var limitContains_1 = require_limitContains();
|
|
11865
|
-
var next = [dependentRequired_1.default, dependentSchemas_1.default, limitContains_1.default];
|
|
11866
|
-
exports.default = next;
|
|
11867
|
-
});
|
|
11868
|
-
|
|
11869
|
-
// ../../node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedProperties.js
|
|
11870
|
-
var require_unevaluatedProperties = __commonJS((exports) => {
|
|
11871
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11872
|
-
var codegen_1 = require_codegen();
|
|
11873
|
-
var util_1 = require_util2();
|
|
11874
|
-
var names_1 = require_names();
|
|
11875
|
-
var error = {
|
|
11876
|
-
message: "must NOT have unevaluated properties",
|
|
11877
|
-
params: ({ params }) => (0, codegen_1._)`{unevaluatedProperty: ${params.unevaluatedProperty}}`
|
|
11878
|
-
};
|
|
11879
|
-
var def = {
|
|
11880
|
-
keyword: "unevaluatedProperties",
|
|
11881
|
-
type: "object",
|
|
11882
|
-
schemaType: ["boolean", "object"],
|
|
11883
|
-
trackErrors: true,
|
|
11884
|
-
error,
|
|
11885
|
-
code(cxt) {
|
|
11886
|
-
const { gen, schema, data, errsCount, it } = cxt;
|
|
11887
|
-
if (!errsCount)
|
|
11888
|
-
throw new Error("ajv implementation error");
|
|
11889
|
-
const { allErrors, props } = it;
|
|
11890
|
-
if (props instanceof codegen_1.Name) {
|
|
11891
|
-
gen.if((0, codegen_1._)`${props} !== true`, () => gen.forIn("key", data, (key) => gen.if(unevaluatedDynamic(props, key), () => unevaluatedPropCode(key))));
|
|
11892
|
-
} else if (props !== true) {
|
|
11893
|
-
gen.forIn("key", data, (key) => props === undefined ? unevaluatedPropCode(key) : gen.if(unevaluatedStatic(props, key), () => unevaluatedPropCode(key)));
|
|
11894
|
-
}
|
|
11895
|
-
it.props = true;
|
|
11896
|
-
cxt.ok((0, codegen_1._)`${errsCount} === ${names_1.default.errors}`);
|
|
11897
|
-
function unevaluatedPropCode(key) {
|
|
11898
|
-
if (schema === false) {
|
|
11899
|
-
cxt.setParams({ unevaluatedProperty: key });
|
|
11900
|
-
cxt.error();
|
|
11901
|
-
if (!allErrors)
|
|
11902
|
-
gen.break();
|
|
11903
|
-
return;
|
|
11904
|
-
}
|
|
11905
|
-
if (!(0, util_1.alwaysValidSchema)(it, schema)) {
|
|
11906
|
-
const valid = gen.name("valid");
|
|
11907
|
-
cxt.subschema({
|
|
11908
|
-
keyword: "unevaluatedProperties",
|
|
11909
|
-
dataProp: key,
|
|
11910
|
-
dataPropType: util_1.Type.Str
|
|
11911
|
-
}, valid);
|
|
11912
|
-
if (!allErrors)
|
|
11490
|
+
it.items = true;
|
|
11491
|
+
function validateItems(valid, from) {
|
|
11492
|
+
gen.forRange("i", from, len, (i2) => {
|
|
11493
|
+
cxt.subschema({ keyword: "unevaluatedItems", dataProp: i2, dataPropType: util_1.Type.Num }, valid);
|
|
11494
|
+
if (!it.allErrors)
|
|
11913
11495
|
gen.if((0, codegen_1.not)(valid), () => gen.break());
|
|
11914
|
-
}
|
|
11915
|
-
}
|
|
11916
|
-
function unevaluatedDynamic(evaluatedProps, key) {
|
|
11917
|
-
return (0, codegen_1._)`!${evaluatedProps} || !${evaluatedProps}[${key}]`;
|
|
11918
|
-
}
|
|
11919
|
-
function unevaluatedStatic(evaluatedProps, key) {
|
|
11920
|
-
const ps = [];
|
|
11921
|
-
for (const p3 in evaluatedProps) {
|
|
11922
|
-
if (evaluatedProps[p3] === true)
|
|
11923
|
-
ps.push((0, codegen_1._)`${key} !== ${p3}`);
|
|
11924
|
-
}
|
|
11925
|
-
return (0, codegen_1.and)(...ps);
|
|
11496
|
+
});
|
|
11926
11497
|
}
|
|
11927
11498
|
}
|
|
11928
11499
|
};
|
|
11929
11500
|
exports.default = def;
|
|
11930
11501
|
});
|
|
11931
11502
|
|
|
11932
|
-
// ../../node_modules/ajv/dist/vocabularies/unevaluated/
|
|
11933
|
-
var
|
|
11503
|
+
// ../../node_modules/ajv/dist/vocabularies/unevaluated/index.js
|
|
11504
|
+
var require_unevaluated = __commonJS((exports) => {
|
|
11505
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11506
|
+
var unevaluatedProperties_1 = require_unevaluatedProperties();
|
|
11507
|
+
var unevaluatedItems_1 = require_unevaluatedItems();
|
|
11508
|
+
var unevaluated = [unevaluatedProperties_1.default, unevaluatedItems_1.default];
|
|
11509
|
+
exports.default = unevaluated;
|
|
11510
|
+
});
|
|
11511
|
+
|
|
11512
|
+
// ../../node_modules/ajv/dist/vocabularies/format/format.js
|
|
11513
|
+
var require_format = __commonJS((exports) => {
|
|
11934
11514
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11935
11515
|
var codegen_1 = require_codegen();
|
|
11936
|
-
var util_1 = require_util2();
|
|
11937
11516
|
var error = {
|
|
11938
|
-
message: ({
|
|
11939
|
-
params: ({
|
|
11517
|
+
message: ({ schemaCode }) => (0, codegen_1.str)`must match format "${schemaCode}"`,
|
|
11518
|
+
params: ({ schemaCode }) => (0, codegen_1._)`{format: ${schemaCode}}`
|
|
11940
11519
|
};
|
|
11941
11520
|
var def = {
|
|
11942
|
-
keyword: "
|
|
11943
|
-
type: "
|
|
11944
|
-
schemaType:
|
|
11521
|
+
keyword: "format",
|
|
11522
|
+
type: ["number", "string"],
|
|
11523
|
+
schemaType: "string",
|
|
11524
|
+
$data: true,
|
|
11945
11525
|
error,
|
|
11946
|
-
code(cxt) {
|
|
11947
|
-
const { gen,
|
|
11948
|
-
const
|
|
11949
|
-
if (
|
|
11526
|
+
code(cxt, ruleType) {
|
|
11527
|
+
const { gen, data, $data, schema, schemaCode, it } = cxt;
|
|
11528
|
+
const { opts, errSchemaPath, schemaEnv, self: self2 } = it;
|
|
11529
|
+
if (!opts.validateFormats)
|
|
11950
11530
|
return;
|
|
11951
|
-
|
|
11952
|
-
|
|
11953
|
-
|
|
11954
|
-
|
|
11955
|
-
|
|
11956
|
-
const
|
|
11957
|
-
|
|
11958
|
-
|
|
11959
|
-
}
|
|
11960
|
-
it.items = true;
|
|
11961
|
-
function validateItems(valid, from) {
|
|
11962
|
-
gen.forRange("i", from, len, (i2) => {
|
|
11963
|
-
cxt.subschema({ keyword: "unevaluatedItems", dataProp: i2, dataPropType: util_1.Type.Num }, valid);
|
|
11964
|
-
if (!it.allErrors)
|
|
11965
|
-
gen.if((0, codegen_1.not)(valid), () => gen.break());
|
|
11531
|
+
if ($data)
|
|
11532
|
+
validate$DataFormat();
|
|
11533
|
+
else
|
|
11534
|
+
validateFormat();
|
|
11535
|
+
function validate$DataFormat() {
|
|
11536
|
+
const fmts = gen.scopeValue("formats", {
|
|
11537
|
+
ref: self2.formats,
|
|
11538
|
+
code: opts.code.formats
|
|
11966
11539
|
});
|
|
11540
|
+
const fDef = gen.const("fDef", (0, codegen_1._)`${fmts}[${schemaCode}]`);
|
|
11541
|
+
const fType = gen.let("fType");
|
|
11542
|
+
const format = gen.let("format");
|
|
11543
|
+
gen.if((0, codegen_1._)`typeof ${fDef} == "object" && !(${fDef} instanceof RegExp)`, () => gen.assign(fType, (0, codegen_1._)`${fDef}.type || "string"`).assign(format, (0, codegen_1._)`${fDef}.validate`), () => gen.assign(fType, (0, codegen_1._)`"string"`).assign(format, fDef));
|
|
11544
|
+
cxt.fail$data((0, codegen_1.or)(unknownFmt(), invalidFmt()));
|
|
11545
|
+
function unknownFmt() {
|
|
11546
|
+
if (opts.strictSchema === false)
|
|
11547
|
+
return codegen_1.nil;
|
|
11548
|
+
return (0, codegen_1._)`${schemaCode} && !${format}`;
|
|
11549
|
+
}
|
|
11550
|
+
function invalidFmt() {
|
|
11551
|
+
const callFormat = schemaEnv.$async ? (0, codegen_1._)`(${fDef}.async ? await ${format}(${data}) : ${format}(${data}))` : (0, codegen_1._)`${format}(${data})`;
|
|
11552
|
+
const validData = (0, codegen_1._)`(typeof ${format} == "function" ? ${callFormat} : ${format}.test(${data}))`;
|
|
11553
|
+
return (0, codegen_1._)`${format} && ${format} !== true && ${fType} === ${ruleType} && !${validData}`;
|
|
11554
|
+
}
|
|
11555
|
+
}
|
|
11556
|
+
function validateFormat() {
|
|
11557
|
+
const formatDef = self2.formats[schema];
|
|
11558
|
+
if (!formatDef) {
|
|
11559
|
+
unknownFormat();
|
|
11560
|
+
return;
|
|
11561
|
+
}
|
|
11562
|
+
if (formatDef === true)
|
|
11563
|
+
return;
|
|
11564
|
+
const [fmtType, format, fmtRef] = getFormat(formatDef);
|
|
11565
|
+
if (fmtType === ruleType)
|
|
11566
|
+
cxt.pass(validCondition());
|
|
11567
|
+
function unknownFormat() {
|
|
11568
|
+
if (opts.strictSchema === false) {
|
|
11569
|
+
self2.logger.warn(unknownMsg());
|
|
11570
|
+
return;
|
|
11571
|
+
}
|
|
11572
|
+
throw new Error(unknownMsg());
|
|
11573
|
+
function unknownMsg() {
|
|
11574
|
+
return `unknown format "${schema}" ignored in schema at path "${errSchemaPath}"`;
|
|
11575
|
+
}
|
|
11576
|
+
}
|
|
11577
|
+
function getFormat(fmtDef) {
|
|
11578
|
+
const code = fmtDef instanceof RegExp ? (0, codegen_1.regexpCode)(fmtDef) : opts.code.formats ? (0, codegen_1._)`${opts.code.formats}${(0, codegen_1.getProperty)(schema)}` : undefined;
|
|
11579
|
+
const fmt = gen.scopeValue("formats", { key: schema, ref: fmtDef, code });
|
|
11580
|
+
if (typeof fmtDef == "object" && !(fmtDef instanceof RegExp)) {
|
|
11581
|
+
return [fmtDef.type || "string", fmtDef.validate, (0, codegen_1._)`${fmt}.validate`];
|
|
11582
|
+
}
|
|
11583
|
+
return ["string", fmtDef, fmt];
|
|
11584
|
+
}
|
|
11585
|
+
function validCondition() {
|
|
11586
|
+
if (typeof formatDef == "object" && !(formatDef instanceof RegExp) && formatDef.async) {
|
|
11587
|
+
if (!schemaEnv.$async)
|
|
11588
|
+
throw new Error("async format in sync schema");
|
|
11589
|
+
return (0, codegen_1._)`await ${fmtRef}(${data})`;
|
|
11590
|
+
}
|
|
11591
|
+
return typeof format == "function" ? (0, codegen_1._)`${fmtRef}(${data})` : (0, codegen_1._)`${fmtRef}.test(${data})`;
|
|
11592
|
+
}
|
|
11967
11593
|
}
|
|
11968
11594
|
}
|
|
11969
11595
|
};
|
|
11970
11596
|
exports.default = def;
|
|
11971
11597
|
});
|
|
11972
11598
|
|
|
11973
|
-
// ../../node_modules/ajv/dist/vocabularies/
|
|
11974
|
-
var
|
|
11599
|
+
// ../../node_modules/ajv/dist/vocabularies/format/index.js
|
|
11600
|
+
var require_format2 = __commonJS((exports) => {
|
|
11975
11601
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11976
|
-
var
|
|
11977
|
-
var
|
|
11978
|
-
|
|
11979
|
-
|
|
11602
|
+
var format_1 = require_format();
|
|
11603
|
+
var format = [format_1.default];
|
|
11604
|
+
exports.default = format;
|
|
11605
|
+
});
|
|
11606
|
+
|
|
11607
|
+
// ../../node_modules/ajv/dist/vocabularies/metadata.js
|
|
11608
|
+
var require_metadata = __commonJS((exports) => {
|
|
11609
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11610
|
+
exports.contentVocabulary = exports.metadataVocabulary = undefined;
|
|
11611
|
+
exports.metadataVocabulary = [
|
|
11612
|
+
"title",
|
|
11613
|
+
"description",
|
|
11614
|
+
"default",
|
|
11615
|
+
"deprecated",
|
|
11616
|
+
"readOnly",
|
|
11617
|
+
"writeOnly",
|
|
11618
|
+
"examples"
|
|
11619
|
+
];
|
|
11620
|
+
exports.contentVocabulary = [
|
|
11621
|
+
"contentMediaType",
|
|
11622
|
+
"contentEncoding",
|
|
11623
|
+
"contentSchema"
|
|
11624
|
+
];
|
|
11980
11625
|
});
|
|
11981
11626
|
|
|
11982
11627
|
// ../../node_modules/ajv/dist/vocabularies/draft2020.js
|
|
@@ -12004,6 +11649,119 @@ var require_draft2020 = __commonJS((exports) => {
|
|
|
12004
11649
|
exports.default = draft2020Vocabularies;
|
|
12005
11650
|
});
|
|
12006
11651
|
|
|
11652
|
+
// ../../node_modules/ajv/dist/vocabularies/discriminator/types.js
|
|
11653
|
+
var require_types3 = __commonJS((exports) => {
|
|
11654
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11655
|
+
exports.DiscrError = undefined;
|
|
11656
|
+
var DiscrError;
|
|
11657
|
+
(function(DiscrError2) {
|
|
11658
|
+
DiscrError2["Tag"] = "tag";
|
|
11659
|
+
DiscrError2["Mapping"] = "mapping";
|
|
11660
|
+
})(DiscrError || (exports.DiscrError = DiscrError = {}));
|
|
11661
|
+
});
|
|
11662
|
+
|
|
11663
|
+
// ../../node_modules/ajv/dist/vocabularies/discriminator/index.js
|
|
11664
|
+
var require_discriminator = __commonJS((exports) => {
|
|
11665
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11666
|
+
var codegen_1 = require_codegen();
|
|
11667
|
+
var types_1 = require_types3();
|
|
11668
|
+
var compile_1 = require_compile();
|
|
11669
|
+
var ref_error_1 = require_ref_error();
|
|
11670
|
+
var util_1 = require_util3();
|
|
11671
|
+
var error = {
|
|
11672
|
+
message: ({ params: { discrError, tagName } }) => discrError === types_1.DiscrError.Tag ? `tag "${tagName}" must be string` : `value of tag "${tagName}" must be in oneOf`,
|
|
11673
|
+
params: ({ params: { discrError, tag, tagName } }) => (0, codegen_1._)`{error: ${discrError}, tag: ${tagName}, tagValue: ${tag}}`
|
|
11674
|
+
};
|
|
11675
|
+
var def = {
|
|
11676
|
+
keyword: "discriminator",
|
|
11677
|
+
type: "object",
|
|
11678
|
+
schemaType: "object",
|
|
11679
|
+
error,
|
|
11680
|
+
code(cxt) {
|
|
11681
|
+
const { gen, data, schema, parentSchema, it } = cxt;
|
|
11682
|
+
const { oneOf } = parentSchema;
|
|
11683
|
+
if (!it.opts.discriminator) {
|
|
11684
|
+
throw new Error("discriminator: requires discriminator option");
|
|
11685
|
+
}
|
|
11686
|
+
const tagName = schema.propertyName;
|
|
11687
|
+
if (typeof tagName != "string")
|
|
11688
|
+
throw new Error("discriminator: requires propertyName");
|
|
11689
|
+
if (schema.mapping)
|
|
11690
|
+
throw new Error("discriminator: mapping is not supported");
|
|
11691
|
+
if (!oneOf)
|
|
11692
|
+
throw new Error("discriminator: requires oneOf keyword");
|
|
11693
|
+
const valid = gen.let("valid", false);
|
|
11694
|
+
const tag = gen.const("tag", (0, codegen_1._)`${data}${(0, codegen_1.getProperty)(tagName)}`);
|
|
11695
|
+
gen.if((0, codegen_1._)`typeof ${tag} == "string"`, () => validateMapping(), () => cxt.error(false, { discrError: types_1.DiscrError.Tag, tag, tagName }));
|
|
11696
|
+
cxt.ok(valid);
|
|
11697
|
+
function validateMapping() {
|
|
11698
|
+
const mapping = getMapping();
|
|
11699
|
+
gen.if(false);
|
|
11700
|
+
for (const tagValue in mapping) {
|
|
11701
|
+
gen.elseIf((0, codegen_1._)`${tag} === ${tagValue}`);
|
|
11702
|
+
gen.assign(valid, applyTagSchema(mapping[tagValue]));
|
|
11703
|
+
}
|
|
11704
|
+
gen.else();
|
|
11705
|
+
cxt.error(false, { discrError: types_1.DiscrError.Mapping, tag, tagName });
|
|
11706
|
+
gen.endIf();
|
|
11707
|
+
}
|
|
11708
|
+
function applyTagSchema(schemaProp) {
|
|
11709
|
+
const _valid = gen.name("valid");
|
|
11710
|
+
const schCxt = cxt.subschema({ keyword: "oneOf", schemaProp }, _valid);
|
|
11711
|
+
cxt.mergeEvaluated(schCxt, codegen_1.Name);
|
|
11712
|
+
return _valid;
|
|
11713
|
+
}
|
|
11714
|
+
function getMapping() {
|
|
11715
|
+
var _a2;
|
|
11716
|
+
const oneOfMapping = {};
|
|
11717
|
+
const topRequired = hasRequired(parentSchema);
|
|
11718
|
+
let tagRequired = true;
|
|
11719
|
+
for (let i2 = 0;i2 < oneOf.length; i2++) {
|
|
11720
|
+
let sch = oneOf[i2];
|
|
11721
|
+
if ((sch === null || sch === undefined ? undefined : sch.$ref) && !(0, util_1.schemaHasRulesButRef)(sch, it.self.RULES)) {
|
|
11722
|
+
const ref = sch.$ref;
|
|
11723
|
+
sch = compile_1.resolveRef.call(it.self, it.schemaEnv.root, it.baseId, ref);
|
|
11724
|
+
if (sch instanceof compile_1.SchemaEnv)
|
|
11725
|
+
sch = sch.schema;
|
|
11726
|
+
if (sch === undefined)
|
|
11727
|
+
throw new ref_error_1.default(it.opts.uriResolver, it.baseId, ref);
|
|
11728
|
+
}
|
|
11729
|
+
const propSch = (_a2 = sch === null || sch === undefined ? undefined : sch.properties) === null || _a2 === undefined ? undefined : _a2[tagName];
|
|
11730
|
+
if (typeof propSch != "object") {
|
|
11731
|
+
throw new Error(`discriminator: oneOf subschemas (or referenced schemas) must have "properties/${tagName}"`);
|
|
11732
|
+
}
|
|
11733
|
+
tagRequired = tagRequired && (topRequired || hasRequired(sch));
|
|
11734
|
+
addMappings(propSch, i2);
|
|
11735
|
+
}
|
|
11736
|
+
if (!tagRequired)
|
|
11737
|
+
throw new Error(`discriminator: "${tagName}" must be required`);
|
|
11738
|
+
return oneOfMapping;
|
|
11739
|
+
function hasRequired({ required }) {
|
|
11740
|
+
return Array.isArray(required) && required.includes(tagName);
|
|
11741
|
+
}
|
|
11742
|
+
function addMappings(sch, i2) {
|
|
11743
|
+
if (sch.const) {
|
|
11744
|
+
addMapping(sch.const, i2);
|
|
11745
|
+
} else if (sch.enum) {
|
|
11746
|
+
for (const tagValue of sch.enum) {
|
|
11747
|
+
addMapping(tagValue, i2);
|
|
11748
|
+
}
|
|
11749
|
+
} else {
|
|
11750
|
+
throw new Error(`discriminator: "properties/${tagName}" must have "const" or "enum"`);
|
|
11751
|
+
}
|
|
11752
|
+
}
|
|
11753
|
+
function addMapping(tagValue, i2) {
|
|
11754
|
+
if (typeof tagValue != "string" || tagValue in oneOfMapping) {
|
|
11755
|
+
throw new Error(`discriminator: "${tagName}" values must be unique strings`);
|
|
11756
|
+
}
|
|
11757
|
+
oneOfMapping[tagValue] = i2;
|
|
11758
|
+
}
|
|
11759
|
+
}
|
|
11760
|
+
}
|
|
11761
|
+
};
|
|
11762
|
+
exports.default = def;
|
|
11763
|
+
});
|
|
11764
|
+
|
|
12007
11765
|
// ../../node_modules/ajv/dist/refs/json-schema-2020-12/schema.json
|
|
12008
11766
|
var require_schema = __commonJS((exports, module) => {
|
|
12009
11767
|
module.exports = {
|
|
@@ -17459,7 +17217,7 @@ var require_dist = __commonJS((exports, module) => {
|
|
|
17459
17217
|
|
|
17460
17218
|
// ../../node_modules/@apidevtools/swagger-parser/lib/validators/schema.js
|
|
17461
17219
|
var require_schema5 = __commonJS((exports, module) => {
|
|
17462
|
-
var util =
|
|
17220
|
+
var util = require_util2();
|
|
17463
17221
|
var Ajv = require_2020();
|
|
17464
17222
|
var { openapi } = require_lib3();
|
|
17465
17223
|
module.exports = validateSchema2;
|
|
@@ -17532,7 +17290,7 @@ var require_lib5 = __commonJS((exports, module) => {
|
|
|
17532
17290
|
|
|
17533
17291
|
// ../../node_modules/@apidevtools/swagger-parser/lib/validators/spec.js
|
|
17534
17292
|
var require_spec = __commonJS((exports, module) => {
|
|
17535
|
-
var util =
|
|
17293
|
+
var util = require_util2();
|
|
17536
17294
|
var swaggerMethods = require_lib5();
|
|
17537
17295
|
var primitiveTypes = ["array", "boolean", "integer", "number", "string"];
|
|
17538
17296
|
var schemaTypes = ["array", "boolean", "integer", "number", "string", "object", "null", undefined];
|
|
@@ -23057,7 +22815,7 @@ var require_lib7 = __commonJS((exports, module) => {
|
|
|
23057
22815
|
dereferenceInternal: dereference,
|
|
23058
22816
|
$RefParser: $RefParser2
|
|
23059
22817
|
} = require_lib6();
|
|
23060
|
-
var util =
|
|
22818
|
+
var util = require_util2();
|
|
23061
22819
|
var Options = require_options2();
|
|
23062
22820
|
var maybe = require_maybe2();
|
|
23063
22821
|
var supported31Versions = ["3.1.0", "3.1.1", "3.1.2"];
|
|
@@ -23101,65 +22859,307 @@ var require_lib7 = __commonJS((exports, module) => {
|
|
|
23101
22859
|
return maybe(args.callback, Promise.reject(err));
|
|
23102
22860
|
}
|
|
23103
22861
|
}
|
|
23104
|
-
async validate(path, api, options, callback) {
|
|
23105
|
-
let me3 = this;
|
|
23106
|
-
let args = normalizeArgs(arguments);
|
|
23107
|
-
args.options = new Options(args.options);
|
|
23108
|
-
let circular$RefOption = args.options.dereference.circular;
|
|
23109
|
-
args.options.validate.schema && (args.options.dereference.circular = "ignore");
|
|
23110
|
-
try {
|
|
23111
|
-
await this.dereference(args.path, args.schema, args.options);
|
|
23112
|
-
args.options.dereference.circular = circular$RefOption;
|
|
23113
|
-
if (args.options.validate.schema) {
|
|
23114
|
-
validateSchema2(me3.api);
|
|
23115
|
-
if (me3.$refs.circular) {
|
|
23116
|
-
if (circular$RefOption === true) {
|
|
23117
|
-
dereference(me3, args.options);
|
|
23118
|
-
} else if (circular$RefOption === false) {
|
|
23119
|
-
throw new ReferenceError("The API contains circular references");
|
|
23120
|
-
}
|
|
23121
|
-
}
|
|
23122
|
-
}
|
|
23123
|
-
if (args.options.validate.spec) {
|
|
23124
|
-
validateSpec(me3.api);
|
|
23125
|
-
}
|
|
23126
|
-
return maybe(args.callback, Promise.resolve(me3.schema));
|
|
23127
|
-
} catch (err) {
|
|
23128
|
-
return maybe(args.callback, Promise.reject(err));
|
|
23129
|
-
}
|
|
22862
|
+
async validate(path, api, options, callback) {
|
|
22863
|
+
let me3 = this;
|
|
22864
|
+
let args = normalizeArgs(arguments);
|
|
22865
|
+
args.options = new Options(args.options);
|
|
22866
|
+
let circular$RefOption = args.options.dereference.circular;
|
|
22867
|
+
args.options.validate.schema && (args.options.dereference.circular = "ignore");
|
|
22868
|
+
try {
|
|
22869
|
+
await this.dereference(args.path, args.schema, args.options);
|
|
22870
|
+
args.options.dereference.circular = circular$RefOption;
|
|
22871
|
+
if (args.options.validate.schema) {
|
|
22872
|
+
validateSchema2(me3.api);
|
|
22873
|
+
if (me3.$refs.circular) {
|
|
22874
|
+
if (circular$RefOption === true) {
|
|
22875
|
+
dereference(me3, args.options);
|
|
22876
|
+
} else if (circular$RefOption === false) {
|
|
22877
|
+
throw new ReferenceError("The API contains circular references");
|
|
22878
|
+
}
|
|
22879
|
+
}
|
|
22880
|
+
}
|
|
22881
|
+
if (args.options.validate.spec) {
|
|
22882
|
+
validateSpec(me3.api);
|
|
22883
|
+
}
|
|
22884
|
+
return maybe(args.callback, Promise.resolve(me3.schema));
|
|
22885
|
+
} catch (err) {
|
|
22886
|
+
return maybe(args.callback, Promise.reject(err));
|
|
22887
|
+
}
|
|
22888
|
+
}
|
|
22889
|
+
}
|
|
22890
|
+
Object.defineProperty(SwaggerParser.prototype, "api", {
|
|
22891
|
+
configurable: true,
|
|
22892
|
+
enumerable: true,
|
|
22893
|
+
get() {
|
|
22894
|
+
return this.schema;
|
|
22895
|
+
}
|
|
22896
|
+
});
|
|
22897
|
+
var defaultExport = SwaggerParser;
|
|
22898
|
+
defaultExport.validate = (...args) => {
|
|
22899
|
+
const defaultInstance = new SwaggerParser;
|
|
22900
|
+
return defaultInstance.validate(...args);
|
|
22901
|
+
};
|
|
22902
|
+
defaultExport.dereference = (...args) => {
|
|
22903
|
+
const defaultInstance = new SwaggerParser;
|
|
22904
|
+
return defaultInstance.dereference(...args);
|
|
22905
|
+
};
|
|
22906
|
+
defaultExport.bundle = (...args) => {
|
|
22907
|
+
const defaultInstance = new SwaggerParser;
|
|
22908
|
+
return defaultInstance.bundle(...args);
|
|
22909
|
+
};
|
|
22910
|
+
defaultExport.parse = (...args) => {
|
|
22911
|
+
const defaultInstance = new SwaggerParser;
|
|
22912
|
+
return defaultInstance.parse(...args);
|
|
22913
|
+
};
|
|
22914
|
+
defaultExport.resolve = (...args) => {
|
|
22915
|
+
const defaultInstance = new SwaggerParser;
|
|
22916
|
+
return defaultInstance.resolve(...args);
|
|
22917
|
+
};
|
|
22918
|
+
defaultExport.default = defaultExport;
|
|
22919
|
+
defaultExport.SwaggerParser = defaultExport;
|
|
22920
|
+
module.exports = defaultExport;
|
|
22921
|
+
});
|
|
22922
|
+
|
|
22923
|
+
// ../../node_modules/ajv/dist/vocabularies/draft7.js
|
|
22924
|
+
var require_draft7 = __commonJS((exports) => {
|
|
22925
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22926
|
+
var core_1 = require_core2();
|
|
22927
|
+
var validation_1 = require_validation();
|
|
22928
|
+
var applicator_1 = require_applicator();
|
|
22929
|
+
var format_1 = require_format2();
|
|
22930
|
+
var metadata_1 = require_metadata();
|
|
22931
|
+
var draft7Vocabularies = [
|
|
22932
|
+
core_1.default,
|
|
22933
|
+
validation_1.default,
|
|
22934
|
+
(0, applicator_1.default)(),
|
|
22935
|
+
format_1.default,
|
|
22936
|
+
metadata_1.metadataVocabulary,
|
|
22937
|
+
metadata_1.contentVocabulary
|
|
22938
|
+
];
|
|
22939
|
+
exports.default = draft7Vocabularies;
|
|
22940
|
+
});
|
|
22941
|
+
|
|
22942
|
+
// ../../node_modules/ajv/dist/refs/json-schema-draft-07.json
|
|
22943
|
+
var require_json_schema_draft_07 = __commonJS((exports, module) => {
|
|
22944
|
+
module.exports = {
|
|
22945
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
22946
|
+
$id: "http://json-schema.org/draft-07/schema#",
|
|
22947
|
+
title: "Core schema meta-schema",
|
|
22948
|
+
definitions: {
|
|
22949
|
+
schemaArray: {
|
|
22950
|
+
type: "array",
|
|
22951
|
+
minItems: 1,
|
|
22952
|
+
items: { $ref: "#" }
|
|
22953
|
+
},
|
|
22954
|
+
nonNegativeInteger: {
|
|
22955
|
+
type: "integer",
|
|
22956
|
+
minimum: 0
|
|
22957
|
+
},
|
|
22958
|
+
nonNegativeIntegerDefault0: {
|
|
22959
|
+
allOf: [{ $ref: "#/definitions/nonNegativeInteger" }, { default: 0 }]
|
|
22960
|
+
},
|
|
22961
|
+
simpleTypes: {
|
|
22962
|
+
enum: ["array", "boolean", "integer", "null", "number", "object", "string"]
|
|
22963
|
+
},
|
|
22964
|
+
stringArray: {
|
|
22965
|
+
type: "array",
|
|
22966
|
+
items: { type: "string" },
|
|
22967
|
+
uniqueItems: true,
|
|
22968
|
+
default: []
|
|
22969
|
+
}
|
|
22970
|
+
},
|
|
22971
|
+
type: ["object", "boolean"],
|
|
22972
|
+
properties: {
|
|
22973
|
+
$id: {
|
|
22974
|
+
type: "string",
|
|
22975
|
+
format: "uri-reference"
|
|
22976
|
+
},
|
|
22977
|
+
$schema: {
|
|
22978
|
+
type: "string",
|
|
22979
|
+
format: "uri"
|
|
22980
|
+
},
|
|
22981
|
+
$ref: {
|
|
22982
|
+
type: "string",
|
|
22983
|
+
format: "uri-reference"
|
|
22984
|
+
},
|
|
22985
|
+
$comment: {
|
|
22986
|
+
type: "string"
|
|
22987
|
+
},
|
|
22988
|
+
title: {
|
|
22989
|
+
type: "string"
|
|
22990
|
+
},
|
|
22991
|
+
description: {
|
|
22992
|
+
type: "string"
|
|
22993
|
+
},
|
|
22994
|
+
default: true,
|
|
22995
|
+
readOnly: {
|
|
22996
|
+
type: "boolean",
|
|
22997
|
+
default: false
|
|
22998
|
+
},
|
|
22999
|
+
examples: {
|
|
23000
|
+
type: "array",
|
|
23001
|
+
items: true
|
|
23002
|
+
},
|
|
23003
|
+
multipleOf: {
|
|
23004
|
+
type: "number",
|
|
23005
|
+
exclusiveMinimum: 0
|
|
23006
|
+
},
|
|
23007
|
+
maximum: {
|
|
23008
|
+
type: "number"
|
|
23009
|
+
},
|
|
23010
|
+
exclusiveMaximum: {
|
|
23011
|
+
type: "number"
|
|
23012
|
+
},
|
|
23013
|
+
minimum: {
|
|
23014
|
+
type: "number"
|
|
23015
|
+
},
|
|
23016
|
+
exclusiveMinimum: {
|
|
23017
|
+
type: "number"
|
|
23018
|
+
},
|
|
23019
|
+
maxLength: { $ref: "#/definitions/nonNegativeInteger" },
|
|
23020
|
+
minLength: { $ref: "#/definitions/nonNegativeIntegerDefault0" },
|
|
23021
|
+
pattern: {
|
|
23022
|
+
type: "string",
|
|
23023
|
+
format: "regex"
|
|
23024
|
+
},
|
|
23025
|
+
additionalItems: { $ref: "#" },
|
|
23026
|
+
items: {
|
|
23027
|
+
anyOf: [{ $ref: "#" }, { $ref: "#/definitions/schemaArray" }],
|
|
23028
|
+
default: true
|
|
23029
|
+
},
|
|
23030
|
+
maxItems: { $ref: "#/definitions/nonNegativeInteger" },
|
|
23031
|
+
minItems: { $ref: "#/definitions/nonNegativeIntegerDefault0" },
|
|
23032
|
+
uniqueItems: {
|
|
23033
|
+
type: "boolean",
|
|
23034
|
+
default: false
|
|
23035
|
+
},
|
|
23036
|
+
contains: { $ref: "#" },
|
|
23037
|
+
maxProperties: { $ref: "#/definitions/nonNegativeInteger" },
|
|
23038
|
+
minProperties: { $ref: "#/definitions/nonNegativeIntegerDefault0" },
|
|
23039
|
+
required: { $ref: "#/definitions/stringArray" },
|
|
23040
|
+
additionalProperties: { $ref: "#" },
|
|
23041
|
+
definitions: {
|
|
23042
|
+
type: "object",
|
|
23043
|
+
additionalProperties: { $ref: "#" },
|
|
23044
|
+
default: {}
|
|
23045
|
+
},
|
|
23046
|
+
properties: {
|
|
23047
|
+
type: "object",
|
|
23048
|
+
additionalProperties: { $ref: "#" },
|
|
23049
|
+
default: {}
|
|
23050
|
+
},
|
|
23051
|
+
patternProperties: {
|
|
23052
|
+
type: "object",
|
|
23053
|
+
additionalProperties: { $ref: "#" },
|
|
23054
|
+
propertyNames: { format: "regex" },
|
|
23055
|
+
default: {}
|
|
23056
|
+
},
|
|
23057
|
+
dependencies: {
|
|
23058
|
+
type: "object",
|
|
23059
|
+
additionalProperties: {
|
|
23060
|
+
anyOf: [{ $ref: "#" }, { $ref: "#/definitions/stringArray" }]
|
|
23061
|
+
}
|
|
23062
|
+
},
|
|
23063
|
+
propertyNames: { $ref: "#" },
|
|
23064
|
+
const: true,
|
|
23065
|
+
enum: {
|
|
23066
|
+
type: "array",
|
|
23067
|
+
items: true,
|
|
23068
|
+
minItems: 1,
|
|
23069
|
+
uniqueItems: true
|
|
23070
|
+
},
|
|
23071
|
+
type: {
|
|
23072
|
+
anyOf: [
|
|
23073
|
+
{ $ref: "#/definitions/simpleTypes" },
|
|
23074
|
+
{
|
|
23075
|
+
type: "array",
|
|
23076
|
+
items: { $ref: "#/definitions/simpleTypes" },
|
|
23077
|
+
minItems: 1,
|
|
23078
|
+
uniqueItems: true
|
|
23079
|
+
}
|
|
23080
|
+
]
|
|
23081
|
+
},
|
|
23082
|
+
format: { type: "string" },
|
|
23083
|
+
contentMediaType: { type: "string" },
|
|
23084
|
+
contentEncoding: { type: "string" },
|
|
23085
|
+
if: { $ref: "#" },
|
|
23086
|
+
then: { $ref: "#" },
|
|
23087
|
+
else: { $ref: "#" },
|
|
23088
|
+
allOf: { $ref: "#/definitions/schemaArray" },
|
|
23089
|
+
anyOf: { $ref: "#/definitions/schemaArray" },
|
|
23090
|
+
oneOf: { $ref: "#/definitions/schemaArray" },
|
|
23091
|
+
not: { $ref: "#" }
|
|
23092
|
+
},
|
|
23093
|
+
default: true
|
|
23094
|
+
};
|
|
23095
|
+
});
|
|
23096
|
+
|
|
23097
|
+
// ../../node_modules/ajv/dist/ajv.js
|
|
23098
|
+
var require_ajv = __commonJS((exports, module) => {
|
|
23099
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23100
|
+
exports.MissingRefError = exports.ValidationError = exports.CodeGen = exports.Name = exports.nil = exports.stringify = exports.str = exports._ = exports.KeywordCxt = exports.Ajv = undefined;
|
|
23101
|
+
var core_1 = require_core();
|
|
23102
|
+
var draft7_1 = require_draft7();
|
|
23103
|
+
var discriminator_1 = require_discriminator();
|
|
23104
|
+
var draft7MetaSchema = require_json_schema_draft_07();
|
|
23105
|
+
var META_SUPPORT_DATA = ["/properties"];
|
|
23106
|
+
var META_SCHEMA_ID = "http://json-schema.org/draft-07/schema";
|
|
23107
|
+
|
|
23108
|
+
class Ajv extends core_1.default {
|
|
23109
|
+
_addVocabularies() {
|
|
23110
|
+
super._addVocabularies();
|
|
23111
|
+
draft7_1.default.forEach((v3) => this.addVocabulary(v3));
|
|
23112
|
+
if (this.opts.discriminator)
|
|
23113
|
+
this.addKeyword(discriminator_1.default);
|
|
23114
|
+
}
|
|
23115
|
+
_addDefaultMetaSchema() {
|
|
23116
|
+
super._addDefaultMetaSchema();
|
|
23117
|
+
if (!this.opts.meta)
|
|
23118
|
+
return;
|
|
23119
|
+
const metaSchema = this.opts.$data ? this.$dataMetaSchema(draft7MetaSchema, META_SUPPORT_DATA) : draft7MetaSchema;
|
|
23120
|
+
this.addMetaSchema(metaSchema, META_SCHEMA_ID, false);
|
|
23121
|
+
this.refs["http://json-schema.org/schema"] = META_SCHEMA_ID;
|
|
23130
23122
|
}
|
|
23131
|
-
|
|
23132
|
-
|
|
23133
|
-
configurable: true,
|
|
23134
|
-
enumerable: true,
|
|
23135
|
-
get() {
|
|
23136
|
-
return this.schema;
|
|
23123
|
+
defaultMeta() {
|
|
23124
|
+
return this.opts.defaultMeta = super.defaultMeta() || (this.getSchema(META_SCHEMA_ID) ? META_SCHEMA_ID : undefined);
|
|
23137
23125
|
}
|
|
23138
|
-
}
|
|
23139
|
-
|
|
23140
|
-
|
|
23141
|
-
|
|
23142
|
-
|
|
23143
|
-
|
|
23144
|
-
|
|
23145
|
-
|
|
23146
|
-
return
|
|
23147
|
-
};
|
|
23148
|
-
|
|
23149
|
-
|
|
23150
|
-
return
|
|
23151
|
-
};
|
|
23152
|
-
|
|
23153
|
-
|
|
23154
|
-
|
|
23155
|
-
|
|
23156
|
-
|
|
23157
|
-
|
|
23158
|
-
|
|
23159
|
-
|
|
23160
|
-
|
|
23161
|
-
|
|
23162
|
-
|
|
23126
|
+
}
|
|
23127
|
+
exports.Ajv = Ajv;
|
|
23128
|
+
module.exports = exports = Ajv;
|
|
23129
|
+
module.exports.Ajv = Ajv;
|
|
23130
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23131
|
+
exports.default = Ajv;
|
|
23132
|
+
var validate_1 = require_validate();
|
|
23133
|
+
Object.defineProperty(exports, "KeywordCxt", { enumerable: true, get: function() {
|
|
23134
|
+
return validate_1.KeywordCxt;
|
|
23135
|
+
} });
|
|
23136
|
+
var codegen_1 = require_codegen();
|
|
23137
|
+
Object.defineProperty(exports, "_", { enumerable: true, get: function() {
|
|
23138
|
+
return codegen_1._;
|
|
23139
|
+
} });
|
|
23140
|
+
Object.defineProperty(exports, "str", { enumerable: true, get: function() {
|
|
23141
|
+
return codegen_1.str;
|
|
23142
|
+
} });
|
|
23143
|
+
Object.defineProperty(exports, "stringify", { enumerable: true, get: function() {
|
|
23144
|
+
return codegen_1.stringify;
|
|
23145
|
+
} });
|
|
23146
|
+
Object.defineProperty(exports, "nil", { enumerable: true, get: function() {
|
|
23147
|
+
return codegen_1.nil;
|
|
23148
|
+
} });
|
|
23149
|
+
Object.defineProperty(exports, "Name", { enumerable: true, get: function() {
|
|
23150
|
+
return codegen_1.Name;
|
|
23151
|
+
} });
|
|
23152
|
+
Object.defineProperty(exports, "CodeGen", { enumerable: true, get: function() {
|
|
23153
|
+
return codegen_1.CodeGen;
|
|
23154
|
+
} });
|
|
23155
|
+
var validation_error_1 = require_validation_error();
|
|
23156
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function() {
|
|
23157
|
+
return validation_error_1.default;
|
|
23158
|
+
} });
|
|
23159
|
+
var ref_error_1 = require_ref_error();
|
|
23160
|
+
Object.defineProperty(exports, "MissingRefError", { enumerable: true, get: function() {
|
|
23161
|
+
return ref_error_1.default;
|
|
23162
|
+
} });
|
|
23163
23163
|
});
|
|
23164
23164
|
|
|
23165
23165
|
// src/cli.ts
|
|
@@ -23195,6 +23195,10 @@ function isStatusTuple(value) {
|
|
|
23195
23195
|
}
|
|
23196
23196
|
|
|
23197
23197
|
// ../core/src/errors.ts
|
|
23198
|
+
function errorMessage(error) {
|
|
23199
|
+
return error instanceof Error ? error.message : "Unknown error";
|
|
23200
|
+
}
|
|
23201
|
+
|
|
23198
23202
|
class SchmockError extends Error {
|
|
23199
23203
|
code;
|
|
23200
23204
|
context;
|
|
@@ -23333,11 +23337,128 @@ function parseRouteKey(routeKey) {
|
|
|
23333
23337
|
};
|
|
23334
23338
|
}
|
|
23335
23339
|
|
|
23336
|
-
// ../core/src/
|
|
23337
|
-
function
|
|
23338
|
-
|
|
23340
|
+
// ../core/src/plugin-pipeline.ts
|
|
23341
|
+
async function runPluginPipeline(plugins, context, initialResponse, logger) {
|
|
23342
|
+
let currentContext = context;
|
|
23343
|
+
let response = initialResponse;
|
|
23344
|
+
logger.log("pipeline", `Running plugin pipeline for ${plugins.length} plugins`);
|
|
23345
|
+
for (const plugin of plugins) {
|
|
23346
|
+
logger.log("pipeline", `Processing plugin: ${plugin.name}`);
|
|
23347
|
+
try {
|
|
23348
|
+
const result = await plugin.process(currentContext, response);
|
|
23349
|
+
if (!result || !result.context) {
|
|
23350
|
+
throw new Error(`Plugin ${plugin.name} didn't return valid result`);
|
|
23351
|
+
}
|
|
23352
|
+
currentContext = result.context;
|
|
23353
|
+
if (result.response !== undefined && (response === undefined || response === null)) {
|
|
23354
|
+
logger.log("pipeline", `Plugin ${plugin.name} generated response`);
|
|
23355
|
+
response = result.response;
|
|
23356
|
+
} else if (result.response !== undefined && response !== undefined) {
|
|
23357
|
+
logger.log("pipeline", `Plugin ${plugin.name} transformed response`);
|
|
23358
|
+
response = result.response;
|
|
23359
|
+
}
|
|
23360
|
+
} catch (error) {
|
|
23361
|
+
logger.log("pipeline", `Plugin ${plugin.name} failed: ${errorMessage(error)}`);
|
|
23362
|
+
if (plugin.onError) {
|
|
23363
|
+
try {
|
|
23364
|
+
const pluginError = error instanceof Error ? error : new Error(errorMessage(error));
|
|
23365
|
+
const errorResult = await plugin.onError(pluginError, currentContext);
|
|
23366
|
+
if (errorResult) {
|
|
23367
|
+
logger.log("pipeline", `Plugin ${plugin.name} handled error`);
|
|
23368
|
+
if (errorResult instanceof Error) {
|
|
23369
|
+
throw new PluginError(plugin.name, errorResult);
|
|
23370
|
+
}
|
|
23371
|
+
if (typeof errorResult === "object" && errorResult !== null && "status" in errorResult) {
|
|
23372
|
+
response = errorResult;
|
|
23373
|
+
break;
|
|
23374
|
+
}
|
|
23375
|
+
}
|
|
23376
|
+
} catch (hookError) {
|
|
23377
|
+
if (hookError instanceof PluginError) {
|
|
23378
|
+
throw hookError;
|
|
23379
|
+
}
|
|
23380
|
+
logger.log("pipeline", `Plugin ${plugin.name} error handler failed: ${errorMessage(hookError)}`);
|
|
23381
|
+
}
|
|
23382
|
+
}
|
|
23383
|
+
const cause = error instanceof Error ? error : new Error(errorMessage(error));
|
|
23384
|
+
throw new PluginError(plugin.name, cause);
|
|
23385
|
+
}
|
|
23386
|
+
}
|
|
23387
|
+
return { context: currentContext, response };
|
|
23388
|
+
}
|
|
23389
|
+
|
|
23390
|
+
// ../core/src/response-parser.ts
|
|
23391
|
+
function isResponseObject(value) {
|
|
23392
|
+
return typeof value === "object" && value !== null && "status" in value && "body" in value;
|
|
23393
|
+
}
|
|
23394
|
+
function parseResponse(result, routeConfig) {
|
|
23395
|
+
let status = 200;
|
|
23396
|
+
let body = result;
|
|
23397
|
+
let headers = {};
|
|
23398
|
+
let tupleFormat = false;
|
|
23399
|
+
if (isResponseObject(result)) {
|
|
23400
|
+
return {
|
|
23401
|
+
status: result.status,
|
|
23402
|
+
body: result.body,
|
|
23403
|
+
headers: result.headers || {}
|
|
23404
|
+
};
|
|
23405
|
+
}
|
|
23406
|
+
if (isStatusTuple(result)) {
|
|
23407
|
+
[status, body, headers = {}] = result;
|
|
23408
|
+
tupleFormat = true;
|
|
23409
|
+
}
|
|
23410
|
+
if (body === null || body === undefined) {
|
|
23411
|
+
if (!tupleFormat) {
|
|
23412
|
+
status = status === 200 ? 204 : status;
|
|
23413
|
+
}
|
|
23414
|
+
body = undefined;
|
|
23415
|
+
}
|
|
23416
|
+
if (!headers["content-type"] && routeConfig.contentType && !tupleFormat) {
|
|
23417
|
+
headers["content-type"] = routeConfig.contentType;
|
|
23418
|
+
if (routeConfig.contentType === "text/plain" && body !== undefined) {
|
|
23419
|
+
if (typeof body === "object" && !Buffer.isBuffer(body)) {
|
|
23420
|
+
body = JSON.stringify(body);
|
|
23421
|
+
} else if (typeof body !== "string") {
|
|
23422
|
+
body = String(body);
|
|
23423
|
+
}
|
|
23424
|
+
}
|
|
23425
|
+
}
|
|
23426
|
+
return {
|
|
23427
|
+
status,
|
|
23428
|
+
body,
|
|
23429
|
+
headers
|
|
23430
|
+
};
|
|
23431
|
+
}
|
|
23432
|
+
|
|
23433
|
+
// ../core/src/route-matcher.ts
|
|
23434
|
+
function isGeneratorFunction(gen) {
|
|
23435
|
+
return typeof gen === "function";
|
|
23436
|
+
}
|
|
23437
|
+
function findRoute(method, path, staticRoutes, routes) {
|
|
23438
|
+
const normalizedPath = path.endsWith("/") && path !== "/" ? path.slice(0, -1) : path;
|
|
23439
|
+
const staticMatch = staticRoutes.get(`${method} ${normalizedPath}`);
|
|
23440
|
+
if (staticMatch) {
|
|
23441
|
+
return staticMatch;
|
|
23442
|
+
}
|
|
23443
|
+
for (const route of routes) {
|
|
23444
|
+
if (route.method === method && route.params.length > 0 && route.pattern.test(path)) {
|
|
23445
|
+
return route;
|
|
23446
|
+
}
|
|
23447
|
+
}
|
|
23448
|
+
return;
|
|
23449
|
+
}
|
|
23450
|
+
function extractParams(route, path) {
|
|
23451
|
+
const match = path.match(route.pattern);
|
|
23452
|
+
if (!match)
|
|
23453
|
+
return {};
|
|
23454
|
+
const params = {};
|
|
23455
|
+
route.params.forEach((param, index) => {
|
|
23456
|
+
params[param] = match[index + 1];
|
|
23457
|
+
});
|
|
23458
|
+
return params;
|
|
23339
23459
|
}
|
|
23340
23460
|
|
|
23461
|
+
// ../core/src/builder.ts
|
|
23341
23462
|
class DebugLogger {
|
|
23342
23463
|
enabled;
|
|
23343
23464
|
constructor(enabled = false) {
|
|
@@ -23365,12 +23486,6 @@ class DebugLogger {
|
|
|
23365
23486
|
console.timeEnd(`[SCHMOCK] ${label}`);
|
|
23366
23487
|
}
|
|
23367
23488
|
}
|
|
23368
|
-
function isGeneratorFunction(gen) {
|
|
23369
|
-
return typeof gen === "function";
|
|
23370
|
-
}
|
|
23371
|
-
function isResponseObject(value) {
|
|
23372
|
-
return typeof value === "object" && value !== null && "status" in value && "body" in value;
|
|
23373
|
-
}
|
|
23374
23489
|
|
|
23375
23490
|
class CallableMockInstance {
|
|
23376
23491
|
globalConfig;
|
|
@@ -23609,7 +23724,7 @@ class CallableMockInstance {
|
|
|
23609
23724
|
const stripped = pathToCheck.slice(namespace.length);
|
|
23610
23725
|
requestPath = stripped.startsWith("/") ? stripped : `/${stripped}`;
|
|
23611
23726
|
}
|
|
23612
|
-
const matchedRoute =
|
|
23727
|
+
const matchedRoute = findRoute(method, requestPath, this.staticRoutes, this.routes);
|
|
23613
23728
|
if (!matchedRoute) {
|
|
23614
23729
|
this.logger.log("route", `[${requestId}] No route found for ${method} ${requestPath}`);
|
|
23615
23730
|
this.emit("request:notfound", { method, path: requestPath });
|
|
@@ -23629,7 +23744,7 @@ class CallableMockInstance {
|
|
|
23629
23744
|
return response2;
|
|
23630
23745
|
}
|
|
23631
23746
|
this.logger.log("route", `[${requestId}] Matched route: ${method} ${matchedRoute.path}`);
|
|
23632
|
-
const params =
|
|
23747
|
+
const params = extractParams(matchedRoute, requestPath);
|
|
23633
23748
|
this.emit("request:match", {
|
|
23634
23749
|
method,
|
|
23635
23750
|
path: requestPath,
|
|
@@ -23663,14 +23778,14 @@ class CallableMockInstance {
|
|
|
23663
23778
|
routeState: this.globalConfig.state || {}
|
|
23664
23779
|
};
|
|
23665
23780
|
try {
|
|
23666
|
-
const pipelineResult = await this.
|
|
23781
|
+
const pipelineResult = await runPluginPipeline(this.plugins, pluginContext, result, this.logger);
|
|
23667
23782
|
pluginContext = pipelineResult.context;
|
|
23668
23783
|
result = pipelineResult.response;
|
|
23669
23784
|
} catch (error) {
|
|
23670
23785
|
this.logger.log("error", `[${requestId}] Plugin pipeline error: ${errorMessage(error)}`);
|
|
23671
23786
|
throw error;
|
|
23672
23787
|
}
|
|
23673
|
-
const response =
|
|
23788
|
+
const response = parseResponse(result, matchedRoute.config);
|
|
23674
23789
|
await this.applyDelay(matchedRoute.config.delay);
|
|
23675
23790
|
this.requestHistory.push({
|
|
23676
23791
|
method,
|
|
@@ -23719,152 +23834,120 @@ class CallableMockInstance {
|
|
|
23719
23834
|
const ms = Array.isArray(effectiveDelay) ? Math.random() * (effectiveDelay[1] - effectiveDelay[0]) + effectiveDelay[0] : effectiveDelay;
|
|
23720
23835
|
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
23721
23836
|
}
|
|
23722
|
-
|
|
23723
|
-
|
|
23724
|
-
|
|
23725
|
-
|
|
23726
|
-
|
|
23727
|
-
|
|
23728
|
-
|
|
23729
|
-
|
|
23730
|
-
|
|
23731
|
-
|
|
23732
|
-
|
|
23733
|
-
|
|
23734
|
-
|
|
23735
|
-
|
|
23736
|
-
|
|
23737
|
-
|
|
23738
|
-
|
|
23739
|
-
|
|
23740
|
-
|
|
23741
|
-
|
|
23742
|
-
|
|
23837
|
+
}
|
|
23838
|
+
|
|
23839
|
+
// ../core/src/index.ts
|
|
23840
|
+
function schmock(config) {
|
|
23841
|
+
const instance = new CallableMockInstance(config || {});
|
|
23842
|
+
const callableInstance = Object.assign((route, generator, routeConfig = {}) => {
|
|
23843
|
+
instance.defineRoute(route, generator, routeConfig);
|
|
23844
|
+
return callableInstance;
|
|
23845
|
+
}, {
|
|
23846
|
+
pipe: (plugin) => {
|
|
23847
|
+
instance.pipe(plugin);
|
|
23848
|
+
return callableInstance;
|
|
23849
|
+
},
|
|
23850
|
+
handle: instance.handle.bind(instance),
|
|
23851
|
+
history: instance.history.bind(instance),
|
|
23852
|
+
called: instance.called.bind(instance),
|
|
23853
|
+
callCount: instance.callCount.bind(instance),
|
|
23854
|
+
lastRequest: instance.lastRequest.bind(instance),
|
|
23855
|
+
reset: instance.reset.bind(instance),
|
|
23856
|
+
resetHistory: instance.resetHistory.bind(instance),
|
|
23857
|
+
resetState: instance.resetState.bind(instance),
|
|
23858
|
+
on(event, listener) {
|
|
23859
|
+
instance.on(event, listener);
|
|
23860
|
+
return callableInstance;
|
|
23861
|
+
},
|
|
23862
|
+
off(event, listener) {
|
|
23863
|
+
instance.off(event, listener);
|
|
23864
|
+
return callableInstance;
|
|
23865
|
+
},
|
|
23866
|
+
getRoutes: instance.getRoutes.bind(instance),
|
|
23867
|
+
getState: instance.getState.bind(instance),
|
|
23868
|
+
listen: instance.listen.bind(instance),
|
|
23869
|
+
close: instance.close.bind(instance)
|
|
23870
|
+
});
|
|
23871
|
+
instance.setCallableRef(callableInstance);
|
|
23872
|
+
return callableInstance;
|
|
23873
|
+
}
|
|
23874
|
+
|
|
23875
|
+
// ../openapi/src/utils.ts
|
|
23876
|
+
function isRecord(value) {
|
|
23877
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23878
|
+
}
|
|
23879
|
+
function toJsonSchema(node) {
|
|
23880
|
+
return Object.assign({}, node);
|
|
23881
|
+
}
|
|
23882
|
+
|
|
23883
|
+
// ../openapi/src/callbacks.ts
|
|
23884
|
+
function getRouteCallbacks(route) {
|
|
23885
|
+
const value = route["openapi:callbacks"];
|
|
23886
|
+
return Array.isArray(value) ? value : undefined;
|
|
23887
|
+
}
|
|
23888
|
+
function fireCallbacks(callbacks, context, response) {
|
|
23889
|
+
for (const callback of callbacks) {
|
|
23890
|
+
const url = resolveCallbackUrl(callback.urlExpression, context, response);
|
|
23891
|
+
if (!url || !url.startsWith("http"))
|
|
23892
|
+
continue;
|
|
23893
|
+
const body = Array.isArray(response) ? response[1] : response;
|
|
23894
|
+
fetch(url, {
|
|
23895
|
+
method: callback.method,
|
|
23896
|
+
headers: { "content-type": "application/json" },
|
|
23897
|
+
body: body !== undefined ? JSON.stringify(body) : undefined
|
|
23898
|
+
}).catch(() => {});
|
|
23899
|
+
}
|
|
23900
|
+
}
|
|
23901
|
+
function resolveCallbackUrl(expression, context, response) {
|
|
23902
|
+
return expression.replace(/\{\$([^}]+)\}/g, (_, expr) => {
|
|
23903
|
+
if (expr.startsWith("request.body#")) {
|
|
23904
|
+
const pointer = expr.slice("request.body#".length);
|
|
23905
|
+
const value = resolveJsonPointer(context.body, pointer);
|
|
23906
|
+
return typeof value === "string" ? value : "";
|
|
23743
23907
|
}
|
|
23744
|
-
if (
|
|
23745
|
-
|
|
23746
|
-
|
|
23747
|
-
if (typeof body === "object" && !Buffer.isBuffer(body)) {
|
|
23748
|
-
body = JSON.stringify(body);
|
|
23749
|
-
} else if (typeof body !== "string") {
|
|
23750
|
-
body = String(body);
|
|
23751
|
-
}
|
|
23752
|
-
}
|
|
23908
|
+
if (expr.startsWith("request.header.")) {
|
|
23909
|
+
const headerName = expr.slice("request.header.".length).toLowerCase();
|
|
23910
|
+
return context.headers[headerName] ?? "";
|
|
23753
23911
|
}
|
|
23754
|
-
|
|
23755
|
-
|
|
23756
|
-
|
|
23757
|
-
headers
|
|
23758
|
-
};
|
|
23759
|
-
}
|
|
23760
|
-
async runPluginPipeline(context, initialResponse, _routeConfig, _requestId) {
|
|
23761
|
-
let currentContext = context;
|
|
23762
|
-
let response = initialResponse;
|
|
23763
|
-
this.logger.log("pipeline", `Running plugin pipeline for ${this.plugins.length} plugins`);
|
|
23764
|
-
for (const plugin of this.plugins) {
|
|
23765
|
-
this.logger.log("pipeline", `Processing plugin: ${plugin.name}`);
|
|
23766
|
-
try {
|
|
23767
|
-
const result = await plugin.process(currentContext, response);
|
|
23768
|
-
if (!result || !result.context) {
|
|
23769
|
-
throw new Error(`Plugin ${plugin.name} didn't return valid result`);
|
|
23770
|
-
}
|
|
23771
|
-
currentContext = result.context;
|
|
23772
|
-
if (result.response !== undefined && (response === undefined || response === null)) {
|
|
23773
|
-
this.logger.log("pipeline", `Plugin ${plugin.name} generated response`);
|
|
23774
|
-
response = result.response;
|
|
23775
|
-
} else if (result.response !== undefined && response !== undefined) {
|
|
23776
|
-
this.logger.log("pipeline", `Plugin ${plugin.name} transformed response`);
|
|
23777
|
-
response = result.response;
|
|
23778
|
-
}
|
|
23779
|
-
} catch (error) {
|
|
23780
|
-
this.logger.log("pipeline", `Plugin ${plugin.name} failed: ${errorMessage(error)}`);
|
|
23781
|
-
if (plugin.onError) {
|
|
23782
|
-
try {
|
|
23783
|
-
const pluginError = error instanceof Error ? error : new Error(errorMessage(error));
|
|
23784
|
-
const errorResult = await plugin.onError(pluginError, currentContext);
|
|
23785
|
-
if (errorResult) {
|
|
23786
|
-
this.logger.log("pipeline", `Plugin ${plugin.name} handled error`);
|
|
23787
|
-
if (errorResult instanceof Error) {
|
|
23788
|
-
throw new PluginError(plugin.name, errorResult);
|
|
23789
|
-
}
|
|
23790
|
-
if (typeof errorResult === "object" && errorResult !== null && "status" in errorResult) {
|
|
23791
|
-
response = errorResult;
|
|
23792
|
-
break;
|
|
23793
|
-
}
|
|
23794
|
-
}
|
|
23795
|
-
} catch (hookError) {
|
|
23796
|
-
if (hookError instanceof PluginError) {
|
|
23797
|
-
throw hookError;
|
|
23798
|
-
}
|
|
23799
|
-
this.logger.log("pipeline", `Plugin ${plugin.name} error handler failed: ${errorMessage(hookError)}`);
|
|
23800
|
-
}
|
|
23801
|
-
}
|
|
23802
|
-
const cause = error instanceof Error ? error : new Error(errorMessage(error));
|
|
23803
|
-
throw new PluginError(plugin.name, cause);
|
|
23804
|
-
}
|
|
23912
|
+
if (expr.startsWith("request.query.")) {
|
|
23913
|
+
const queryName = expr.slice("request.query.".length);
|
|
23914
|
+
return context.query[queryName] ?? "";
|
|
23805
23915
|
}
|
|
23806
|
-
|
|
23807
|
-
|
|
23808
|
-
|
|
23809
|
-
const normalizedPath = path.endsWith("/") && path !== "/" ? path.slice(0, -1) : path;
|
|
23810
|
-
const staticMatch = this.staticRoutes.get(`${method} ${normalizedPath}`);
|
|
23811
|
-
if (staticMatch) {
|
|
23812
|
-
return staticMatch;
|
|
23916
|
+
if (expr.startsWith("request.path.")) {
|
|
23917
|
+
const paramName = expr.slice("request.path.".length);
|
|
23918
|
+
return context.params[paramName] ?? "";
|
|
23813
23919
|
}
|
|
23814
|
-
|
|
23815
|
-
|
|
23816
|
-
|
|
23817
|
-
|
|
23920
|
+
if (expr.startsWith("response.body#")) {
|
|
23921
|
+
const pointer = expr.slice("response.body#".length);
|
|
23922
|
+
const responseBody = Array.isArray(response) ? response[1] : response;
|
|
23923
|
+
const value = resolveJsonPointer(responseBody, pointer);
|
|
23924
|
+
return typeof value === "string" ? value : "";
|
|
23818
23925
|
}
|
|
23926
|
+
return "";
|
|
23927
|
+
});
|
|
23928
|
+
}
|
|
23929
|
+
function resolveJsonPointer(obj, pointer) {
|
|
23930
|
+
if (!isRecord(obj) || !pointer.startsWith("/"))
|
|
23819
23931
|
return;
|
|
23932
|
+
const parts = pointer.slice(1).split("/");
|
|
23933
|
+
let current = obj;
|
|
23934
|
+
for (const part of parts) {
|
|
23935
|
+
if (!isRecord(current))
|
|
23936
|
+
return;
|
|
23937
|
+
current = current[part];
|
|
23820
23938
|
}
|
|
23821
|
-
|
|
23822
|
-
const match = path.match(route.pattern);
|
|
23823
|
-
if (!match)
|
|
23824
|
-
return {};
|
|
23825
|
-
const params = {};
|
|
23826
|
-
route.params.forEach((param, index) => {
|
|
23827
|
-
params[param] = match[index + 1];
|
|
23828
|
-
});
|
|
23829
|
-
return params;
|
|
23830
|
-
}
|
|
23939
|
+
return current;
|
|
23831
23940
|
}
|
|
23832
23941
|
|
|
23833
|
-
// ../
|
|
23834
|
-
|
|
23835
|
-
|
|
23836
|
-
|
|
23837
|
-
|
|
23838
|
-
|
|
23839
|
-
|
|
23840
|
-
|
|
23841
|
-
|
|
23842
|
-
return callableInstance;
|
|
23843
|
-
},
|
|
23844
|
-
handle: instance.handle.bind(instance),
|
|
23845
|
-
history: instance.history.bind(instance),
|
|
23846
|
-
called: instance.called.bind(instance),
|
|
23847
|
-
callCount: instance.callCount.bind(instance),
|
|
23848
|
-
lastRequest: instance.lastRequest.bind(instance),
|
|
23849
|
-
reset: instance.reset.bind(instance),
|
|
23850
|
-
resetHistory: instance.resetHistory.bind(instance),
|
|
23851
|
-
resetState: instance.resetState.bind(instance),
|
|
23852
|
-
on: (event, listener) => {
|
|
23853
|
-
instance.on(event, listener);
|
|
23854
|
-
return callableInstance;
|
|
23855
|
-
},
|
|
23856
|
-
off: (event, listener) => {
|
|
23857
|
-
instance.off(event, listener);
|
|
23858
|
-
return callableInstance;
|
|
23859
|
-
},
|
|
23860
|
-
getRoutes: instance.getRoutes.bind(instance),
|
|
23861
|
-
getState: instance.getState.bind(instance),
|
|
23862
|
-
listen: instance.listen.bind(instance),
|
|
23863
|
-
close: instance.close.bind(instance)
|
|
23864
|
-
});
|
|
23865
|
-
instance.setCallableRef(callableInstance);
|
|
23866
|
-
return callableInstance;
|
|
23867
|
-
}
|
|
23942
|
+
// ../openapi/src/generators.ts
|
|
23943
|
+
import { randomUUID } from "node:crypto";
|
|
23944
|
+
|
|
23945
|
+
// ../faker/src/constants.ts
|
|
23946
|
+
var MAX_ARRAY_SIZE = 1e4;
|
|
23947
|
+
var MAX_NESTING_DEPTH = 10;
|
|
23948
|
+
var DEFAULT_ARRAY_COUNT = 3;
|
|
23949
|
+
var DEEP_NESTING_THRESHOLD = 3;
|
|
23950
|
+
var LARGE_ARRAY_THRESHOLD = 100;
|
|
23868
23951
|
|
|
23869
23952
|
// ../../node_modules/@faker-js/faker/dist/chunk-ZES2MVAN.js
|
|
23870
23953
|
var e = [{ name: "Aegean Airlines", iataCode: "A3" }, { name: "Aeroflot", iataCode: "SU" }, { name: "Aerolineas Argentinas", iataCode: "AR" }, { name: "Aeromexico", iataCode: "AM" }, { name: "Air Algerie", iataCode: "AH" }, { name: "Air Arabia", iataCode: "G9" }, { name: "Air Canada", iataCode: "AC" }, { name: "Air China", iataCode: "CA" }, { name: "Air Europa", iataCode: "UX" }, { name: "Air France", iataCode: "AF" }, { name: "Air India", iataCode: "AI" }, { name: "Air Mauritius", iataCode: "MK" }, { name: "Air New Zealand", iataCode: "NZ" }, { name: "Air Niugini", iataCode: "PX" }, { name: "Air Tahiti", iataCode: "VT" }, { name: "Air Tahiti Nui", iataCode: "TN" }, { name: "Air Transat", iataCode: "TS" }, { name: "AirAsia X", iataCode: "D7" }, { name: "AirAsia", iataCode: "AK" }, { name: "Aircalin", iataCode: "SB" }, { name: "Alaska Airlines", iataCode: "AS" }, { name: "Alitalia", iataCode: "AZ" }, { name: "All Nippon Airways", iataCode: "NH" }, { name: "Allegiant Air", iataCode: "G4" }, { name: "American Airlines", iataCode: "AA" }, { name: "Asiana Airlines", iataCode: "OZ" }, { name: "Avianca", iataCode: "AV" }, { name: "Azul Linhas Aereas Brasileiras", iataCode: "AD" }, { name: "Azur Air", iataCode: "ZF" }, { name: "Beijing Capital Airlines", iataCode: "JD" }, { name: "Boliviana de Aviacion", iataCode: "OB" }, { name: "British Airways", iataCode: "BA" }, { name: "Cathay Pacific", iataCode: "CX" }, { name: "Cebu Pacific Air", iataCode: "5J" }, { name: "China Airlines", iataCode: "CI" }, { name: "China Eastern Airlines", iataCode: "MU" }, { name: "China Southern Airlines", iataCode: "CZ" }, { name: "Condor", iataCode: "DE" }, { name: "Copa Airlines", iataCode: "CM" }, { name: "Delta Air Lines", iataCode: "DL" }, { name: "Easyfly", iataCode: "VE" }, { name: "EasyJet", iataCode: "U2" }, { name: "EcoJet", iataCode: "8J" }, { name: "Egyptair", iataCode: "MS" }, { name: "El Al", iataCode: "LY" }, { name: "Emirates Airlines", iataCode: "EK" }, { name: "Ethiopian Airlines", iataCode: "ET" }, { name: "Etihad Airways", iataCode: "EY" }, { name: "EVA Air", iataCode: "BR" }, { name: "Fiji Airways", iataCode: "FJ" }, { name: "Finnair", iataCode: "AY" }, { name: "Flybondi", iataCode: "FO" }, { name: "Flydubai", iataCode: "FZ" }, { name: "FlySafair", iataCode: "FA" }, { name: "Frontier Airlines", iataCode: "F9" }, { name: "Garuda Indonesia", iataCode: "GA" }, { name: "Go First", iataCode: "G8" }, { name: "Gol Linhas Aereas Inteligentes", iataCode: "G3" }, { name: "Hainan Airlines", iataCode: "HU" }, { name: "Hawaiian Airlines", iataCode: "HA" }, { name: "IndiGo Airlines", iataCode: "6E" }, { name: "Japan Airlines", iataCode: "JL" }, { name: "Jeju Air", iataCode: "7C" }, { name: "Jet2", iataCode: "LS" }, { name: "JetBlue Airways", iataCode: "B6" }, { name: "JetSMART", iataCode: "JA" }, { name: "Juneyao Airlines", iataCode: "HO" }, { name: "Kenya Airways", iataCode: "KQ" }, { name: "KLM Royal Dutch Airlines", iataCode: "KL" }, { name: "Korean Air", iataCode: "KE" }, { name: "Kulula.com", iataCode: "MN" }, { name: "LATAM Airlines", iataCode: "LA" }, { name: "Lion Air", iataCode: "JT" }, { name: "LOT Polish Airlines", iataCode: "LO" }, { name: "Lufthansa", iataCode: "LH" }, { name: "Libyan Airlines", iataCode: "LN" }, { name: "Linea Aerea Amaszonas", iataCode: "Z8" }, { name: "Malaysia Airlines", iataCode: "MH" }, { name: "Nordwind Airlines", iataCode: "N4" }, { name: "Norwegian Air Shuttle", iataCode: "DY" }, { name: "Oman Air", iataCode: "WY" }, { name: "Pakistan International Airlines", iataCode: "PK" }, { name: "Pegasus Airlines", iataCode: "PC" }, { name: "Philippine Airlines", iataCode: "PR" }, { name: "Qantas Group", iataCode: "QF" }, { name: "Qatar Airways", iataCode: "QR" }, { name: "Republic Airways", iataCode: "YX" }, { name: "Royal Air Maroc", iataCode: "AT" }, { name: "Ryanair", iataCode: "FR" }, { name: "S7 Airlines", iataCode: "S7" }, { name: "SAS", iataCode: "SK" }, { name: "Satena", iataCode: "9R" }, { name: "Saudia", iataCode: "SV" }, { name: "Shandong Airlines", iataCode: "SC" }, { name: "Sichuan Airlines", iataCode: "3U" }, { name: "Singapore Airlines", iataCode: "SQ" }, { name: "Sky Airline", iataCode: "H2" }, { name: "SkyWest Airlines", iataCode: "OO" }, { name: "South African Airways", iataCode: "SA" }, { name: "Southwest Airlines", iataCode: "WN" }, { name: "SpiceJet", iataCode: "SG" }, { name: "Spirit Airlines", iataCode: "NK" }, { name: "Spring Airlines", iataCode: "9C" }, { name: "SriLankan Airlines", iataCode: "UL" }, { name: "Star Peru", iataCode: "2I" }, { name: "Sun Country Airlines", iataCode: "SY" }, { name: "SunExpress", iataCode: "XQ" }, { name: "TAP Air Portugal", iataCode: "TP" }, { name: "Thai AirAsia", iataCode: "FD" }, { name: "Thai Airways", iataCode: "TG" }, { name: "TUI Airways", iataCode: "BY" }, { name: "Tunisair", iataCode: "TU" }, { name: "Turkish Airlines", iataCode: "TK" }, { name: "Ukraine International", iataCode: "PS" }, { name: "United Airlines", iataCode: "UA" }, { name: "Ural Airlines", iataCode: "U6" }, { name: "VietJet Air", iataCode: "VJ" }, { name: "Vietnam Airlines", iataCode: "VN" }, { name: "Virgin Atlantic Airways", iataCode: "VS" }, { name: "Virgin Australia", iataCode: "VA" }, { name: "VivaAerobus", iataCode: "VB" }, { name: "VOEPASS Linhas Aereas", iataCode: "2Z" }, { name: "Volaris", iataCode: "Y4" }, { name: "WestJet", iataCode: "WS" }, { name: "Wingo", iataCode: "P5" }, { name: "Wizz Air", iataCode: "W6" }];
|
|
@@ -31923,10 +32006,7 @@ if (typeof $RefParser !== "undefined" && typeof JSONPath !== "undefined") {
|
|
|
31923
32006
|
setDependencies({ ...JSONPath, $RefParser });
|
|
31924
32007
|
}
|
|
31925
32008
|
|
|
31926
|
-
// ../faker/src/
|
|
31927
|
-
function isJSONSchema7(value) {
|
|
31928
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31929
|
-
}
|
|
32009
|
+
// ../faker/src/jsf-config.ts
|
|
31930
32010
|
function createFakerInstance(seed) {
|
|
31931
32011
|
const faker = new er2({ locale: [ys] });
|
|
31932
32012
|
if (seed !== undefined) {
|
|
@@ -31967,37 +32047,99 @@ function getJsf(seed) {
|
|
|
31967
32047
|
}
|
|
31968
32048
|
return lib_default;
|
|
31969
32049
|
}
|
|
31970
|
-
|
|
31971
|
-
|
|
31972
|
-
|
|
31973
|
-
|
|
31974
|
-
|
|
31975
|
-
|
|
31976
|
-
const { schema, count, overrides, params, state, query, seed } = options;
|
|
31977
|
-
validateSchema(schema);
|
|
31978
|
-
let generated;
|
|
31979
|
-
if (schema.type === "array" && schema.items) {
|
|
31980
|
-
const itemCount = determineArrayCount(schema, count);
|
|
31981
|
-
if (itemCount > MAX_ARRAY_SIZE) {
|
|
31982
|
-
throw new ResourceLimitError("array_size", MAX_ARRAY_SIZE, itemCount);
|
|
32050
|
+
|
|
32051
|
+
// ../faker/src/overrides.ts
|
|
32052
|
+
function determineArrayCount(schema, explicitCount) {
|
|
32053
|
+
if (explicitCount !== undefined) {
|
|
32054
|
+
if (explicitCount < 0) {
|
|
32055
|
+
return 0;
|
|
31983
32056
|
}
|
|
31984
|
-
|
|
31985
|
-
|
|
31986
|
-
|
|
32057
|
+
return explicitCount;
|
|
32058
|
+
}
|
|
32059
|
+
if (schema.minItems !== undefined && schema.maxItems !== undefined) {
|
|
32060
|
+
return Math.floor(Math.random() * (schema.maxItems - schema.minItems + 1)) + schema.minItems;
|
|
32061
|
+
}
|
|
32062
|
+
if (schema.minItems !== undefined) {
|
|
32063
|
+
return Math.max(schema.minItems, DEFAULT_ARRAY_COUNT);
|
|
32064
|
+
}
|
|
32065
|
+
if (schema.maxItems !== undefined) {
|
|
32066
|
+
return Math.min(schema.maxItems, DEFAULT_ARRAY_COUNT);
|
|
32067
|
+
}
|
|
32068
|
+
return DEFAULT_ARRAY_COUNT;
|
|
32069
|
+
}
|
|
32070
|
+
function applyOverrides(data, overrides, params, state, query) {
|
|
32071
|
+
if (!overrides)
|
|
32072
|
+
return data;
|
|
32073
|
+
const result = structuredClone(data);
|
|
32074
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
32075
|
+
if (key.includes(".")) {
|
|
32076
|
+
setNestedProperty(result, key, value, { params, state, query });
|
|
32077
|
+
} else {
|
|
32078
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
32079
|
+
if (result[key] && typeof result[key] === "object") {
|
|
32080
|
+
result[key] = applyOverrides(result[key], value, params, state, query);
|
|
32081
|
+
} else {
|
|
32082
|
+
result[key] = applyOverrides({}, value, params, state, query);
|
|
32083
|
+
}
|
|
32084
|
+
} else if (typeof value === "string" && value.includes("{{")) {
|
|
32085
|
+
result[key] = processTemplate(value, { params, state, query });
|
|
32086
|
+
} else {
|
|
32087
|
+
result[key] = value;
|
|
32088
|
+
}
|
|
31987
32089
|
}
|
|
31988
|
-
|
|
31989
|
-
|
|
31990
|
-
|
|
31991
|
-
|
|
31992
|
-
|
|
31993
|
-
|
|
32090
|
+
}
|
|
32091
|
+
return result;
|
|
32092
|
+
}
|
|
32093
|
+
function setNestedProperty(obj, path, value, context) {
|
|
32094
|
+
const parts = path.split(".");
|
|
32095
|
+
let current = obj;
|
|
32096
|
+
for (let i2 = 0;i2 < parts.length - 1; i2++) {
|
|
32097
|
+
const part = parts[i2];
|
|
32098
|
+
if (!(part in current) || typeof current[part] !== "object" || current[part] === null) {
|
|
32099
|
+
current[part] = {};
|
|
31994
32100
|
}
|
|
32101
|
+
current = current[part];
|
|
32102
|
+
}
|
|
32103
|
+
const finalKey = parts[parts.length - 1];
|
|
32104
|
+
if (typeof value === "string" && value.includes("{{")) {
|
|
32105
|
+
current[finalKey] = processTemplate(value, context);
|
|
31995
32106
|
} else {
|
|
31996
|
-
|
|
31997
|
-
generated = getJsf(seed).generate(enhancedSchema);
|
|
31998
|
-
generated = applyOverrides(generated, overrides, params, state, query);
|
|
32107
|
+
current[finalKey] = value;
|
|
31999
32108
|
}
|
|
32000
|
-
|
|
32109
|
+
}
|
|
32110
|
+
function processTemplate(template2, context) {
|
|
32111
|
+
const singleTemplateMatch = template2.match(/^\{\{\s*([^}]+)\s*\}\}$/);
|
|
32112
|
+
if (singleTemplateMatch) {
|
|
32113
|
+
const expression = singleTemplateMatch[1];
|
|
32114
|
+
const parts = expression.trim().split(".");
|
|
32115
|
+
let result = context;
|
|
32116
|
+
for (const part of parts) {
|
|
32117
|
+
if (result && typeof result === "object") {
|
|
32118
|
+
result = result[part];
|
|
32119
|
+
} else {
|
|
32120
|
+
return template2;
|
|
32121
|
+
}
|
|
32122
|
+
}
|
|
32123
|
+
return result !== undefined ? result : template2;
|
|
32124
|
+
}
|
|
32125
|
+
const processed = template2.replace(/\{\{\s*([^}]+)\s*\}\}/g, (match, expression) => {
|
|
32126
|
+
const parts = expression.trim().split(".");
|
|
32127
|
+
let result = context;
|
|
32128
|
+
for (const part of parts) {
|
|
32129
|
+
if (result && typeof result === "object") {
|
|
32130
|
+
result = result[part];
|
|
32131
|
+
} else {
|
|
32132
|
+
return match;
|
|
32133
|
+
}
|
|
32134
|
+
}
|
|
32135
|
+
return result !== undefined ? String(result) : match;
|
|
32136
|
+
});
|
|
32137
|
+
return processed;
|
|
32138
|
+
}
|
|
32139
|
+
|
|
32140
|
+
// ../faker/src/validation.ts
|
|
32141
|
+
function isJSONSchema7(value) {
|
|
32142
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
32001
32143
|
}
|
|
32002
32144
|
function validateSchema(schema, path = "$") {
|
|
32003
32145
|
if (!schema || typeof schema !== "object") {
|
|
@@ -32198,93 +32340,6 @@ function checkArraySizeLimits(schema, path) {
|
|
|
32198
32340
|
}
|
|
32199
32341
|
}
|
|
32200
32342
|
}
|
|
32201
|
-
function determineArrayCount(schema, explicitCount) {
|
|
32202
|
-
if (explicitCount !== undefined) {
|
|
32203
|
-
if (explicitCount < 0) {
|
|
32204
|
-
return 0;
|
|
32205
|
-
}
|
|
32206
|
-
return explicitCount;
|
|
32207
|
-
}
|
|
32208
|
-
if (schema.minItems !== undefined && schema.maxItems !== undefined) {
|
|
32209
|
-
return Math.floor(Math.random() * (schema.maxItems - schema.minItems + 1)) + schema.minItems;
|
|
32210
|
-
}
|
|
32211
|
-
if (schema.minItems !== undefined) {
|
|
32212
|
-
return Math.max(schema.minItems, DEFAULT_ARRAY_COUNT);
|
|
32213
|
-
}
|
|
32214
|
-
if (schema.maxItems !== undefined) {
|
|
32215
|
-
return Math.min(schema.maxItems, DEFAULT_ARRAY_COUNT);
|
|
32216
|
-
}
|
|
32217
|
-
return DEFAULT_ARRAY_COUNT;
|
|
32218
|
-
}
|
|
32219
|
-
function applyOverrides(data, overrides, params, state, query) {
|
|
32220
|
-
if (!overrides)
|
|
32221
|
-
return data;
|
|
32222
|
-
const result = structuredClone(data);
|
|
32223
|
-
for (const [key, value] of Object.entries(overrides)) {
|
|
32224
|
-
if (key.includes(".")) {
|
|
32225
|
-
setNestedProperty(result, key, value, { params, state, query });
|
|
32226
|
-
} else {
|
|
32227
|
-
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
32228
|
-
if (result[key] && typeof result[key] === "object") {
|
|
32229
|
-
result[key] = applyOverrides(result[key], value, params, state, query);
|
|
32230
|
-
} else {
|
|
32231
|
-
result[key] = applyOverrides({}, value, params, state, query);
|
|
32232
|
-
}
|
|
32233
|
-
} else if (typeof value === "string" && value.includes("{{")) {
|
|
32234
|
-
result[key] = processTemplate(value, { params, state, query });
|
|
32235
|
-
} else {
|
|
32236
|
-
result[key] = value;
|
|
32237
|
-
}
|
|
32238
|
-
}
|
|
32239
|
-
}
|
|
32240
|
-
return result;
|
|
32241
|
-
}
|
|
32242
|
-
function setNestedProperty(obj, path, value, context) {
|
|
32243
|
-
const parts = path.split(".");
|
|
32244
|
-
let current = obj;
|
|
32245
|
-
for (let i2 = 0;i2 < parts.length - 1; i2++) {
|
|
32246
|
-
const part = parts[i2];
|
|
32247
|
-
if (!(part in current) || typeof current[part] !== "object" || current[part] === null) {
|
|
32248
|
-
current[part] = {};
|
|
32249
|
-
}
|
|
32250
|
-
current = current[part];
|
|
32251
|
-
}
|
|
32252
|
-
const finalKey = parts[parts.length - 1];
|
|
32253
|
-
if (typeof value === "string" && value.includes("{{")) {
|
|
32254
|
-
current[finalKey] = processTemplate(value, context);
|
|
32255
|
-
} else {
|
|
32256
|
-
current[finalKey] = value;
|
|
32257
|
-
}
|
|
32258
|
-
}
|
|
32259
|
-
function processTemplate(template2, context) {
|
|
32260
|
-
const singleTemplateMatch = template2.match(/^\{\{\s*([^}]+)\s*\}\}$/);
|
|
32261
|
-
if (singleTemplateMatch) {
|
|
32262
|
-
const expression = singleTemplateMatch[1];
|
|
32263
|
-
const parts = expression.trim().split(".");
|
|
32264
|
-
let result = context;
|
|
32265
|
-
for (const part of parts) {
|
|
32266
|
-
if (result && typeof result === "object") {
|
|
32267
|
-
result = result[part];
|
|
32268
|
-
} else {
|
|
32269
|
-
return template2;
|
|
32270
|
-
}
|
|
32271
|
-
}
|
|
32272
|
-
return result !== undefined ? result : template2;
|
|
32273
|
-
}
|
|
32274
|
-
const processed = template2.replace(/\{\{\s*([^}]+)\s*\}\}/g, (match, expression) => {
|
|
32275
|
-
const parts = expression.trim().split(".");
|
|
32276
|
-
let result = context;
|
|
32277
|
-
for (const part of parts) {
|
|
32278
|
-
if (result && typeof result === "object") {
|
|
32279
|
-
result = result[part];
|
|
32280
|
-
} else {
|
|
32281
|
-
return match;
|
|
32282
|
-
}
|
|
32283
|
-
}
|
|
32284
|
-
return result !== undefined ? String(result) : match;
|
|
32285
|
-
});
|
|
32286
|
-
return processed;
|
|
32287
|
-
}
|
|
32288
32343
|
function validateFakerMethod(fakerMethod) {
|
|
32289
32344
|
const parts = fakerMethod.split(".");
|
|
32290
32345
|
if (parts.length < 2) {
|
|
@@ -32303,6 +32358,8 @@ function validateFakerMethod(fakerMethod) {
|
|
|
32303
32358
|
throw new SchemaValidationError("$.faker", `Invalid faker method: "${fakerMethod}" is not a function`, "Check faker.js documentation for valid methods");
|
|
32304
32359
|
}
|
|
32305
32360
|
}
|
|
32361
|
+
|
|
32362
|
+
// ../faker/src/schema-enhancement.ts
|
|
32306
32363
|
function enhanceSchemaWithSmartMapping(schema) {
|
|
32307
32364
|
if (!schema || typeof schema !== "object") {
|
|
32308
32365
|
return schema;
|
|
@@ -32357,54 +32414,33 @@ function enhanceFieldSchema(fieldName, fieldSchema) {
|
|
|
32357
32414
|
return enhanced;
|
|
32358
32415
|
}
|
|
32359
32416
|
|
|
32360
|
-
// ../
|
|
32361
|
-
|
|
32362
|
-
|
|
32363
|
-
|
|
32364
|
-
|
|
32365
|
-
if (
|
|
32366
|
-
|
|
32367
|
-
|
|
32368
|
-
|
|
32369
|
-
const [type, ...params] = part.trim().split(";");
|
|
32370
|
-
let q3 = 1;
|
|
32371
|
-
for (const param of params) {
|
|
32372
|
-
const match = param.trim().match(/^q\s*=\s*([\d.]+)$/);
|
|
32373
|
-
if (match) {
|
|
32374
|
-
q3 = Number.parseFloat(match[1]);
|
|
32375
|
-
}
|
|
32376
|
-
}
|
|
32377
|
-
return { type: type.trim(), q: q3 };
|
|
32378
|
-
}).sort((a2, b2) => b2.q - a2.q);
|
|
32379
|
-
for (const entry of entries) {
|
|
32380
|
-
if (entry.q === 0)
|
|
32381
|
-
continue;
|
|
32382
|
-
if (entry.type === "*/*") {
|
|
32383
|
-
return available[0] ?? null;
|
|
32417
|
+
// ../faker/src/index.ts
|
|
32418
|
+
function generateFromSchema(options) {
|
|
32419
|
+
const { schema, count, overrides, params, state, query, seed } = options;
|
|
32420
|
+
validateSchema(schema);
|
|
32421
|
+
let generated;
|
|
32422
|
+
if (schema.type === "array" && schema.items) {
|
|
32423
|
+
const itemCount = determineArrayCount(schema, count);
|
|
32424
|
+
if (itemCount > MAX_ARRAY_SIZE) {
|
|
32425
|
+
throw new ResourceLimitError("array_size", MAX_ARRAY_SIZE, itemCount);
|
|
32384
32426
|
}
|
|
32385
|
-
|
|
32386
|
-
|
|
32387
|
-
|
|
32388
|
-
if (match)
|
|
32389
|
-
return match;
|
|
32390
|
-
continue;
|
|
32427
|
+
const rawItemSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items;
|
|
32428
|
+
if (!rawItemSchema || typeof rawItemSchema === "boolean") {
|
|
32429
|
+
throw new SchemaValidationError("$.items", "Array schema must have valid items definition");
|
|
32391
32430
|
}
|
|
32392
|
-
|
|
32393
|
-
|
|
32431
|
+
const itemSchema = rawItemSchema;
|
|
32432
|
+
generated = [];
|
|
32433
|
+
for (let i2 = 0;i2 < itemCount; i2++) {
|
|
32434
|
+
let item = getJsf(seed).generate(enhanceSchemaWithSmartMapping(itemSchema));
|
|
32435
|
+
item = applyOverrides(item, overrides, params, state, query);
|
|
32436
|
+
generated.push(item);
|
|
32394
32437
|
}
|
|
32438
|
+
} else {
|
|
32439
|
+
const enhancedSchema = enhanceSchemaWithSmartMapping(schema);
|
|
32440
|
+
generated = getJsf(seed).generate(enhancedSchema);
|
|
32441
|
+
generated = applyOverrides(generated, overrides, params, state, query);
|
|
32395
32442
|
}
|
|
32396
|
-
return
|
|
32397
|
-
}
|
|
32398
|
-
|
|
32399
|
-
// ../openapi/src/generators.ts
|
|
32400
|
-
import { randomUUID } from "node:crypto";
|
|
32401
|
-
|
|
32402
|
-
// ../openapi/src/utils.ts
|
|
32403
|
-
function isRecord(value) {
|
|
32404
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
32405
|
-
}
|
|
32406
|
-
function toJsonSchema(node) {
|
|
32407
|
-
return Object.assign({}, node);
|
|
32443
|
+
return generated;
|
|
32408
32444
|
}
|
|
32409
32445
|
|
|
32410
32446
|
// ../openapi/src/generators.ts
|
|
@@ -32831,11 +32867,210 @@ function getSuccessResponseSchema(p3) {
|
|
|
32831
32867
|
if (resp?.schema)
|
|
32832
32868
|
return resp.schema;
|
|
32833
32869
|
}
|
|
32834
|
-
for (const [code, resp] of p3.responses) {
|
|
32835
|
-
if (code >= 200 && code < 300 && resp.schema)
|
|
32836
|
-
return resp.schema;
|
|
32870
|
+
for (const [code, resp] of p3.responses) {
|
|
32871
|
+
if (code >= 200 && code < 300 && resp.schema)
|
|
32872
|
+
return resp.schema;
|
|
32873
|
+
}
|
|
32874
|
+
return;
|
|
32875
|
+
}
|
|
32876
|
+
|
|
32877
|
+
// ../openapi/src/crud-registration.ts
|
|
32878
|
+
function registerCrudRoutes(instance, resource, seedItems, allParsedPaths) {
|
|
32879
|
+
const ensureSeeded = createSeeder(resource, seedItems);
|
|
32880
|
+
for (const op of resource.operations) {
|
|
32881
|
+
const meta = resource.operationMeta?.get(op);
|
|
32882
|
+
const routeEntries = getCrudRouteEntries(op, resource);
|
|
32883
|
+
for (const { routeKey, method } of routeEntries) {
|
|
32884
|
+
const gen = createCrudGenerator(op, resource, meta);
|
|
32885
|
+
const parsedPath = allParsedPaths.get(`${method} ${resource.basePath}`) ?? allParsedPaths.get(`${method} ${resource.itemPath}`);
|
|
32886
|
+
const config = {};
|
|
32887
|
+
if (parsedPath) {
|
|
32888
|
+
config["openapi:responses"] = parsedPath.responses;
|
|
32889
|
+
config["openapi:path"] = parsedPath.path;
|
|
32890
|
+
config["openapi:requestBody"] = parsedPath.requestBody;
|
|
32891
|
+
config["openapi:security"] = parsedPath.security;
|
|
32892
|
+
config["openapi:callbacks"] = parsedPath.callbacks;
|
|
32893
|
+
}
|
|
32894
|
+
instance(routeKey, wrapWithSeeder(ensureSeeded, gen), config);
|
|
32895
|
+
}
|
|
32896
|
+
}
|
|
32897
|
+
}
|
|
32898
|
+
function registerNonCrudRoutes(instance, nonCrudPaths, fakerSeed) {
|
|
32899
|
+
for (const parsedPath of nonCrudPaths) {
|
|
32900
|
+
const routeKey = `${parsedPath.method} ${parsedPath.path}`;
|
|
32901
|
+
const config = {
|
|
32902
|
+
"openapi:responses": parsedPath.responses,
|
|
32903
|
+
"openapi:path": parsedPath.path,
|
|
32904
|
+
"openapi:requestBody": parsedPath.requestBody,
|
|
32905
|
+
"openapi:security": parsedPath.security,
|
|
32906
|
+
"openapi:callbacks": parsedPath.callbacks
|
|
32907
|
+
};
|
|
32908
|
+
instance(routeKey, createStaticGenerator(parsedPath, fakerSeed), config);
|
|
32909
|
+
}
|
|
32910
|
+
}
|
|
32911
|
+
function getCrudRouteEntries(op, resource) {
|
|
32912
|
+
switch (op) {
|
|
32913
|
+
case "list":
|
|
32914
|
+
return [
|
|
32915
|
+
{
|
|
32916
|
+
routeKey: `GET ${resource.basePath}`,
|
|
32917
|
+
method: "GET"
|
|
32918
|
+
}
|
|
32919
|
+
];
|
|
32920
|
+
case "create":
|
|
32921
|
+
return [
|
|
32922
|
+
{
|
|
32923
|
+
routeKey: `POST ${resource.basePath}`,
|
|
32924
|
+
method: "POST"
|
|
32925
|
+
}
|
|
32926
|
+
];
|
|
32927
|
+
case "read":
|
|
32928
|
+
return [
|
|
32929
|
+
{
|
|
32930
|
+
routeKey: `GET ${resource.itemPath}`,
|
|
32931
|
+
method: "GET"
|
|
32932
|
+
}
|
|
32933
|
+
];
|
|
32934
|
+
case "update":
|
|
32935
|
+
return [
|
|
32936
|
+
{
|
|
32937
|
+
routeKey: `PUT ${resource.itemPath}`,
|
|
32938
|
+
method: "PUT"
|
|
32939
|
+
},
|
|
32940
|
+
{
|
|
32941
|
+
routeKey: `PATCH ${resource.itemPath}`,
|
|
32942
|
+
method: "PATCH"
|
|
32943
|
+
}
|
|
32944
|
+
];
|
|
32945
|
+
case "delete":
|
|
32946
|
+
return [
|
|
32947
|
+
{
|
|
32948
|
+
routeKey: `DELETE ${resource.itemPath}`,
|
|
32949
|
+
method: "DELETE"
|
|
32950
|
+
}
|
|
32951
|
+
];
|
|
32952
|
+
}
|
|
32953
|
+
}
|
|
32954
|
+
function createCrudGenerator(op, resource, meta) {
|
|
32955
|
+
switch (op) {
|
|
32956
|
+
case "list":
|
|
32957
|
+
return createListGenerator(resource, meta);
|
|
32958
|
+
case "create":
|
|
32959
|
+
return createCreateGenerator(resource, meta);
|
|
32960
|
+
case "read":
|
|
32961
|
+
return createReadGenerator(resource, meta);
|
|
32962
|
+
case "update":
|
|
32963
|
+
return createUpdateGenerator(resource, meta);
|
|
32964
|
+
case "delete":
|
|
32965
|
+
return createDeleteGenerator(resource, meta);
|
|
32966
|
+
}
|
|
32967
|
+
}
|
|
32968
|
+
function createSeeder(resource, seedItems) {
|
|
32969
|
+
const stateKey = `openapi:collections:${resource.name}`;
|
|
32970
|
+
const counterKey = `openapi:counter:${resource.name}`;
|
|
32971
|
+
const seededKey = `openapi:seeded:${resource.name}`;
|
|
32972
|
+
return (state) => {
|
|
32973
|
+
if (state[seededKey])
|
|
32974
|
+
return;
|
|
32975
|
+
state[seededKey] = true;
|
|
32976
|
+
if (seedItems && seedItems.length > 0) {
|
|
32977
|
+
state[stateKey] = [...seedItems];
|
|
32978
|
+
let maxId = 0;
|
|
32979
|
+
for (const item of seedItems) {
|
|
32980
|
+
if (isRecord(item) && resource.idParam in item) {
|
|
32981
|
+
const id = item[resource.idParam];
|
|
32982
|
+
if (typeof id === "number" && id > maxId) {
|
|
32983
|
+
maxId = id;
|
|
32984
|
+
}
|
|
32985
|
+
}
|
|
32986
|
+
}
|
|
32987
|
+
state[counterKey] = maxId;
|
|
32988
|
+
} else {
|
|
32989
|
+
state[stateKey] = [];
|
|
32990
|
+
state[counterKey] = 0;
|
|
32991
|
+
}
|
|
32992
|
+
};
|
|
32993
|
+
}
|
|
32994
|
+
function wrapWithSeeder(seeder, generator) {
|
|
32995
|
+
return (ctx) => {
|
|
32996
|
+
seeder(ctx.state);
|
|
32997
|
+
return generator(ctx);
|
|
32998
|
+
};
|
|
32999
|
+
}
|
|
33000
|
+
function applyOverrides2(resource, override) {
|
|
33001
|
+
if (!resource.operationMeta) {
|
|
33002
|
+
resource.operationMeta = new Map;
|
|
33003
|
+
}
|
|
33004
|
+
if (override.listWrapProperty !== undefined || override.listFlat !== undefined) {
|
|
33005
|
+
const listMeta = resource.operationMeta.get("list") ?? {};
|
|
33006
|
+
if (override.listFlat) {
|
|
33007
|
+
delete listMeta.responseSchema;
|
|
33008
|
+
} else if (override.listWrapProperty && listMeta.responseSchema) {
|
|
33009
|
+
const arrayInfo = findArrayProperty(listMeta.responseSchema);
|
|
33010
|
+
if (!arrayInfo.property || arrayInfo.property !== override.listWrapProperty) {
|
|
33011
|
+
const itemSchema = arrayInfo.itemSchema ?? resource.schema ?? {};
|
|
33012
|
+
listMeta.responseSchema = {
|
|
33013
|
+
type: "object",
|
|
33014
|
+
properties: {
|
|
33015
|
+
[override.listWrapProperty]: {
|
|
33016
|
+
type: "array",
|
|
33017
|
+
items: itemSchema
|
|
33018
|
+
}
|
|
33019
|
+
}
|
|
33020
|
+
};
|
|
33021
|
+
}
|
|
33022
|
+
} else if (override.listWrapProperty) {
|
|
33023
|
+
const itemSchema = resource.schema ?? {};
|
|
33024
|
+
listMeta.responseSchema = {
|
|
33025
|
+
type: "object",
|
|
33026
|
+
properties: {
|
|
33027
|
+
[override.listWrapProperty]: {
|
|
33028
|
+
type: "array",
|
|
33029
|
+
items: itemSchema
|
|
33030
|
+
}
|
|
33031
|
+
}
|
|
33032
|
+
};
|
|
33033
|
+
}
|
|
33034
|
+
resource.operationMeta.set("list", listMeta);
|
|
33035
|
+
}
|
|
33036
|
+
if (override.errorSchema) {
|
|
33037
|
+
const errorSchemaMap = new Map;
|
|
33038
|
+
errorSchemaMap.set(404, override.errorSchema);
|
|
33039
|
+
errorSchemaMap.set(400, override.errorSchema);
|
|
33040
|
+
errorSchemaMap.set(409, override.errorSchema);
|
|
33041
|
+
for (const op of ["read", "update", "delete"]) {
|
|
33042
|
+
const meta = resource.operationMeta.get(op) ?? {};
|
|
33043
|
+
meta.errorSchemas = errorSchemaMap;
|
|
33044
|
+
resource.operationMeta.set(op, meta);
|
|
33045
|
+
}
|
|
33046
|
+
}
|
|
33047
|
+
}
|
|
33048
|
+
function logResourceDetection(resource, override) {
|
|
33049
|
+
const listMeta = resource.operationMeta?.get("list");
|
|
33050
|
+
let listFormat = "flat";
|
|
33051
|
+
if (listMeta?.responseSchema) {
|
|
33052
|
+
const arrayInfo = findArrayProperty(listMeta.responseSchema);
|
|
33053
|
+
if (arrayInfo.property) {
|
|
33054
|
+
const hasAllOf = "allOf" in (listMeta.responseSchema ?? {});
|
|
33055
|
+
listFormat = `wrapped("${arrayInfo.property}"${hasAllOf ? " via allOf" : ""})`;
|
|
33056
|
+
}
|
|
33057
|
+
}
|
|
33058
|
+
const readMeta = resource.operationMeta?.get("read");
|
|
33059
|
+
const errorFormat = readMeta?.errorSchemas?.has(404) ? "schema(404)" : "default";
|
|
33060
|
+
const headerCount = listMeta?.responseHeaders ? Object.keys(listMeta.responseHeaders).length : 0;
|
|
33061
|
+
console.log(`[@schmock/openapi] ${resource.name}: list=${listFormat}, error=${errorFormat}, headers=${headerCount}`);
|
|
33062
|
+
if (override) {
|
|
33063
|
+
const definedKeys = [];
|
|
33064
|
+
if (override.listWrapProperty !== undefined)
|
|
33065
|
+
definedKeys.push("listWrapProperty");
|
|
33066
|
+
if (override.listFlat !== undefined)
|
|
33067
|
+
definedKeys.push("listFlat");
|
|
33068
|
+
if (override.errorSchema !== undefined)
|
|
33069
|
+
definedKeys.push("errorSchema");
|
|
33070
|
+
if (definedKeys.length > 0) {
|
|
33071
|
+
console.log(`[@schmock/openapi] Override applied: ${resource.name}.${definedKeys.join(", ")}`);
|
|
33072
|
+
}
|
|
32837
33073
|
}
|
|
32838
|
-
return;
|
|
32839
33074
|
}
|
|
32840
33075
|
|
|
32841
33076
|
// ../openapi/src/parser.ts
|
|
@@ -33363,6 +33598,45 @@ function extractCallbacks(callbacks) {
|
|
|
33363
33598
|
return result.length > 0 ? result : undefined;
|
|
33364
33599
|
}
|
|
33365
33600
|
|
|
33601
|
+
// ../openapi/src/request-pipeline.ts
|
|
33602
|
+
var import_ajv = __toESM(require_ajv(), 1);
|
|
33603
|
+
|
|
33604
|
+
// ../openapi/src/content-negotiation.ts
|
|
33605
|
+
function negotiateContentType(accept, available) {
|
|
33606
|
+
if (!accept || accept === "*/*") {
|
|
33607
|
+
return available[0] ?? null;
|
|
33608
|
+
}
|
|
33609
|
+
const entries = accept.split(",").map((part) => {
|
|
33610
|
+
const [type, ...params] = part.trim().split(";");
|
|
33611
|
+
let q3 = 1;
|
|
33612
|
+
for (const param of params) {
|
|
33613
|
+
const match = param.trim().match(/^q\s*=\s*([\d.]+)$/);
|
|
33614
|
+
if (match) {
|
|
33615
|
+
q3 = Number.parseFloat(match[1]);
|
|
33616
|
+
}
|
|
33617
|
+
}
|
|
33618
|
+
return { type: type.trim(), q: q3 };
|
|
33619
|
+
}).sort((a2, b2) => b2.q - a2.q);
|
|
33620
|
+
for (const entry of entries) {
|
|
33621
|
+
if (entry.q === 0)
|
|
33622
|
+
continue;
|
|
33623
|
+
if (entry.type === "*/*") {
|
|
33624
|
+
return available[0] ?? null;
|
|
33625
|
+
}
|
|
33626
|
+
if (entry.type.endsWith("/*")) {
|
|
33627
|
+
const prefix = entry.type.slice(0, -1);
|
|
33628
|
+
const match = available.find((ct) => ct.startsWith(prefix));
|
|
33629
|
+
if (match)
|
|
33630
|
+
return match;
|
|
33631
|
+
continue;
|
|
33632
|
+
}
|
|
33633
|
+
if (available.includes(entry.type)) {
|
|
33634
|
+
return entry.type;
|
|
33635
|
+
}
|
|
33636
|
+
}
|
|
33637
|
+
return null;
|
|
33638
|
+
}
|
|
33639
|
+
|
|
33366
33640
|
// ../openapi/src/prefer.ts
|
|
33367
33641
|
function parsePreferHeader(value) {
|
|
33368
33642
|
const result = {};
|
|
@@ -33385,107 +33659,21 @@ function parsePreferHeader(value) {
|
|
|
33385
33659
|
return result;
|
|
33386
33660
|
}
|
|
33387
33661
|
|
|
33388
|
-
// ../openapi/src/
|
|
33389
|
-
|
|
33390
|
-
|
|
33391
|
-
|
|
33392
|
-
for (const [resourceName, source] of Object.entries(config)) {
|
|
33393
|
-
const resource = resources.find((r2) => r2.name === resourceName);
|
|
33394
|
-
if (Array.isArray(source)) {
|
|
33395
|
-
result.set(resourceName, [...source]);
|
|
33396
|
-
} else if (typeof source === "string") {
|
|
33397
|
-
const content = readFileSync(source, "utf-8");
|
|
33398
|
-
let parsed;
|
|
33399
|
-
try {
|
|
33400
|
-
parsed = JSON.parse(content);
|
|
33401
|
-
} catch {
|
|
33402
|
-
throw new Error(`Seed file "${source}" for resource "${resourceName}" contains invalid JSON`);
|
|
33403
|
-
}
|
|
33404
|
-
if (!Array.isArray(parsed)) {
|
|
33405
|
-
throw new Error(`Seed file "${source}" for resource "${resourceName}" must contain a JSON array`);
|
|
33406
|
-
}
|
|
33407
|
-
result.set(resourceName, parsed);
|
|
33408
|
-
} else if (typeof source === "object" && source !== null && "count" in source) {
|
|
33409
|
-
const rawCount = source.count;
|
|
33410
|
-
if (typeof rawCount !== "number" || !Number.isInteger(rawCount) || rawCount < 0) {
|
|
33411
|
-
throw new Error(`Seed count for "${resourceName}" must be a non-negative integer, got: ${String(rawCount)}`);
|
|
33412
|
-
}
|
|
33413
|
-
if (!resource?.schema) {
|
|
33414
|
-
throw new Error(`Cannot auto-generate seed for "${resourceName}": no schema found in spec`);
|
|
33415
|
-
}
|
|
33416
|
-
const items = generateSeedItems(resource.schema, rawCount, resource.idParam);
|
|
33417
|
-
result.set(resourceName, items);
|
|
33418
|
-
}
|
|
33419
|
-
}
|
|
33420
|
-
return result;
|
|
33662
|
+
// ../openapi/src/request-pipeline.ts
|
|
33663
|
+
function getRouteSecurity(route) {
|
|
33664
|
+
const value = route["openapi:security"];
|
|
33665
|
+
return Array.isArray(value) ? value : undefined;
|
|
33421
33666
|
}
|
|
33422
|
-
|
|
33423
|
-
|
|
33424
|
-
|
|
33425
|
-
|
|
33426
|
-
|
|
33427
|
-
const
|
|
33428
|
-
|
|
33429
|
-
for (const pp of [...spec.paths]) {
|
|
33430
|
-
allParsedPaths.set(`${pp.method} ${pp.path}`, pp);
|
|
33431
|
-
}
|
|
33432
|
-
const securitySchemes = spec.securitySchemes;
|
|
33433
|
-
const globalSecurity = spec.globalSecurity;
|
|
33434
|
-
return {
|
|
33435
|
-
name: "@schmock/openapi",
|
|
33436
|
-
version: "1.4.0",
|
|
33437
|
-
install(instance) {
|
|
33438
|
-
if (options.debug) {
|
|
33439
|
-
console.log(`[@schmock/openapi] Detected ${resources.length} CRUD resources, ${nonCrudPaths.length} static routes`);
|
|
33440
|
-
}
|
|
33441
|
-
for (const resource of resources) {
|
|
33442
|
-
const override = options.resources?.[resource.name];
|
|
33443
|
-
if (override) {
|
|
33444
|
-
applyOverrides2(resource, override);
|
|
33445
|
-
}
|
|
33446
|
-
if (options.debug) {
|
|
33447
|
-
logResourceDetection(resource, override);
|
|
33448
|
-
}
|
|
33449
|
-
registerCrudRoutes(instance, resource, seedData.get(resource.name), allParsedPaths);
|
|
33450
|
-
}
|
|
33451
|
-
for (const parsedPath of nonCrudPaths) {
|
|
33452
|
-
const routeKey = `${parsedPath.method} ${parsedPath.path}`;
|
|
33453
|
-
const config = {
|
|
33454
|
-
"openapi:responses": parsedPath.responses,
|
|
33455
|
-
"openapi:path": parsedPath.path,
|
|
33456
|
-
"openapi:requestBody": parsedPath.requestBody,
|
|
33457
|
-
"openapi:security": parsedPath.security,
|
|
33458
|
-
"openapi:callbacks": parsedPath.callbacks
|
|
33459
|
-
};
|
|
33460
|
-
instance(routeKey, createStaticGenerator(parsedPath, options.fakerSeed), config);
|
|
33461
|
-
}
|
|
33462
|
-
},
|
|
33463
|
-
process(context, response) {
|
|
33464
|
-
if (options.security && securitySchemes) {
|
|
33465
|
-
const securityResult = validateSecurity(context, securitySchemes, globalSecurity);
|
|
33466
|
-
if (securityResult)
|
|
33467
|
-
return securityResult;
|
|
33468
|
-
}
|
|
33469
|
-
const contentResult = processContentNegotiation(context);
|
|
33470
|
-
if (contentResult)
|
|
33471
|
-
return contentResult;
|
|
33472
|
-
if (options.validateRequests) {
|
|
33473
|
-
const validationResult = validateRequestBody(context);
|
|
33474
|
-
if (validationResult) {
|
|
33475
|
-
return validationResult;
|
|
33476
|
-
}
|
|
33477
|
-
}
|
|
33478
|
-
const result = processPreferHeader(context, response, options.fakerSeed);
|
|
33479
|
-
const callbacks = context.route["openapi:callbacks"];
|
|
33480
|
-
if (callbacks && callbacks.length > 0) {
|
|
33481
|
-
fireCallbacks(callbacks, context, result.response);
|
|
33482
|
-
}
|
|
33483
|
-
return result;
|
|
33484
|
-
}
|
|
33485
|
-
};
|
|
33667
|
+
function getRouteResponses(route) {
|
|
33668
|
+
const value = route["openapi:responses"];
|
|
33669
|
+
return value instanceof Map ? value : undefined;
|
|
33670
|
+
}
|
|
33671
|
+
function getRouteRequestBody(route) {
|
|
33672
|
+
const value = route["openapi:requestBody"];
|
|
33673
|
+
return isRecord(value) ? value : undefined;
|
|
33486
33674
|
}
|
|
33487
33675
|
function validateSecurity(context, schemes, globalSecurity) {
|
|
33488
|
-
const routeSecurity = context.route
|
|
33676
|
+
const routeSecurity = getRouteSecurity(context.route);
|
|
33489
33677
|
const security = routeSecurity ?? globalSecurity;
|
|
33490
33678
|
if (!security || security.length === 0)
|
|
33491
33679
|
return;
|
|
@@ -33567,7 +33755,7 @@ function processContentNegotiation(context) {
|
|
|
33567
33755
|
const accept = context.headers.accept ?? context.headers.Accept;
|
|
33568
33756
|
if (!accept || accept === "*/*")
|
|
33569
33757
|
return;
|
|
33570
|
-
const responses = context.route
|
|
33758
|
+
const responses = getRouteResponses(context.route);
|
|
33571
33759
|
if (!responses)
|
|
33572
33760
|
return;
|
|
33573
33761
|
const allContentTypes = new Set;
|
|
@@ -33596,46 +33784,9 @@ function processContentNegotiation(context) {
|
|
|
33596
33784
|
}
|
|
33597
33785
|
return;
|
|
33598
33786
|
}
|
|
33599
|
-
function processPreferHeader(context, response, fakerSeed) {
|
|
33600
|
-
const preferValue = context.headers.prefer ?? context.headers.Prefer;
|
|
33601
|
-
if (!preferValue) {
|
|
33602
|
-
return { context, response };
|
|
33603
|
-
}
|
|
33604
|
-
const prefer = parsePreferHeader(preferValue);
|
|
33605
|
-
const responses = context.route["openapi:responses"];
|
|
33606
|
-
if (!responses) {
|
|
33607
|
-
return { context, response };
|
|
33608
|
-
}
|
|
33609
|
-
if (prefer.code !== undefined) {
|
|
33610
|
-
const entry = responses.get(prefer.code);
|
|
33611
|
-
if (entry) {
|
|
33612
|
-
const body = entry.schema ? generateResponseBody(entry.schema, fakerSeed) : {};
|
|
33613
|
-
return { context, response: [prefer.code, body] };
|
|
33614
|
-
}
|
|
33615
|
-
}
|
|
33616
|
-
if (prefer.example !== undefined) {
|
|
33617
|
-
for (const [code, entry] of responses) {
|
|
33618
|
-
if (entry.examples?.has(prefer.example)) {
|
|
33619
|
-
return {
|
|
33620
|
-
context,
|
|
33621
|
-
response: [code, entry.examples.get(prefer.example)]
|
|
33622
|
-
};
|
|
33623
|
-
}
|
|
33624
|
-
}
|
|
33625
|
-
}
|
|
33626
|
-
if (prefer.dynamic) {
|
|
33627
|
-
for (const [code, entry] of responses) {
|
|
33628
|
-
if (code >= 200 && code < 300 && entry.schema) {
|
|
33629
|
-
const body = generateResponseBody(entry.schema, fakerSeed);
|
|
33630
|
-
return { context, response: [code, body] };
|
|
33631
|
-
}
|
|
33632
|
-
}
|
|
33633
|
-
}
|
|
33634
|
-
return { context, response };
|
|
33635
|
-
}
|
|
33636
33787
|
var ajv = new import_ajv.default({ allErrors: true });
|
|
33637
33788
|
function validateRequestBody(context) {
|
|
33638
|
-
const requestBodySchema = context.route
|
|
33789
|
+
const requestBodySchema = getRouteRequestBody(context.route);
|
|
33639
33790
|
if (!requestBodySchema || context.body === undefined) {
|
|
33640
33791
|
return;
|
|
33641
33792
|
}
|
|
@@ -33660,58 +33811,42 @@ function validateRequestBody(context) {
|
|
|
33660
33811
|
}
|
|
33661
33812
|
return;
|
|
33662
33813
|
}
|
|
33663
|
-
function
|
|
33664
|
-
|
|
33665
|
-
|
|
33666
|
-
|
|
33667
|
-
|
|
33668
|
-
|
|
33669
|
-
|
|
33670
|
-
|
|
33671
|
-
|
|
33672
|
-
|
|
33673
|
-
|
|
33674
|
-
|
|
33675
|
-
|
|
33676
|
-
|
|
33677
|
-
|
|
33678
|
-
if (expr.startsWith("request.path.")) {
|
|
33679
|
-
const paramName = expr.slice("request.path.".length);
|
|
33680
|
-
return context.params[paramName] ?? "";
|
|
33814
|
+
function processPreferHeader(context, response, fakerSeed) {
|
|
33815
|
+
const preferValue = context.headers.prefer ?? context.headers.Prefer;
|
|
33816
|
+
if (!preferValue) {
|
|
33817
|
+
return { context, response };
|
|
33818
|
+
}
|
|
33819
|
+
const prefer = parsePreferHeader(preferValue);
|
|
33820
|
+
const responses = getRouteResponses(context.route);
|
|
33821
|
+
if (!responses) {
|
|
33822
|
+
return { context, response };
|
|
33823
|
+
}
|
|
33824
|
+
if (prefer.code !== undefined) {
|
|
33825
|
+
const entry = responses.get(prefer.code);
|
|
33826
|
+
if (entry) {
|
|
33827
|
+
const body = entry.schema ? generateResponseBody(entry.schema, fakerSeed) : {};
|
|
33828
|
+
return { context, response: [prefer.code, body] };
|
|
33681
33829
|
}
|
|
33682
|
-
|
|
33683
|
-
|
|
33684
|
-
|
|
33685
|
-
|
|
33686
|
-
|
|
33830
|
+
}
|
|
33831
|
+
if (prefer.example !== undefined) {
|
|
33832
|
+
for (const [code, entry] of responses) {
|
|
33833
|
+
if (entry.examples?.has(prefer.example)) {
|
|
33834
|
+
return {
|
|
33835
|
+
context,
|
|
33836
|
+
response: [code, entry.examples.get(prefer.example)]
|
|
33837
|
+
};
|
|
33838
|
+
}
|
|
33687
33839
|
}
|
|
33688
|
-
return "";
|
|
33689
|
-
});
|
|
33690
|
-
}
|
|
33691
|
-
function resolveJsonPointer(obj, pointer) {
|
|
33692
|
-
if (!isRecord(obj) || !pointer.startsWith("/"))
|
|
33693
|
-
return;
|
|
33694
|
-
const parts = pointer.slice(1).split("/");
|
|
33695
|
-
let current = obj;
|
|
33696
|
-
for (const part of parts) {
|
|
33697
|
-
if (!isRecord(current))
|
|
33698
|
-
return;
|
|
33699
|
-
current = current[part];
|
|
33700
33840
|
}
|
|
33701
|
-
|
|
33702
|
-
|
|
33703
|
-
|
|
33704
|
-
|
|
33705
|
-
|
|
33706
|
-
|
|
33707
|
-
|
|
33708
|
-
const body = Array.isArray(response) ? response[1] : response;
|
|
33709
|
-
fetch(url, {
|
|
33710
|
-
method: callback.method,
|
|
33711
|
-
headers: { "content-type": "application/json" },
|
|
33712
|
-
body: body !== undefined ? JSON.stringify(body) : undefined
|
|
33713
|
-
}).catch(() => {});
|
|
33841
|
+
if (prefer.dynamic) {
|
|
33842
|
+
for (const [code, entry] of responses) {
|
|
33843
|
+
if (code >= 200 && code < 300 && entry.schema) {
|
|
33844
|
+
const body = generateResponseBody(entry.schema, fakerSeed);
|
|
33845
|
+
return { context, response: [code, body] };
|
|
33846
|
+
}
|
|
33847
|
+
}
|
|
33714
33848
|
}
|
|
33849
|
+
return { context, response };
|
|
33715
33850
|
}
|
|
33716
33851
|
function generateResponseBody(schema, seed) {
|
|
33717
33852
|
try {
|
|
@@ -33720,189 +33855,95 @@ function generateResponseBody(schema, seed) {
|
|
|
33720
33855
|
return {};
|
|
33721
33856
|
}
|
|
33722
33857
|
}
|
|
33723
|
-
|
|
33724
|
-
|
|
33725
|
-
|
|
33726
|
-
|
|
33727
|
-
|
|
33728
|
-
|
|
33729
|
-
|
|
33730
|
-
|
|
33731
|
-
|
|
33732
|
-
|
|
33733
|
-
|
|
33734
|
-
|
|
33735
|
-
|
|
33736
|
-
|
|
33737
|
-
|
|
33858
|
+
|
|
33859
|
+
// ../openapi/src/seed.ts
|
|
33860
|
+
import { readFileSync } from "node:fs";
|
|
33861
|
+
function loadSeed(config, resources) {
|
|
33862
|
+
const result = new Map;
|
|
33863
|
+
for (const [resourceName, source] of Object.entries(config)) {
|
|
33864
|
+
const resource = resources.find((r2) => r2.name === resourceName);
|
|
33865
|
+
if (Array.isArray(source)) {
|
|
33866
|
+
result.set(resourceName, [...source]);
|
|
33867
|
+
} else if (typeof source === "string") {
|
|
33868
|
+
const content = readFileSync(source, "utf-8");
|
|
33869
|
+
let parsed;
|
|
33870
|
+
try {
|
|
33871
|
+
parsed = JSON.parse(content);
|
|
33872
|
+
} catch {
|
|
33873
|
+
throw new Error(`Seed file "${source}" for resource "${resourceName}" contains invalid JSON`);
|
|
33738
33874
|
}
|
|
33739
|
-
|
|
33875
|
+
if (!Array.isArray(parsed)) {
|
|
33876
|
+
throw new Error(`Seed file "${source}" for resource "${resourceName}" must contain a JSON array`);
|
|
33877
|
+
}
|
|
33878
|
+
result.set(resourceName, parsed);
|
|
33879
|
+
} else if (typeof source === "object" && source !== null && "count" in source) {
|
|
33880
|
+
const rawCount = source.count;
|
|
33881
|
+
if (typeof rawCount !== "number" || !Number.isInteger(rawCount) || rawCount < 0) {
|
|
33882
|
+
throw new Error(`Seed count for "${resourceName}" must be a non-negative integer, got: ${String(rawCount)}`);
|
|
33883
|
+
}
|
|
33884
|
+
if (!resource?.schema) {
|
|
33885
|
+
throw new Error(`Cannot auto-generate seed for "${resourceName}": no schema found in spec`);
|
|
33886
|
+
}
|
|
33887
|
+
const items = generateSeedItems(resource.schema, rawCount, resource.idParam);
|
|
33888
|
+
result.set(resourceName, items);
|
|
33740
33889
|
}
|
|
33741
33890
|
}
|
|
33891
|
+
return result;
|
|
33742
33892
|
}
|
|
33743
|
-
|
|
33744
|
-
|
|
33745
|
-
|
|
33746
|
-
|
|
33747
|
-
|
|
33748
|
-
|
|
33749
|
-
|
|
33750
|
-
|
|
33751
|
-
|
|
33752
|
-
case "create":
|
|
33753
|
-
return [
|
|
33754
|
-
{
|
|
33755
|
-
routeKey: `POST ${resource.basePath}`,
|
|
33756
|
-
method: "POST"
|
|
33757
|
-
}
|
|
33758
|
-
];
|
|
33759
|
-
case "read":
|
|
33760
|
-
return [
|
|
33761
|
-
{
|
|
33762
|
-
routeKey: `GET ${resource.itemPath}`,
|
|
33763
|
-
method: "GET"
|
|
33764
|
-
}
|
|
33765
|
-
];
|
|
33766
|
-
case "update":
|
|
33767
|
-
return [
|
|
33768
|
-
{
|
|
33769
|
-
routeKey: `PUT ${resource.itemPath}`,
|
|
33770
|
-
method: "PUT"
|
|
33771
|
-
},
|
|
33772
|
-
{
|
|
33773
|
-
routeKey: `PATCH ${resource.itemPath}`,
|
|
33774
|
-
method: "PATCH"
|
|
33775
|
-
}
|
|
33776
|
-
];
|
|
33777
|
-
case "delete":
|
|
33778
|
-
return [
|
|
33779
|
-
{
|
|
33780
|
-
routeKey: `DELETE ${resource.itemPath}`,
|
|
33781
|
-
method: "DELETE"
|
|
33782
|
-
}
|
|
33783
|
-
];
|
|
33784
|
-
}
|
|
33785
|
-
}
|
|
33786
|
-
function createCrudGenerator(op, resource, meta) {
|
|
33787
|
-
switch (op) {
|
|
33788
|
-
case "list":
|
|
33789
|
-
return createListGenerator(resource, meta);
|
|
33790
|
-
case "create":
|
|
33791
|
-
return createCreateGenerator(resource, meta);
|
|
33792
|
-
case "read":
|
|
33793
|
-
return createReadGenerator(resource, meta);
|
|
33794
|
-
case "update":
|
|
33795
|
-
return createUpdateGenerator(resource, meta);
|
|
33796
|
-
case "delete":
|
|
33797
|
-
return createDeleteGenerator(resource, meta);
|
|
33893
|
+
|
|
33894
|
+
// ../openapi/src/plugin.ts
|
|
33895
|
+
async function openapi(options) {
|
|
33896
|
+
const spec = await parseSpec(options.spec);
|
|
33897
|
+
const { resources, nonCrudPaths } = detectCrudResources(spec.paths);
|
|
33898
|
+
const seedData = options.seed ? loadSeed(options.seed, resources) : new Map;
|
|
33899
|
+
const allParsedPaths = new Map;
|
|
33900
|
+
for (const pp of [...spec.paths]) {
|
|
33901
|
+
allParsedPaths.set(`${pp.method} ${pp.path}`, pp);
|
|
33798
33902
|
}
|
|
33799
|
-
|
|
33800
|
-
|
|
33801
|
-
|
|
33802
|
-
|
|
33803
|
-
|
|
33804
|
-
|
|
33805
|
-
|
|
33806
|
-
|
|
33807
|
-
|
|
33808
|
-
|
|
33809
|
-
|
|
33810
|
-
|
|
33811
|
-
|
|
33812
|
-
if (isRecord(item) && resource.idParam in item) {
|
|
33813
|
-
const id = item[resource.idParam];
|
|
33814
|
-
if (typeof id === "number" && id > maxId) {
|
|
33815
|
-
maxId = id;
|
|
33816
|
-
}
|
|
33903
|
+
const securitySchemes = spec.securitySchemes;
|
|
33904
|
+
const globalSecurity = spec.globalSecurity;
|
|
33905
|
+
return {
|
|
33906
|
+
name: "@schmock/openapi",
|
|
33907
|
+
version: "1.4.0",
|
|
33908
|
+
install(instance) {
|
|
33909
|
+
if (options.debug) {
|
|
33910
|
+
console.log(`[@schmock/openapi] Detected ${resources.length} CRUD resources, ${nonCrudPaths.length} static routes`);
|
|
33911
|
+
}
|
|
33912
|
+
for (const resource of resources) {
|
|
33913
|
+
const override = options.resources?.[resource.name];
|
|
33914
|
+
if (override) {
|
|
33915
|
+
applyOverrides2(resource, override);
|
|
33817
33916
|
}
|
|
33917
|
+
if (options.debug) {
|
|
33918
|
+
logResourceDetection(resource, override);
|
|
33919
|
+
}
|
|
33920
|
+
registerCrudRoutes(instance, resource, seedData.get(resource.name), allParsedPaths);
|
|
33818
33921
|
}
|
|
33819
|
-
|
|
33820
|
-
}
|
|
33821
|
-
|
|
33822
|
-
|
|
33823
|
-
|
|
33824
|
-
|
|
33825
|
-
|
|
33826
|
-
function wrapWithSeeder(seeder, generator) {
|
|
33827
|
-
return (ctx) => {
|
|
33828
|
-
seeder(ctx.state);
|
|
33829
|
-
return generator(ctx);
|
|
33830
|
-
};
|
|
33831
|
-
}
|
|
33832
|
-
function applyOverrides2(resource, override) {
|
|
33833
|
-
if (!resource.operationMeta) {
|
|
33834
|
-
resource.operationMeta = new Map;
|
|
33835
|
-
}
|
|
33836
|
-
if (override.listWrapProperty !== undefined || override.listFlat !== undefined) {
|
|
33837
|
-
const listMeta = resource.operationMeta.get("list") ?? {};
|
|
33838
|
-
if (override.listFlat) {
|
|
33839
|
-
delete listMeta.responseSchema;
|
|
33840
|
-
} else if (override.listWrapProperty && listMeta.responseSchema) {
|
|
33841
|
-
const arrayInfo = findArrayProperty(listMeta.responseSchema);
|
|
33842
|
-
if (!arrayInfo.property || arrayInfo.property !== override.listWrapProperty) {
|
|
33843
|
-
const itemSchema = arrayInfo.itemSchema ?? resource.schema ?? {};
|
|
33844
|
-
listMeta.responseSchema = {
|
|
33845
|
-
type: "object",
|
|
33846
|
-
properties: {
|
|
33847
|
-
[override.listWrapProperty]: {
|
|
33848
|
-
type: "array",
|
|
33849
|
-
items: itemSchema
|
|
33850
|
-
}
|
|
33851
|
-
}
|
|
33852
|
-
};
|
|
33922
|
+
registerNonCrudRoutes(instance, nonCrudPaths, options.fakerSeed);
|
|
33923
|
+
},
|
|
33924
|
+
process(context, response) {
|
|
33925
|
+
if (options.security && securitySchemes) {
|
|
33926
|
+
const securityResult = validateSecurity(context, securitySchemes, globalSecurity);
|
|
33927
|
+
if (securityResult)
|
|
33928
|
+
return securityResult;
|
|
33853
33929
|
}
|
|
33854
|
-
|
|
33855
|
-
|
|
33856
|
-
|
|
33857
|
-
|
|
33858
|
-
|
|
33859
|
-
|
|
33860
|
-
|
|
33861
|
-
items: itemSchema
|
|
33862
|
-
}
|
|
33930
|
+
const contentResult = processContentNegotiation(context);
|
|
33931
|
+
if (contentResult)
|
|
33932
|
+
return contentResult;
|
|
33933
|
+
if (options.validateRequests) {
|
|
33934
|
+
const validationResult = validateRequestBody(context);
|
|
33935
|
+
if (validationResult) {
|
|
33936
|
+
return validationResult;
|
|
33863
33937
|
}
|
|
33864
|
-
}
|
|
33865
|
-
|
|
33866
|
-
|
|
33867
|
-
|
|
33868
|
-
|
|
33869
|
-
|
|
33870
|
-
|
|
33871
|
-
errorSchemaMap.set(400, override.errorSchema);
|
|
33872
|
-
errorSchemaMap.set(409, override.errorSchema);
|
|
33873
|
-
for (const op of ["read", "update", "delete"]) {
|
|
33874
|
-
const meta = resource.operationMeta.get(op) ?? {};
|
|
33875
|
-
meta.errorSchemas = errorSchemaMap;
|
|
33876
|
-
resource.operationMeta.set(op, meta);
|
|
33877
|
-
}
|
|
33878
|
-
}
|
|
33879
|
-
}
|
|
33880
|
-
function logResourceDetection(resource, override) {
|
|
33881
|
-
const listMeta = resource.operationMeta?.get("list");
|
|
33882
|
-
let listFormat = "flat";
|
|
33883
|
-
if (listMeta?.responseSchema) {
|
|
33884
|
-
const arrayInfo = findArrayProperty(listMeta.responseSchema);
|
|
33885
|
-
if (arrayInfo.property) {
|
|
33886
|
-
const hasAllOf = "allOf" in (listMeta.responseSchema ?? {});
|
|
33887
|
-
listFormat = `wrapped("${arrayInfo.property}"${hasAllOf ? " via allOf" : ""})`;
|
|
33888
|
-
}
|
|
33889
|
-
}
|
|
33890
|
-
const readMeta = resource.operationMeta?.get("read");
|
|
33891
|
-
const errorFormat = readMeta?.errorSchemas?.has(404) ? "schema(404)" : "default";
|
|
33892
|
-
const headerCount = listMeta?.responseHeaders ? Object.keys(listMeta.responseHeaders).length : 0;
|
|
33893
|
-
console.log(`[@schmock/openapi] ${resource.name}: list=${listFormat}, error=${errorFormat}, headers=${headerCount}`);
|
|
33894
|
-
if (override) {
|
|
33895
|
-
const definedKeys = [];
|
|
33896
|
-
if (override.listWrapProperty !== undefined)
|
|
33897
|
-
definedKeys.push("listWrapProperty");
|
|
33898
|
-
if (override.listFlat !== undefined)
|
|
33899
|
-
definedKeys.push("listFlat");
|
|
33900
|
-
if (override.errorSchema !== undefined)
|
|
33901
|
-
definedKeys.push("errorSchema");
|
|
33902
|
-
if (definedKeys.length > 0) {
|
|
33903
|
-
console.log(`[@schmock/openapi] Override applied: ${resource.name}.${definedKeys.join(", ")}`);
|
|
33938
|
+
}
|
|
33939
|
+
const result = processPreferHeader(context, response, options.fakerSeed);
|
|
33940
|
+
const callbacks = getRouteCallbacks(context.route);
|
|
33941
|
+
if (callbacks && callbacks.length > 0) {
|
|
33942
|
+
fireCallbacks(callbacks, context, result.response);
|
|
33943
|
+
}
|
|
33944
|
+
return result;
|
|
33904
33945
|
}
|
|
33905
|
-
}
|
|
33946
|
+
};
|
|
33906
33947
|
}
|
|
33907
33948
|
// src/cli.ts
|
|
33908
33949
|
var CORS_HEADERS = {
|
|
@@ -33955,7 +33996,7 @@ function handleAdminRequest(method, path, mock, res, headers) {
|
|
|
33955
33996
|
res.end(JSON.stringify({ error: "Unknown admin endpoint", code: "NOT_FOUND" }));
|
|
33956
33997
|
}
|
|
33957
33998
|
async function createCliServer(options) {
|
|
33958
|
-
const mock = schmock({ debug: options.debug });
|
|
33999
|
+
const mock = schmock({ debug: options.debug, state: {} });
|
|
33959
34000
|
const openapiOptions = {
|
|
33960
34001
|
spec: options.spec,
|
|
33961
34002
|
fakerSeed: options.fakerSeed,
|