Skip to content

Commit fda99f0

Browse files
feat: initial implementation with bugs
1 parent 5cf6013 commit fda99f0

File tree

2 files changed

+775
-498
lines changed

2 files changed

+775
-498
lines changed

src/framework/types.ts

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import AjvDraft4 from 'ajv-draft-04';
77
import Ajv2020 from 'ajv/dist/2020';
88
export { OpenAPIFrameworkArgs };
99

10-
export type AjvInstance = AjvDraft4 | Ajv2020
10+
export type AjvInstance = AjvDraft4 | Ajv2020;
1111

1212
export type BodySchema =
1313
| OpenAPIV3.ReferenceObject
@@ -48,7 +48,7 @@ export interface Options extends ajv.Options {
4848
ajvFormats?: FormatsPluginOptions;
4949
}
5050

51-
export interface RequestValidatorOptions extends Options, ValidateRequestOpts { }
51+
export interface RequestValidatorOptions extends Options, ValidateRequestOpts {}
5252

5353
export type ValidateRequestOpts = {
5454
/**
@@ -125,32 +125,42 @@ export class SerDesSingleton implements SerDes {
125125
serialize: param.serialize,
126126
};
127127
}
128-
};
128+
}
129129

130130
export type SerDesMap = {
131-
[format: string]: SerDes
131+
[format: string]: SerDes;
132132
};
133133

134-
type Primitive = undefined | null | boolean | string | number | Function
134+
type Primitive = undefined | null | boolean | string | number | Function;
135135

136-
type Immutable<T> =
137-
T extends Primitive ? T :
138-
T extends Array<infer U> ? ReadonlyArray<U> :
139-
T extends Map<infer K, infer V> ? ReadonlyMap<K, V> : Readonly<T>
136+
type Immutable<T> = T extends Primitive
137+
? T
138+
: T extends Array<infer U>
139+
? ReadonlyArray<U>
140+
: T extends Map<infer K, infer V>
141+
? ReadonlyMap<K, V>
142+
: Readonly<T>;
140143

141-
type DeepImmutable<T> =
142-
T extends Primitive ? T :
143-
T extends Array<infer U> ? DeepImmutableArray<U> :
144-
T extends Map<infer K, infer V> ? DeepImmutableMap<K, V> : DeepImmutableObject<T>
144+
type DeepImmutable<T> = T extends Primitive
145+
? T
146+
: T extends Array<infer U>
147+
? DeepImmutableArray<U>
148+
: T extends Map<infer K, infer V>
149+
? DeepImmutableMap<K, V>
150+
: DeepImmutableObject<T>;
145151

146152
interface DeepImmutableArray<T> extends ReadonlyArray<DeepImmutable<T>> {}
147-
interface DeepImmutableMap<K, V> extends ReadonlyMap<DeepImmutable<K>, DeepImmutable<V>> {}
153+
interface DeepImmutableMap<K, V>
154+
extends ReadonlyMap<DeepImmutable<K>, DeepImmutable<V>> {}
148155
type DeepImmutableObject<T> = {
149-
readonly [K in keyof T]: DeepImmutable<T[K]>
150-
}
156+
readonly [K in keyof T]: DeepImmutable<T[K]>;
157+
};
151158

152159
export interface OpenApiValidatorOpts {
153-
apiSpec: DeepImmutable<OpenAPIV3.DocumentV3> | DeepImmutable<OpenAPIV3.DocumentV3_1> | string;
160+
apiSpec:
161+
| DeepImmutable<OpenAPIV3.DocumentV3>
162+
| DeepImmutable<OpenAPIV3.DocumentV3_1>
163+
| string;
154164
validateApiSpec?: boolean;
155165
validateResponses?: boolean | ValidateResponseOpts;
156166
validateRequests?: boolean | ValidateRequestOpts;
@@ -204,18 +214,19 @@ export namespace OpenAPIV3 {
204214
externalDocs?: ExternalDocumentationObject;
205215
}
206216

207-
interface ComponentsV3_1 extends ComponentsObject {
208-
pathItems?: { [path: string]: PathItemObject | ReferenceObject }
217+
export interface ComponentsV3_1 extends ComponentsObject {
218+
pathItems?: { [path: string]: PathItemObject | ReferenceObject };
209219
}
210220

211-
export interface DocumentV3_1 extends Omit<DocumentV3, 'paths' | 'info' | 'components'| "openapi" > {
221+
export interface DocumentV3_1
222+
extends Omit<DocumentV3, 'paths' | 'info' | 'components' | 'openapi'> {
212223
openapi: `3.1.${string}`;
213224
paths?: DocumentV3['paths'];
214225
info: InfoObjectV3_1;
215226
components: ComponentsV3_1;
216227
webhooks: {
217-
[name: string]: PathItemObject | ReferenceObject
218-
}
228+
[name: string]: PathItemObject | ReferenceObject;
229+
};
219230
}
220231

221232
export interface InfoObject {
@@ -299,7 +310,7 @@ export namespace OpenAPIV3 {
299310
in: string;
300311
}
301312

302-
export interface HeaderObject extends ParameterBaseObject { }
313+
export interface HeaderObject extends ParameterBaseObject {}
303314

304315
interface ParameterBaseObject {
305316
description?: string;
@@ -323,14 +334,18 @@ export namespace OpenAPIV3 {
323334
| 'integer';
324335
export type ArraySchemaObjectType = 'array';
325336

326-
export type SchemaObject = ArraySchemaObject | NonArraySchemaObject | CompositionSchemaObject;
337+
export type SchemaObject =
338+
| ArraySchemaObject
339+
| NonArraySchemaObject
340+
| CompositionSchemaObject;
327341

328-
export interface ArraySchemaObject extends BaseSchemaObject<ArraySchemaObjectType> {
342+
export interface ArraySchemaObject
343+
extends BaseSchemaObject<ArraySchemaObjectType> {
329344
items: ReferenceObject | SchemaObject;
330345
}
331346

332-
export interface NonArraySchemaObject extends BaseSchemaObject<NonArraySchemaObjectType> {
333-
}
347+
export interface NonArraySchemaObject
348+
extends BaseSchemaObject<NonArraySchemaObjectType> {}
334349

335350
export interface CompositionSchemaObject extends BaseSchemaObject<undefined> {
336351
// JSON schema allowed properties, adjusted for OpenAPI

0 commit comments

Comments
 (0)