Skip to content

Commit 0485791

Browse files
committed
chore: avoid a circular dep
1 parent 29f9266 commit 0485791

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

lib/ApiLowLevel.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Construct, type IConstruct } from 'constructs';
2+
import type { Api } from './api.js';
3+
4+
export class ApiLowLevel extends Construct {
5+
public static of(c: IConstruct): Api {
6+
const { scope } = c.node;
7+
8+
if (!scope) {
9+
// Api is the only construct without a scope.
10+
return c as Api;
11+
}
12+
13+
return ApiLowLevel.of(scope);
14+
}
15+
}

lib/api.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Construct, type IConstruct } from 'constructs';
22
import type { JSONSchema7 } from 'json-schema';
33
import type { OpenAPIV3_1 } from 'openapi-types';
4+
import { ApiLowLevel } from './ApiLowLevel.js';
45
import { Parameter } from './parameter.js';
56
import { Path } from './path.js';
67
import { Reference } from './reference.js';
@@ -19,7 +20,7 @@ export interface ApiOptions {
1920
info: OpenAPIV3_1.InfoObject;
2021
}
2122

22-
export class Api extends Construct {
23+
export class Api extends ApiLowLevel {
2324
private options: ApiOptions;
2425

2526
constructor(options: ApiOptions) {
@@ -29,17 +30,6 @@ export class Api extends Construct {
2930
this.options = options;
3031
}
3132

32-
public static of(c: IConstruct): Api {
33-
const { scope } = c.node;
34-
35-
if (!scope) {
36-
// Api is the only construct without a scope.
37-
return c as Api;
38-
}
39-
40-
return Api.of(scope);
41-
}
42-
4333
public synth() {
4434
return {
4535
openapi: this.options.openapi,

lib/reference.ts

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

66
type Target = Schema; // | Parameter;
77

@@ -10,7 +10,8 @@ export class Reference<T extends Target> extends Construct {
1010

1111
constructor(target: T, id: string) {
1212
super(target, id);
13-
this.schema = new Schema(Api.of(this), id, {
13+
// NOTE: Api.of causes a circular dependency
14+
this.schema = new Schema(ApiLowLevel.of(this), id, {
1415
// NOTE: synth because refs are not valid as #/component/schemas
1516
// if it did, we could use referenceObject here instead
1617
schema: target.synth(),

0 commit comments

Comments
 (0)