@hey-api/json-schema-ref-parser 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,17 @@ const __1 = require("..");
11
11
  const refParser = new __1.$RefParser();
12
12
  const pathOrUrlOrSchema = path_1.default.resolve("lib", "__tests__", "spec", "circular-ref-with-description.json");
13
13
  const schema = await refParser.bundle({ pathOrUrlOrSchema });
14
- (0, vitest_1.expect)(schema).not.toBeUndefined();
14
+ (0, vitest_1.expect)(schema).toEqual({
15
+ schemas: {
16
+ Bar: {
17
+ $ref: '#/schemas/Foo',
18
+ description: 'ok',
19
+ },
20
+ Foo: {
21
+ $ref: '#/schemas/Bar',
22
+ },
23
+ },
24
+ });
15
25
  });
16
26
  (0, vitest_1.it)("bundles multiple references to the same file correctly", async () => {
17
27
  const refParser = new __1.$RefParser();
@@ -11,7 +11,6 @@ const path_1 = __importDefault(require("path"));
11
11
  const refParser = new __1.$RefParser();
12
12
  const pathOrUrlOrSchema = path_1.default.resolve("lib", "__tests__", "spec", "openapi-paths-ref.json");
13
13
  const schema = (await refParser.bundle({ pathOrUrlOrSchema }));
14
- console.log(JSON.stringify(schema, null, 2));
15
14
  // The GET endpoint should have its schema defined inline
16
15
  const getSchema = schema.paths["/foo"].get.responses["200"].content["application/json"].schema;
17
16
  (0, vitest_1.expect)(getSchema.$ref).toBeUndefined();
@@ -470,9 +470,11 @@ function remap(parser, inventory) {
470
470
  perf.warn(`Skipping invalid inventory entry:`, entry);
471
471
  continue;
472
472
  }
473
- // Keep internal refs internal
473
+ // Keep internal refs internal. However, if the $ref extends the resolved value
474
+ // (i.e. it has additional properties in addition to "$ref"), then we must
475
+ // preserve the original $ref rather than rewriting it to the resolved hash.
474
476
  if (!entry.external) {
475
- if (entry.$ref && typeof entry.$ref === "object") {
477
+ if (!entry.extended && entry.$ref && typeof entry.$ref === "object") {
476
478
  entry.$ref.$ref = entry.hash;
477
479
  }
478
480
  continue;
@@ -9,7 +9,17 @@ describe("bundle", () => {
9
9
  const refParser = new $RefParser();
10
10
  const pathOrUrlOrSchema = path.resolve("lib", "__tests__", "spec", "circular-ref-with-description.json");
11
11
  const schema = await refParser.bundle({ pathOrUrlOrSchema });
12
- expect(schema).not.toBeUndefined();
12
+ expect(schema).toEqual({
13
+ schemas: {
14
+ Bar: {
15
+ $ref: '#/schemas/Foo',
16
+ description: 'ok',
17
+ },
18
+ Foo: {
19
+ $ref: '#/schemas/Bar',
20
+ },
21
+ },
22
+ });
13
23
  });
14
24
 
15
25
  it("bundles multiple references to the same file correctly", async () => {
@@ -7,7 +7,6 @@ describe("pointer", () => {
7
7
  const refParser = new $RefParser();
8
8
  const pathOrUrlOrSchema = path.resolve("lib", "__tests__", "spec", "openapi-paths-ref.json");
9
9
  const schema = (await refParser.bundle({ pathOrUrlOrSchema })) as any;
10
- console.log(JSON.stringify(schema, null, 2));
11
10
 
12
11
  // The GET endpoint should have its schema defined inline
13
12
  const getSchema = schema.paths["/foo"].get.responses["200"].content["application/json"].schema;
package/lib/bundle.ts CHANGED
@@ -579,9 +579,11 @@ function remap(parser: $RefParser, inventory: InventoryEntry[]) {
579
579
  continue;
580
580
  }
581
581
 
582
- // Keep internal refs internal
582
+ // Keep internal refs internal. However, if the $ref extends the resolved value
583
+ // (i.e. it has additional properties in addition to "$ref"), then we must
584
+ // preserve the original $ref rather than rewriting it to the resolved hash.
583
585
  if (!entry.external) {
584
- if (entry.$ref && typeof entry.$ref === "object") {
586
+ if (!entry.extended && entry.$ref && typeof entry.$ref === "object") {
585
587
  entry.$ref.$ref = entry.hash;
586
588
  }
587
589
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hey-api/json-schema-ref-parser",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",
5
5
  "homepage": "https://heyapi.dev/",
6
6
  "repository": {