File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 11import { Construct , type IConstruct } from 'constructs' ;
22import type { JSONSchema7 } from 'json-schema' ;
33import type { OpenAPIV3_1 } from 'openapi-types' ;
4+ import { ApiLowLevel } from './ApiLowLevel.js' ;
45import { Parameter } from './parameter.js' ;
56import { Path } from './path.js' ;
67import { 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 ,
Original file line number Diff line number Diff line change 11import { Construct } from 'constructs' ;
22import type { OpenAPIV3_1 } from 'openapi-types' ;
3+ import { ApiLowLevel } from './ApiLowLevel.js' ;
34import { Schema } from './schema.js' ;
4- import { Api } from './api.js' ;
55
66type 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 ( ) ,
You can’t perform that action at this time.
0 commit comments