1
1
import { BaseModel } from "../base" ;
2
2
import { Info } from "./info" ;
3
+ import { Channels } from "./channels" ;
4
+ import { Channel } from "./channel" ;
5
+ import { Components } from "./components" ;
6
+ import { Messages } from "./messages" ;
7
+ import { Operations } from "./operations" ;
3
8
import { Servers } from "./servers" ;
4
9
import { Server } from "./server" ;
10
+ import { SecuritySchemes } from "./security-schemes" ;
11
+ import { SecurityScheme } from "./security-scheme" ;
12
+ import { Schemas } from "./schemas" ;
5
13
6
14
import { Mixin } from '../utils' ;
7
15
import { ExtensionsMixin } from './mixins/extensions' ;
8
16
9
- import type { AsyncAPIDocumentInterface , InfoInterface } from "../../models" ;
10
- import type { ServersInterface } from "models/servers" ;
17
+ import { tilde } from '../../utils' ;
18
+
19
+ import type { AsyncAPIDocumentInterface } from "../asyncapi" ;
20
+ import type { InfoInterface } from "../info" ;
21
+ import type { ServersInterface } from "../servers" ;
22
+ import type { ChannelsInterface } from "../channels" ;
23
+ import type { ComponentsInterface } from "../components" ;
24
+ import type { OperationsInterface } from "../operations" ;
25
+ import type { OperationInterface } from "../operation" ;
26
+ import type { MessagesInterface } from "../messages" ;
27
+ import type { MessageInterface } from "../message" ;
28
+ import type { SchemasInterface } from "../schemas" ;
29
+ import type { SecuritySchemesInterface } from "../security-schemes" ;
11
30
12
31
export class AsyncAPIDocument extends Mixin ( BaseModel , ExtensionsMixin ) implements AsyncAPIDocumentInterface {
13
32
version ( ) : string {
14
33
return this . _json . asyncapi ;
15
34
}
16
35
36
+ defaultContentType ( ) : string | undefined {
37
+ return this . _json . defaultContentType ;
38
+ }
39
+
40
+ hasDefaultContentType ( ) : boolean {
41
+ return ! ! this . _json . defaultContentType ;
42
+ }
43
+
17
44
info ( ) : InfoInterface {
18
45
return this . createModel ( Info , this . _json . info , { pointer : '/info' } ) ;
19
46
}
@@ -25,4 +52,40 @@ export class AsyncAPIDocument extends Mixin(BaseModel, ExtensionsMixin) implemen
25
52
)
26
53
) ;
27
54
}
55
+
56
+ channels ( ) : ChannelsInterface {
57
+ return new Channels (
58
+ Object . entries ( this . _json . channels || { } ) . map ( ( [ channelAddress , channel ] ) =>
59
+ this . createModel ( Channel , channel , { id : channelAddress , address : channelAddress , pointer : `/channels/${ tilde ( channelAddress ) } ` } )
60
+ )
61
+ ) ;
62
+ }
63
+
64
+ operations ( ) : OperationsInterface {
65
+ const operations : OperationInterface [ ] = [ ] ;
66
+ this . channels ( ) . forEach ( channel => operations . push ( ...channel . operations ( ) . all ( ) ) ) ;
67
+ return new Operations ( operations ) ;
68
+ }
69
+
70
+ messages ( ) : MessagesInterface {
71
+ const messages : MessageInterface [ ] = [ ] ;
72
+ this . operations ( ) . forEach ( operation => messages . push ( ...operation . messages ( ) . all ( ) ) ) ;
73
+ return new Messages ( messages ) ;
74
+ }
75
+
76
+ schemas ( ) : SchemasInterface {
77
+ return new Schemas ( [ ] ) ;
78
+ }
79
+
80
+ securitySchemes ( ) : SecuritySchemesInterface {
81
+ return new SecuritySchemes (
82
+ Object . entries ( this . _json . components ?. securitySchemes || { } ) . map ( ( [ securitySchemeName , securityScheme ] ) =>
83
+ this . createModel ( SecurityScheme , securityScheme , { id : securitySchemeName , pointer : `/components/securitySchemes/${ securitySchemeName } ` } )
84
+ )
85
+ ) ;
86
+ }
87
+
88
+ components ( ) : ComponentsInterface {
89
+ return new Components ( this . _json . components || { } ) ;
90
+ }
28
91
}
0 commit comments