Skip to content

Commit f525bd1

Browse files
committed
fix: use generics to maintain the correct type when refererencing the object externally
1 parent 9b449f9 commit f525bd1

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

lib/schema.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { Construct } from 'constructs';
22
import type { OpenAPIV3 } from 'openapi-types';
33

4-
interface SchemaOptions {
5-
schema: OpenAPIV3.SchemaObject;
4+
interface SchemaOptions<T extends OpenAPIV3.SchemaObject> {
5+
schema: T;
66
}
77

8-
export class Schema extends Construct {
9-
private options: SchemaOptions;
8+
export class Schema<
9+
T extends OpenAPIV3.SchemaObject = OpenAPIV3.SchemaObject,
10+
> extends Construct {
11+
private options: SchemaOptions<T>;
1012

11-
constructor(scope: Construct, id: string, options: SchemaOptions) {
13+
constructor(scope: Construct, id: string, options: SchemaOptions<T>) {
1214
super(scope, id);
1315

1416
this.options = options;
@@ -36,7 +38,7 @@ export class Schema extends Construct {
3638
return [];
3739
}
3840

39-
public synth(): OpenAPIV3.SchemaObject {
41+
public synth(): T {
4042
return this.options.schema;
4143
}
4244
}

0 commit comments

Comments
 (0)