@tsed/schema 6.70.0 → 6.71.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/lib/constants/httpStatusMessages.d.ts +1 -0
- package/lib/decorators/index.d.ts +2 -0
- package/lib/decorators/operations/location.d.ts +22 -0
- package/lib/decorators/operations/redirect.d.ts +52 -0
- package/lib/decorators/operations/returns.d.ts +5 -1
- package/lib/domain/JsonOperation.d.ts +7 -5
- package/lib/index.js +136 -16
- package/lib/index.js.map +1 -1
- package/lib/index.modern.js +134 -18
- package/lib/index.modern.js.map +1 -1
- package/lib/utils/isSuccessStatus.d.ts +1 -0
- package/package.json +5 -5
|
@@ -22,6 +22,8 @@ export * from "./operations/security";
|
|
|
22
22
|
export * from "./operations/tags";
|
|
23
23
|
export * from "./operations/summary";
|
|
24
24
|
export * from "./operations/partial";
|
|
25
|
+
export * from "./operations/redirect";
|
|
26
|
+
export * from "./operations/location";
|
|
25
27
|
export * from "./common/additionalProperties";
|
|
26
28
|
export * from "./common/allow";
|
|
27
29
|
export * from "./common/any";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { JsonHeader } from "../../interfaces/JsonOpenSpec";
|
|
2
|
+
/**
|
|
3
|
+
* Sets the response Location HTTP header to the specified path parameter.
|
|
4
|
+
*
|
|
5
|
+
* ```typescript
|
|
6
|
+
* @Location('/foo/bar', {description: 'Location to the next step'})
|
|
7
|
+
* @Location('http://example.com')
|
|
8
|
+
* @Location('back')
|
|
9
|
+
* private myMethod() {
|
|
10
|
+
*
|
|
11
|
+
* }
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* A path value of “back” has a special meaning, it refers to the URL specified in the `Referer` header of the request. If the `Referer` header was not specified, it refers to “/”.
|
|
15
|
+
*
|
|
16
|
+
* @param location
|
|
17
|
+
* @param meta
|
|
18
|
+
* @returns {Function}
|
|
19
|
+
* @decorator
|
|
20
|
+
* @operation
|
|
21
|
+
*/
|
|
22
|
+
export declare function Location(location: string, meta?: JsonHeader): import("./returns").ReturnsChainedDecorators;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { JsonHeader } from "../../interfaces/JsonOpenSpec";
|
|
2
|
+
/**
|
|
3
|
+
* Redirects to the URL derived from the specified path, with specified status, a positive integer that corresponds to an HTTP status code . If not specified, status defaults to “302 “Found”.
|
|
4
|
+
*
|
|
5
|
+
* ```typescript
|
|
6
|
+
* @Redirect('/foo/bar')
|
|
7
|
+
* @Redirect(301, 'http://example.com').Type(Model)
|
|
8
|
+
* private myMethod() {}
|
|
9
|
+
* ```
|
|
10
|
+
* Redirects can be a fully-qualified URL for redirecting to a different site:
|
|
11
|
+
*
|
|
12
|
+
* ```typescript
|
|
13
|
+
* @Redirect('http://google.com');
|
|
14
|
+
* private myMethod() {}
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Redirects can be relative to the root of the host name. For example, if the application is on http://example.com/admin/post/new, the following would redirect to the URL http://example.com/admin:
|
|
18
|
+
*
|
|
19
|
+
* ```typescript
|
|
20
|
+
* @Redirect('/admin');
|
|
21
|
+
* ```
|
|
22
|
+
* Redirects can be relative to the current URL. For example, from http://example.com/blog/admin/ (notice the trailing slash), the following would redirect to the URL http://example.com/blog/admin/post/new.
|
|
23
|
+
*
|
|
24
|
+
* ```typescript
|
|
25
|
+
* @Redirect('post/new');
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Redirecting to post/new from http://example.com/blog/admin (no trailing slash), will redirect to http://example.com/blog/post/new.
|
|
29
|
+
*
|
|
30
|
+
* If you found the above behavior confusing, think of path segments as directories (with trailing slashes) and files, it will start to make sense.
|
|
31
|
+
*
|
|
32
|
+
* Path-relative redirects are also possible. If you were on http://example.com/admin/post/new, the following would redirect to http//example.com/admin/post:
|
|
33
|
+
*
|
|
34
|
+
* ```typescript
|
|
35
|
+
* @Redirect('..');
|
|
36
|
+
* ``
|
|
37
|
+
*
|
|
38
|
+
* A back redirection redirects the request back to the referer, defaulting to / when the referer is missing.
|
|
39
|
+
*
|
|
40
|
+
* ```typescript
|
|
41
|
+
* @Redirect('back');
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @param url
|
|
45
|
+
* @param meta
|
|
46
|
+
* @decorator
|
|
47
|
+
* @operation
|
|
48
|
+
* @response
|
|
49
|
+
* @headers
|
|
50
|
+
*/
|
|
51
|
+
export declare function Redirect(url: string, meta?: JsonHeader): Function;
|
|
52
|
+
export declare function Redirect(status: number, url: string, meta?: JsonHeader): Function;
|
|
@@ -51,12 +51,16 @@ export interface ReturnsChainedDecorators {
|
|
|
51
51
|
* @param value
|
|
52
52
|
*/
|
|
53
53
|
Header(key: string, value: number | string | (JsonHeader & {
|
|
54
|
-
value?: string | number;
|
|
54
|
+
value?: string | number | boolean;
|
|
55
55
|
})): this;
|
|
56
56
|
/**
|
|
57
57
|
* Add headers
|
|
58
58
|
*/
|
|
59
59
|
Headers(headers: JsonHeaders): this;
|
|
60
|
+
/**
|
|
61
|
+
* Add location hea
|
|
62
|
+
*/
|
|
63
|
+
Location(location: string, meta?: JsonHeader): this;
|
|
60
64
|
/**
|
|
61
65
|
* Assign partial schema
|
|
62
66
|
* @param schema
|
|
@@ -14,8 +14,8 @@ export interface JsonOperationOptions extends OS3Operation<JsonSchema, JsonParam
|
|
|
14
14
|
produces: string[];
|
|
15
15
|
}
|
|
16
16
|
export declare class JsonOperation extends JsonMap<JsonOperationOptions> {
|
|
17
|
+
#private;
|
|
17
18
|
readonly operationPaths: Map<string, JsonMethodPath>;
|
|
18
|
-
private _status;
|
|
19
19
|
constructor(obj?: Partial<JsonOperationOptions>);
|
|
20
20
|
get response(): JsonResponse | undefined;
|
|
21
21
|
get status(): number;
|
|
@@ -24,15 +24,17 @@ export declare class JsonOperation extends JsonMap<JsonOperationOptions> {
|
|
|
24
24
|
summary(summary: string): this;
|
|
25
25
|
operationId(operationId: string): this;
|
|
26
26
|
responses(responses: JsonMap<any>): this;
|
|
27
|
-
defaultStatus(status: number):
|
|
27
|
+
defaultStatus(status: number): this;
|
|
28
28
|
getStatus(): number;
|
|
29
|
+
setRedirection(status?: number): this;
|
|
30
|
+
isRedirection(status?: number): boolean | 0;
|
|
29
31
|
addResponse(statusCode: string | number, response: JsonResponse): this;
|
|
30
32
|
getResponses(): JsonMap<JsonResponse>;
|
|
31
33
|
getResponseOf(status: number | string): JsonResponse;
|
|
32
34
|
ensureResponseOf(status: number | string): JsonResponse;
|
|
33
|
-
getHeadersOf(status: number): {
|
|
34
|
-
|
|
35
|
-
}
|
|
35
|
+
getHeadersOf(status: number): Record<string, JsonHeader & {
|
|
36
|
+
example: string;
|
|
37
|
+
}>;
|
|
36
38
|
getContentTypeOf(status: number): any;
|
|
37
39
|
security(security: OpenSpecSecurity): this;
|
|
38
40
|
addSecurityScopes(name: string, scopes: string[]): this;
|
package/lib/index.js
CHANGED
|
@@ -78,6 +78,9 @@ const HTTP_STATUS_MESSAGES = {
|
|
|
78
78
|
function getStatusConstant(status) {
|
|
79
79
|
return changeCase.constantCase(HTTP_STATUS_MESSAGES[status]);
|
|
80
80
|
}
|
|
81
|
+
function getStatusMessage(status) {
|
|
82
|
+
return HTTP_STATUS_MESSAGES[status];
|
|
83
|
+
}
|
|
81
84
|
|
|
82
85
|
function _extends() {
|
|
83
86
|
_extends = Object.assign || function (target) {
|
|
@@ -112,6 +115,20 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
112
115
|
return target;
|
|
113
116
|
}
|
|
114
117
|
|
|
118
|
+
var id = 0;
|
|
119
|
+
|
|
120
|
+
function _classPrivateFieldLooseKey(name) {
|
|
121
|
+
return "__private_" + id++ + "_" + name;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function _classPrivateFieldLooseBase(receiver, privateKey) {
|
|
125
|
+
if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
|
|
126
|
+
throw new TypeError("attempted to use private field on non-instance");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return receiver;
|
|
130
|
+
}
|
|
131
|
+
|
|
115
132
|
/**
|
|
116
133
|
* @ignore
|
|
117
134
|
*/
|
|
@@ -331,6 +348,7 @@ function anyMapper(input, options = {}) {
|
|
|
331
348
|
registerJsonSchemaMapper("any", anyMapper);
|
|
332
349
|
|
|
333
350
|
const isSuccessStatus = code => Number(code) && 200 <= Number(code) && Number(code) < 300;
|
|
351
|
+
const isRedirectionStatus = code => Number(code) && 300 <= Number(code) && Number(code) < 400;
|
|
334
352
|
|
|
335
353
|
class JsonMap extends Map {
|
|
336
354
|
constructor(obj = {}) {
|
|
@@ -1475,13 +1493,27 @@ class JsonSchema extends Map {
|
|
|
1475
1493
|
}
|
|
1476
1494
|
|
|
1477
1495
|
const _excluded$6 = ["schema", "in"];
|
|
1496
|
+
|
|
1497
|
+
var _status = /*#__PURE__*/_classPrivateFieldLooseKey("status");
|
|
1498
|
+
|
|
1499
|
+
var _redirection = /*#__PURE__*/_classPrivateFieldLooseKey("redirection");
|
|
1500
|
+
|
|
1478
1501
|
class JsonOperation extends JsonMap {
|
|
1479
1502
|
constructor(obj = {}) {
|
|
1480
1503
|
super(_extends({
|
|
1481
1504
|
parameters: [],
|
|
1482
1505
|
responses: new JsonMap()
|
|
1483
1506
|
}, obj));
|
|
1507
|
+
Object.defineProperty(this, _status, {
|
|
1508
|
+
writable: true,
|
|
1509
|
+
value: void 0
|
|
1510
|
+
});
|
|
1511
|
+
Object.defineProperty(this, _redirection, {
|
|
1512
|
+
writable: true,
|
|
1513
|
+
value: void 0
|
|
1514
|
+
});
|
|
1484
1515
|
this.operationPaths = new Map();
|
|
1516
|
+
_classPrivateFieldLooseBase(this, _redirection)[_redirection] = false;
|
|
1485
1517
|
}
|
|
1486
1518
|
|
|
1487
1519
|
get response() {
|
|
@@ -1489,7 +1521,7 @@ class JsonOperation extends JsonMap {
|
|
|
1489
1521
|
}
|
|
1490
1522
|
|
|
1491
1523
|
get status() {
|
|
1492
|
-
return this
|
|
1524
|
+
return _classPrivateFieldLooseBase(this, _status)[_status];
|
|
1493
1525
|
}
|
|
1494
1526
|
|
|
1495
1527
|
tags(tags) {
|
|
@@ -1518,15 +1550,32 @@ class JsonOperation extends JsonMap {
|
|
|
1518
1550
|
}
|
|
1519
1551
|
|
|
1520
1552
|
defaultStatus(status) {
|
|
1521
|
-
this
|
|
1553
|
+
_classPrivateFieldLooseBase(this, _status)[_status] = status;
|
|
1554
|
+
return this;
|
|
1522
1555
|
}
|
|
1523
1556
|
|
|
1524
1557
|
getStatus() {
|
|
1525
|
-
return this
|
|
1558
|
+
return _classPrivateFieldLooseBase(this, _status)[_status] || 200;
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
setRedirection(status = 302) {
|
|
1562
|
+
_classPrivateFieldLooseBase(this, _redirection)[_redirection] = true;
|
|
1563
|
+
_classPrivateFieldLooseBase(this, _status)[_status] = status;
|
|
1564
|
+
return this;
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
isRedirection(status) {
|
|
1568
|
+
if (_classPrivateFieldLooseBase(this, _redirection)[_redirection]) {
|
|
1569
|
+
if (status) {
|
|
1570
|
+
return isRedirectionStatus(status);
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
return _classPrivateFieldLooseBase(this, _redirection)[_redirection];
|
|
1526
1575
|
}
|
|
1527
1576
|
|
|
1528
1577
|
addResponse(statusCode, response) {
|
|
1529
|
-
if (isSuccessStatus(statusCode) && !this
|
|
1578
|
+
if ((isSuccessStatus(statusCode) || isRedirectionStatus(statusCode)) && !_classPrivateFieldLooseBase(this, _status)[_status]) {
|
|
1530
1579
|
const res = this.getResponseOf(200);
|
|
1531
1580
|
this.getResponses().set(statusCode.toString(), res).delete("200");
|
|
1532
1581
|
this.defaultStatus(Number(statusCode));
|
|
@@ -4290,17 +4339,9 @@ class ReturnDecoratorContext extends DecoratorContext {
|
|
|
4290
4339
|
model
|
|
4291
4340
|
}) {
|
|
4292
4341
|
super();
|
|
4293
|
-
this.methods = ["contentType", "description", "examples", "type", "status", "of", "nested", "header", "headers", "schema", "title", "groups"];
|
|
4294
|
-
this.
|
|
4295
|
-
this.
|
|
4296
|
-
|
|
4297
|
-
if (status && HTTP_STATUS_MESSAGES[status]) {
|
|
4298
|
-
this.set("description", HTTP_STATUS_MESSAGES[status]);
|
|
4299
|
-
|
|
4300
|
-
if (!model) {
|
|
4301
|
-
this.model(getStatusModel(+status));
|
|
4302
|
-
}
|
|
4303
|
-
}
|
|
4342
|
+
this.methods = ["contentType", "description", "examples", "type", "status", "of", "nested", "header", "headers", "schema", "title", "groups", "location"];
|
|
4343
|
+
this.model(model);
|
|
4344
|
+
this.status(status);
|
|
4304
4345
|
}
|
|
4305
4346
|
|
|
4306
4347
|
type(model) {
|
|
@@ -4308,12 +4349,21 @@ class ReturnDecoratorContext extends DecoratorContext {
|
|
|
4308
4349
|
}
|
|
4309
4350
|
|
|
4310
4351
|
model(model) {
|
|
4311
|
-
this.set("model", model);
|
|
4352
|
+
model && this.set("model", model);
|
|
4312
4353
|
return this;
|
|
4313
4354
|
}
|
|
4314
4355
|
|
|
4315
4356
|
status(status) {
|
|
4316
4357
|
this.set("status", status);
|
|
4358
|
+
|
|
4359
|
+
if (status && HTTP_STATUS_MESSAGES[status] && !this.get("description")) {
|
|
4360
|
+
this.set("description", HTTP_STATUS_MESSAGES[status]);
|
|
4361
|
+
|
|
4362
|
+
if (!this.get("model")) {
|
|
4363
|
+
this.model(getStatusModel(+status));
|
|
4364
|
+
}
|
|
4365
|
+
}
|
|
4366
|
+
|
|
4317
4367
|
return this;
|
|
4318
4368
|
}
|
|
4319
4369
|
|
|
@@ -4328,6 +4378,15 @@ class ReturnDecoratorContext extends DecoratorContext {
|
|
|
4328
4378
|
});
|
|
4329
4379
|
}
|
|
4330
4380
|
|
|
4381
|
+
location(path, meta = {}) {
|
|
4382
|
+
this.headers({
|
|
4383
|
+
Location: _extends({}, meta, {
|
|
4384
|
+
value: path
|
|
4385
|
+
})
|
|
4386
|
+
});
|
|
4387
|
+
return this;
|
|
4388
|
+
}
|
|
4389
|
+
|
|
4331
4390
|
groups(...groups) {
|
|
4332
4391
|
this.set("groups", groups);
|
|
4333
4392
|
return this;
|
|
@@ -4427,6 +4486,8 @@ class ReturnDecoratorContext extends DecoratorContext {
|
|
|
4427
4486
|
default:
|
|
4428
4487
|
throw new core.UnsupportedDecoratorType(Returns, args);
|
|
4429
4488
|
}
|
|
4489
|
+
|
|
4490
|
+
this.clear();
|
|
4430
4491
|
}
|
|
4431
4492
|
|
|
4432
4493
|
map() {
|
|
@@ -5115,6 +5176,61 @@ function Partial() {
|
|
|
5115
5176
|
return Groups("partial");
|
|
5116
5177
|
}
|
|
5117
5178
|
|
|
5179
|
+
function Redirect(...args) {
|
|
5180
|
+
const {
|
|
5181
|
+
status,
|
|
5182
|
+
url,
|
|
5183
|
+
meta
|
|
5184
|
+
} = args.reduce((options, value) => {
|
|
5185
|
+
if (core.isNumber(value)) {
|
|
5186
|
+
options.status = value;
|
|
5187
|
+
return options;
|
|
5188
|
+
}
|
|
5189
|
+
|
|
5190
|
+
if (core.isString(value)) {
|
|
5191
|
+
options.url = value;
|
|
5192
|
+
return options;
|
|
5193
|
+
}
|
|
5194
|
+
|
|
5195
|
+
options.meta = value;
|
|
5196
|
+
return options;
|
|
5197
|
+
}, {
|
|
5198
|
+
status: 302,
|
|
5199
|
+
url: "",
|
|
5200
|
+
meta: {}
|
|
5201
|
+
});
|
|
5202
|
+
return core.useDecorators(Returns(status).Location(url, meta), JsonEntityFn(entity => {
|
|
5203
|
+
var _entity$operation;
|
|
5204
|
+
|
|
5205
|
+
(_entity$operation = entity.operation) == null ? void 0 : _entity$operation.setRedirection(status);
|
|
5206
|
+
}));
|
|
5207
|
+
}
|
|
5208
|
+
|
|
5209
|
+
/**
|
|
5210
|
+
* Sets the response Location HTTP header to the specified path parameter.
|
|
5211
|
+
*
|
|
5212
|
+
* ```typescript
|
|
5213
|
+
* @Location('/foo/bar', {description: 'Location to the next step'})
|
|
5214
|
+
* @Location('http://example.com')
|
|
5215
|
+
* @Location('back')
|
|
5216
|
+
* private myMethod() {
|
|
5217
|
+
*
|
|
5218
|
+
* }
|
|
5219
|
+
* ```
|
|
5220
|
+
*
|
|
5221
|
+
* A path value of “back” has a special meaning, it refers to the URL specified in the `Referer` header of the request. If the `Referer` header was not specified, it refers to “/”.
|
|
5222
|
+
*
|
|
5223
|
+
* @param location
|
|
5224
|
+
* @param meta
|
|
5225
|
+
* @returns {Function}
|
|
5226
|
+
* @decorator
|
|
5227
|
+
* @operation
|
|
5228
|
+
*/
|
|
5229
|
+
|
|
5230
|
+
function Location(location, meta) {
|
|
5231
|
+
return Returns().Location(location, meta);
|
|
5232
|
+
}
|
|
5233
|
+
|
|
5118
5234
|
/**
|
|
5119
5235
|
* Accept unknown properties on the deserialized model.
|
|
5120
5236
|
*
|
|
@@ -7425,6 +7541,7 @@ exports.JsonParameter = JsonParameter;
|
|
|
7425
7541
|
exports.JsonRequestBody = JsonRequestBody;
|
|
7426
7542
|
exports.JsonResponse = JsonResponse;
|
|
7427
7543
|
exports.JsonSchema = JsonSchema;
|
|
7544
|
+
exports.Location = Location;
|
|
7428
7545
|
exports.MapOf = MapOf;
|
|
7429
7546
|
exports.Max = Max;
|
|
7430
7547
|
exports.MaxItems = MaxItems;
|
|
@@ -7449,6 +7566,7 @@ exports.Pattern = Pattern;
|
|
|
7449
7566
|
exports.Produces = Produces;
|
|
7450
7567
|
exports.Property = Property;
|
|
7451
7568
|
exports.ReadOnly = ReadOnly;
|
|
7569
|
+
exports.Redirect = Redirect;
|
|
7452
7570
|
exports.Required = Required;
|
|
7453
7571
|
exports.RequiredGroups = RequiredGroups;
|
|
7454
7572
|
exports.Returns = Returns;
|
|
@@ -7483,9 +7601,11 @@ exports.getProperties = getProperties;
|
|
|
7483
7601
|
exports.getPropertiesStores = getPropertiesStores;
|
|
7484
7602
|
exports.getSpec = getSpec;
|
|
7485
7603
|
exports.getStatusConstant = getStatusConstant;
|
|
7604
|
+
exports.getStatusMessage = getStatusMessage;
|
|
7486
7605
|
exports.getStatusModel = getStatusModel;
|
|
7487
7606
|
exports.integer = integer;
|
|
7488
7607
|
exports.isParameterType = isParameterType;
|
|
7608
|
+
exports.isRedirectionStatus = isRedirectionStatus;
|
|
7489
7609
|
exports.isSuccessStatus = isSuccessStatus;
|
|
7490
7610
|
exports.lazyRef = lazyRef;
|
|
7491
7611
|
exports.map = map;
|