@loopback/openapi-v3 1.12.0 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.13.0](https://github.com/strongloop/loopback-next/compare/@loopback/openapi-v3@1.12.0...@loopback/openapi-v3@1.13.0) (2020-02-05)
7
+
8
+
9
+ ### Features
10
+
11
+ * adds [@oas](https://github.com/oas).deprecated() decorator ([6b6b5f0](https://github.com/strongloop/loopback-next/commit/6b6b5f05d224053d6a9735a506841d19b7331dac))
12
+ * adds [@oas](https://github.com/oas).tags convenience decorator ([a8722dc](https://github.com/strongloop/loopback-next/commit/a8722dc68838344684a5d3de76fa6915e08d2e56))
13
+
14
+
15
+
16
+
17
+
6
18
  # [1.12.0](https://github.com/strongloop/loopback-next/compare/@loopback/openapi-v3@1.11.0...@loopback/openapi-v3@1.12.0) (2020-01-27)
7
19
 
8
20
 
@@ -18,7 +18,7 @@ exports.TS_TYPE_KEY = 'x-ts-type';
18
18
  * @param constructor - Controller class
19
19
  */
20
20
  function resolveControllerSpec(constructor) {
21
- var _a, _b;
21
+ var _a, _b, _c, _d;
22
22
  debug(`Retrieving OpenAPI specification for controller ${constructor.name}`);
23
23
  let spec = core_1.MetadataInspector.getClassMetadata(keys_1.OAI3Keys.CLASS_KEY, constructor);
24
24
  if (spec) {
@@ -28,6 +28,34 @@ function resolveControllerSpec(constructor) {
28
28
  else {
29
29
  spec = { paths: {} };
30
30
  }
31
+ const isClassDeprecated = core_1.MetadataInspector.getClassMetadata(keys_1.OAI3Keys.DEPRECATED_CLASS_KEY, constructor);
32
+ if (isClassDeprecated) {
33
+ debug(' using class-level @deprecated()');
34
+ }
35
+ const classTags = core_1.MetadataInspector.getClassMetadata(keys_1.OAI3Keys.TAGS_CLASS_KEY, constructor);
36
+ if (classTags) {
37
+ debug(' using class-level @oas.tags()');
38
+ }
39
+ if (classTags || isClassDeprecated) {
40
+ for (const path of Object.keys(spec.paths)) {
41
+ for (const method of Object.keys(spec.paths[path])) {
42
+ /* istanbul ignore else */
43
+ if (isClassDeprecated) {
44
+ spec.paths[path][method].deprecated = true;
45
+ }
46
+ /* istanbul ignore else */
47
+ if (classTags) {
48
+ if (spec.paths[path][method].tags &&
49
+ spec.paths[path][method].tags.length) {
50
+ spec.paths[path][method].tags = spec.paths[path][method].tags.concat(classTags.tags);
51
+ }
52
+ else {
53
+ spec.paths[path][method].tags = classTags.tags;
54
+ }
55
+ }
56
+ }
57
+ }
58
+ }
31
59
  let endpoints = (_a = core_1.MetadataInspector.getAllMethodMetadata(keys_1.OAI3Keys.METHODS_KEY, constructor.prototype), (_a !== null && _a !== void 0 ? _a : {}));
32
60
  endpoints = core_1.DecoratorFactory.cloneDeep(endpoints);
33
61
  for (const op in endpoints) {
@@ -35,6 +63,14 @@ function resolveControllerSpec(constructor) {
35
63
  const endpoint = endpoints[op];
36
64
  const verb = endpoint.verb;
37
65
  const path = endpoint.path;
66
+ const isMethodDeprecated = core_1.MetadataInspector.getMethodMetadata(keys_1.OAI3Keys.DEPRECATED_METHOD_KEY, constructor.prototype, op);
67
+ if (isMethodDeprecated) {
68
+ debug(' using method-level deprecation via @deprecated()');
69
+ }
70
+ const methodTags = core_1.MetadataInspector.getMethodMetadata(keys_1.OAI3Keys.TAGS_METHOD_KEY, constructor.prototype, op);
71
+ if (methodTags) {
72
+ debug(' using method-level tags via @oas.tags()');
73
+ }
38
74
  let endpointName = '';
39
75
  /* istanbul ignore if */
40
76
  if (debug.enabled) {
@@ -55,13 +91,29 @@ function resolveControllerSpec(constructor) {
55
91
  };
56
92
  endpoint.spec = operationSpec;
57
93
  }
94
+ if (classTags && !operationSpec.tags) {
95
+ operationSpec.tags = classTags.tags;
96
+ }
97
+ if (methodTags) {
98
+ if (operationSpec.tags && operationSpec.tags.length) {
99
+ operationSpec.tags = operationSpec.tags.concat(methodTags.tags);
100
+ }
101
+ else {
102
+ operationSpec.tags = methodTags.tags;
103
+ }
104
+ }
58
105
  debug(' operation for method %s: %j', op, endpoint);
59
106
  debug(' spec responses for method %s: %o', op, operationSpec.responses);
107
+ // Prescedence: method decorator > class decorator > operationSpec > undefined
108
+ const deprecationSpec = (_c = (_b = (isMethodDeprecated !== null && isMethodDeprecated !== void 0 ? isMethodDeprecated : isClassDeprecated), (_b !== null && _b !== void 0 ? _b : operationSpec.deprecated)), (_c !== null && _c !== void 0 ? _c : false));
109
+ if (deprecationSpec) {
110
+ operationSpec.deprecated = true;
111
+ }
60
112
  for (const code in operationSpec.responses) {
61
113
  const responseObject = operationSpec.responses[code];
62
114
  if (types_1.isReferenceObject(responseObject))
63
115
  continue;
64
- const content = (_b = responseObject.content, (_b !== null && _b !== void 0 ? _b : {}));
116
+ const content = (_d = responseObject.content, (_d !== null && _d !== void 0 ? _d : {}));
65
117
  for (const c in content) {
66
118
  debug(' processing response code %s with content-type %', code, c);
67
119
  processSchemaExtensions(spec, content[c].schema);
@@ -1 +1 @@
1
- {"version":3,"file":"controller-spec.js","sourceRoot":"","sources":["../src/controller-spec.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;AAEhE,yCAAmE;AACnE,6EAI0C;AAC1C,mCAAgC;AAChC,uDAAgD;AAChD,qDAA+D;AAC/D,iCAAgC;AAChC,mCAYiB;AAEjB,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,4CAA4C,CAAC,CAAC;AA8BhE,QAAA,WAAW,GAAG,WAAW,CAAC;AAEvC;;;GAGG;AACH,SAAS,qBAAqB,CAAC,WAAqB;;IAClD,KAAK,CAAC,mDAAmD,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;IAE7E,IAAI,IAAI,GAAG,wBAAiB,CAAC,gBAAgB,CAC3C,eAAQ,CAAC,SAAS,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Ae,EAAE,IAAI,EAAC,CACxB,CAAC;IACF,IAAI,CAAC,IAAI,EAAE;QACT,IAAI,GAAG,qBAAqB,CAAC,WAAW,CAAC,CAAC;QAC1C,wBAAiB,CAAC,cAAc,CAC9B,eAAQ,CAAC,mBAAmB,CAAC,GAAG,EAChC,IAAI,EACJ,WAAW,CACZ,CAAC;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAfD,8CAeC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,iBAAiB,CAC/B,SAAoC,EACpC,OAA8B;IAE9B,MAAM,UAAU,GAAG,yCAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACxD,OAAO,mCAAkB,CAAC,UAAU,CAAc,CAAC;AACrD,CAAC;AAND,8CAMC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Marks an api path as deprecated. When applied to a class, this decorator
3
+ * marks all paths as deprecated.
4
+ *
5
+ * You can optionally mark all controllers in a class as deprecated, but use
6
+ * `@deprecated(false)` on a specific method to ensure it is not marked
7
+ * as deprecated in the specification.
8
+ *
9
+ * @param isDeprecated - whether or not the path should be marked as deprecated.
10
+ * This is useful for marking a class as deprecated, but a method as
11
+ * not deprecated.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * @oas.deprecated()
16
+ * class MyController {
17
+ * @get('/greet')
18
+ * public async function greet() {
19
+ * return 'Hello, World!'
20
+ * }
21
+ *
22
+ * @get('/greet-v2')
23
+ * @oas.deprecated(false)
24
+ * public async function greetV2() {
25
+ * return 'Hello, World!'
26
+ * }
27
+ * }
28
+ *
29
+ * class MyOtherController {
30
+ * @get('/echo')
31
+ * public async function echo() {
32
+ * return 'Echo!'
33
+ * }
34
+ * }
35
+ * ```
36
+ */
37
+ export declare function deprecated(isDeprecated?: boolean): (target: any, method?: string | undefined, methodDescriptor?: TypedPropertyDescriptor<any> | undefined) => any;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ // Copyright IBM Corp. 2018. All Rights Reserved.
3
+ // Node module: @loopback/openapi-v3
4
+ // This file is licensed under the MIT License.
5
+ // License text available at https://opensource.org/licenses/MIT
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const core_1 = require("@loopback/core");
8
+ const keys_1 = require("../keys");
9
+ const debug = require('debug')('loopback:openapi3:metadata:controller-spec:deprecated');
10
+ /**
11
+ * Marks an api path as deprecated. When applied to a class, this decorator
12
+ * marks all paths as deprecated.
13
+ *
14
+ * You can optionally mark all controllers in a class as deprecated, but use
15
+ * `@deprecated(false)` on a specific method to ensure it is not marked
16
+ * as deprecated in the specification.
17
+ *
18
+ * @param isDeprecated - whether or not the path should be marked as deprecated.
19
+ * This is useful for marking a class as deprecated, but a method as
20
+ * not deprecated.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * @oas.deprecated()
25
+ * class MyController {
26
+ * @get('/greet')
27
+ * public async function greet() {
28
+ * return 'Hello, World!'
29
+ * }
30
+ *
31
+ * @get('/greet-v2')
32
+ * @oas.deprecated(false)
33
+ * public async function greetV2() {
34
+ * return 'Hello, World!'
35
+ * }
36
+ * }
37
+ *
38
+ * class MyOtherController {
39
+ * @get('/echo')
40
+ * public async function echo() {
41
+ * return 'Echo!'
42
+ * }
43
+ * }
44
+ * ```
45
+ */
46
+ function deprecated(isDeprecated = true) {
47
+ return function deprecatedDecoratorForClassOrMethod(
48
+ // Class or a prototype
49
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
+ target, method,
51
+ // Use `any` to for `TypedPropertyDescriptor`
52
+ // See https://github.com/strongloop/loopback-next/pull/2704
53
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
54
+ methodDescriptor) {
55
+ debug(target, method, methodDescriptor);
56
+ if (method && methodDescriptor) {
57
+ // Method
58
+ return core_1.MethodDecoratorFactory.createDecorator(keys_1.OAI3Keys.DEPRECATED_METHOD_KEY, isDeprecated, { decoratorName: '@oas.deprecated' })(target, method, methodDescriptor);
59
+ }
60
+ else if (typeof target === 'function' && !method && !methodDescriptor) {
61
+ // Class
62
+ return core_1.ClassDecoratorFactory.createDecorator(keys_1.OAI3Keys.DEPRECATED_CLASS_KEY, isDeprecated, { decoratorName: '@oas.deprecated' })(target);
63
+ }
64
+ else {
65
+ throw new Error('@oas.deprecated cannot be used on a property: ' +
66
+ core_1.DecoratorFactory.getTargetName(target, method, methodDescriptor));
67
+ }
68
+ };
69
+ }
70
+ exports.deprecated = deprecated;
71
+ //# sourceMappingURL=deprecated.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deprecated.decorator.js","sourceRoot":"","sources":["../../src/decorators/deprecated.decorator.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;AAEhE,yCAIwB;AACxB,kCAAiC;AAEjC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAC5B,uDAAuD,CACxD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,SAAgB,UAAU,CAAC,YAAY,GAAG,IAAI;IAC5C,OAAO,SAAS,mCAAmC;IACjD,uBAAuB;IACvB,8DAA8D;IAC9D,MAAW,EACX,MAAe;IACf,6CAA6C;IAC7C,4DAA4D;IAC5D,8DAA8D;IAC9D,gBAA+C;QAE/C,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC;QAExC,IAAI,MAAM,IAAI,gBAAgB,EAAE;YAC9B,SAAS;YACT,OAAO,6BAAsB,CAAC,eAAe,CAC3C,eAAQ,CAAC,qBAAqB,EAC9B,YAAY,EACZ,EAAC,aAAa,EAAE,iBAAiB,EAAC,CACnC,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC;SACrC;aAAM,IAAI,OAAO,MAAM,KAAK,UAAU,IAAI,CAAC,MAAM,IAAI,CAAC,gBAAgB,EAAE;YACvE,QAAQ;YACR,OAAO,4BAAqB,CAAC,eAAe,CAC1C,eAAQ,CAAC,oBAAoB,EAC7B,YAAY,EACZ,EAAC,aAAa,EAAE,iBAAiB,EAAC,CACnC,CAAC,MAAM,CAAC,CAAC;SACX;aAAM;YACL,MAAM,IAAI,KAAK,CACb,gDAAgD;gBAC9C,uBAAgB,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,CAAC,CACnE,CAAC;SACH;IACH,CAAC,CAAC;AACJ,CAAC;AAlCD,gCAkCC"}
@@ -1,4 +1,24 @@
1
1
  export * from './api.decorator';
2
+ export * from './deprecated.decorator';
2
3
  export * from './operation.decorator';
3
4
  export * from './parameter.decorator';
4
5
  export * from './request-body.decorator';
6
+ import { api } from './api.decorator';
7
+ import { deprecated } from './deprecated.decorator';
8
+ import { del, get, operation, patch, post, put } from './operation.decorator';
9
+ import { param } from './parameter.decorator';
10
+ import { requestBody } from './request-body.decorator';
11
+ import { tags } from './tags.decorator';
12
+ export declare const oas: {
13
+ api: typeof api;
14
+ operation: typeof operation;
15
+ get: typeof get;
16
+ post: typeof post;
17
+ del: typeof del;
18
+ patch: typeof patch;
19
+ put: typeof put;
20
+ param: typeof param;
21
+ requestBody: typeof requestBody;
22
+ deprecated: typeof deprecated;
23
+ tags: typeof tags;
24
+ };
@@ -8,7 +8,31 @@ function __export(m) {
8
8
  }
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  __export(require("./api.decorator"));
11
+ __export(require("./deprecated.decorator"));
11
12
  __export(require("./operation.decorator"));
12
13
  __export(require("./parameter.decorator"));
13
14
  __export(require("./request-body.decorator"));
15
+ const api_decorator_1 = require("./api.decorator");
16
+ const deprecated_decorator_1 = require("./deprecated.decorator");
17
+ const operation_decorator_1 = require("./operation.decorator");
18
+ const parameter_decorator_1 = require("./parameter.decorator");
19
+ const request_body_decorator_1 = require("./request-body.decorator");
20
+ const tags_decorator_1 = require("./tags.decorator");
21
+ exports.oas = {
22
+ api: api_decorator_1.api,
23
+ operation: operation_decorator_1.operation,
24
+ // methods
25
+ get: operation_decorator_1.get,
26
+ post: operation_decorator_1.post,
27
+ del: operation_decorator_1.del,
28
+ patch: operation_decorator_1.patch,
29
+ put: operation_decorator_1.put,
30
+ //param
31
+ param: parameter_decorator_1.param,
32
+ // request body
33
+ requestBody: request_body_decorator_1.requestBody,
34
+ // oas convenience decorators
35
+ deprecated: deprecated_decorator_1.deprecated,
36
+ tags: tags_decorator_1.tags,
37
+ };
14
38
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;;;AAEhE,qCAAgC;AAChC,2CAAsC;AACtC,2CAAsC;AACtC,8CAAyC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;;;AAEhE,qCAAgC;AAChC,4CAAuC;AACvC,2CAAsC;AACtC,2CAAsC;AACtC,8CAAyC;AAEzC,mDAAoC;AACpC,iEAAkD;AAClD,+DAA4E;AAC5E,+DAA4C;AAC5C,qEAAqD;AACrD,qDAAsC;AAEzB,QAAA,GAAG,GAAG;IACjB,GAAG,EAAH,mBAAG;IACH,SAAS,EAAT,+BAAS;IAET,UAAU;IACV,GAAG,EAAH,yBAAG;IACH,IAAI,EAAJ,0BAAI;IACJ,GAAG,EAAH,yBAAG;IACH,KAAK,EAAL,2BAAK;IACL,GAAG,EAAH,yBAAG;IAEH,OAAO;IACP,KAAK,EAAL,2BAAK;IAEL,eAAe;IACf,WAAW,EAAX,oCAAW;IAEX,6BAA6B;IAC7B,UAAU,EAAV,iCAAU;IACV,IAAI,EAAJ,qBAAI;CACL,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function tags(...tagNames: string[]): (target: any, method?: string | undefined, methodDescriptor?: TypedPropertyDescriptor<any> | undefined) => any;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ // Copyright IBM Corp. 2018. All Rights Reserved.
3
+ // Node module: @loopback/openapi-v3
4
+ // This file is licensed under the MIT License.
5
+ // License text available at https://opensource.org/licenses/MIT
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const core_1 = require("@loopback/core");
8
+ const keys_1 = require("../keys");
9
+ function tags(...tagNames) {
10
+ return function tagsDecoratorForClassOrMethod(
11
+ // Class or a prototype
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ target, method,
14
+ // Use `any` to for `TypedPropertyDescriptor`
15
+ // See https://github.com/strongloop/loopback-next/pull/2704
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ methodDescriptor) {
18
+ if (method && methodDescriptor) {
19
+ // Method
20
+ return core_1.MethodDecoratorFactory.createDecorator(keys_1.OAI3Keys.TAGS_METHOD_KEY, { tags: tagNames }, { decoratorName: '@oas.tags' })(target, method, methodDescriptor);
21
+ }
22
+ else if (typeof target === 'function' && !method && !methodDescriptor) {
23
+ // Class
24
+ return core_1.ClassDecoratorFactory.createDecorator(keys_1.OAI3Keys.TAGS_CLASS_KEY, { tags: tagNames }, { decoratorName: '@oas.tags' })(target);
25
+ }
26
+ else {
27
+ throw new Error('@oas.tags cannot be used on a property: ' +
28
+ core_1.DecoratorFactory.getTargetName(target, method, methodDescriptor));
29
+ }
30
+ };
31
+ }
32
+ exports.tags = tags;
33
+ //# sourceMappingURL=tags.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tags.decorator.js","sourceRoot":"","sources":["../../src/decorators/tags.decorator.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;AAEhE,yCAIwB;AACxB,kCAAiC;AAGjC,SAAgB,IAAI,CAAC,GAAG,QAAkB;IACxC,OAAO,SAAS,6BAA6B;IAC3C,uBAAuB;IACvB,8DAA8D;IAC9D,MAAW,EACX,MAAe;IACf,6CAA6C;IAC7C,4DAA4D;IAC5D,8DAA8D;IAC9D,gBAA+C;QAE/C,IAAI,MAAM,IAAI,gBAAgB,EAAE;YAC9B,SAAS;YACT,OAAO,6BAAsB,CAAC,eAAe,CAC3C,eAAQ,CAAC,eAAe,EACxB,EAAC,IAAI,EAAE,QAAQ,EAAC,EAChB,EAAC,aAAa,EAAE,WAAW,EAAC,CAC7B,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC;SACrC;aAAM,IAAI,OAAO,MAAM,KAAK,UAAU,IAAI,CAAC,MAAM,IAAI,CAAC,gBAAgB,EAAE;YACvE,QAAQ;YACR,OAAO,4BAAqB,CAAC,eAAe,CAC1C,eAAQ,CAAC,cAAc,EACvB,EAAC,IAAI,EAAE,QAAQ,EAAC,EAChB,EAAC,aAAa,EAAE,WAAW,EAAC,CAC7B,CAAC,MAAM,CAAC,CAAC;SACX;aAAM;YACL,MAAM,IAAI,KAAK,CACb,0CAA0C;gBACxC,uBAAgB,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,CAAC,CACnE,CAAC;SACH;IACH,CAAC,CAAC;AACJ,CAAC;AAhCD,oBAgCC"}
package/dist/keys.d.ts CHANGED
@@ -6,10 +6,26 @@ export declare namespace OAI3Keys {
6
6
  * Metadata key used to set or retrieve `@operation` metadata.
7
7
  */
8
8
  const METHODS_KEY: MetadataAccessor<Partial<RestEndpoint>, MethodDecorator>;
9
+ /**
10
+ * Metadata key used to set or retrieve `@deprecated` metadata on a method.
11
+ */
12
+ const DEPRECATED_METHOD_KEY: MetadataAccessor<boolean, MethodDecorator>;
13
+ /**
14
+ * Metadata key used to set or retrieve `@deprecated` metadata on a class
15
+ */
16
+ const DEPRECATED_CLASS_KEY: MetadataAccessor<boolean, ClassDecorator>;
9
17
  /**
10
18
  * Metadata key used to set or retrieve `param` decorator metadata
11
19
  */
12
20
  const PARAMETERS_KEY: MetadataAccessor<ParameterObject, ParameterDecorator>;
21
+ /**
22
+ * Metadata key used to set or retrieve `@deprecated` metadata on a method.
23
+ */
24
+ const TAGS_METHOD_KEY: MetadataAccessor<string[], MethodDecorator>;
25
+ /**
26
+ * Metadata key used to set or retrieve `@deprecated` metadata on a class
27
+ */
28
+ const TAGS_CLASS_KEY: MetadataAccessor<string[], ClassDecorator>;
13
29
  /**
14
30
  * Metadata key used to set or retrieve `@api` metadata
15
31
  */
package/dist/keys.js CHANGED
@@ -11,10 +11,26 @@ var OAI3Keys;
11
11
  * Metadata key used to set or retrieve `@operation` metadata.
12
12
  */
13
13
  OAI3Keys.METHODS_KEY = core_1.MetadataAccessor.create('openapi-v3:methods');
14
+ /**
15
+ * Metadata key used to set or retrieve `@deprecated` metadata on a method.
16
+ */
17
+ OAI3Keys.DEPRECATED_METHOD_KEY = core_1.MetadataAccessor.create('openapi-v3:methods:deprecated');
18
+ /**
19
+ * Metadata key used to set or retrieve `@deprecated` metadata on a class
20
+ */
21
+ OAI3Keys.DEPRECATED_CLASS_KEY = core_1.MetadataAccessor.create('openapi-v3:class:deprecated');
14
22
  /**
15
23
  * Metadata key used to set or retrieve `param` decorator metadata
16
24
  */
17
25
  OAI3Keys.PARAMETERS_KEY = core_1.MetadataAccessor.create('openapi-v3:parameters');
26
+ /**
27
+ * Metadata key used to set or retrieve `@deprecated` metadata on a method.
28
+ */
29
+ OAI3Keys.TAGS_METHOD_KEY = core_1.MetadataAccessor.create('openapi-v3:methods:tags');
30
+ /**
31
+ * Metadata key used to set or retrieve `@deprecated` metadata on a class
32
+ */
33
+ OAI3Keys.TAGS_CLASS_KEY = core_1.MetadataAccessor.create('openapi-v3:class:tags');
18
34
  /**
19
35
  * Metadata key used to set or retrieve `@api` metadata
20
36
  */
package/dist/keys.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAg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U,kBAAS,GAAG,uBAAgB,CAAC,MAAM,CAG9C,kBAAkB,CAAC,CAAC;IAEtB;;OAEG;IACU,4BAAmB,GAAG,uBAAgB,CAAC,MAAM,CAGxD,4BAA4B,CAAC,CAAC;IAEhC;;OAEG;IACU,yBAAgB,GAAG,uBAAgB,CAAC,MAAM,CAGrD,yBAAyB,CAAC,CAAC;AAC/B,CAAC,EAxEgB,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAwExB"}
package/dist/types.d.ts CHANGED
@@ -7,3 +7,6 @@ export * from 'openapi3-ts';
7
7
  * @deprecated Use `OpenApiBuilder` from `openapi3-ts` instead.
8
8
  */
9
9
  export declare function createEmptyApiSpec(): OpenApiSpec;
10
+ export interface TagsDecoratorMetadata {
11
+ tags: string[];
12
+ }
package/package.json CHANGED
@@ -1,27 +1,27 @@
1
1
  {
2
2
  "name": "@loopback/openapi-v3",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "description": "Processes openapi v3 related metadata",
5
5
  "engines": {
6
6
  "node": ">=8.9"
7
7
  },
8
8
  "dependencies": {
9
- "@loopback/core": "^1.12.2",
10
- "@loopback/repository-json-schema": "^1.12.0",
9
+ "@loopback/core": "^1.12.3",
10
+ "@loopback/repository-json-schema": "^1.12.1",
11
11
  "debug": "^4.1.1",
12
12
  "json-merge-patch": "^0.2.3",
13
13
  "lodash": "^4.17.15",
14
14
  "openapi3-ts": "^1.3.0"
15
15
  },
16
16
  "devDependencies": {
17
- "@loopback/build": "^3.1.0",
18
- "@loopback/eslint-config": "^5.0.2",
19
- "@loopback/openapi-spec-builder": "^1.3.0",
20
- "@loopback/repository": "^1.18.0",
21
- "@loopback/testlab": "^1.10.2",
17
+ "@loopback/build": "^3.1.1",
18
+ "@loopback/eslint-config": "^5.0.3",
19
+ "@loopback/openapi-spec-builder": "^1.3.1",
20
+ "@loopback/repository": "^1.19.0",
21
+ "@loopback/testlab": "^1.10.3",
22
22
  "@types/debug": "^4.1.5",
23
23
  "@types/lodash": "^4.14.149",
24
- "@types/node": "^10.17.13"
24
+ "@types/node": "^10.17.14"
25
25
  },
26
26
  "scripts": {
27
27
  "build": "lb-tsc",
@@ -56,5 +56,5 @@
56
56
  "url": "https://github.com/strongloop/loopback-next.git",
57
57
  "directory": "packages/openapi-v3"
58
58
  },
59
- "gitHead": "d08f135a0d1040edc61497739a8d86a866e4e29a"
59
+ "gitHead": "b5e53892d327c6cf4c6023055d2b38f13fe4729e"
60
60
  }
@@ -25,6 +25,7 @@ import {
25
25
  ResponseObject,
26
26
  SchemaObject,
27
27
  SchemasObject,
28
+ TagsDecoratorMetadata,
28
29
  } from './types';
29
30
 
30
31
  const debug = require('debug')('loopback:openapi3:metadata:controller-spec');
@@ -77,6 +78,47 @@ function resolveControllerSpec(constructor: Function): ControllerSpec {
77
78
  spec = {paths: {}};
78
79
  }
79
80
 
81
+ const isClassDeprecated = MetadataInspector.getClassMetadata<boolean>(
82
+ OAI3Keys.DEPRECATED_CLASS_KEY,
83
+ constructor,
84
+ );
85
+
86
+ if (isClassDeprecated) {
87
+ debug(' using class-level @deprecated()');
88
+ }
89
+ const classTags = MetadataInspector.getClassMetadata<TagsDecoratorMetadata>(
90
+ OAI3Keys.TAGS_CLASS_KEY,
91
+ constructor,
92
+ );
93
+
94
+ if (classTags) {
95
+ debug(' using class-level @oas.tags()');
96
+ }
97
+
98
+ if (classTags || isClassDeprecated) {
99
+ for (const path of Object.keys(spec.paths)) {
100
+ for (const method of Object.keys(spec.paths[path])) {
101
+ /* istanbul ignore else */
102
+ if (isClassDeprecated) {
103
+ spec.paths[path][method].deprecated = true;
104
+ }
105
+ /* istanbul ignore else */
106
+ if (classTags) {
107
+ if (
108
+ spec.paths[path][method].tags &&
109
+ spec.paths[path][method].tags.length
110
+ ) {
111
+ spec.paths[path][method].tags = spec.paths[path][
112
+ method
113
+ ].tags.concat(classTags.tags);
114
+ } else {
115
+ spec.paths[path][method].tags = classTags.tags;
116
+ }
117
+ }
118
+ }
119
+ }
120
+ }
121
+
80
122
  let endpoints =
81
123
  MetadataInspector.getAllMethodMetadata<RestEndpoint>(
82
124
  OAI3Keys.METHODS_KEY,
@@ -91,6 +133,23 @@ function resolveControllerSpec(constructor: Function): ControllerSpec {
91
133
  const verb = endpoint.verb!;
92
134
  const path = endpoint.path!;
93
135
 
136
+ const isMethodDeprecated = MetadataInspector.getMethodMetadata<boolean>(
137
+ OAI3Keys.DEPRECATED_METHOD_KEY,
138
+ constructor.prototype,
139
+ op,
140
+ );
141
+ if (isMethodDeprecated) {
142
+ debug(' using method-level deprecation via @deprecated()');
143
+ }
144
+
145
+ const methodTags = MetadataInspector.getMethodMetadata<
146
+ TagsDecoratorMetadata
147
+ >(OAI3Keys.TAGS_METHOD_KEY, constructor.prototype, op);
148
+
149
+ if (methodTags) {
150
+ debug(' using method-level tags via @oas.tags()');
151
+ }
152
+
94
153
  let endpointName = '';
95
154
  /* istanbul ignore if */
96
155
  if (debug.enabled) {
@@ -113,10 +172,34 @@ function resolveControllerSpec(constructor: Function): ControllerSpec {
113
172
  };
114
173
  endpoint.spec = operationSpec;
115
174
  }
175
+
176
+ if (classTags && !operationSpec.tags) {
177
+ operationSpec.tags = classTags.tags;
178
+ }
179
+
180
+ if (methodTags) {
181
+ if (operationSpec.tags && operationSpec.tags.length) {
182
+ operationSpec.tags = operationSpec.tags.concat(methodTags.tags);
183
+ } else {
184
+ operationSpec.tags = methodTags.tags;
185
+ }
186
+ }
187
+
116
188
  debug(' operation for method %s: %j', op, endpoint);
117
189
 
118
190
  debug(' spec responses for method %s: %o', op, operationSpec.responses);
119
191
 
192
+ // Prescedence: method decorator > class decorator > operationSpec > undefined
193
+ const deprecationSpec =
194
+ isMethodDeprecated ??
195
+ isClassDeprecated ??
196
+ operationSpec.deprecated ??
197
+ false;
198
+
199
+ if (deprecationSpec) {
200
+ operationSpec.deprecated = true;
201
+ }
202
+
120
203
  for (const code in operationSpec.responses) {
121
204
  const responseObject: ResponseObject | ReferenceObject =
122
205
  operationSpec.responses[code];
@@ -0,0 +1,87 @@
1
+ // Copyright IBM Corp. 2018. All Rights Reserved.
2
+ // Node module: @loopback/openapi-v3
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ import {
7
+ ClassDecoratorFactory,
8
+ DecoratorFactory,
9
+ MethodDecoratorFactory,
10
+ } from '@loopback/core';
11
+ import {OAI3Keys} from '../keys';
12
+
13
+ const debug = require('debug')(
14
+ 'loopback:openapi3:metadata:controller-spec:deprecated',
15
+ );
16
+
17
+ /**
18
+ * Marks an api path as deprecated. When applied to a class, this decorator
19
+ * marks all paths as deprecated.
20
+ *
21
+ * You can optionally mark all controllers in a class as deprecated, but use
22
+ * `@deprecated(false)` on a specific method to ensure it is not marked
23
+ * as deprecated in the specification.
24
+ *
25
+ * @param isDeprecated - whether or not the path should be marked as deprecated.
26
+ * This is useful for marking a class as deprecated, but a method as
27
+ * not deprecated.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * @oas.deprecated()
32
+ * class MyController {
33
+ * @get('/greet')
34
+ * public async function greet() {
35
+ * return 'Hello, World!'
36
+ * }
37
+ *
38
+ * @get('/greet-v2')
39
+ * @oas.deprecated(false)
40
+ * public async function greetV2() {
41
+ * return 'Hello, World!'
42
+ * }
43
+ * }
44
+ *
45
+ * class MyOtherController {
46
+ * @get('/echo')
47
+ * public async function echo() {
48
+ * return 'Echo!'
49
+ * }
50
+ * }
51
+ * ```
52
+ */
53
+ export function deprecated(isDeprecated = true) {
54
+ return function deprecatedDecoratorForClassOrMethod(
55
+ // Class or a prototype
56
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
+ target: any,
58
+ method?: string,
59
+ // Use `any` to for `TypedPropertyDescriptor`
60
+ // See https://github.com/strongloop/loopback-next/pull/2704
61
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
62
+ methodDescriptor?: TypedPropertyDescriptor<any>,
63
+ ) {
64
+ debug(target, method, methodDescriptor);
65
+
66
+ if (method && methodDescriptor) {
67
+ // Method
68
+ return MethodDecoratorFactory.createDecorator<boolean>(
69
+ OAI3Keys.DEPRECATED_METHOD_KEY,
70
+ isDeprecated,
71
+ {decoratorName: '@oas.deprecated'},
72
+ )(target, method, methodDescriptor);
73
+ } else if (typeof target === 'function' && !method && !methodDescriptor) {
74
+ // Class
75
+ return ClassDecoratorFactory.createDecorator<boolean>(
76
+ OAI3Keys.DEPRECATED_CLASS_KEY,
77
+ isDeprecated,
78
+ {decoratorName: '@oas.deprecated'},
79
+ )(target);
80
+ } else {
81
+ throw new Error(
82
+ '@oas.deprecated cannot be used on a property: ' +
83
+ DecoratorFactory.getTargetName(target, method, methodDescriptor),
84
+ );
85
+ }
86
+ };
87
+ }
@@ -4,6 +4,36 @@
4
4
  // License text available at https://opensource.org/licenses/MIT
5
5
 
6
6
  export * from './api.decorator';
7
+ export * from './deprecated.decorator';
7
8
  export * from './operation.decorator';
8
9
  export * from './parameter.decorator';
9
10
  export * from './request-body.decorator';
11
+
12
+ import {api} from './api.decorator';
13
+ import {deprecated} from './deprecated.decorator';
14
+ import {del, get, operation, patch, post, put} from './operation.decorator';
15
+ import {param} from './parameter.decorator';
16
+ import {requestBody} from './request-body.decorator';
17
+ import {tags} from './tags.decorator';
18
+
19
+ export const oas = {
20
+ api,
21
+ operation,
22
+
23
+ // methods
24
+ get,
25
+ post,
26
+ del,
27
+ patch,
28
+ put,
29
+
30
+ //param
31
+ param,
32
+
33
+ // request body
34
+ requestBody,
35
+
36
+ // oas convenience decorators
37
+ deprecated,
38
+ tags,
39
+ };
@@ -0,0 +1,46 @@
1
+ // Copyright IBM Corp. 2018. All Rights Reserved.
2
+ // Node module: @loopback/openapi-v3
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ import {
7
+ ClassDecoratorFactory,
8
+ DecoratorFactory,
9
+ MethodDecoratorFactory,
10
+ } from '@loopback/core';
11
+ import {OAI3Keys} from '../keys';
12
+ import {TagsDecoratorMetadata} from '../types';
13
+
14
+ export function tags(...tagNames: string[]) {
15
+ return function tagsDecoratorForClassOrMethod(
16
+ // Class or a prototype
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ target: any,
19
+ method?: string,
20
+ // Use `any` to for `TypedPropertyDescriptor`
21
+ // See https://github.com/strongloop/loopback-next/pull/2704
22
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
+ methodDescriptor?: TypedPropertyDescriptor<any>,
24
+ ) {
25
+ if (method && methodDescriptor) {
26
+ // Method
27
+ return MethodDecoratorFactory.createDecorator<TagsDecoratorMetadata>(
28
+ OAI3Keys.TAGS_METHOD_KEY,
29
+ {tags: tagNames},
30
+ {decoratorName: '@oas.tags'},
31
+ )(target, method, methodDescriptor);
32
+ } else if (typeof target === 'function' && !method && !methodDescriptor) {
33
+ // Class
34
+ return ClassDecoratorFactory.createDecorator<TagsDecoratorMetadata>(
35
+ OAI3Keys.TAGS_CLASS_KEY,
36
+ {tags: tagNames},
37
+ {decoratorName: '@oas.tags'},
38
+ )(target);
39
+ } else {
40
+ throw new Error(
41
+ '@oas.tags cannot be used on a property: ' +
42
+ DecoratorFactory.getTargetName(target, method, methodDescriptor),
43
+ );
44
+ }
45
+ };
46
+ }
package/src/keys.ts CHANGED
@@ -16,6 +16,22 @@ export namespace OAI3Keys {
16
16
  MethodDecorator
17
17
  >('openapi-v3:methods');
18
18
 
19
+ /**
20
+ * Metadata key used to set or retrieve `@deprecated` metadata on a method.
21
+ */
22
+ export const DEPRECATED_METHOD_KEY = MetadataAccessor.create<
23
+ boolean,
24
+ MethodDecorator
25
+ >('openapi-v3:methods:deprecated');
26
+
27
+ /**
28
+ * Metadata key used to set or retrieve `@deprecated` metadata on a class
29
+ */
30
+ export const DEPRECATED_CLASS_KEY = MetadataAccessor.create<
31
+ boolean,
32
+ ClassDecorator
33
+ >('openapi-v3:class:deprecated');
34
+
19
35
  /**
20
36
  * Metadata key used to set or retrieve `param` decorator metadata
21
37
  */
@@ -24,6 +40,22 @@ export namespace OAI3Keys {
24
40
  ParameterDecorator
25
41
  >('openapi-v3:parameters');
26
42
 
43
+ /**
44
+ * Metadata key used to set or retrieve `@deprecated` metadata on a method.
45
+ */
46
+ export const TAGS_METHOD_KEY = MetadataAccessor.create<
47
+ string[],
48
+ MethodDecorator
49
+ >('openapi-v3:methods:tags');
50
+
51
+ /**
52
+ * Metadata key used to set or retrieve `@deprecated` metadata on a class
53
+ */
54
+ export const TAGS_CLASS_KEY = MetadataAccessor.create<
55
+ string[],
56
+ ClassDecorator
57
+ >('openapi-v3:class:tags');
58
+
27
59
  /**
28
60
  * Metadata key used to set or retrieve `@api` metadata
29
61
  */
package/src/types.ts CHANGED
@@ -28,3 +28,7 @@ export function createEmptyApiSpec(): OpenApiSpec {
28
28
  servers: [{url: '/'}],
29
29
  };
30
30
  }
31
+
32
+ export interface TagsDecoratorMetadata {
33
+ tags: string[];
34
+ }