Skip to content

Commit 3eb981c

Browse files
committed
- Filter empty composition models resolving "{...} & any" in extends
1 parent 5559a15 commit 3eb981c

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

src/openApi/v2/parser/getModelComposition.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,19 @@ export function getModelComposition(openApi: OpenApi, definitions: OpenApiSchema
1515
};
1616

1717
const modes = definitions.map(definition => getModel(openApi, definition));
18-
modes.forEach(model => {
19-
composition.imports.push(...model.imports);
20-
composition.enums.push(...model.enums);
21-
composition.properties.push(model);
22-
});
18+
modes
19+
.filter(model => {
20+
const hasProperties = model.properties.length;
21+
const hasEnums = model.enums.length;
22+
const isObject = model.type === 'any';
23+
const isEmpty = isObject && !hasProperties && !hasEnums;
24+
return !isEmpty;
25+
})
26+
.forEach(model => {
27+
composition.imports.push(...model.imports);
28+
composition.enums.push(...model.enums);
29+
composition.properties.push(model);
30+
});
2331

2432
return composition;
2533
}

src/openApi/v3/parser/getModelComposition.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,19 @@ export function getModelComposition(openApi: OpenApi, definitions: OpenApiSchema
1515
};
1616

1717
const modes = definitions.map(definition => getModel(openApi, definition));
18-
modes.forEach(model => {
19-
composition.imports.push(...model.imports);
20-
composition.enums.push(...model.enums);
21-
composition.properties.push(model);
22-
});
18+
modes
19+
.filter(model => {
20+
const hasProperties = model.properties.length;
21+
const hasEnums = model.enums.length;
22+
const isObject = model.type === 'any';
23+
const isEmpty = isObject && !hasProperties && !hasEnums;
24+
return !isEmpty;
25+
})
26+
.forEach(model => {
27+
composition.imports.push(...model.imports);
28+
composition.enums.push(...model.enums);
29+
composition.properties.push(model);
30+
});
2331

2432
return composition;
2533
}

0 commit comments

Comments
 (0)