From f6e3cce3bf456f924af43027ec76ad31b9513bcb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Feb 2026 22:18:18 +0000 Subject: [PATCH] Add comprehensive tests for sibling schema hoisting - Created test specs with external files containing multiple schemas - Added test case for sibling schema hoisting in bundle.test.ts - All tests pass - sibling schemas are correctly hoisted - Tested with local files, nested references, and HTTP URLs Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com> --- .../src/__tests__/bundle.test.ts | 50 +++++++++++++++++++ .../external-with-siblings.json | 33 ++++++++++++ .../main-with-external-siblings.json | 43 ++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 specs/json-schema-ref-parser/external-with-siblings.json create mode 100644 specs/json-schema-ref-parser/main-with-external-siblings.json diff --git a/packages/json-schema-ref-parser/src/__tests__/bundle.test.ts b/packages/json-schema-ref-parser/src/__tests__/bundle.test.ts index 36667ee88..0f8af600e 100644 --- a/packages/json-schema-ref-parser/src/__tests__/bundle.test.ts +++ b/packages/json-schema-ref-parser/src/__tests__/bundle.test.ts @@ -56,4 +56,54 @@ describe('bundle', () => { }, }); }); + + it('hoists sibling schemas from external files', async () => { + const refParser = new $RefParser(); + const pathOrUrlOrSchema = path.join( + getSpecsPath(), + 'json-schema-ref-parser', + 'main-with-external-siblings.json', + ); + const schema = (await refParser.bundle({ pathOrUrlOrSchema })) as any; + + // Main schema should reference the hoisted schemas + const resolutionStepSchema = + schema.paths['/resolution'].get.responses['200'].content['application/json'].schema; + expect(resolutionStepSchema.$ref).toBe( + '#/components/schemas/external-with-siblings_ResolutionStep', + ); + + const actionInfoSchema = + schema.paths['/action'].get.responses['200'].content['application/json'].schema; + expect(actionInfoSchema.$ref).toBe('#/components/schemas/external-with-siblings_ActionInfo'); + + // All schemas from the external file should be hoisted + expect(schema.components).toBeDefined(); + expect(schema.components.schemas).toBeDefined(); + + // ResolutionStep should be hoisted + expect(schema.components.schemas['external-with-siblings_ResolutionStep']).toBeDefined(); + expect( + schema.components.schemas['external-with-siblings_ResolutionStep'].properties.ResolutionType + .oneOf[0].$ref, + ).toBe('#/components/schemas/external-with-siblings_ResolutionType'); + + // ResolutionType (sibling schema) should also be hoisted + expect(schema.components.schemas['external-with-siblings_ResolutionType']).toBeDefined(); + expect(schema.components.schemas['external-with-siblings_ResolutionType']).toEqual({ + enum: ['ContactVendor', 'ResetToDefaults', 'RetryOperation'], + type: 'string', + }); + + // ActionInfo (another sibling schema) should also be hoisted + expect(schema.components.schemas['external-with-siblings_ActionInfo']).toBeDefined(); + expect(schema.components.schemas['external-with-siblings_ActionInfo']).toEqual({ + properties: { + ActionId: { + type: 'string', + }, + }, + type: 'object', + }); + }); }); diff --git a/specs/json-schema-ref-parser/external-with-siblings.json b/specs/json-schema-ref-parser/external-with-siblings.json new file mode 100644 index 000000000..324c806ea --- /dev/null +++ b/specs/json-schema-ref-parser/external-with-siblings.json @@ -0,0 +1,33 @@ +{ + "components": { + "schemas": { + "ResolutionStep": { + "type": "object", + "properties": { + "ResolutionType": { + "oneOf": [ + { + "$ref": "#/components/schemas/ResolutionType" + } + ] + }, + "ActionName": { + "type": "string" + } + } + }, + "ResolutionType": { + "type": "string", + "enum": ["ContactVendor", "ResetToDefaults", "RetryOperation"] + }, + "ActionInfo": { + "type": "object", + "properties": { + "ActionId": { + "type": "string" + } + } + } + } + } +} diff --git a/specs/json-schema-ref-parser/main-with-external-siblings.json b/specs/json-schema-ref-parser/main-with-external-siblings.json new file mode 100644 index 000000000..fc3103914 --- /dev/null +++ b/specs/json-schema-ref-parser/main-with-external-siblings.json @@ -0,0 +1,43 @@ +{ + "openapi": "3.0.0", + "info": { + "title": "Test API", + "version": "1.0.0" + }, + "paths": { + "/resolution": { + "get": { + "summary": "Get resolution step", + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "$ref": "external-with-siblings.json#/components/schemas/ResolutionStep" + } + } + } + } + } + } + }, + "/action": { + "get": { + "summary": "Get action info", + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "$ref": "external-with-siblings.json#/components/schemas/ActionInfo" + } + } + } + } + } + } + } + } +} -- 2.51.2