Skip to content

Commit 1ea35b6

Browse files
committed
feat: output is now always openapi 3.1
1 parent 9407389 commit 1ea35b6

7 files changed

Lines changed: 24 additions & 24 deletions

File tree

lib/api.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Construct, type IConstruct } from 'constructs';
2-
import type { JSONSchema4, JSONSchema7 } from 'json-schema';
2+
import type { JSONSchema7 } from 'json-schema';
33
import type { OpenAPIV3_1 } from 'openapi-types';
44
import { Parameter } from './parameter.js';
55
import { Path } from './path.js';
@@ -9,7 +9,7 @@ import { SecurityRequirement } from './security-requirement.js';
99
import { SecurityScheme } from './security-scheme.js';
1010

1111
export enum OpenApiVersion {
12-
V2 = '2.0',
12+
// V2 = '2.0',
1313
V3 = '3.0',
1414
V3_1 = '3.1.0',
1515
}
@@ -40,7 +40,7 @@ export class Api extends Construct {
4040
return Api.of(scope);
4141
}
4242

43-
public synth(): OpenAPIV3_1.Document {
43+
public synth() {
4444
return {
4545
openapi: this.options.openapi,
4646
info: this.options.info,
@@ -78,17 +78,17 @@ export class Api extends Construct {
7878
child instanceof SecurityRequirement,
7979
)
8080
.map((child) => child.synth()),
81-
};
81+
} satisfies OpenAPIV3_1.Document;
8282
}
8383

84-
public synthJsonSchema(): JSONSchema4 | JSONSchema7 {
84+
public synthJsonSchema() {
8585
return {
8686
$schema: 'http://json-schema.org/draft-07/schema#',
8787
definitions: Object.fromEntries(
8888
this.node.children
8989
.filter((child): child is Schema => child instanceof Schema)
9090
.map((child) => [child.schemaKey, child.synth()]),
9191
),
92-
};
92+
} satisfies JSONSchema7;
9393
}
9494
}

lib/media-type.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Construct } from 'constructs';
2-
import type { OpenAPIV3 } from 'openapi-types';
2+
import type { OpenAPIV3_1 } from 'openapi-types';
33
import { Reference } from './reference.js';
44
import type { Schema } from './schema.js';
55

@@ -24,7 +24,7 @@ export class MediaType extends Construct {
2424
this.options = options;
2525
}
2626

27-
public synth(): OpenAPIV3.MediaTypeObject {
27+
public synth(): OpenAPIV3_1.MediaTypeObject {
2828
return {
2929
schema:
3030
this.options.schema instanceof Reference

lib/operation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class Operation<TPath extends string = '/'> extends Construct {
6666
return [];
6767
}
6868

69-
public synth(): OpenAPIV3_1.OperationObject {
69+
public synth() {
7070
return {
7171
...(this.options.operationId && {
7272
operationId: this.options.operationId,
@@ -91,6 +91,6 @@ export class Operation<TPath extends string = '/'> extends Construct {
9191
]),
9292
),
9393
}),
94-
};
94+
} satisfies OpenAPIV3_1.OperationObject;
9595
}
9696
}

lib/parameter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Construct } from 'constructs';
2-
import type { OpenAPIV3 } from 'openapi-types';
2+
import type { OpenAPIV3_1 } from 'openapi-types';
33
import type { Api } from './api.js';
44
import type { Schema } from './schema.js';
55

@@ -34,7 +34,7 @@ export class Parameter<
3434
this.options = options;
3535
}
3636

37-
public referenceObject(): OpenAPIV3.ReferenceObject {
37+
public referenceObject(): OpenAPIV3_1.ReferenceObject {
3838
return {
3939
$ref: this.jsonPointer(),
4040
};
@@ -48,7 +48,7 @@ export class Parameter<
4848
return `#/components/parameters/${this.schemaKey}`;
4949
}
5050

51-
public synth(): OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject {
51+
public synth() {
5252
return {
5353
name: this.options.name.toString(),
5454
in: this.options.in,
@@ -66,6 +66,6 @@ export class Parameter<
6666
...(this.options.schema && {
6767
schema: this.options.schema.referenceObject(),
6868
}),
69-
};
69+
} satisfies OpenAPIV3_1.ParameterObject | OpenAPIV3_1.ReferenceObject;
7070
}
7171
}

lib/path.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ export class Path<TPath extends string = '/'> extends Construct {
6262
),
6363
}),
6464
...(this.options.summary && { summary: this.options.summary }),
65-
};
65+
} satisfies OpenAPIV3_1.PathItemObject;
6666
}
6767
}

lib/response.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ export class Response extends Construct {
2626
}
2727
}
2828

29-
public synth(): OpenAPIV3_1.ResponseObject {
29+
public synth() {
3030
return {
3131
description: this.options.description || '',
3232
content: {
3333
...(this.content && {
3434
[this.content.contentType]: this.content.synth(),
3535
}),
3636
},
37-
};
37+
} satisfies OpenAPIV3_1.ResponseObject;
3838
}
3939
}

lib/schema.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Construct } from 'constructs';
2-
import type { OpenAPIV3 } from 'openapi-types';
2+
import type { OpenAPIV3_1 } from 'openapi-types';
33

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

88
export class Schema<
9-
T extends OpenAPIV3.SchemaObject = OpenAPIV3.SchemaObject,
9+
T extends OpenAPIV3_1.SchemaObject = OpenAPIV3_1.SchemaObject,
1010
> extends Construct {
1111
private options: SchemaOptions<T>;
1212

@@ -24,22 +24,22 @@ export class Schema<
2424
return this.node.id;
2525
}
2626

27-
public jsonPointer(): string {
27+
public jsonPointer() {
2828
return `#/components/schemas/${this.schemaKey}`;
2929
}
3030

31-
public referenceObject(): OpenAPIV3.ReferenceObject {
31+
public referenceObject() {
3232
return {
3333
$ref: this.jsonPointer(),
34-
};
34+
} satisfies OpenAPIV3_1.ReferenceObject;
3535
}
3636

3737
// eslint-disable-next-line class-methods-use-this
3838
public validate() {
3939
return [];
4040
}
4141

42-
public synth(): T {
42+
public synth() {
4343
return this.options.schema;
4444
}
4545
}

0 commit comments

Comments
 (0)