@@ -2,7 +2,7 @@ import * as path from "path";
2
2
3
3
import { Factory } from "../../../CodeGenerator" ;
4
4
import * as Name from "../Name" ;
5
- import { Def , State , Store } from "../store" ;
5
+ import { Store } from "../store" ;
6
6
import * as ToTypeNode from "../toTypeNode" ;
7
7
import { OpenApi } from "../types" ;
8
8
import * as Header from "./Header" ;
@@ -20,28 +20,22 @@ export const generateNamespace = (
20
20
) : void => {
21
21
const basePath = `${ parentPath } /${ name } ` ;
22
22
store . addStatement ( basePath , {
23
- type : "namespace" ,
23
+ kind : "namespace" ,
24
24
name,
25
- value : factory . Namespace . create ( {
26
- export : true ,
27
- name : name ,
28
- comment : response . description ,
29
- statements : [ ] ,
30
- } ) ,
31
- statements : { } ,
25
+ comment : response . description ,
32
26
} ) ;
33
27
34
28
if ( response . headers ) {
35
29
store . addStatement ( `${ basePath } /Header` , {
36
- type : "interface" ,
30
+ kind : "interface" ,
37
31
name : Name . ComponentChild . Header ,
38
32
value : Header . generateInterface ( entryPoint , currentPoint , factory , Name . ComponentChild . Header , response . headers , context ) ,
39
33
} ) ;
40
34
}
41
35
42
36
if ( response . content ) {
43
37
store . addStatement ( `${ basePath } /Content` , {
44
- type : "interface" ,
38
+ kind : "interface" ,
45
39
name : Name . ComponentChild . Content ,
46
40
value : MediaType . generateInterface ( entryPoint , currentPoint , factory , Name . ComponentChild . Content , response . content , context ) ,
47
41
} ) ;
@@ -61,42 +55,27 @@ export const generateReferenceNamespace = (
61
55
const basePath = `${ parentPath } /${ nameWithStatusCode } ` ;
62
56
const referenceNamespaceName = context . resolveReferencePath ( currentPoint , responseReference . path ) . name ;
63
57
store . addStatement ( basePath , {
64
- type : "namespace" ,
58
+ kind : "namespace" ,
65
59
name : nameWithStatusCode ,
66
- value : factory . Namespace . create ( {
67
- export : true ,
68
- name : nameWithStatusCode ,
69
- statements : [ ] ,
70
- } ) ,
71
- statements : { } ,
72
60
} ) ;
73
- // TODO Type Guard
74
- const headerNamespace = store . getStatement ( path . join ( responseReference . path , "Header" ) , "namespace" ) as
75
- | Def . NamespaceStatement < State . A , State . B , State . C >
76
- | undefined ;
61
+ const headerNamespace = store . getStatement ( path . join ( responseReference . path , "Header" ) , "namespace" ) ;
77
62
if ( headerNamespace ) {
78
63
store . addStatement ( `${ basePath } /Header` , {
79
- type : "namespace" ,
64
+ kind : "namespace" ,
80
65
name : Name . ComponentChild . Header ,
81
- value : factory . Namespace . create ( {
82
- export : true ,
83
- name : Name . ComponentChild . Header ,
84
- statements : [ ] ,
85
- } ) ,
86
- statements : { } ,
87
66
} ) ;
88
- Object . values ( headerNamespace . statements ) . forEach ( statement => {
67
+ Object . values ( headerNamespace . getChildren ( ) ) . forEach ( statement => {
89
68
if ( ! statement ) {
90
69
return ;
91
70
}
92
- if ( statement . type === "interface" || statement . type === "typeAlias" ) {
71
+ if ( statement . kind === "interface" || statement . kind === "typeAlias" ) {
93
72
const aliasName = [ referenceNamespaceName , Name . ComponentChild . Header , statement . name ] . join ( "." ) ;
94
- store . addStatement ( `${ basePath } /Header/${ statement . value . name . text } ` , {
95
- type : "typeAlias" ,
73
+ store . addStatement ( `${ basePath } /Header/${ statement . name } ` , {
74
+ kind : "typeAlias" ,
96
75
name : aliasName ,
97
76
value : factory . TypeAliasDeclaration . create ( {
98
77
export : true ,
99
- name : statement . value . name . text ,
78
+ name : statement . name ,
100
79
type : factory . TypeReferenceNode . create ( {
101
80
name : aliasName ,
102
81
} ) ,
@@ -106,7 +85,7 @@ export const generateReferenceNamespace = (
106
85
} ) ;
107
86
}
108
87
store . addStatement ( `${ basePath } /Content` , {
109
- type : "typeAlias" ,
88
+ kind : "typeAlias" ,
110
89
name : Name . ComponentChild . Content ,
111
90
value : factory . TypeAliasDeclaration . create ( {
112
91
export : true ,
0 commit comments