Skip to content

Commit 1b0095a

Browse files
committed
lint
1 parent 3bd9749 commit 1b0095a

File tree

12 files changed

+32
-117
lines changed

12 files changed

+32
-117
lines changed

packages/openapi-metadata/src/decorators/api-body.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import type { SetOptional } from "type-fest";
2-
import {
3-
type OperationBodyMetadata,
4-
OperationBodyMetadataStorage,
5-
} from "../metadata/operation-body.js";
2+
import { type OperationBodyMetadata, OperationBodyMetadataStorage } from "../metadata/operation-body.js";
63

74
export type ApiBodyOptions = SetOptional<OperationBodyMetadata, "mediaType">;
85

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
type OperationParameterMetadata,
3-
OperationParameterMetadataStorage,
4-
} from "../metadata/operation-parameter.js";
1+
import { type OperationParameterMetadata, OperationParameterMetadataStorage } from "../metadata/operation-parameter.js";
52

63
export type ApiCookieOptions = Omit<OperationParameterMetadata, "in">;
74

@@ -13,10 +10,6 @@ export type ApiCookieOptions = Omit<OperationParameterMetadata, "in">;
1310
*/
1411
export function ApiCookie(options: ApiCookieOptions) {
1512
return (target: Object, propertyKey?: string | symbol) => {
16-
OperationParameterMetadataStorage.mergeMetadata(
17-
target,
18-
[{ in: "cookie", ...options }],
19-
propertyKey,
20-
);
13+
OperationParameterMetadataStorage.mergeMetadata(target, [{ in: "cookie", ...options }], propertyKey);
2114
};
2215
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
type OperationParameterMetadata,
3-
OperationParameterMetadataStorage,
4-
} from "../metadata/operation-parameter.js";
1+
import { type OperationParameterMetadata, OperationParameterMetadataStorage } from "../metadata/operation-parameter.js";
52

63
export type ApiHeaderOptions = Omit<OperationParameterMetadata, "in">;
74

@@ -13,10 +10,6 @@ export type ApiHeaderOptions = Omit<OperationParameterMetadata, "in">;
1310
*/
1411
export function ApiHeader(options: ApiHeaderOptions) {
1512
return (target: Object, propertyKey?: string | symbol) => {
16-
OperationParameterMetadataStorage.mergeMetadata(
17-
target,
18-
[{ in: "header", ...options }],
19-
propertyKey,
20-
);
13+
OperationParameterMetadataStorage.mergeMetadata(target, [{ in: "header", ...options }], propertyKey);
2114
};
2215
}

packages/openapi-metadata/src/decorators/api-operation.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
type OperationMetadata,
3-
OperationMetadataStorage,
4-
} from "../metadata/operation.js";
1+
import { type OperationMetadata, OperationMetadataStorage } from "../metadata/operation.js";
52

63
export type ApiOperationOptions = OperationMetadata;
74

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
type OperationParameterMetadata,
3-
OperationParameterMetadataStorage,
4-
} from "../metadata/operation-parameter.js";
1+
import { type OperationParameterMetadata, OperationParameterMetadataStorage } from "../metadata/operation-parameter.js";
52

63
export type ApiParamOptions = Omit<OperationParameterMetadata, "in">;
74

@@ -13,10 +10,6 @@ export type ApiParamOptions = Omit<OperationParameterMetadata, "in">;
1310
*/
1411
export function ApiParam(options: ApiParamOptions) {
1512
return function (target: Object, propertyKey?: string | symbol) {
16-
OperationParameterMetadataStorage.mergeMetadata(
17-
target,
18-
[{ in: "path", ...options }],
19-
propertyKey,
20-
);
13+
OperationParameterMetadataStorage.mergeMetadata(target, [{ in: "path", ...options }], propertyKey);
2114
};
2215
}

packages/openapi-metadata/src/decorators/api-property.ts

+4-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import type { Context } from "../context.js";
22
import { SymbolKeysNotSupportedError } from "../errors/symbol-keys-not-supported.js";
3-
import {
4-
type PropertyMetadata,
5-
PropertyMetadataStorage,
6-
} from "../metadata/property.js";
3+
import { type PropertyMetadata, PropertyMetadataStorage } from "../metadata/property.js";
74
import { findType } from "../utils/metadata.js";
85

