Skip to content

Commit da28651

Browse files
fix(import-specs): prevent injection of components into swagger 2.0 spec when no external refs (#3038)
1 parent 7d9bf95 commit da28651

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

packages/orval/src/import-specs.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,4 +726,17 @@ describe('dereferenceExternalRefs', () => {
726726

727727
expect(result).not.toHaveProperty('x-ext');
728728
});
729+
730+
it('should not inject components into Swagger 2.0 spec when no external refs exist', () => {
731+
const input = {
732+
swagger: '2.0',
733+
info: { title: 'Test', version: '1.0' },
734+
paths: {},
735+
definitions: { Foo: { type: 'object' } },
736+
};
737+
738+
const result = dereferenceExternalRef(input);
739+
740+
expect(result).not.toHaveProperty('components');
741+
});
729742
});

packages/orval/src/import-specs.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ function mergeExternalSchemas(
105105
): Record<string, Record<string, string>> {
106106
const schemaNameMappings: Record<string, Record<string, string>> = {};
107107

108+
if (Object.keys(extensions).length === 0) return schemaNameMappings;
109+
108110
data.components ??= {};
109111
const mainComponents = data.components as Record<string, unknown>;
110112
mainComponents.schemas ??= {};

0 commit comments

Comments
 (0)