Skip to content

bundle() leaves a $ref back to the root file as a relative file ref (regression in 15.5.1) #434

Closed

Description

@trackoor

Since 15.5.1, bundle() no longer rewrites a $ref inside an inlined external file that points back into the root document, so the "bundled" output still contains ../openapi.yaml#/.... 15.5.0 rewrote it to #/....

import fs from "node:fs";
import $RefParser from "@apidevtools/json-schema-ref-parser";

fs.mkdirSync("schemas", { recursive: true });
fs.writeFileSync(
  "openapi.yaml",
  `openapi: 3.0.3
info: { title: t, version: "1" }
paths:
  /pets:
    get:
      responses:
        "200":
          description: ok
          content:
            application/json:
              schema: { $ref: "./schemas/pet.yaml" }
components:
  schemas:
    Error:
      type: object
      properties:
        message: { type: string }
`
);
fs.writeFileSync(
  "schemas/pet.yaml",
  `type: object
properties:
  name: { type: string }
  lastError: { $ref: "../openapi.yaml#/components/schemas/Error" }
`
);

const bundled = await new $RefParser().bundle("openapi.yaml");
console.log(JSON.stringify(bundled.paths["/pets"].get.responses["200"].content["application/json"].schema.properties.lastError));

node t1.mjs (in a package with "type": "module")

15.5.1 to 16.0.5:

{"$ref":"../openapi.yaml#/components/schemas/Error"}

15.5.0 and earlier (expected; the docs say the result "only has internal $ref pointers"):

{"$ref":"#/components/schemas/Error"}

Tested 15.5.0 and 16.0.5 on Node.js v26.13.0; main (520f3cb) has no lib/ changes since v16.0.5. It needs a whole-file ref (./schemas/pet.yaml, no fragment); with a fragment the inner ref is remapped correctly.

In remap() in lib/bundle.ts, the ref inside the inlined pet.yaml takes the targetResourceBase !== locationResourceBase branch added in e8190c1 and goes through referenceToResource(), although pet.yaml was inlined and is not a separate $id resource.

Credit: https://ucsbplse.github.io/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions