diff --git a/.github/workflows/pullfrog.yml b/.github/workflows/pullfrog.yml index d86479432..e5a760711 100644 --- a/.github/workflows/pullfrog.yml +++ b/.github/workflows/pullfrog.yml @@ -43,4 +43,3 @@ jobs: GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }} DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }} OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }} - 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 0f8af600e..5f712ce75 100644 --- a/packages/json-schema-ref-parser/src/__tests__/bundle.test.ts +++ b/packages/json-schema-ref-parser/src/__tests__/bundle.test.ts @@ -106,4 +106,59 @@ describe('bundle', () => { type: 'object', }); }); + + it('hoists sibling schemas from YAML files with versioned names (Redfish-like)', async () => { + const refParser = new $RefParser(); + const pathOrUrlOrSchema = path.join( + getSpecsPath(), + 'json-schema-ref-parser', + 'redfish-like.yaml', + ); + const schema = (await refParser.bundle({ pathOrUrlOrSchema })) as any; + + // Verify the main schema references are hoisted + const systemsSchema = + schema.paths['/redfish/v1/Systems'].get.responses['200'].content['application/json'].schema; + expect(systemsSchema.$ref).toContain('ResolutionStep'); + + const actionsSchema = + schema.paths['/redfish/v1/Actions'].post.responses['200'].content['application/json'].schema; + expect(actionsSchema.$ref).toContain('ActionParameters'); + + // All three schemas from the external YAML should be hoisted + expect(schema.components).toBeDefined(); + expect(schema.components.schemas).toBeDefined(); + + const schemaKeys = Object.keys(schema.components.schemas); + + // ResolutionStep (directly referenced) + const resolutionStepKey = schemaKeys.find( + (k) => k.includes('ResolutionStep') && !k.includes('Type') && !k.includes('ActionParameters'), + ); + expect(resolutionStepKey).toBeDefined(); + + // ResolutionType (sibling, referenced by ResolutionStep and ActionParameters) + const resolutionTypeKey = schemaKeys.find((k) => k.includes('ResolutionType')); + expect(resolutionTypeKey).toBeDefined(); + expect(schema.components.schemas[resolutionTypeKey!]).toEqual({ + description: 'Types of resolution actions', + enum: ['ContactVendor', 'ResetToDefaults', 'RetryOperation'], + type: 'string', + }); + + // ActionParameters (directly referenced) + const actionParamsKey = schemaKeys.find((k) => k.includes('ActionParameters')); + expect(actionParamsKey).toBeDefined(); + + // Verify that internal $refs in hoisted schemas point to hoisted locations + const resolutionStep = schema.components.schemas[resolutionStepKey!]; + expect(resolutionStep.properties.ResolutionType.oneOf[0].$ref).toContain('ResolutionType'); + expect(resolutionStep.properties.ResolutionType.oneOf[0].$ref).toMatch( + /^#\/components\/schemas\//, + ); + + const actionParams = schema.components.schemas[actionParamsKey!]; + expect(actionParams.properties.ActionType.$ref).toContain('ResolutionType'); + expect(actionParams.properties.ActionType.$ref).toMatch(/^#\/components\/schemas\//); + }); }); diff --git a/specs/json-schema-ref-parser/ResolutionStep.v1_0_1.yaml b/specs/json-schema-ref-parser/ResolutionStep.v1_0_1.yaml new file mode 100644 index 000000000..64b0377f2 --- /dev/null +++ b/specs/json-schema-ref-parser/ResolutionStep.v1_0_1.yaml @@ -0,0 +1,25 @@ +components: + schemas: + ResolutionStep_v1_0_1_ResolutionStep: + type: object + properties: + ResolutionType: + oneOf: + - $ref: '#/components/schemas/ResolutionStep_v1_0_1_ResolutionType' + ActionName: + type: string + description: Name of the action + ResolutionStep_v1_0_1_ResolutionType: + type: string + enum: + - ContactVendor + - ResetToDefaults + - RetryOperation + description: Types of resolution actions + ResolutionStep_v1_0_1_ActionParameters: + type: object + properties: + ActionId: + type: string + ActionType: + $ref: '#/components/schemas/ResolutionStep_v1_0_1_ResolutionType' diff --git a/specs/json-schema-ref-parser/redfish-like.yaml b/specs/json-schema-ref-parser/redfish-like.yaml new file mode 100644 index 000000000..5255e1ff6 --- /dev/null +++ b/specs/json-schema-ref-parser/redfish-like.yaml @@ -0,0 +1,28 @@ +openapi: 3.0.0 +info: + title: Redfish-like API + version: '1.0.0' + description: Test API simulating Redfish structure with versioned schemas +paths: + /redfish/v1/Systems: + get: + summary: Get Systems + responses: + '200': + description: Success + content: + application/json: + schema: + $ref: 'ResolutionStep.v1_0_1.yaml#/components/schemas/ResolutionStep_v1_0_1_ResolutionStep' + default: + description: Error + /redfish/v1/Actions: + post: + summary: Submit Action + responses: + '200': + description: Success + content: + application/json: + schema: + $ref: 'ResolutionStep.v1_0_1.yaml#/components/schemas/ResolutionStep_v1_0_1_ActionParameters'