Skip to content

Commit 3d4751a

Browse files
committed
fix(schema): fix typing for operation decorators
1 parent 7060d65 commit 3d4751a

19 files changed

+33
-17
lines changed

packages/specs/schema/src/decorators/generics/generics.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {JsonEntityStore} from "../../domain/JsonEntityStore.js";
1313
* @input
1414
* @generics
1515
*/
16-
export function Generics(...generics: string[]) {
16+
export function Generics(...generics: string[]): ClassDecorator {
1717
return (target: any) => {
1818
const storedSchema = JsonEntityStore.from(target);
1919

packages/specs/schema/src/decorators/operations/acceptMime.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ import {Produces} from "./produces.js";
2020
* @operation
2121
* @response
2222
*/
23-
export function AcceptMime(...mimes: string[]): Function {
23+
export function AcceptMime(...mimes: string[]): ClassDecorator & MethodDecorator {
2424
return useDecorators(Produces(...mimes), StoreSet("acceptMimes", mimes));
2525
}

packages/specs/schema/src/decorators/operations/consumes.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ describe("Consumes", () => {
7979

8080
let actualError: any;
8181
try {
82+
// @ts-ignore
8283
Consumes("text/json")(Test.prototype, "test", 0);
8384
} catch (er) {
8485
actualError = er;

packages/specs/schema/src/decorators/operations/consumes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {JsonEntityFn} from "../common/jsonEntityFn.js";
2020
* @classDecorator
2121
* @operation
2222
*/
23-
export function Consumes(...consumes: string[]) {
23+
export function Consumes(...consumes: string[]): ClassDecorator & MethodDecorator {
2424
return JsonEntityFn((store, args) => {
2525
switch (store.decoratorType) {
2626
case DecoratorTypes.METHOD:

packages/specs/schema/src/decorators/operations/header.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import {Returns} from "./returns.js";
5050
* @operation
5151
* @response
5252
*/
53-
export function Header(headers: string | number | JsonHeaders, value?: string | number | JsonHeader): Function {
53+
export function Header(headers: string | number | JsonHeaders, value?: string | number | JsonHeader) {
5454
if (value !== undefined) {
5555
headers = {[headers as string]: value};
5656
}

packages/specs/schema/src/decorators/operations/operationId.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe("OperationId", () => {
3333
it("should throw error for unsupported usage", () => {
3434
let actualError: any;
3535
try {
36+
// @ts-ignore
3637
OperationId("id")(class Test {});
3738
} catch (er) {
3839
actualError = er;

packages/specs/schema/src/decorators/operations/operationId.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {JsonEntityFn} from "../common/jsonEntityFn.js";
1111
* @schema
1212
* @operation
1313
*/
14-
export function OperationId(operationId: string) {
14+
export function OperationId(operationId: string): MethodDecorator {
1515
return JsonEntityFn((store, args) => {
1616
if (store.decoratorType !== DecoratorTypes.METHOD) {
1717
throw new UnsupportedDecoratorType(OperationId, args);

packages/specs/schema/src/decorators/operations/operationPath.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {JsonEntityFn} from "../common/jsonEntityFn.js";
99
* ::: warning
1010
* Don't use decorator with Ts.ED application.
1111
*
12-
* Use theses decorators instead:
12+
* Use these decorators instead:
1313
*
1414
* <ApiList query="status.includes('decorator') && status.includes('httpMethod')" />
1515
*

packages/specs/schema/src/decorators/operations/path.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe("Path", () => {
3737

3838
let actualError: any;
3939
try {
40+
// @ts-ignore
4041
Path("/")(Test.prototype, "test", 0);
4142
} catch (er) {
4243
actualError = er;

packages/specs/schema/src/decorators/operations/path.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {JsonEntityFn} from "../common/jsonEntityFn.js";
1616
* @classDecorator
1717
* @operation
1818
*/
19-
export function Path(path: string) {
19+
export function Path(path: string): ClassDecorator {
2020
return JsonEntityFn((store, args) => {
2121
if (store.decoratorType !== DecoratorTypes.CLASS) {
2222
throw new UnsupportedDecoratorType(Path, args);

packages/specs/schema/src/decorators/operations/produces.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ describe("Produces", () => {
7979

8080
let actualError: any;
8181
try {
82+
// @ts-ignore
8283
Produces("text/json")(Test.prototype, "test", 0);
8384
} catch (er) {
8485
actualError = er;

packages/specs/schema/src/decorators/operations/produces.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {JsonEntityFn} from "../common/jsonEntityFn.js";
2727
* @operation
2828
* @response
2929
*/
30-
export function Produces(...produces: string[]) {
30+
export function Produces(...produces: string[]): ClassDecorator & MethodDecorator {
3131
return JsonEntityFn((store, args) => {
3232
switch (store.decoratorType) {
3333
case DecoratorTypes.METHOD:

packages/specs/schema/src/decorators/operations/redirect.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ import {Returns} from "./returns.js";
5353
* @response
5454
* @headers
5555
*/
56-
export function Redirect(url: string, meta?: JsonHeader): Function;
57-
export function Redirect(status: number, url: string, meta?: JsonHeader): Function;
58-
export function Redirect(...args: any[]): Function {
56+
export function Redirect(url: string, meta?: JsonHeader): MethodDecorator;
57+
export function Redirect(status: number, url: string, meta?: JsonHeader): MethodDecorator;
58+
export function Redirect(...args: any[]): MethodDecorator {
5959
const {status, url, meta} = args.reduce(
6060
(options: any, value: any) => {
6161
if (isNumber(value)) {

packages/specs/schema/src/decorators/operations/security.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ describe("Security", () => {
152152

153153
let actualError: any;
154154
try {
155+
// @ts-ignore
155156
Security("POST", "/")(Test.prototype, "test", 0);
156157
} catch (er) {
157158
actualError = er;

packages/specs/schema/src/decorators/operations/security.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {JsonEntityFn} from "../common/jsonEntityFn.js";
2525
* @classDecorator
2626
* @operation
2727
*/
28-
export function Security(name: string, ...scopes: string[]): Function;
28+
export function Security(name: string, ...scopes: string[]): ClassDecorator & MethodDecorator;
2929
/**
3030
* Add security metadata on the decorated method.
3131
*
@@ -57,8 +57,8 @@ export function Security(name: string, ...scopes: string[]): Function;
5757
* @classDecorator
5858
* @operation
5959
*/
60-
export function Security(security: OpenSpecSecurity): Function;
61-
export function Security(nameOrSecurity: string | OpenSpecSecurity, ...scopes: string[]): Function {
60+
export function Security(security: OpenSpecSecurity): ClassDecorator & MethodDecorator;
61+
export function Security(nameOrSecurity: string | OpenSpecSecurity, ...scopes: string[]): ClassDecorator & MethodDecorator {
6262
return JsonEntityFn((store, args) => {
6363
switch (store.decoratorType) {
6464
case DecoratorTypes.METHOD:

packages/specs/schema/src/decorators/operations/summary.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe("Summary", () => {
3535
it("should throw error for unsupported usage", () => {
3636
let actualError: any;
3737
try {
38+
// @ts-ignore
3839
Summary("summary")(class Test {});
3940
} catch (er) {
4041
actualError = er;

packages/specs/schema/src/decorators/operations/summary.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {JsonEntityFn} from "../common/jsonEntityFn.js";
2121
* @schema
2222
* @operation
2323
*/
24-
export function Summary(summary: string) {
24+
export function Summary(summary: string): MethodDecorator {
2525
return JsonEntityFn((store, args) => {
2626
if (store.decoratorType !== DecoratorTypes.METHOD) {
2727
throw new UnsupportedDecoratorType(Summary, args);

packages/specs/schema/src/decorators/operations/tags.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ describe("Tags", () => {
103103

104104
let actualError: any;
105105
try {
106+
// @ts-ignore
106107
Tags("tags")(Test.prototype, "test", 0);
107108
} catch (er) {
108109
actualError = er;

packages/specs/schema/src/decorators/operations/tags.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function mapTags(tags: (string | OpenSpecTag)[]) {
1616
}
1717

1818
/**
19-
* Add tags metadata on the decorated element.
19+
* Add metadata tags to the decorated element (class or method).
2020
*
2121
* ## Examples
2222
* ### On method
@@ -28,6 +28,15 @@ function mapTags(tags: (string | OpenSpecTag)[]) {
2828
* get() {}
2929
* }
3030
* ```
31+
* ### On Class
32+
*
33+
* ```typescript
34+
* @Controller("/")
35+
* @Tags("api")
36+
* class MyController {
37+
* get() {}
38+
* }
39+
* ```
3140
*
3241
* @param tags
3342
* @decorator
@@ -36,7 +45,7 @@ function mapTags(tags: (string | OpenSpecTag)[]) {
3645
* @classDecorator
3746
* @operation
3847
*/
39-
export function Tags(...tags: (string | OpenSpecTag)[]) {
48+
export function Tags(...tags: (string | OpenSpecTag)[]): ClassDecorator & MethodDecorator {
4049
return JsonEntityFn((store, args) => {
4150
switch (store.decoratorType) {
4251
case DecoratorTypes.METHOD:

0 commit comments

Comments
 (0)