Skip to content

Commit b67583a

Browse files
authored
Ignore top-level array definitions (#10)
1 parent 7a2d872 commit b67583a

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

example/output.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ namespace OpenAPI2 {
9494
type: 'provider';
9595
body: ProviderBody;
9696
}
97-
export interface ProductTags {}
9897
export interface ProductListing {
9998
// When true, everyone can see the product when requested. When false it will
10099
// not be visible to anyone except those on the provider team.
@@ -184,7 +183,6 @@ namespace OpenAPI2 {
184183
type: 'product';
185184
body: ProductBody;
186185
}
187-
export interface PlanResizeList {}
188186
export interface PlanBody {
189187
provider_id: string;
190188
product_id: string;
@@ -209,7 +207,6 @@ namespace OpenAPI2 {
209207
type: 'plan';
210208
body: PlanBody;
211209
}
212-
export interface FeatureValuesList {}
213210
export interface FeatureValueDetails {
214211
label: string;
215212
name: string;

src/swagger-2.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,12 @@ function parse(spec: Swagger2, options: Swagger2Options = {}): string {
175175
}
176176

177177
// Begin parsing top-level entries
178-
Object.entries(definitions).forEach(entry => queue.push(entry));
178+
Object.entries(definitions).forEach(entry => {
179+
// Ignore top-level array definitions
180+
if (entry[1].type === 'object') {
181+
queue.push(entry);
182+
}
183+
});
179184
queue.sort((a, b) => a[0].localeCompare(b[0]));
180185
while (queue.length > 0) {
181186
buildNextInterface();

tests/swagger-2.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,5 +362,21 @@ describe('Swagger 2 spec', () => {
362362

363363
expect(swaggerToTS(input)).toBe(format(output, false));
364364
});
365+
366+
it('skips top-level array definitions', () => {
367+
const swagger: Swagger2 = {
368+
definitions: {
369+
Colors: {
370+
type: 'array',
371+
items: { $ref: '#/definitions/Color' },
372+
},
373+
Color: { type: 'string' },
374+
},
375+
};
376+
377+
const ts = format('');
378+
379+
expect(swaggerToTS(swagger)).toBe(ts);
380+
});
365381
});
366382
});

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"removeComments": true,
1414
"sourceMap": true,
1515
"strict": true,
16-
"target": "es5"
16+
"target": "es2018"
1717
},
1818
"exclude": ["example/*", "tests/**/*"]
1919
}

0 commit comments

Comments
 (0)