@opra/common 1.0.0-alpha.4 → 1.0.0-alpha.6
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/browser.js +94 -26
- package/cjs/document/decorators/http-controller.decorator.js +25 -0
- package/cjs/document/decorators/http-operation-entity.decorator.js +48 -12
- package/cjs/document/http/http-api.js +2 -2
- package/cjs/document/http/http-controller.js +17 -11
- package/cjs/document/http/http-operation.js +11 -4
- package/cjs/document/http/http-parameter.js +2 -0
- package/esm/document/decorators/http-controller.decorator.js +25 -0
- package/esm/document/decorators/http-operation-entity.decorator.js +48 -12
- package/esm/document/http/http-api.js +2 -2
- package/esm/document/http/http-controller.js +17 -11
- package/esm/document/http/http-operation.js +11 -4
- package/esm/document/http/http-parameter.js +2 -0
- package/package.json +1 -1
- package/types/document/decorators/http-controller.decorator.d.ts +1 -0
- package/types/document/http/http-parameter.d.ts +3 -2
- package/types/schema/http/http-parameter.interface.d.ts +4 -0
package/browser.js
CHANGED
|
@@ -2428,6 +2428,26 @@ function HttpControllerDecoratorFactory(options) {
|
|
|
2428
2428
|
});
|
|
2429
2429
|
return decorator;
|
|
2430
2430
|
};
|
|
2431
|
+
decorator.KeyParam = (name, arg1) => {
|
|
2432
|
+
decoratorChain.push((meta) => {
|
|
2433
|
+
if (!meta.path?.includes(":" + name))
|
|
2434
|
+
meta.path = (meta.path || "") + "@:" + name;
|
|
2435
|
+
const paramMeta = typeof arg1 === "string" || typeof arg1 === "function" ? {
|
|
2436
|
+
name,
|
|
2437
|
+
location: "path",
|
|
2438
|
+
type: arg1,
|
|
2439
|
+
keyParam: true
|
|
2440
|
+
} : {
|
|
2441
|
+
...arg1,
|
|
2442
|
+
name,
|
|
2443
|
+
location: "path",
|
|
2444
|
+
keyParam: true
|
|
2445
|
+
};
|
|
2446
|
+
meta.parameters = meta.parameters || [];
|
|
2447
|
+
meta.parameters.push(paramMeta);
|
|
2448
|
+
});
|
|
2449
|
+
return decorator;
|
|
2450
|
+
};
|
|
2431
2451
|
decorator.UseType = (...type) => {
|
|
2432
2452
|
decoratorChain.push((meta) => {
|
|
2433
2453
|
meta.types = meta.types || [];
|
|
@@ -2505,9 +2525,17 @@ var HttpControllerClass = class extends DocumentElement {
|
|
|
2505
2525
|
return this.controllers.get(arg0);
|
|
2506
2526
|
}
|
|
2507
2527
|
findParameter(paramName, location) {
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2528
|
+
const paramNameLower = paramName.toLowerCase();
|
|
2529
|
+
let prm;
|
|
2530
|
+
for (prm of this.parameters) {
|
|
2531
|
+
if (location && location !== prm.location)
|
|
2532
|
+
continue;
|
|
2533
|
+
if (typeof prm.name === "string") {
|
|
2534
|
+
prm._nameLower = prm._nameLower || prm.name.toLowerCase();
|
|
2535
|
+
if (prm._nameLower === paramNameLower)
|
|
2536
|
+
return prm;
|
|
2537
|
+
}
|
|
2538
|
+
if (prm.name instanceof RegExp && prm.name.test(paramName))
|
|
2511
2539
|
return prm;
|
|
2512
2540
|
}
|
|
2513
2541
|
if (this.node.parent && this.node.parent.element instanceof HttpController2)
|
|
@@ -2530,20 +2558,20 @@ var HttpControllerClass = class extends DocumentElement {
|
|
|
2530
2558
|
});
|
|
2531
2559
|
if (this.operations.size) {
|
|
2532
2560
|
out.operations = {};
|
|
2533
|
-
for (const
|
|
2534
|
-
out.operations[name] = v.toJSON();
|
|
2561
|
+
for (const v of this.operations.values()) {
|
|
2562
|
+
out.operations[v.name] = v.toJSON();
|
|
2535
2563
|
}
|
|
2536
2564
|
}
|
|
2537
2565
|
if (this.controllers.size) {
|
|
2538
2566
|
out.controllers = {};
|
|
2539
|
-
for (const
|
|
2540
|
-
out.controllers[name] = v.toJSON();
|
|
2567
|
+
for (const v of this.controllers.values()) {
|
|
2568
|
+
out.controllers[v.name] = v.toJSON();
|
|
2541
2569
|
}
|
|
2542
2570
|
}
|
|
2543
2571
|
if (this.types.size) {
|
|
2544
2572
|
out.types = {};
|
|
2545
|
-
for (const
|
|
2546
|
-
out.types[name] = v.toJSON();
|
|
2573
|
+
for (const v of this.types.values()) {
|
|
2574
|
+
out.types[v.name] = v.toJSON();
|
|
2547
2575
|
}
|
|
2548
2576
|
}
|
|
2549
2577
|
if (this.parameters.length) {
|
|
@@ -2592,8 +2620,8 @@ var HttpApi = class extends ApiBase {
|
|
|
2592
2620
|
url: this.url,
|
|
2593
2621
|
controllers: {}
|
|
2594
2622
|
};
|
|
2595
|
-
for (const
|
|
2596
|
-
out.controllers[name] = v.toJSON();
|
|
2623
|
+
for (const v of this.controllers.values()) {
|
|
2624
|
+
out.controllers[v.name] = v.toJSON();
|
|
2597
2625
|
}
|
|
2598
2626
|
return out;
|
|
2599
2627
|
}
|
|
@@ -3120,9 +3148,17 @@ var HttpOperationClass = class extends DocumentElement {
|
|
|
3120
3148
|
__name(this, "HttpOperationClass");
|
|
3121
3149
|
}
|
|
3122
3150
|
findParameter(paramName, location) {
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3151
|
+
const paramNameLower = paramName.toLowerCase();
|
|
3152
|
+
let prm;
|
|
3153
|
+
for (prm of this.parameters) {
|
|
3154
|
+
if (location && location !== prm.location)
|
|
3155
|
+
continue;
|
|
3156
|
+
if (typeof prm.name === "string") {
|
|
3157
|
+
prm._nameLower = prm._nameLower || prm.name.toLowerCase();
|
|
3158
|
+
if (prm._nameLower === paramNameLower)
|
|
3159
|
+
return prm;
|
|
3160
|
+
}
|
|
3161
|
+
if (prm.name instanceof RegExp && prm.name.test(paramName))
|
|
3126
3162
|
return prm;
|
|
3127
3163
|
}
|
|
3128
3164
|
}
|
|
@@ -3294,6 +3330,7 @@ var HttpParameter = /* @__PURE__ */ __name(function(owner, initArgs) {
|
|
|
3294
3330
|
_this.deprecated = initArgs.deprecated;
|
|
3295
3331
|
_this.required = initArgs.required;
|
|
3296
3332
|
_this.arraySeparator = initArgs.arraySeparator;
|
|
3333
|
+
_this.keyParam = initArgs.keyParam;
|
|
3297
3334
|
}, "HttpParameter");
|
|
3298
3335
|
var HttpParameterClass = class extends Value {
|
|
3299
3336
|
static {
|
|
@@ -3305,6 +3342,7 @@ var HttpParameterClass = class extends Value {
|
|
|
3305
3342
|
name: this.name,
|
|
3306
3343
|
location: this.location,
|
|
3307
3344
|
arraySeparator: this.arraySeparator,
|
|
3345
|
+
keyParam: this.keyParam,
|
|
3308
3346
|
required: this.required,
|
|
3309
3347
|
deprecated: this.deprecated
|
|
3310
3348
|
});
|
|
@@ -12710,11 +12748,21 @@ HttpOperation2.Entity.Delete = function(arg0, arg1) {
|
|
|
12710
12748
|
if (typeof args.type === "function")
|
|
12711
12749
|
decorator.UseType(args.type);
|
|
12712
12750
|
decorator.KeyParam = (name, prmOptions) => {
|
|
12713
|
-
|
|
12751
|
+
const paramMeta = typeof prmOptions === "string" || typeof prmOptions === "function" ? {
|
|
12752
|
+
name,
|
|
12753
|
+
location: "path",
|
|
12754
|
+
type: prmOptions,
|
|
12755
|
+
keyParam: true
|
|
12756
|
+
} : {
|
|
12757
|
+
...prmOptions,
|
|
12758
|
+
name,
|
|
12759
|
+
location: "path",
|
|
12760
|
+
keyParam: true
|
|
12761
|
+
};
|
|
12762
|
+
decorator.PathParam(name, paramMeta);
|
|
12714
12763
|
decoratorChain.push((meta) => {
|
|
12715
|
-
|
|
12716
|
-
|
|
12717
|
-
meta.compositionOptions.keyParameter = name;
|
|
12764
|
+
if (!meta.path?.includes(":" + name))
|
|
12765
|
+
meta.path = (meta.path || "") + "@:" + name;
|
|
12718
12766
|
});
|
|
12719
12767
|
return decorator;
|
|
12720
12768
|
};
|
|
@@ -12880,11 +12928,21 @@ HttpOperation2.Entity.Get = function(arg0, arg1) {
|
|
|
12880
12928
|
if (typeof args.type === "function")
|
|
12881
12929
|
decorator.UseType(args.type);
|
|
12882
12930
|
decorator.KeyParam = (name, prmOptions) => {
|
|
12883
|
-
|
|
12931
|
+
const paramMeta = typeof prmOptions === "string" || typeof prmOptions === "function" ? {
|
|
12932
|
+
name,
|
|
12933
|
+
location: "path",
|
|
12934
|
+
type: prmOptions,
|
|
12935
|
+
keyParam: true
|
|
12936
|
+
} : {
|
|
12937
|
+
...prmOptions,
|
|
12938
|
+
name,
|
|
12939
|
+
location: "path",
|
|
12940
|
+
keyParam: true
|
|
12941
|
+
};
|
|
12942
|
+
decorator.PathParam(name, paramMeta);
|
|
12884
12943
|
decoratorChain.push((meta) => {
|
|
12885
|
-
|
|
12886
|
-
|
|
12887
|
-
meta.compositionOptions.keyParameter = name;
|
|
12944
|
+
if (!meta.path?.includes(":" + name))
|
|
12945
|
+
meta.path = (meta.path || "") + "@:" + name;
|
|
12888
12946
|
});
|
|
12889
12947
|
return decorator;
|
|
12890
12948
|
};
|
|
@@ -12987,11 +13045,21 @@ HttpOperation2.Entity.Update = function(arg0, arg1) {
|
|
|
12987
13045
|
if (typeof args.type === "function")
|
|
12988
13046
|
decorator.UseType(args.type);
|
|
12989
13047
|
decorator.KeyParam = (name, prmOptions) => {
|
|
12990
|
-
|
|
13048
|
+
const paramMeta = typeof prmOptions === "string" || typeof prmOptions === "function" ? {
|
|
13049
|
+
name,
|
|
13050
|
+
location: "path",
|
|
13051
|
+
type: prmOptions,
|
|
13052
|
+
keyParam: true
|
|
13053
|
+
} : {
|
|
13054
|
+
...prmOptions,
|
|
13055
|
+
name,
|
|
13056
|
+
location: "path",
|
|
13057
|
+
keyParam: true
|
|
13058
|
+
};
|
|
13059
|
+
decorator.PathParam(name, paramMeta);
|
|
12991
13060
|
decoratorChain.push((meta) => {
|
|
12992
|
-
|
|
12993
|
-
|
|
12994
|
-
meta.compositionOptions.keyParameter = name;
|
|
13061
|
+
if (!meta.path?.includes(":" + name))
|
|
13062
|
+
meta.path = (meta.path || "") + "@:" + name;
|
|
12995
13063
|
});
|
|
12996
13064
|
return decorator;
|
|
12997
13065
|
};
|
|
@@ -102,6 +102,31 @@ function HttpControllerDecoratorFactory(options) {
|
|
|
102
102
|
});
|
|
103
103
|
return decorator;
|
|
104
104
|
};
|
|
105
|
+
/**
|
|
106
|
+
*
|
|
107
|
+
*/
|
|
108
|
+
decorator.KeyParam = (name, arg1) => {
|
|
109
|
+
decoratorChain.push((meta) => {
|
|
110
|
+
if (!meta.path?.includes(':' + name))
|
|
111
|
+
meta.path = (meta.path || '') + '@:' + name;
|
|
112
|
+
const paramMeta = typeof arg1 === 'string' || typeof arg1 === 'function'
|
|
113
|
+
? {
|
|
114
|
+
name,
|
|
115
|
+
location: 'path',
|
|
116
|
+
type: arg1,
|
|
117
|
+
keyParam: true,
|
|
118
|
+
}
|
|
119
|
+
: {
|
|
120
|
+
...arg1,
|
|
121
|
+
name,
|
|
122
|
+
location: 'path',
|
|
123
|
+
keyParam: true,
|
|
124
|
+
};
|
|
125
|
+
meta.parameters = meta.parameters || [];
|
|
126
|
+
meta.parameters.push(paramMeta);
|
|
127
|
+
});
|
|
128
|
+
return decorator;
|
|
129
|
+
};
|
|
105
130
|
/**
|
|
106
131
|
*
|
|
107
132
|
*/
|
|
@@ -93,11 +93,23 @@ http_operation_js_1.HttpOperation.Entity.Delete = function (arg0, arg1) {
|
|
|
93
93
|
*
|
|
94
94
|
*/
|
|
95
95
|
decorator.KeyParam = (name, prmOptions) => {
|
|
96
|
-
|
|
96
|
+
const paramMeta = typeof prmOptions === 'string' || typeof prmOptions === 'function'
|
|
97
|
+
? {
|
|
98
|
+
name,
|
|
99
|
+
location: 'path',
|
|
100
|
+
type: prmOptions,
|
|
101
|
+
keyParam: true,
|
|
102
|
+
}
|
|
103
|
+
: {
|
|
104
|
+
...prmOptions,
|
|
105
|
+
name,
|
|
106
|
+
location: 'path',
|
|
107
|
+
keyParam: true,
|
|
108
|
+
};
|
|
109
|
+
decorator.PathParam(name, paramMeta);
|
|
97
110
|
decoratorChain.push((meta) => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
meta.compositionOptions.keyParameter = name;
|
|
111
|
+
if (!meta.path?.includes(':' + name))
|
|
112
|
+
meta.path = (meta.path || '') + '@:' + name;
|
|
101
113
|
});
|
|
102
114
|
return decorator;
|
|
103
115
|
};
|
|
@@ -296,11 +308,23 @@ http_operation_js_1.HttpOperation.Entity.Get = function (arg0, arg1) {
|
|
|
296
308
|
*
|
|
297
309
|
*/
|
|
298
310
|
decorator.KeyParam = (name, prmOptions) => {
|
|
299
|
-
|
|
311
|
+
const paramMeta = typeof prmOptions === 'string' || typeof prmOptions === 'function'
|
|
312
|
+
? {
|
|
313
|
+
name,
|
|
314
|
+
location: 'path',
|
|
315
|
+
type: prmOptions,
|
|
316
|
+
keyParam: true,
|
|
317
|
+
}
|
|
318
|
+
: {
|
|
319
|
+
...prmOptions,
|
|
320
|
+
name,
|
|
321
|
+
location: 'path',
|
|
322
|
+
keyParam: true,
|
|
323
|
+
};
|
|
324
|
+
decorator.PathParam(name, paramMeta);
|
|
300
325
|
decoratorChain.push((meta) => {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
meta.compositionOptions.keyParameter = name;
|
|
326
|
+
if (!meta.path?.includes(':' + name))
|
|
327
|
+
meta.path = (meta.path || '') + '@:' + name;
|
|
304
328
|
});
|
|
305
329
|
return decorator;
|
|
306
330
|
};
|
|
@@ -425,11 +449,23 @@ http_operation_js_1.HttpOperation.Entity.Update = function (arg0, arg1) {
|
|
|
425
449
|
*
|
|
426
450
|
*/
|
|
427
451
|
decorator.KeyParam = (name, prmOptions) => {
|
|
428
|
-
|
|
452
|
+
const paramMeta = typeof prmOptions === 'string' || typeof prmOptions === 'function'
|
|
453
|
+
? {
|
|
454
|
+
name,
|
|
455
|
+
location: 'path',
|
|
456
|
+
type: prmOptions,
|
|
457
|
+
keyParam: true,
|
|
458
|
+
}
|
|
459
|
+
: {
|
|
460
|
+
...prmOptions,
|
|
461
|
+
name,
|
|
462
|
+
location: 'path',
|
|
463
|
+
keyParam: true,
|
|
464
|
+
};
|
|
465
|
+
decorator.PathParam(name, paramMeta);
|
|
429
466
|
decoratorChain.push((meta) => {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
meta.compositionOptions.keyParameter = name;
|
|
467
|
+
if (!meta.path?.includes(':' + name))
|
|
468
|
+
meta.path = (meta.path || '') + '@:' + name;
|
|
433
469
|
});
|
|
434
470
|
return decorator;
|
|
435
471
|
};
|
|
@@ -31,8 +31,8 @@ class HttpApi extends api_base_js_1.ApiBase {
|
|
|
31
31
|
url: this.url,
|
|
32
32
|
controllers: {},
|
|
33
33
|
};
|
|
34
|
-
for (const
|
|
35
|
-
out.controllers[name] = v.toJSON();
|
|
34
|
+
for (const v of this.controllers.values()) {
|
|
35
|
+
out.controllers[v.name] = v.toJSON();
|
|
36
36
|
}
|
|
37
37
|
return out;
|
|
38
38
|
}
|
|
@@ -82,11 +82,17 @@ class HttpControllerClass extends document_element_js_1.DocumentElement {
|
|
|
82
82
|
return this.controllers.get(arg0);
|
|
83
83
|
}
|
|
84
84
|
findParameter(paramName, location) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
const paramNameLower = paramName.toLowerCase();
|
|
86
|
+
let prm;
|
|
87
|
+
for (prm of this.parameters) {
|
|
88
|
+
if (location && location !== prm.location)
|
|
89
|
+
continue;
|
|
90
|
+
if (typeof prm.name === 'string') {
|
|
91
|
+
prm._nameLower = prm._nameLower || prm.name.toLowerCase();
|
|
92
|
+
if (prm._nameLower === paramNameLower)
|
|
93
|
+
return prm;
|
|
94
|
+
}
|
|
95
|
+
if (prm.name instanceof RegExp && prm.name.test(paramName))
|
|
90
96
|
return prm;
|
|
91
97
|
}
|
|
92
98
|
if (this.node.parent && this.node.parent.element instanceof exports.HttpController)
|
|
@@ -109,20 +115,20 @@ class HttpControllerClass extends document_element_js_1.DocumentElement {
|
|
|
109
115
|
});
|
|
110
116
|
if (this.operations.size) {
|
|
111
117
|
out.operations = {};
|
|
112
|
-
for (const
|
|
113
|
-
out.operations[name] = v.toJSON();
|
|
118
|
+
for (const v of this.operations.values()) {
|
|
119
|
+
out.operations[v.name] = v.toJSON();
|
|
114
120
|
}
|
|
115
121
|
}
|
|
116
122
|
if (this.controllers.size) {
|
|
117
123
|
out.controllers = {};
|
|
118
|
-
for (const
|
|
119
|
-
out.controllers[name] = v.toJSON();
|
|
124
|
+
for (const v of this.controllers.values()) {
|
|
125
|
+
out.controllers[v.name] = v.toJSON();
|
|
120
126
|
}
|
|
121
127
|
}
|
|
122
128
|
if (this.types.size) {
|
|
123
129
|
out.types = {};
|
|
124
|
-
for (const
|
|
125
|
-
out.types[name] = v.toJSON();
|
|
130
|
+
for (const v of this.types.values()) {
|
|
131
|
+
out.types[v.name] = v.toJSON();
|
|
126
132
|
}
|
|
127
133
|
}
|
|
128
134
|
if (this.parameters.length) {
|
|
@@ -39,10 +39,17 @@ exports.HttpOperation = function (...args) {
|
|
|
39
39
|
*/
|
|
40
40
|
class HttpOperationClass extends document_element_js_1.DocumentElement {
|
|
41
41
|
findParameter(paramName, location) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
const paramNameLower = paramName.toLowerCase();
|
|
43
|
+
let prm;
|
|
44
|
+
for (prm of this.parameters) {
|
|
45
|
+
if (location && location !== prm.location)
|
|
46
|
+
continue;
|
|
47
|
+
if (typeof prm.name === 'string') {
|
|
48
|
+
prm._nameLower = prm._nameLower || prm.name.toLowerCase();
|
|
49
|
+
if (prm._nameLower === paramNameLower)
|
|
50
|
+
return prm;
|
|
51
|
+
}
|
|
52
|
+
if (prm.name instanceof RegExp && prm.name.test(paramName))
|
|
46
53
|
return prm;
|
|
47
54
|
}
|
|
48
55
|
}
|
|
@@ -25,6 +25,7 @@ exports.HttpParameter = function (owner, initArgs) {
|
|
|
25
25
|
_this.deprecated = initArgs.deprecated;
|
|
26
26
|
_this.required = initArgs.required;
|
|
27
27
|
_this.arraySeparator = initArgs.arraySeparator;
|
|
28
|
+
_this.keyParam = initArgs.keyParam;
|
|
28
29
|
};
|
|
29
30
|
/**
|
|
30
31
|
* @class HttpParameter
|
|
@@ -36,6 +37,7 @@ class HttpParameterClass extends value_js_1.Value {
|
|
|
36
37
|
name: this.name,
|
|
37
38
|
location: this.location,
|
|
38
39
|
arraySeparator: this.arraySeparator,
|
|
40
|
+
keyParam: this.keyParam,
|
|
39
41
|
required: this.required,
|
|
40
42
|
deprecated: this.deprecated,
|
|
41
43
|
});
|
|
@@ -98,6 +98,31 @@ export function HttpControllerDecoratorFactory(options) {
|
|
|
98
98
|
});
|
|
99
99
|
return decorator;
|
|
100
100
|
};
|
|
101
|
+
/**
|
|
102
|
+
*
|
|
103
|
+
*/
|
|
104
|
+
decorator.KeyParam = (name, arg1) => {
|
|
105
|
+
decoratorChain.push((meta) => {
|
|
106
|
+
if (!meta.path?.includes(':' + name))
|
|
107
|
+
meta.path = (meta.path || '') + '@:' + name;
|
|
108
|
+
const paramMeta = typeof arg1 === 'string' || typeof arg1 === 'function'
|
|
109
|
+
? {
|
|
110
|
+
name,
|
|
111
|
+
location: 'path',
|
|
112
|
+
type: arg1,
|
|
113
|
+
keyParam: true,
|
|
114
|
+
}
|
|
115
|
+
: {
|
|
116
|
+
...arg1,
|
|
117
|
+
name,
|
|
118
|
+
location: 'path',
|
|
119
|
+
keyParam: true,
|
|
120
|
+
};
|
|
121
|
+
meta.parameters = meta.parameters || [];
|
|
122
|
+
meta.parameters.push(paramMeta);
|
|
123
|
+
});
|
|
124
|
+
return decorator;
|
|
125
|
+
};
|
|
101
126
|
/**
|
|
102
127
|
*
|
|
103
128
|
*/
|
|
@@ -91,11 +91,23 @@ HttpOperation.Entity.Delete = function (arg0, arg1) {
|
|
|
91
91
|
*
|
|
92
92
|
*/
|
|
93
93
|
decorator.KeyParam = (name, prmOptions) => {
|
|
94
|
-
|
|
94
|
+
const paramMeta = typeof prmOptions === 'string' || typeof prmOptions === 'function'
|
|
95
|
+
? {
|
|
96
|
+
name,
|
|
97
|
+
location: 'path',
|
|
98
|
+
type: prmOptions,
|
|
99
|
+
keyParam: true,
|
|
100
|
+
}
|
|
101
|
+
: {
|
|
102
|
+
...prmOptions,
|
|
103
|
+
name,
|
|
104
|
+
location: 'path',
|
|
105
|
+
keyParam: true,
|
|
106
|
+
};
|
|
107
|
+
decorator.PathParam(name, paramMeta);
|
|
95
108
|
decoratorChain.push((meta) => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
meta.compositionOptions.keyParameter = name;
|
|
109
|
+
if (!meta.path?.includes(':' + name))
|
|
110
|
+
meta.path = (meta.path || '') + '@:' + name;
|
|
99
111
|
});
|
|
100
112
|
return decorator;
|
|
101
113
|
};
|
|
@@ -294,11 +306,23 @@ HttpOperation.Entity.Get = function (arg0, arg1) {
|
|
|
294
306
|
*
|
|
295
307
|
*/
|
|
296
308
|
decorator.KeyParam = (name, prmOptions) => {
|
|
297
|
-
|
|
309
|
+
const paramMeta = typeof prmOptions === 'string' || typeof prmOptions === 'function'
|
|
310
|
+
? {
|
|
311
|
+
name,
|
|
312
|
+
location: 'path',
|
|
313
|
+
type: prmOptions,
|
|
314
|
+
keyParam: true,
|
|
315
|
+
}
|
|
316
|
+
: {
|
|
317
|
+
...prmOptions,
|
|
318
|
+
name,
|
|
319
|
+
location: 'path',
|
|
320
|
+
keyParam: true,
|
|
321
|
+
};
|
|
322
|
+
decorator.PathParam(name, paramMeta);
|
|
298
323
|
decoratorChain.push((meta) => {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
meta.compositionOptions.keyParameter = name;
|
|
324
|
+
if (!meta.path?.includes(':' + name))
|
|
325
|
+
meta.path = (meta.path || '') + '@:' + name;
|
|
302
326
|
});
|
|
303
327
|
return decorator;
|
|
304
328
|
};
|
|
@@ -423,11 +447,23 @@ HttpOperation.Entity.Update = function (arg0, arg1) {
|
|
|
423
447
|
*
|
|
424
448
|
*/
|
|
425
449
|
decorator.KeyParam = (name, prmOptions) => {
|
|
426
|
-
|
|
450
|
+
const paramMeta = typeof prmOptions === 'string' || typeof prmOptions === 'function'
|
|
451
|
+
? {
|
|
452
|
+
name,
|
|
453
|
+
location: 'path',
|
|
454
|
+
type: prmOptions,
|
|
455
|
+
keyParam: true,
|
|
456
|
+
}
|
|
457
|
+
: {
|
|
458
|
+
...prmOptions,
|
|
459
|
+
name,
|
|
460
|
+
location: 'path',
|
|
461
|
+
keyParam: true,
|
|
462
|
+
};
|
|
463
|
+
decorator.PathParam(name, paramMeta);
|
|
427
464
|
decoratorChain.push((meta) => {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
meta.compositionOptions.keyParameter = name;
|
|
465
|
+
if (!meta.path?.includes(':' + name))
|
|
466
|
+
meta.path = (meta.path || '') + '@:' + name;
|
|
431
467
|
});
|
|
432
468
|
return decorator;
|
|
433
469
|
};
|
|
@@ -28,8 +28,8 @@ export class HttpApi extends ApiBase {
|
|
|
28
28
|
url: this.url,
|
|
29
29
|
controllers: {},
|
|
30
30
|
};
|
|
31
|
-
for (const
|
|
32
|
-
out.controllers[name] = v.toJSON();
|
|
31
|
+
for (const v of this.controllers.values()) {
|
|
32
|
+
out.controllers[v.name] = v.toJSON();
|
|
33
33
|
}
|
|
34
34
|
return out;
|
|
35
35
|
}
|
|
@@ -79,11 +79,17 @@ class HttpControllerClass extends DocumentElement {
|
|
|
79
79
|
return this.controllers.get(arg0);
|
|
80
80
|
}
|
|
81
81
|
findParameter(paramName, location) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
const paramNameLower = paramName.toLowerCase();
|
|
83
|
+
let prm;
|
|
84
|
+
for (prm of this.parameters) {
|
|
85
|
+
if (location && location !== prm.location)
|
|
86
|
+
continue;
|
|
87
|
+
if (typeof prm.name === 'string') {
|
|
88
|
+
prm._nameLower = prm._nameLower || prm.name.toLowerCase();
|
|
89
|
+
if (prm._nameLower === paramNameLower)
|
|
90
|
+
return prm;
|
|
91
|
+
}
|
|
92
|
+
if (prm.name instanceof RegExp && prm.name.test(paramName))
|
|
87
93
|
return prm;
|
|
88
94
|
}
|
|
89
95
|
if (this.node.parent && this.node.parent.element instanceof HttpController)
|
|
@@ -106,20 +112,20 @@ class HttpControllerClass extends DocumentElement {
|
|
|
106
112
|
});
|
|
107
113
|
if (this.operations.size) {
|
|
108
114
|
out.operations = {};
|
|
109
|
-
for (const
|
|
110
|
-
out.operations[name] = v.toJSON();
|
|
115
|
+
for (const v of this.operations.values()) {
|
|
116
|
+
out.operations[v.name] = v.toJSON();
|
|
111
117
|
}
|
|
112
118
|
}
|
|
113
119
|
if (this.controllers.size) {
|
|
114
120
|
out.controllers = {};
|
|
115
|
-
for (const
|
|
116
|
-
out.controllers[name] = v.toJSON();
|
|
121
|
+
for (const v of this.controllers.values()) {
|
|
122
|
+
out.controllers[v.name] = v.toJSON();
|
|
117
123
|
}
|
|
118
124
|
}
|
|
119
125
|
if (this.types.size) {
|
|
120
126
|
out.types = {};
|
|
121
|
-
for (const
|
|
122
|
-
out.types[name] = v.toJSON();
|
|
127
|
+
for (const v of this.types.values()) {
|
|
128
|
+
out.types[v.name] = v.toJSON();
|
|
123
129
|
}
|
|
124
130
|
}
|
|
125
131
|
if (this.parameters.length) {
|
|
@@ -36,10 +36,17 @@ export const HttpOperation = function (...args) {
|
|
|
36
36
|
*/
|
|
37
37
|
class HttpOperationClass extends DocumentElement {
|
|
38
38
|
findParameter(paramName, location) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
const paramNameLower = paramName.toLowerCase();
|
|
40
|
+
let prm;
|
|
41
|
+
for (prm of this.parameters) {
|
|
42
|
+
if (location && location !== prm.location)
|
|
43
|
+
continue;
|
|
44
|
+
if (typeof prm.name === 'string') {
|
|
45
|
+
prm._nameLower = prm._nameLower || prm.name.toLowerCase();
|
|
46
|
+
if (prm._nameLower === paramNameLower)
|
|
47
|
+
return prm;
|
|
48
|
+
}
|
|
49
|
+
if (prm.name instanceof RegExp && prm.name.test(paramName))
|
|
43
50
|
return prm;
|
|
44
51
|
}
|
|
45
52
|
}
|
|
@@ -22,6 +22,7 @@ export const HttpParameter = function (owner, initArgs) {
|
|
|
22
22
|
_this.deprecated = initArgs.deprecated;
|
|
23
23
|
_this.required = initArgs.required;
|
|
24
24
|
_this.arraySeparator = initArgs.arraySeparator;
|
|
25
|
+
_this.keyParam = initArgs.keyParam;
|
|
25
26
|
};
|
|
26
27
|
/**
|
|
27
28
|
* @class HttpParameter
|
|
@@ -33,6 +34,7 @@ class HttpParameterClass extends Value {
|
|
|
33
34
|
name: this.name,
|
|
34
35
|
location: this.location,
|
|
35
36
|
arraySeparator: this.arraySeparator,
|
|
37
|
+
keyParam: this.keyParam,
|
|
36
38
|
required: this.required,
|
|
37
39
|
deprecated: this.deprecated,
|
|
38
40
|
});
|
package/package.json
CHANGED
|
@@ -6,6 +6,7 @@ export interface HttpControllerDecorator<T extends HttpControllerDecorator<any>
|
|
|
6
6
|
Header(name: string | RegExp, optionsOrType?: StrictOmit<HttpParameter.Options, 'location'> | string | TypeThunkAsync | false): T;
|
|
7
7
|
QueryParam(name: string | RegExp, optionsOrType?: StrictOmit<HttpParameter.Options, 'location'> | string | TypeThunkAsync | false): T;
|
|
8
8
|
PathParam(name: string | RegExp, optionsOrType?: StrictOmit<HttpParameter.Options, 'location'> | string | TypeThunkAsync | false): T;
|
|
9
|
+
KeyParam(name: string | RegExp, optionsOrType?: StrictOmit<HttpParameter.Options, 'location'> | string | TypeThunkAsync | false): T;
|
|
9
10
|
UseType(...type: TypeThunkAsync[]): T;
|
|
10
11
|
}
|
|
11
12
|
export interface HttpControllerDecoratorFactory {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Combine, StrictOmit, TypeThunkAsync } from 'ts-gems';
|
|
2
2
|
import type { OpraSchema } from '../../schema/index.js';
|
|
3
|
-
import { HttpParameterLocation } from '../../schema/types.js';
|
|
4
3
|
import { DocumentElement } from '../common/document-element.js';
|
|
5
4
|
import { Value } from '../common/value.js';
|
|
6
5
|
import { DataType } from '../data-type/data-type.js';
|
|
@@ -12,6 +11,7 @@ export declare namespace HttpParameter {
|
|
|
12
11
|
interface Metadata extends StrictOmit<OpraSchema.HttpParameter, 'type'> {
|
|
13
12
|
name: string | RegExp;
|
|
14
13
|
type?: string | TypeThunkAsync | EnumType.EnumObject | EnumType.EnumArray | object;
|
|
14
|
+
keyParam?: boolean;
|
|
15
15
|
}
|
|
16
16
|
interface Options extends Partial<StrictOmit<Metadata, 'type'>> {
|
|
17
17
|
type?: string | TypeThunkAsync | object;
|
|
@@ -41,10 +41,11 @@ export declare const HttpParameter: HttpParameterStatic;
|
|
|
41
41
|
*/
|
|
42
42
|
declare class HttpParameterClass extends Value {
|
|
43
43
|
readonly owner: DocumentElement;
|
|
44
|
+
keyParam?: boolean;
|
|
44
45
|
deprecated?: boolean | string;
|
|
45
46
|
required?: boolean;
|
|
46
47
|
arraySeparator?: string;
|
|
47
|
-
location: HttpParameterLocation;
|
|
48
|
+
location: OpraSchema.HttpParameterLocation;
|
|
48
49
|
toJSON(): OpraSchema.HttpParameter;
|
|
49
50
|
}
|
|
50
51
|
export {};
|
|
@@ -13,6 +13,10 @@ export interface HttpParameter extends Value {
|
|
|
13
13
|
* Name of the parameter. RegExp pattern can be used matching parameter name
|
|
14
14
|
*/
|
|
15
15
|
name: string | RegExp;
|
|
16
|
+
/**
|
|
17
|
+
* Determines if parameter is key
|
|
18
|
+
*/
|
|
19
|
+
keyParam?: boolean;
|
|
16
20
|
/**
|
|
17
21
|
* Defines array separator
|
|
18
22
|
*/
|