@@ -9,6 +9,7 @@ export interface Swagger2Definition {
9
9
items ?: Swagger2Definition ;
10
10
oneOf ?: Swagger2Definition [ ] ;
11
11
properties ?: { [ index : string ] : Swagger2Definition } ;
12
+ additionalProperties ?: boolean | Swagger2Definition ;
12
13
required ?: string [ ] ;
13
14
type ?: 'array' | 'boolean' | 'integer' | 'number' | 'object' | 'string' ;
14
15
}
@@ -113,7 +114,7 @@ function parse(spec: Swagger2, namespace: string) {
113
114
function buildNextInterface ( ) {
114
115
const nextObject = queue . pop ( ) ;
115
116
if ( ! nextObject ) return ; // Geez TypeScript it’s going to be OK
116
- const [ ID , { allOf, properties, required } ] = nextObject ;
117
+ const [ ID , { allOf, properties, required, additionalProperties , type } ] = nextObject ;
117
118
118
119
let allProperties = properties || { } ;
119
120
const includes : string [ ] = [ ] ;
@@ -132,7 +133,12 @@ function parse(spec: Swagger2, namespace: string) {
132
133
}
133
134
134
135
// If nothing’s here, let’s skip this one.
135
- if ( ! Object . keys ( allProperties ) . length ) {
136
+ if (
137
+ ! Object . keys ( allProperties ) . length &&
138
+ additionalProperties !== true &&
139
+ type &&
140
+ TYPES [ type ]
141
+ ) {
136
142
return ;
137
143
}
138
144
// Open interface
@@ -162,6 +168,17 @@ function parse(spec: Swagger2, namespace: string) {
162
168
output . push ( `${ name } : ${ type } ;` ) ;
163
169
} ) ;
164
170
171
+ if ( additionalProperties ) {
172
+ if ( < boolean > additionalProperties === true ) {
173
+ output . push ( `[name: string]: ${ ID } ` ) ;
174
+ }
175
+
176
+ if ( ( < Swagger2Definition > additionalProperties ) . type ) {
177
+ const type = getType ( < Swagger2Definition > additionalProperties , '' ) ;
178
+ output . push ( `[name: string]: ${ type } ` ) ;
179
+ }
180
+ }
181
+
165
182
// Close interface
166
183
output . push ( '}' ) ;
167
184
@@ -181,7 +198,7 @@ function parse(spec: Swagger2, namespace: string) {
181
198
182
199
output . push ( '}' ) ; // Close namespace
183
200
184
- return prettier . format ( output . join ( '\n' ) , { parser : 'typescript' } ) ;
201
+ return prettier . format ( output . join ( '\n' ) , { parser : 'typescript' , singleQuote : true } ) ;
185
202
}
186
203
187
204
export default parse ;
0 commit comments