@hey-api/json-schema-ref-parser 1.2.3 → 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.
Files changed (92) hide show
  1. package/README.md +9 -84
  2. package/dist/index.d.mts +629 -0
  3. package/dist/index.d.mts.map +1 -0
  4. package/dist/index.mjs +1887 -0
  5. package/dist/index.mjs.map +1 -0
  6. package/package.json +42 -78
  7. package/src/__tests__/bundle.test.ts +59 -0
  8. package/src/__tests__/index.test.ts +43 -0
  9. package/src/__tests__/pointer.test.ts +34 -0
  10. package/src/__tests__/utils.ts +3 -0
  11. package/{lib → src}/bundle.ts +143 -229
  12. package/{lib → src}/dereference.ts +20 -43
  13. package/{lib → src}/index.ts +103 -125
  14. package/{lib → src}/options.ts +13 -9
  15. package/{lib → src}/parse.ts +19 -15
  16. package/src/parsers/binary.ts +13 -0
  17. package/{lib → src}/parsers/json.ts +5 -6
  18. package/src/parsers/text.ts +21 -0
  19. package/{lib → src}/parsers/yaml.ts +9 -9
  20. package/{lib → src}/pointer.ts +42 -23
  21. package/{lib → src}/ref.ts +25 -21
  22. package/{lib → src}/refs.ts +23 -26
  23. package/{lib → src}/resolve-external.ts +91 -60
  24. package/{lib → src}/resolvers/file.ts +7 -10
  25. package/{lib → src}/resolvers/url.ts +12 -8
  26. package/{lib → src}/types/index.ts +9 -2
  27. package/src/util/convert-path-to-posix.ts +8 -0
  28. package/{lib → src}/util/errors.ts +38 -36
  29. package/{lib → src}/util/is-windows.ts +1 -1
  30. package/{lib → src}/util/plugins.ts +7 -8
  31. package/{lib → src}/util/url.ts +41 -42
  32. package/dist/lib/__tests__/bundle.test.d.ts +0 -1
  33. package/dist/lib/__tests__/bundle.test.js +0 -50
  34. package/dist/lib/__tests__/index.test.d.ts +0 -1
  35. package/dist/lib/__tests__/index.test.js +0 -43
  36. package/dist/lib/__tests__/pointer.test.d.ts +0 -1
  37. package/dist/lib/__tests__/pointer.test.js +0 -27
  38. package/dist/lib/bundle.d.ts +0 -26
  39. package/dist/lib/bundle.js +0 -600
  40. package/dist/lib/dereference.d.ts +0 -11
  41. package/dist/lib/dereference.js +0 -226
  42. package/dist/lib/index.d.ts +0 -92
  43. package/dist/lib/index.js +0 -525
  44. package/dist/lib/options.d.ts +0 -61
  45. package/dist/lib/options.js +0 -45
  46. package/dist/lib/parse.d.ts +0 -13
  47. package/dist/lib/parse.js +0 -87
  48. package/dist/lib/parsers/binary.d.ts +0 -2
  49. package/dist/lib/parsers/binary.js +0 -12
  50. package/dist/lib/parsers/json.d.ts +0 -2
  51. package/dist/lib/parsers/json.js +0 -38
  52. package/dist/lib/parsers/text.d.ts +0 -2
  53. package/dist/lib/parsers/text.js +0 -18
  54. package/dist/lib/parsers/yaml.d.ts +0 -2
  55. package/dist/lib/parsers/yaml.js +0 -28
  56. package/dist/lib/pointer.d.ts +0 -88
  57. package/dist/lib/pointer.js +0 -297
  58. package/dist/lib/ref.d.ts +0 -180
  59. package/dist/lib/ref.js +0 -226
  60. package/dist/lib/refs.d.ts +0 -127
  61. package/dist/lib/refs.js +0 -232
  62. package/dist/lib/resolve-external.d.ts +0 -13
  63. package/dist/lib/resolve-external.js +0 -151
  64. package/dist/lib/resolvers/file.d.ts +0 -6
  65. package/dist/lib/resolvers/file.js +0 -61
  66. package/dist/lib/resolvers/url.d.ts +0 -17
  67. package/dist/lib/resolvers/url.js +0 -62
  68. package/dist/lib/types/index.d.ts +0 -43
  69. package/dist/lib/types/index.js +0 -2
  70. package/dist/lib/util/convert-path-to-posix.d.ts +0 -1
  71. package/dist/lib/util/convert-path-to-posix.js +0 -14
  72. package/dist/lib/util/errors.d.ts +0 -56
  73. package/dist/lib/util/errors.js +0 -112
  74. package/dist/lib/util/is-windows.d.ts +0 -1
  75. package/dist/lib/util/is-windows.js +0 -6
  76. package/dist/lib/util/plugins.d.ts +0 -16
  77. package/dist/lib/util/plugins.js +0 -45
  78. package/dist/lib/util/url.d.ts +0 -79
  79. package/dist/lib/util/url.js +0 -285
  80. package/dist/vite.config.d.ts +0 -2
  81. package/dist/vite.config.js +0 -19
  82. package/lib/__tests__/bundle.test.ts +0 -52
  83. package/lib/__tests__/index.test.ts +0 -45
  84. package/lib/__tests__/pointer.test.ts +0 -26
  85. package/lib/__tests__/spec/circular-ref-with-description.json +0 -11
  86. package/lib/__tests__/spec/multiple-refs.json +0 -34
  87. package/lib/__tests__/spec/openapi-paths-ref.json +0 -46
  88. package/lib/__tests__/spec/path-parameter.json +0 -16
  89. package/lib/parsers/binary.ts +0 -13
  90. package/lib/parsers/text.ts +0 -21
  91. package/lib/util/convert-path-to-posix.ts +0 -11
  92. /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,11 +0,0 @@
1
- {
2
- "schemas": {
3
- "Foo": {
4
- "$ref": "#/schemas/Bar"
5
- },
6
- "Bar": {
7
- "description": "ok",
8
- "$ref": "#/schemas/Foo"
9
- }
10
- }
11
- }
@@ -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
- }
@@ -1,16 +0,0 @@
1
- {
2
- "components": {
3
- "parameters": {
4
- "pathId": {
5
- "name": "pathId",
6
- "in": "path",
7
- "required": true,
8
- "schema": {
9
- "type": "string",
10
- "format": "uuid",
11
- "description": "Unique identifier for the path"
12
- }
13
- }
14
- }
15
- }
16
- }
@@ -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
- };
@@ -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
- }
File without changes