@hey-api/json-schema-ref-parser 1.2.4 → 1.3.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.
Files changed (94) 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 +1920 -0
  5. package/dist/index.mjs.map +1 -0
  6. package/package.json +42 -78
  7. package/{lib/__tests__/spec → src/__tests__/__snapshots__}/circular-ref-with-description.json +1 -1
  8. package/src/__tests__/__snapshots__/main-with-external-siblings.json +78 -0
  9. package/{lib/__tests__/spec → src/__tests__/__snapshots__}/multiple-refs.json +17 -3
  10. package/src/__tests__/__snapshots__/redfish-like.json +87 -0
  11. package/src/__tests__/bundle.test.ts +393 -0
  12. package/src/__tests__/index.test.ts +43 -0
  13. package/src/__tests__/pointer.test.ts +34 -0
  14. package/src/__tests__/utils.ts +3 -0
  15. package/{lib → src}/bundle.ts +191 -231
  16. package/{lib → src}/dereference.ts +20 -43
  17. package/{lib → src}/index.ts +129 -127
  18. package/{lib → src}/options.ts +13 -9
  19. package/{lib → src}/parse.ts +19 -15
  20. package/src/parsers/binary.ts +13 -0
  21. package/{lib → src}/parsers/json.ts +5 -6
  22. package/src/parsers/text.ts +21 -0
  23. package/{lib → src}/parsers/yaml.ts +9 -9
  24. package/{lib → src}/pointer.ts +42 -23
  25. package/{lib → src}/ref.ts +25 -21
  26. package/{lib → src}/refs.ts +23 -26
  27. package/{lib → src}/resolve-external.ts +91 -60
  28. package/{lib → src}/resolvers/file.ts +7 -10
  29. package/{lib → src}/resolvers/url.ts +12 -8
  30. package/{lib → src}/types/index.ts +9 -2
  31. package/src/util/convert-path-to-posix.ts +8 -0
  32. package/{lib → src}/util/errors.ts +38 -36
  33. package/{lib → src}/util/is-windows.ts +1 -1
  34. package/{lib → src}/util/plugins.ts +7 -8
  35. package/{lib → src}/util/url.ts +41 -42
  36. package/dist/lib/__tests__/bundle.test.d.ts +0 -1
  37. package/dist/lib/__tests__/bundle.test.js +0 -50
  38. package/dist/lib/__tests__/index.test.d.ts +0 -1
  39. package/dist/lib/__tests__/index.test.js +0 -43
  40. package/dist/lib/__tests__/pointer.test.d.ts +0 -1
  41. package/dist/lib/__tests__/pointer.test.js +0 -27
  42. package/dist/lib/bundle.d.ts +0 -26
  43. package/dist/lib/bundle.js +0 -600
  44. package/dist/lib/dereference.d.ts +0 -11
  45. package/dist/lib/dereference.js +0 -226
  46. package/dist/lib/index.d.ts +0 -92
  47. package/dist/lib/index.js +0 -525
  48. package/dist/lib/options.d.ts +0 -61
  49. package/dist/lib/options.js +0 -45
  50. package/dist/lib/parse.d.ts +0 -13
  51. package/dist/lib/parse.js +0 -87
  52. package/dist/lib/parsers/binary.d.ts +0 -2
  53. package/dist/lib/parsers/binary.js +0 -12
  54. package/dist/lib/parsers/json.d.ts +0 -2
  55. package/dist/lib/parsers/json.js +0 -38
  56. package/dist/lib/parsers/text.d.ts +0 -2
  57. package/dist/lib/parsers/text.js +0 -18
  58. package/dist/lib/parsers/yaml.d.ts +0 -2
  59. package/dist/lib/parsers/yaml.js +0 -28
  60. package/dist/lib/pointer.d.ts +0 -88
  61. package/dist/lib/pointer.js +0 -297
  62. package/dist/lib/ref.d.ts +0 -180
  63. package/dist/lib/ref.js +0 -226
  64. package/dist/lib/refs.d.ts +0 -127
  65. package/dist/lib/refs.js +0 -232
  66. package/dist/lib/resolve-external.d.ts +0 -13
  67. package/dist/lib/resolve-external.js +0 -151
  68. package/dist/lib/resolvers/file.d.ts +0 -6
  69. package/dist/lib/resolvers/file.js +0 -61
  70. package/dist/lib/resolvers/url.d.ts +0 -17
  71. package/dist/lib/resolvers/url.js +0 -62
  72. package/dist/lib/types/index.d.ts +0 -43
  73. package/dist/lib/types/index.js +0 -2
  74. package/dist/lib/util/convert-path-to-posix.d.ts +0 -1
  75. package/dist/lib/util/convert-path-to-posix.js +0 -14
  76. package/dist/lib/util/errors.d.ts +0 -56
  77. package/dist/lib/util/errors.js +0 -112
  78. package/dist/lib/util/is-windows.d.ts +0 -1
  79. package/dist/lib/util/is-windows.js +0 -6
  80. package/dist/lib/util/plugins.d.ts +0 -16
  81. package/dist/lib/util/plugins.js +0 -45
  82. package/dist/lib/util/url.d.ts +0 -79
  83. package/dist/lib/util/url.js +0 -285
  84. package/dist/vite.config.d.ts +0 -2
  85. package/dist/vite.config.js +0 -19
  86. package/lib/__tests__/bundle.test.ts +0 -52
  87. package/lib/__tests__/index.test.ts +0 -45
  88. package/lib/__tests__/pointer.test.ts +0 -26
  89. package/lib/__tests__/spec/openapi-paths-ref.json +0 -46
  90. package/lib/__tests__/spec/path-parameter.json +0 -16
  91. package/lib/parsers/binary.ts +0 -13
  92. package/lib/parsers/text.ts +0 -21
  93. package/lib/util/convert-path-to-posix.ts +0 -11
  94. /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,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