96
export type ApiPropertyOptions = Partial<PropertyMetadata>;
@@ -16,9 +13,7 @@ export type ApiPropertyOptions = Partial<PropertyMetadata>;
1613
*/
1714
export function ApiProperty(options?: ApiPropertyOptions): PropertyDecorator;
1815
export function ApiProperty(options?: ApiPropertyOptions): MethodDecorator;
19-
export function ApiProperty(
20-
options?: ApiPropertyOptions,
21-
): PropertyDecorator | MethodDecorator {
16+
export function ApiProperty(options?: ApiPropertyOptions): PropertyDecorator | MethodDecorator {
2217
return (prototype, propertyKey, descriptor) => {
2318
const isMethod = Boolean(descriptor?.value);
2419

@@ -54,12 +49,8 @@ export function ApiProperty(
5449
*
5550
* @see https://swagger.io/specification/#schema-object
5651
*/
57-
export function ApiPropertyOptional(
58-
options?: Omit<ApiPropertyOptions, "required">,
59-
): PropertyDecorator;
60-
export function ApiPropertyOptional(
61-
options?: Omit<ApiPropertyOptions, "required">,
62-
): MethodDecorator;
52+
export function ApiPropertyOptional(options?: Omit<ApiPropertyOptions, "required">): PropertyDecorator;
53+
export function ApiPropertyOptional(options?: Omit<ApiPropertyOptions, "required">): MethodDecorator;
6354
export function ApiPropertyOptional(
6455
options?: Omit<ApiPropertyOptions, "required">,
6556
): PropertyDecorator | MethodDecorator {
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
type OperationParameterMetadata,
3-
OperationParameterMetadataStorage,
4-
} from "../metadata/operation-parameter.js";
1+
import { type OperationParameterMetadata, OperationParameterMetadataStorage } from "../metadata/operation-parameter.js";
52

63
export type ApiQueryOptions = Omit<OperationParameterMetadata, "in">;
74

@@ -13,10 +10,6 @@ export type ApiQueryOptions = Omit<OperationParameterMetadata, "in">;
1310
*/
1411
export function ApiQuery(options: ApiQueryOptions) {
1512
return function (target: Object, propertyKey?: string | symbol) {
16-
OperationParameterMetadataStorage.mergeMetadata(
17-
target,
18-
[{ in: "query", ...options }],
19-
propertyKey,
20-
);
13+
OperationParameterMetadataStorage.mergeMetadata(target, [{ in: "query", ...options }], propertyKey);
2114
};
2215
}

packages/openapi-metadata/src/decorators/api-response.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import type { SetOptional } from "type-fest";
2-
import {
3-
type OperationResponseMetadata,
4-
OperationResponseMetadataStorage,
5-
} from "../metadata/operation-response.js";
2+
import { type OperationResponseMetadata, OperationResponseMetadataStorage } from "../metadata/operation-response.js";
63

7-
export type ApiResponseOptions = SetOptional<
8-
OperationResponseMetadata,
9-
"status" | "mediaType"
10-
>;
4+
export type ApiResponseOptions = SetOptional<OperationResponseMetadata, "status" | "mediaType">;
115

126
/**
137
* Configures a response.

packages/openapi-metadata/src/loaders/type.ts

+10-28
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ export const ArrayTypeLoader: TypeLoaderFn = async (context, value) => {
5555

5656
// TODO: Better warn stack trace
5757
if (!itemsSchema) {
58-
context.logger.warn(
59-
"You tried to specify an array type with an item that resolves to undefined.",
60-
);
58+
context.logger.warn("You tried to specify an array type with an item that resolves to undefined.");
6159
return;
6260
}
6361

@@ -81,32 +79,22 @@ export const ClassTypeLoader: TypeLoaderFn = async (context, value) => {
8179
return { $ref: getSchemaPath(model) };
8280
}
8381

84-
const schema: SetRequired<OpenAPIV3.SchemaObject, "properties" | "required"> =
85-
{
86-
type: "object",
87-
properties: {},
88-
required: [],
89-
};
82+
const schema: SetRequired<OpenAPIV3.SchemaObject, "properties" | "required"> = {
83+
type: "object",
84+
properties: {},
85+
required: [],
86+
};
9087

9188
const properties = PropertyMetadataStorage.getMetadata(value.prototype);
9289

9390
if (!properties) {
94-
context.logger.warn(
95-
`You tried to use '${model}' as a type but it does not contain any ApiProperty.`,
96-
);
91+
context.logger.warn(`You tried to use '${model}' as a type but it does not contain any ApiProperty.`);
9792
}
9893

9994
context.schemas[model] = schema;
10095

10196
for (const [key, property] of Object.entries(properties)) {
102-
const {
103-
required,
104-
type,
105-
name,
106-
enum: e,
107-
schema: s,
108-
...metadata
109-
} = property as any;
97+
const { required, type, name, enum: e, schema: s, ...metadata } = property as any;
11098
schema.properties[key] = {
11199
...(await loadType(context, property)),
112100
...metadata,
@@ -149,18 +137,12 @@ export async function loadType(
149137
const thunk = isThunk(options.type);
150138
const value = thunk ? (options.type as Function)(context) : options.type;
151139

152-
for (const loader of [
153-
PrimitiveTypeLoader,
154-
...context.typeLoaders,
155-
ClassTypeLoader,
156-
]) {
140+
for (const loader of [PrimitiveTypeLoader, ...context.typeLoaders, ClassTypeLoader]) {
157141
const result = await loader(context, value, options.type);
158142
if (result) {
159143
return result;
160144
}
161145
}
162146

163-
context.logger.warn(
164-
`You tried to use '${options.type.toString()}' as a type but no loader supports it ${thunk}`,
165-
);
147+
context.logger.warn(`You tried to use '${options.type.toString()}' as a type but no loader supports it ${thunk}`);
166148
}

packages/openapi-metadata/src/metadata/operation.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ export type OperationMetadata = Omit<OpenAPIV3.OperationObject, "responses"> & {
1717

1818
export const OperationMetadataKey = Symbol("Operation");
1919

20-
export const OperationMetadataStorage =
21-
createMetadataStorage<OperationMetadata>(OperationMetadataKey, {});
20+
export const OperationMetadataStorage = createMetadataStorage<OperationMetadata>(OperationMetadataKey, {});

packages/openapi-metadata/src/ui/swagger.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ export type GenerateSwaggerUIOptions = {
77
*
88
* @see https://swagger.io/tools/swagger-ui/
99
*/
10-
export function generateSwaggerUI(
11-
url: string,
12-
options?: GenerateSwaggerUIOptions,
13-
) {
10+
export function generateSwaggerUI(url: string, options?: GenerateSwaggerUIOptions) {
1411
const swaggerOptions = {
1512
url,
1613
...options,

packages/openapi-metadata/src/utils/metadata.ts

+4-18
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,12 @@ import { ReflectMetadataMissingError } from "../errors/reflect-metadata-missing.
77
* Asserts that `reflect-metadata` exists.
88
*/
99
export function assertReflectMetadata() {
10-
if (
11-
typeof Reflect !== "object" ||
12-
typeof Reflect.getMetadata !== "function"
13-
) {
10+
if (typeof Reflect !== "object" || typeof Reflect.getMetadata !== "function") {
1411
throw new ReflectMetadataMissingError();
1512
}
1613
}
1714

18-
export type MetadataKey =
19-
| "design:type"
20-
| "design:returntype"
21-
| "design:paramtypes";
15+
export type MetadataKey = "design:type" | "design:returntype" | "design:paramtypes";
2216

2317
export type FindTypeOptions = {
2418
context: Context;
@@ -30,17 +24,9 @@ export type FindTypeOptions = {
3024
/**
3125
* Returns the type inferred from class member.
3226
*/
33-
export function findType({
34-
metadataKey,
35-
prototype,
36-
propertyKey,
37-
}: FindTypeOptions) {
27+
export function findType({ metadataKey, prototype, propertyKey }: FindTypeOptions) {
3828
assertReflectMetadata();
39-
const reflectedType: Function | undefined = Reflect.getMetadata(
40-
metadataKey,
41-
prototype,
42-
propertyKey,
43-
);
29+
const reflectedType: Function | undefined = Reflect.getMetadata(metadataKey, prototype, propertyKey);
4430

4531
if (!reflectedType) {
4632
throw new NoExplicitTypeError(prototype.constructor.name, propertyKey);

0 commit comments

Comments
 (0)