File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { Construct } from 'constructs' ;
22import type { oas31 } from 'openapi3-ts' ;
33
4- interface SchemaOptions < T extends oas31 . SchemaObject > {
5- schema : T ;
6- }
4+ type InferExample < T > = T extends oas31 . ReferenceObject
5+ ? any
6+ : T extends {
7+ type : 'string' ;
8+ }
9+ ? string
10+ : T extends {
11+ type : 'number' | 'integer' ;
12+ }
13+ ? number
14+ : T extends {
15+ type : 'boolean' ;
16+ }
17+ ? boolean
18+ : T extends oas31 . SchemaObject & { type : 'object' }
19+ ? {
20+ [ K in keyof T [ 'properties' ] ] : InferExample < T [ 'properties' ] [ K ] > ;
21+ }
22+ : T extends oas31 . SchemaObject & { type : 'array' }
23+ ? InferExample < T [ 'items' ] > [ ]
24+ : any ;
25+
26+ export type SchemaOptions < T extends oas31 . SchemaObject > = {
27+ schema : T & {
28+ examples ?: InferExample < T > [ ] ;
29+ } ;
30+ } ;
731
832export class Schema <
9- T extends oas31 . SchemaObject = oas31 . SchemaObject ,
33+ const T extends oas31 . SchemaObject = oas31 . SchemaObject ,
1034> extends Construct {
1135 private options : SchemaOptions < T > ;
1236
@@ -40,6 +64,9 @@ export class Schema<
4064 }
4165
4266 public synth ( ) {
43- return this . options . schema ;
67+ return {
68+ additionalProperties : false ,
69+ ...this . options . schema ,
70+ } ;
4471 }
4572}
You can’t perform that action at this time.
0 commit comments