@hey-api/json-schema-ref-parser 1.0.7 → 1.0.8
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const vitest_1 = require("vitest");
|
|
7
|
+
const __1 = require("..");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
(0, vitest_1.describe)("pointer", () => {
|
|
10
|
+
(0, vitest_1.it)("inlines internal JSON Pointer refs under #/paths/ for OpenAPI bundling", async () => {
|
|
11
|
+
const refParser = new __1.$RefParser();
|
|
12
|
+
const pathOrUrlOrSchema = path_1.default.resolve("lib", "__tests__", "spec", "openapi-paths-ref.json");
|
|
13
|
+
const schema = (await refParser.bundle({ pathOrUrlOrSchema }));
|
|
14
|
+
// The GET endpoint should have its schema defined inline
|
|
15
|
+
const getSchema = schema.paths["/foo"].get.responses["200"].content["application/json"].schema;
|
|
16
|
+
(0, vitest_1.expect)(getSchema.$ref).toBeUndefined();
|
|
17
|
+
(0, vitest_1.expect)(getSchema.type).toBe("object");
|
|
18
|
+
(0, vitest_1.expect)(getSchema.properties.bar.type).toBe("string");
|
|
19
|
+
// The POST endpoint should have its schema inlined (copied) instead of a $ref
|
|
20
|
+
const postSchema = schema.paths["/foo"].post.responses["200"].content["application/json"].schema;
|
|
21
|
+
(0, vitest_1.expect)(postSchema.$ref).toBeUndefined();
|
|
22
|
+
(0, vitest_1.expect)(postSchema.type).toBe("object");
|
|
23
|
+
(0, vitest_1.expect)(postSchema.properties.bar.type).toBe("string");
|
|
24
|
+
// Both schemas should be identical objects
|
|
25
|
+
(0, vitest_1.expect)(postSchema).toEqual(getSchema);
|
|
26
|
+
});
|
|
27
|
+
});
|
package/dist/lib/bundle.js
CHANGED
|
@@ -249,7 +249,7 @@ function remap(inventory) {
|
|
|
249
249
|
let file, hash, pathFromRoot;
|
|
250
250
|
for (const entry of inventory) {
|
|
251
251
|
// console.log('Re-mapping $ref pointer "%s" at %s', entry.$ref.$ref, entry.pathFromRoot);
|
|
252
|
-
if (!entry.external) {
|
|
252
|
+
if (!entry.external && !entry.hash?.startsWith("#/paths/")) {
|
|
253
253
|
// This $ref already resolves to the main JSON Schema file
|
|
254
254
|
entry.$ref.$ref = entry.hash;
|
|
255
255
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { $RefParser } from "..";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
describe("pointer", () => {
|
|
6
|
+
it("inlines internal JSON Pointer refs under #/paths/ for OpenAPI bundling", async () => {
|
|
7
|
+
const refParser = new $RefParser();
|
|
8
|
+
const pathOrUrlOrSchema = path.resolve("lib", "__tests__", "spec", "openapi-paths-ref.json");
|
|
9
|
+
const schema = (await refParser.bundle({ pathOrUrlOrSchema })) as any;
|
|
10
|
+
|
|
11
|
+
// The GET endpoint should have its schema defined inline
|
|
12
|
+
const getSchema = schema.paths["/foo"].get.responses["200"].content["application/json"].schema;
|
|
13
|
+
expect(getSchema.$ref).toBeUndefined();
|
|
14
|
+
expect(getSchema.type).toBe("object");
|
|
15
|
+
expect(getSchema.properties.bar.type).toBe("string");
|
|
16
|
+
|
|
17
|
+
// The POST endpoint should have its schema inlined (copied) instead of a $ref
|
|
18
|
+
const postSchema = schema.paths["/foo"].post.responses["200"].content["application/json"].schema;
|
|
19
|
+
expect(postSchema.$ref).toBeUndefined();
|
|
20
|
+
expect(postSchema.type).toBe("object");
|
|
21
|
+
expect(postSchema.properties.bar.type).toBe("string");
|
|
22
|
+
|
|
23
|
+
// Both schemas should be identical objects
|
|
24
|
+
expect(postSchema).toEqual(getSchema);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"openapi": "3.1.0",
|
|
3
|
+
"info": {
|
|
4
|
+
"title": "Sample API",
|
|
5
|
+
"version": "1.0.0"
|
|
6
|
+
},
|
|
7
|
+
"paths": {
|
|
8
|
+
"/foo": {
|
|
9
|
+
"get": {
|
|
10
|
+
"summary": "Get foo",
|
|
11
|
+
"responses": {
|
|
12
|
+
"200": {
|
|
13
|
+
"description": "OK",
|
|
14
|
+
"content": {
|
|
15
|
+
"application/json": {
|
|
16
|
+
"schema": {
|
|
17
|
+
"type": "object",
|
|
18
|
+
"properties": {
|
|
19
|
+
"bar": {
|
|
20
|
+
"type": "string"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"post": {
|
|
30
|
+
"summary": "Create foo",
|
|
31
|
+
"responses": {
|
|
32
|
+
"200": {
|
|
33
|
+
"description": "OK",
|
|
34
|
+
"content": {
|
|
35
|
+
"application/json": {
|
|
36
|
+
"schema": {
|
|
37
|
+
"$ref": "#/paths/~1foo/get/responses/200/content/application~1json/schema"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
package/lib/bundle.ts
CHANGED
|
@@ -300,7 +300,7 @@ function remap(inventory: InventoryEntry[]) {
|
|
|
300
300
|
for (const entry of inventory) {
|
|
301
301
|
// console.log('Re-mapping $ref pointer "%s" at %s', entry.$ref.$ref, entry.pathFromRoot);
|
|
302
302
|
|
|
303
|
-
if (!entry.external) {
|
|
303
|
+
if (!entry.external && !entry.hash?.startsWith("#/paths/")) {
|
|
304
304
|
// This $ref already resolves to the main JSON Schema file
|
|
305
305
|
entry.$ref.$ref = entry.hash;
|
|
306
306
|
} else if (entry.file === file && entry.hash === hash) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hey-api/json-schema-ref-parser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",
|
|
5
5
|
"homepage": "https://heyapi.dev/",
|
|
6
6
|
"repository": {
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
],
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "rimraf dist && tsc",
|
|
45
|
+
"dev": "rimraf dist && tsc --watch",
|
|
45
46
|
"lint": "eslint lib",
|
|
46
47
|
"prepublishOnly": "yarn build",
|
|
47
48
|
"prettier": "prettier --write \"**/*.+(js|jsx|ts|tsx|har||json|css|md)\"",
|