@@ -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
}
@@ -108,7 +109,7 @@ function parse(spec: Swagger2, namespace: string) {
108
109
function buildNextInterface ( ) {
109
110
const nextObject = queue . pop ( ) ;
110
111
if ( ! nextObject ) return ; // Geez TypeScript it’s going to be OK
111
- const [ ID , { allOf, properties, required } ] = nextObject ;
112
+ const [ ID , { allOf, properties, required, additionalProperties , type } ] = nextObject ;
112
113
113
114
let allProperties = properties || { } ;
114
115
const includes : string [ ] = [ ] ;
@@ -127,7 +128,12 @@ function parse(spec: Swagger2, namespace: string) {
127
128
}
128
129
129
130
// If nothing’s here, let’s skip this one.
130
- if ( ! Object . keys ( allProperties ) . length ) {
131
+ if (
132
+ ! Object . keys ( allProperties ) . length &&
133
+ additionalProperties !== true &&
134
+ type &&
135
+ TYPES [ type ]
136
+ ) {
131
137
return ;
132
138
}
133
139
// Open interface
@@ -157,6 +163,17 @@ function parse(spec: Swagger2, namespace: string) {
157
163
output . push ( `${ name } : ${ type } ;` ) ;
158
164
} ) ;
159
165
166
+ if ( additionalProperties ) {
167
+ if ( < boolean > additionalProperties === true ) {
168
+ output . push ( `[name: string]: ${ ID } ` ) ;
169
+ }
170
+
171
+ if ( ( < Swagger2Definition > additionalProperties ) . type ) {
172
+ const type = getType ( < Swagger2Definition > additionalProperties , '' ) ;
173
+ output . push ( `[name: string]: ${ type } ` ) ;
174
+ }
175
+ }
176
+
160
177
// Close interface
161
178
output . push ( '}' ) ;
162
179
@@ -176,7 +193,7 @@ function parse(spec: Swagger2, namespace: string) {
176
193
177
194
output . push ( '}' ) ; // Close namespace
178
195
179
- return prettier . format ( output . join ( '\n' ) , { parser : 'typescript' } ) ;
196
+ return prettier . format ( output . join ( '\n' ) , { parser : 'typescript' , singleQuote : true } ) ;
180
197
}
181
198
182
199
export default parse ;
0 commit comments