fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+126
+50
packages/json-schema-ref-parser/src/__tests__/bundle.test.ts
··· 56 56 }, 57 57 }); 58 58 }); 59 + 60 + it('hoists sibling schemas from external files', async () => { 61 + const refParser = new $RefParser(); 62 + const pathOrUrlOrSchema = path.join( 63 + getSpecsPath(), 64 + 'json-schema-ref-parser', 65 + 'main-with-external-siblings.json', 66 + ); 67 + const schema = (await refParser.bundle({ pathOrUrlOrSchema })) as any; 68 + 69 + // Main schema should reference the hoisted schemas 70 + const resolutionStepSchema = 71 + schema.paths['/resolution'].get.responses['200'].content['application/json'].schema; 72 + expect(resolutionStepSchema.$ref).toBe( 73 + '#/components/schemas/external-with-siblings_ResolutionStep', 74 + ); 75 + 76 + const actionInfoSchema = 77 + schema.paths['/action'].get.responses['200'].content['application/json'].schema; 78 + expect(actionInfoSchema.$ref).toBe('#/components/schemas/external-with-siblings_ActionInfo'); 79 + 80 + // All schemas from the external file should be hoisted 81 + expect(schema.components).toBeDefined(); 82 + expect(schema.components.schemas).toBeDefined(); 83 + 84 + // ResolutionStep should be hoisted 85 + expect(schema.components.schemas['external-with-siblings_ResolutionStep']).toBeDefined(); 86 + expect( 87 + schema.components.schemas['external-with-siblings_ResolutionStep'].properties.ResolutionType 88 + .oneOf[0].$ref, 89 + ).toBe('#/components/schemas/external-with-siblings_ResolutionType'); 90 + 91 + // ResolutionType (sibling schema) should also be hoisted 92 + expect(schema.components.schemas['external-with-siblings_ResolutionType']).toBeDefined(); 93 + expect(schema.components.schemas['external-with-siblings_ResolutionType']).toEqual({ 94 + enum: ['ContactVendor', 'ResetToDefaults', 'RetryOperation'], 95 + type: 'string', 96 + }); 97 + 98 + // ActionInfo (another sibling schema) should also be hoisted 99 + expect(schema.components.schemas['external-with-siblings_ActionInfo']).toBeDefined(); 100 + expect(schema.components.schemas['external-with-siblings_ActionInfo']).toEqual({ 101 + properties: { 102 + ActionId: { 103 + type: 'string', 104 + }, 105 + }, 106 + type: 'object', 107 + }); 108 + }); 59 109 });
+33
specs/json-schema-ref-parser/external-with-siblings.json
··· 1 + { 2 + "components": { 3 + "schemas": { 4 + "ResolutionStep": { 5 + "type": "object", 6 + "properties": { 7 + "ResolutionType": { 8 + "oneOf": [ 9 + { 10 + "$ref": "#/components/schemas/ResolutionType" 11 + } 12 + ] 13 + }, 14 + "ActionName": { 15 + "type": "string" 16 + } 17 + } 18 + }, 19 + "ResolutionType": { 20 + "type": "string", 21 + "enum": ["ContactVendor", "ResetToDefaults", "RetryOperation"] 22 + }, 23 + "ActionInfo": { 24 + "type": "object", 25 + "properties": { 26 + "ActionId": { 27 + "type": "string" 28 + } 29 + } 30 + } 31 + } 32 + } 33 + }
+43
specs/json-schema-ref-parser/main-with-external-siblings.json
··· 1 + { 2 + "openapi": "3.0.0", 3 + "info": { 4 + "title": "Test API", 5 + "version": "1.0.0" 6 + }, 7 + "paths": { 8 + "/resolution": { 9 + "get": { 10 + "summary": "Get resolution step", 11 + "responses": { 12 + "200": { 13 + "description": "Success", 14 + "content": { 15 + "application/json": { 16 + "schema": { 17 + "$ref": "external-with-siblings.json#/components/schemas/ResolutionStep" 18 + } 19 + } 20 + } 21 + } 22 + } 23 + } 24 + }, 25 + "/action": { 26 + "get": { 27 + "summary": "Get action info", 28 + "responses": { 29 + "200": { 30 + "description": "Success", 31 + "content": { 32 + "application/json": { 33 + "schema": { 34 + "$ref": "external-with-siblings.json#/components/schemas/ActionInfo" 35 + } 36 + } 37 + } 38 + } 39 + } 40 + } 41 + } 42 + } 43 + }