@hey-api/json-schema-ref-parser 1.2.4 → 1.3.0
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.
- package/README.md +9 -84
- package/dist/index.d.mts +629 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1887 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +42 -78
- package/src/__tests__/bundle.test.ts +59 -0
- package/src/__tests__/index.test.ts +43 -0
- package/src/__tests__/pointer.test.ts +34 -0
- package/src/__tests__/utils.ts +3 -0
- package/{lib → src}/bundle.ts +143 -229
- package/{lib → src}/dereference.ts +20 -43
- package/{lib → src}/index.ts +103 -125
- package/{lib → src}/options.ts +13 -9
- package/{lib → src}/parse.ts +19 -15
- package/src/parsers/binary.ts +13 -0
- package/{lib → src}/parsers/json.ts +5 -6
- package/src/parsers/text.ts +21 -0
- package/{lib → src}/parsers/yaml.ts +9 -9
- package/{lib → src}/pointer.ts +42 -23
- package/{lib → src}/ref.ts +25 -21
- package/{lib → src}/refs.ts +23 -26
- package/{lib → src}/resolve-external.ts +91 -60
- package/{lib → src}/resolvers/file.ts +7 -10
- package/{lib → src}/resolvers/url.ts +12 -8
- package/{lib → src}/types/index.ts +9 -2
- package/src/util/convert-path-to-posix.ts +8 -0
- package/{lib → src}/util/errors.ts +38 -36
- package/{lib → src}/util/is-windows.ts +1 -1
- package/{lib → src}/util/plugins.ts +7 -8
- package/{lib → src}/util/url.ts +41 -42
- package/dist/lib/__tests__/bundle.test.d.ts +0 -1
- package/dist/lib/__tests__/bundle.test.js +0 -50
- package/dist/lib/__tests__/index.test.d.ts +0 -1
- package/dist/lib/__tests__/index.test.js +0 -43
- package/dist/lib/__tests__/pointer.test.d.ts +0 -1
- package/dist/lib/__tests__/pointer.test.js +0 -27
- package/dist/lib/bundle.d.ts +0 -26
- package/dist/lib/bundle.js +0 -600
- package/dist/lib/dereference.d.ts +0 -11
- package/dist/lib/dereference.js +0 -226
- package/dist/lib/index.d.ts +0 -92
- package/dist/lib/index.js +0 -525
- package/dist/lib/options.d.ts +0 -61
- package/dist/lib/options.js +0 -45
- package/dist/lib/parse.d.ts +0 -13
- package/dist/lib/parse.js +0 -87
- package/dist/lib/parsers/binary.d.ts +0 -2
- package/dist/lib/parsers/binary.js +0 -12
- package/dist/lib/parsers/json.d.ts +0 -2
- package/dist/lib/parsers/json.js +0 -38
- package/dist/lib/parsers/text.d.ts +0 -2
- package/dist/lib/parsers/text.js +0 -18
- package/dist/lib/parsers/yaml.d.ts +0 -2
- package/dist/lib/parsers/yaml.js +0 -28
- package/dist/lib/pointer.d.ts +0 -88
- package/dist/lib/pointer.js +0 -297
- package/dist/lib/ref.d.ts +0 -180
- package/dist/lib/ref.js +0 -226
- package/dist/lib/refs.d.ts +0 -127
- package/dist/lib/refs.js +0 -232
- package/dist/lib/resolve-external.d.ts +0 -13
- package/dist/lib/resolve-external.js +0 -151
- package/dist/lib/resolvers/file.d.ts +0 -6
- package/dist/lib/resolvers/file.js +0 -61
- package/dist/lib/resolvers/url.d.ts +0 -17
- package/dist/lib/resolvers/url.js +0 -62
- package/dist/lib/types/index.d.ts +0 -43
- package/dist/lib/types/index.js +0 -2
- package/dist/lib/util/convert-path-to-posix.d.ts +0 -1
- package/dist/lib/util/convert-path-to-posix.js +0 -14
- package/dist/lib/util/errors.d.ts +0 -56
- package/dist/lib/util/errors.js +0 -112
- package/dist/lib/util/is-windows.d.ts +0 -1
- package/dist/lib/util/is-windows.js +0 -6
- package/dist/lib/util/plugins.d.ts +0 -16
- package/dist/lib/util/plugins.js +0 -45
- package/dist/lib/util/url.d.ts +0 -79
- package/dist/lib/util/url.js +0 -285
- package/dist/vite.config.d.ts +0 -2
- package/dist/vite.config.js +0 -19
- package/lib/__tests__/bundle.test.ts +0 -52
- package/lib/__tests__/index.test.ts +0 -45
- package/lib/__tests__/pointer.test.ts +0 -26
- package/lib/__tests__/spec/circular-ref-with-description.json +0 -11
- package/lib/__tests__/spec/multiple-refs.json +0 -34
- package/lib/__tests__/spec/openapi-paths-ref.json +0 -46
- package/lib/__tests__/spec/path-parameter.json +0 -16
- package/lib/parsers/binary.ts +0 -13
- package/lib/parsers/text.ts +0 -21
- package/lib/util/convert-path-to-posix.ts +0 -11
- /package/{LICENSE → LICENSE.md} +0 -0
|
@@ -1,26 +0,0 @@
|
|
|
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).toBe("#/paths/~1foo/get/responses/200/content/application~1json/schema");
|
|
20
|
-
expect(postSchema.type).toBeUndefined();
|
|
21
|
-
expect(postSchema.properties?.bar?.type).toBeUndefined();
|
|
22
|
-
|
|
23
|
-
// Both schemas should be identical objects
|
|
24
|
-
expect(postSchema).not.toBe(getSchema);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"paths": {
|
|
3
|
-
"/test1/{pathId}": {
|
|
4
|
-
"get": {
|
|
5
|
-
"summary": "First endpoint using the same pathId schema",
|
|
6
|
-
"parameters": [
|
|
7
|
-
{
|
|
8
|
-
"$ref": "path-parameter.json#/components/parameters/pathId"
|
|
9
|
-
}
|
|
10
|
-
],
|
|
11
|
-
"responses": {
|
|
12
|
-
"200": {
|
|
13
|
-
"description": "Test 1 response"
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
"/test2/{pathId}": {
|
|
19
|
-
"get": {
|
|
20
|
-
"summary": "Second endpoint using the same pathId schema",
|
|
21
|
-
"parameters": [
|
|
22
|
-
{
|
|
23
|
-
"$ref": "path-parameter.json#/components/parameters/pathId"
|
|
24
|
-
}
|
|
25
|
-
],
|
|
26
|
-
"responses": {
|
|
27
|
-
"200": {
|
|
28
|
-
"description": "Test 2 response"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
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/parsers/binary.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { FileInfo } from "../types/index.js";
|
|
2
|
-
import type { Plugin } from "../types/index.js";
|
|
3
|
-
|
|
4
|
-
const BINARY_REGEXP = /\.(jpeg|jpg|gif|png|bmp|ico)$/i;
|
|
5
|
-
|
|
6
|
-
export const binaryParser: Plugin = {
|
|
7
|
-
canHandle: (file: FileInfo) => Buffer.isBuffer(file.data) && BINARY_REGEXP.test(file.url),
|
|
8
|
-
handler: (file: FileInfo): Buffer => Buffer.isBuffer(file.data)
|
|
9
|
-
? file.data
|
|
10
|
-
// This will reject if data is anything other than a string or typed array
|
|
11
|
-
: Buffer.from(file.data),
|
|
12
|
-
name: 'binary',
|
|
13
|
-
};
|
package/lib/parsers/text.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { FileInfo } from "../types/index.js";
|
|
2
|
-
import { ParserError } from "../util/errors.js";
|
|
3
|
-
import type { Plugin } from "../types/index.js";
|
|
4
|
-
|
|
5
|
-
const TEXT_REGEXP = /\.(txt|htm|html|md|xml|js|min|map|css|scss|less|svg)$/i;
|
|
6
|
-
|
|
7
|
-
export const textParser: Plugin = {
|
|
8
|
-
canHandle: (file: FileInfo) => (typeof file.data === "string" || Buffer.isBuffer(file.data)) && TEXT_REGEXP.test(file.url),
|
|
9
|
-
handler(file: FileInfo): string {
|
|
10
|
-
if (typeof file.data === "string") {
|
|
11
|
-
return file.data;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (!Buffer.isBuffer(file.data)) {
|
|
15
|
-
throw new ParserError("data is not text", file.url);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return file.data.toString('utf-8');
|
|
19
|
-
},
|
|
20
|
-
name: 'text',
|
|
21
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
|
|
3
|
-
export default function convertPathToPosix(filePath: string) {
|
|
4
|
-
const isExtendedLengthPath = filePath.startsWith("\\\\?\\");
|
|
5
|
-
|
|
6
|
-
if (isExtendedLengthPath) {
|
|
7
|
-
return filePath;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
return filePath.split(path?.win32?.sep).join(path?.posix?.sep ?? "/");
|
|
11
|
-
}
|
/package/{LICENSE → LICENSE.md}
RENAMED
|
File without changes
|