@@ -12,11 +12,14 @@ export class FlightRecorderJsonGenerator {
12
12
fs . mkdirSync ( f ) ;
13
13
this . specification . endpoints . forEach ( api => {
14
14
const pathPrefix = path . join ( f , api . name ) ;
15
+ const body = this . createRequestResponse ( api . typeMapping . request ) ;
16
+ const args = api . queryStringParameters . reduce ( ( o , p ) => ( { ...o , [ p . name ] : p . type } ) , { } ) ;
17
+ // @ts -ignore
18
+ args . body = body ;
19
+
15
20
const request = {
16
21
api : api . name ,
17
- args : {
18
- body : this . createRequestResponse ( api . typeMapping . request )
19
- }
22
+ args
20
23
} ;
21
24
fs . writeFileSync ( pathPrefix + "_request.json" , JSON . stringify ( request , null , 2 ) ) ;
22
25
const response = {
@@ -44,7 +47,9 @@ export class FlightRecorderJsonGenerator {
44
47
const valueType = FlightRecorderJsonGenerator . createValueType ( i . name ) ;
45
48
if ( valueType !== null ) return valueType ;
46
49
47
- return i . properties . reduce ( ( o , p ) => ( { ...o , [ p . name ] : this . createInterfaceProperty ( p , seenTypes ) } ) , { } ) ;
50
+ return i . properties
51
+ . filter ( p => ! p . isRequestParameter )
52
+ . reduce ( ( o , p ) => ( { ...o , [ p . name ] : this . createInterfaceProperty ( p , seenTypes ) } ) , { } ) ;
48
53
}
49
54
50
55
private static createValueType ( typeName ) {
@@ -91,23 +96,24 @@ export class FlightRecorderJsonGenerator {
91
96
return i ;
92
97
}
93
98
94
- private createTypeSchema ( type : Domain . Type , seenTypes ) {
99
+ private createTypeSchema ( type : Domain . Type , seenTypes : Set < string > ) {
95
100
const valueType = FlightRecorderJsonGenerator . createValueType ( type . name ) ;
96
101
if ( valueType !== null ) return valueType ;
97
102
98
103
if ( seenTypes . has ( type . name ) ) return { $type : `Circular reference to: ${ type . name } ` } ;
99
104
seenTypes . add ( type . name ) ;
100
105
101
106
const i = this . lookupType ( type . name ) ;
102
- return this . toSchema ( i , seenTypes , type . name ) ;
107
+ const schema = this . toSchema ( i , seenTypes , type . name ) ;
108
+ seenTypes . delete ( type . name ) ;
109
+ return schema ;
103
110
}
104
111
105
112
private createArraySchema ( arr : Domain . ArrayOf , seenTypes ) {
106
113
return [ this . dispatchInstanceOf ( arr . of , seenTypes ) ] ;
107
114
}
108
115
109
116
private createDictionarySchema ( dict : Domain . Dictionary , seenTypes : Set < string > ) {
110
- // todo handle additionalProperties and find out how we can type the key.
111
117
return { __name__ : this . dispatchInstanceOf ( dict . value , seenTypes ) } ;
112
118
}
113
119
@@ -116,7 +122,6 @@ export class FlightRecorderJsonGenerator {
116
122
}
117
123
118
124
private createUnionOfSchema ( union : Domain . UnionOf , seenTypes : Set < string > ) {
119
- // union should be oneOf but open api does not support the full json-schema draft 4
120
125
return { __anyOf__ : [
121
126
union . items . map ( i => this . dispatchInstanceOf ( i , seenTypes ) )
122
127
] } ;
0 commit comments