@scalar/openapi-parser 0.12.0 → 0.14.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/CHANGELOG.md +12 -0
- package/README.md +134 -0
- package/dist/configuration/index.d.ts +2 -2
- package/dist/configuration/index.js +2 -2
- package/dist/configuration/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +2 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/bundle/bundle.d.ts +193 -0
- package/dist/utils/bundle/bundle.d.ts.map +1 -0
- package/dist/utils/bundle/bundle.js +197 -0
- package/dist/utils/bundle/bundle.js.map +7 -0
- package/dist/utils/bundle/create-limiter.d.ts +21 -0
- package/dist/utils/bundle/create-limiter.d.ts.map +1 -0
- package/dist/utils/bundle/create-limiter.js +31 -0
- package/dist/utils/bundle/create-limiter.js.map +7 -0
- package/dist/utils/bundle/index.d.ts +4 -0
- package/dist/utils/bundle/index.d.ts.map +1 -0
- package/dist/utils/bundle/index.js +9 -0
- package/dist/utils/bundle/index.js.map +7 -0
- package/dist/utils/bundle/plugins/fetch-urls.d.ts +38 -0
- package/dist/utils/bundle/plugins/fetch-urls.d.ts.map +1 -0
- package/dist/utils/bundle/plugins/fetch-urls.js +40 -0
- package/dist/utils/bundle/plugins/fetch-urls.js.map +7 -0
- package/dist/utils/bundle/plugins/read-files.d.ts +29 -0
- package/dist/utils/bundle/plugins/read-files.d.ts.map +1 -0
- package/dist/utils/bundle/plugins/read-files.js +30 -0
- package/dist/utils/bundle/plugins/read-files.js.map +7 -0
- package/dist/utils/details.d.ts +1 -2
- package/dist/utils/details.d.ts.map +1 -1
- package/dist/utils/details.js +12 -9
- package/dist/utils/details.js.map +2 -2
- package/dist/utils/normalize.d.ts +1 -1
- package/dist/utils/normalize.d.ts.map +1 -1
- package/dist/utils/normalize.js +16 -11
- package/dist/utils/normalize.js.map +2 -2
- package/dist/utils/resolve-references.d.ts.map +1 -1
- package/dist/utils/resolve-references.js +11 -0
- package/dist/utils/resolve-references.js.map +2 -2
- package/package.json +5 -5
- package/dist/lib/Validator/Validator.test.js +0 -8
- package/dist/lib/Validator/Validator.test.js.map +0 -7
- package/dist/plugins/fetch-urls/fetch-urls.test.js +0 -50
- package/dist/plugins/fetch-urls/fetch-urls.test.js.map +0 -7
- package/dist/plugins/read-files/read-files.test.js +0 -20
- package/dist/plugins/read-files/read-files.test.js.map +0 -7
- package/dist/utils/dereference.test.js +0 -300
- package/dist/utils/dereference.test.js.map +0 -7
- package/dist/utils/errors.test.js +0 -48
- package/dist/utils/errors.test.js.map +0 -7
- package/dist/utils/escape-json-pointer.test.js +0 -11
- package/dist/utils/escape-json-pointer.test.js.map +0 -7
- package/dist/utils/get-entrypoint.test.js +0 -18
- package/dist/utils/get-entrypoint.test.js.map +0 -7
- package/dist/utils/get-segments-from-path.test.js +0 -13
- package/dist/utils/get-segments-from-path.test.js.map +0 -7
- package/dist/utils/is-filesystem.test.js +0 -15
- package/dist/utils/is-filesystem.test.js.map +0 -7
- package/dist/utils/is-object.test.js +0 -23
- package/dist/utils/is-object.test.js.map +0 -7
- package/dist/utils/load/load.test.js +0 -361
- package/dist/utils/load/load.test.js.map +0 -7
- package/dist/utils/normalize.test.js +0 -88
- package/dist/utils/normalize.test.js.map +0 -7
- package/dist/utils/resolve-references.test.js +0 -567
- package/dist/utils/resolve-references.test.js.map +0 -7
- package/dist/utils/transform/sanitize.test.js +0 -148
- package/dist/utils/transform/sanitize.test.js.map +0 -7
- package/dist/utils/transform-errors.test.js +0 -17
- package/dist/utils/transform-errors.test.js.map +0 -7
- package/dist/utils/traverse.test.js +0 -68
- package/dist/utils/traverse.test.js.map +0 -7
- package/dist/utils/unescape-json-pointer.test.js +0 -19
- package/dist/utils/unescape-json-pointer.test.js.map +0 -7
- package/dist/utils/upgrade-from-three-to-three-one.test.js +0 -462
- package/dist/utils/upgrade-from-three-to-three-one.test.js.map +0 -7
- package/dist/utils/upgrade-from-two-to-three.test.js +0 -589
- package/dist/utils/upgrade-from-two-to-three.test.js.map +0 -7
- package/dist/utils/upgrade.test.js +0 -57
- package/dist/utils/upgrade.test.js.map +0 -7
- package/dist/utils/validate.test.js +0 -64
- package/dist/utils/validate.test.js.map +0 -7
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { DEFAULT_OPENAPI_VERSION, DEFAULT_TITLE, sanitize } from "./sanitize.js";
|
|
3
|
-
describe("sanitize", () => {
|
|
4
|
-
describe("required properties", () => {
|
|
5
|
-
it("adds required properties", () => {
|
|
6
|
-
const result = sanitize({});
|
|
7
|
-
expect(result).toStrictEqual({
|
|
8
|
-
openapi: DEFAULT_OPENAPI_VERSION,
|
|
9
|
-
info: {
|
|
10
|
-
title: DEFAULT_TITLE,
|
|
11
|
-
version: "1.0"
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
it("doesn\u2019t overwrite existing properties", () => {
|
|
16
|
-
const result = sanitize({
|
|
17
|
-
openapi: "3.0.0",
|
|
18
|
-
info: {
|
|
19
|
-
title: "Foobar"
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
expect(result).toStrictEqual({
|
|
23
|
-
openapi: "3.0.0",
|
|
24
|
-
info: {
|
|
25
|
-
title: "Foobar",
|
|
26
|
-
version: "1.0"
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
it("throws an error when it\u2019s a swagger document", () => {
|
|
31
|
-
expect(
|
|
32
|
-
() => sanitize({
|
|
33
|
-
swagger: "2.0"
|
|
34
|
-
})
|
|
35
|
-
).toThrow("Swagger 2.0 documents are not supported. Please upgrade to OpenAPI 3.x.");
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
describe("tags", () => {
|
|
39
|
-
it("adds missing tags", () => {
|
|
40
|
-
const result = sanitize({
|
|
41
|
-
paths: {
|
|
42
|
-
"/pets": {
|
|
43
|
-
get: {
|
|
44
|
-
tags: ["pets"],
|
|
45
|
-
responses: {}
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
"/stores": {
|
|
49
|
-
get: {
|
|
50
|
-
tags: ["stores"],
|
|
51
|
-
responses: {}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
expect(result.tags).toStrictEqual([{ name: "pets" }, { name: "stores" }]);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
describe("components.securitySchemes", () => {
|
|
60
|
-
it("normalizes security scheme types to lowercase", () => {
|
|
61
|
-
const result = sanitize({
|
|
62
|
-
components: {
|
|
63
|
-
securitySchemes: {
|
|
64
|
-
bearerAuth: {
|
|
65
|
-
type: "HTTP",
|
|
66
|
-
scheme: "bearer"
|
|
67
|
-
},
|
|
68
|
-
basicAuth: {
|
|
69
|
-
type: "HTTP",
|
|
70
|
-
scheme: "basic"
|
|
71
|
-
},
|
|
72
|
-
apiKeyHeader: {
|
|
73
|
-
type: "APIKEY",
|
|
74
|
-
in: "header",
|
|
75
|
-
name: "X-API-Key"
|
|
76
|
-
},
|
|
77
|
-
oauth2: {
|
|
78
|
-
type: "OAUTH2",
|
|
79
|
-
flows: {
|
|
80
|
-
authorizationCode: {
|
|
81
|
-
authorizationUrl: "https://example.com/oauth/authorize",
|
|
82
|
-
tokenUrl: "https://example.com/oauth/token",
|
|
83
|
-
scopes: {}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
openIdConnect: {
|
|
88
|
-
type: "OPENIDCONNECT",
|
|
89
|
-
openIdConnectUrl: "https://example.com/.well-known/openid-configuration"
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
expect(result.components?.securitySchemes).toStrictEqual({
|
|
95
|
-
bearerAuth: {
|
|
96
|
-
type: "http",
|
|
97
|
-
scheme: "bearer"
|
|
98
|
-
},
|
|
99
|
-
basicAuth: {
|
|
100
|
-
type: "http",
|
|
101
|
-
scheme: "basic"
|
|
102
|
-
},
|
|
103
|
-
apiKeyHeader: {
|
|
104
|
-
type: "apiKey",
|
|
105
|
-
in: "header",
|
|
106
|
-
name: "X-API-Key"
|
|
107
|
-
},
|
|
108
|
-
oauth2: {
|
|
109
|
-
type: "oauth2",
|
|
110
|
-
flows: {
|
|
111
|
-
authorizationCode: {
|
|
112
|
-
authorizationUrl: "https://example.com/oauth/authorize",
|
|
113
|
-
tokenUrl: "https://example.com/oauth/token",
|
|
114
|
-
scopes: {}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
openIdConnect: {
|
|
119
|
-
type: "openIdConnect",
|
|
120
|
-
openIdConnectUrl: "https://example.com/.well-known/openid-configuration"
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
it("converts array scopes to objects", () => {
|
|
125
|
-
const result = sanitize({
|
|
126
|
-
components: {
|
|
127
|
-
securitySchemes: {
|
|
128
|
-
oauth2: {
|
|
129
|
-
type: "oauth2",
|
|
130
|
-
flows: {
|
|
131
|
-
authorizationCode: {
|
|
132
|
-
authorizationUrl: "https://example.com/oauth/authorize",
|
|
133
|
-
tokenUrl: "https://example.com/oauth/token",
|
|
134
|
-
scopes: ["read:data", "write:data"]
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
expect(result.components?.securitySchemes?.oauth2.flows.authorizationCode.scopes).toStrictEqual({
|
|
142
|
-
"read:data": "",
|
|
143
|
-
"write:data": ""
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
//# sourceMappingURL=sanitize.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/utils/transform/sanitize.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { DEFAULT_OPENAPI_VERSION, DEFAULT_TITLE, sanitize } from './sanitize'\n\ndescribe('sanitize', () => {\n describe('required properties', () => {\n /** @see https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.1.md#openapi-object */\n it('adds required properties', () => {\n const result = sanitize({})\n\n expect(result).toStrictEqual({\n openapi: DEFAULT_OPENAPI_VERSION,\n info: {\n title: DEFAULT_TITLE,\n version: '1.0',\n },\n })\n })\n\n it('doesn\u2019t overwrite existing properties', () => {\n const result = sanitize({\n openapi: '3.0.0',\n info: {\n title: 'Foobar',\n },\n })\n\n expect(result).toStrictEqual({\n openapi: '3.0.0',\n info: {\n title: 'Foobar',\n version: '1.0',\n },\n })\n })\n\n it('throws an error when it\u2019s a swagger document', () => {\n expect(() =>\n sanitize({\n swagger: '2.0',\n }),\n ).toThrow('Swagger 2.0 documents are not supported. Please upgrade to OpenAPI 3.x.')\n })\n })\n\n describe('tags', () => {\n it('adds missing tags', () => {\n const result = sanitize({\n paths: {\n '/pets': {\n get: {\n tags: ['pets'],\n responses: {},\n },\n },\n '/stores': {\n get: {\n tags: ['stores'],\n responses: {},\n },\n },\n },\n })\n\n expect(result.tags).toStrictEqual([{ name: 'pets' }, { name: 'stores' }])\n })\n })\n\n describe('components.securitySchemes', () => {\n it('normalizes security scheme types to lowercase', () => {\n const result = sanitize({\n components: {\n securitySchemes: {\n bearerAuth: {\n type: 'HTTP',\n scheme: 'bearer',\n },\n basicAuth: {\n type: 'HTTP',\n scheme: 'basic',\n },\n apiKeyHeader: {\n type: 'APIKEY',\n in: 'header',\n name: 'X-API-Key',\n },\n oauth2: {\n type: 'OAUTH2',\n flows: {\n authorizationCode: {\n authorizationUrl: 'https://example.com/oauth/authorize',\n tokenUrl: 'https://example.com/oauth/token',\n scopes: {},\n },\n },\n },\n openIdConnect: {\n type: 'OPENIDCONNECT',\n openIdConnectUrl: 'https://example.com/.well-known/openid-configuration',\n },\n },\n },\n })\n\n expect(result.components?.securitySchemes).toStrictEqual({\n bearerAuth: {\n type: 'http',\n scheme: 'bearer',\n },\n basicAuth: {\n type: 'http',\n scheme: 'basic',\n },\n apiKeyHeader: {\n type: 'apiKey',\n in: 'header',\n name: 'X-API-Key',\n },\n oauth2: {\n type: 'oauth2',\n flows: {\n authorizationCode: {\n authorizationUrl: 'https://example.com/oauth/authorize',\n tokenUrl: 'https://example.com/oauth/token',\n scopes: {},\n },\n },\n },\n openIdConnect: {\n type: 'openIdConnect',\n openIdConnectUrl: 'https://example.com/.well-known/openid-configuration',\n },\n })\n })\n\n it('converts array scopes to objects', () => {\n const result = sanitize({\n components: {\n securitySchemes: {\n oauth2: {\n type: 'oauth2',\n flows: {\n authorizationCode: {\n authorizationUrl: 'https://example.com/oauth/authorize',\n tokenUrl: 'https://example.com/oauth/token',\n scopes: ['read:data', 'write:data'],\n },\n },\n },\n },\n },\n })\n\n expect(result.components?.securitySchemes?.oauth2.flows.authorizationCode.scopes).toStrictEqual({\n 'read:data': '',\n 'write:data': '',\n })\n })\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,yBAAyB,eAAe,gBAAgB;AAEjE,SAAS,YAAY,MAAM;AACzB,WAAS,uBAAuB,MAAM;AAEpC,OAAG,4BAA4B,MAAM;AACnC,YAAM,SAAS,SAAS,CAAC,CAAC;AAE1B,aAAO,MAAM,EAAE,cAAc;AAAA,QAC3B,SAAS;AAAA,QACT,MAAM;AAAA,UACJ,OAAO;AAAA,UACP,SAAS;AAAA,QACX;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAED,OAAG,8CAAyC,MAAM;AAChD,YAAM,SAAS,SAAS;AAAA,QACtB,SAAS;AAAA,QACT,MAAM;AAAA,UACJ,OAAO;AAAA,QACT;AAAA,MACF,CAAC;AAED,aAAO,MAAM,EAAE,cA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F;AAAA,YACA,eAAe;AAAA,cACb,MAAM;AAAA,cACN,kBAAkB;AAAA,YACpB;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAED,aAAO,OAAO,YAAY,eAAe,EAAE,cAAc;AAAA,QACvD,YAAY;AAAA,UACV,MAAM;AAAA,UACN,QAAQ;AAAA,QACV;AAAA,QACA,WAAW;AAAA,UACT,MAAM;AAAA,UACN,QAAQ;AAAA,QACV;AAAA,QACA,cAAc;AAAA,UACZ,MAAM;AAAA,UACN,IAAI;AAAA,UACJ,MAAM;AAAA,QACR;AAAA,QACA,QAAQ;AAAA,UACN,MAAM;AAAA,UACN,OAAO;AAAA,YACL,mBAAmB;AAAA,cACjB,kBAAkB;AAAA,cAClB,UAAU;AAAA,cACV,QAAQ,CAAC;AAAA,YACX;AAAA,UACF;AAAA,QACF;AAAA,QACA,eAAe;AAAA,UACb,MAAM;AAAA,UACN,kBAAkB;AAAA,QACpB;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAED,OAAG,oCAAoC,MAAM;AAC3C,YAAM,SAAS,SAAS;AAAA,QACtB,YAAY;AAAA,UACV,iBAAiB;AAAA,YACf,QAAQ;AAAA,cACN,MAAM;AAAA,cACN,OAAO;AAAA,gBACL,mBAAmB;AAAA,kBACjB,kBAAkB;AAAA,kBAClB,UAAU;AAAA,kBACV,QAAQ,CAAC,aAAa,YAAY;AAAA,gBACpC;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAED,aAAO,OAAO,YAAY,iBAAiB,OAAO,MAAM,kBAAkB,MAAM,EAAE,cAAc;AAAA,QAC9F,aAAa;AAAA,QACb,cAAc;AAAA,MAChB,CAAC;AAAA,IACH,CAAC;AAAA,EACH,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { makeFilesystem } from "./make-filesystem.js";
|
|
3
|
-
import { transformErrors } from "./transform-errors.js";
|
|
4
|
-
describe("transformErrors", () => {
|
|
5
|
-
it("transforms a string to a proper error object", () => {
|
|
6
|
-
const result = transformErrors(
|
|
7
|
-
makeFilesystem("").find((entrypoint) => entrypoint.isEntrypoint),
|
|
8
|
-
"example error message"
|
|
9
|
-
);
|
|
10
|
-
expect(result).toEqual([
|
|
11
|
-
{
|
|
12
|
-
message: "example error message"
|
|
13
|
-
}
|
|
14
|
-
]);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
//# sourceMappingURL=transform-errors.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/transform-errors.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { makeFilesystem } from './make-filesystem'\nimport { transformErrors } from './transform-errors'\n\ndescribe('transformErrors', () => {\n it('transforms a string to a proper error object', () => {\n const result = transformErrors(\n makeFilesystem('').find((entrypoint) => entrypoint.isEntrypoint),\n 'example error message',\n )\n\n expect(result).toEqual([\n {\n message: 'example error message',\n },\n ])\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAEhC,SAAS,mBAAmB,MAAM;AAChC,KAAG,gDAAgD,MAAM;AACvD,UAAM,SAAS;AAAA,MACb,eAAe,EAAE,EAAE,KAAK,CAAC,eAAe,WAAW,YAAY;AAAA,MAC/D;AAAA,IACF;AAEA,WAAO,MAAM,EAAE,QAAQ;AAAA,MACrB;AAAA,QACE,SAAS;AAAA,MACX;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { traverse } from "./traverse.js";
|
|
3
|
-
describe("traverse", () => {
|
|
4
|
-
it("applies transform function to a flat object", () => {
|
|
5
|
-
const definition = { a: 1, b: 2 };
|
|
6
|
-
const transform = (schema) => {
|
|
7
|
-
return Object.fromEntries(
|
|
8
|
-
Object.entries(schema).map(([key, value]) => {
|
|
9
|
-
if (typeof value !== "number") {
|
|
10
|
-
return [key, value];
|
|
11
|
-
}
|
|
12
|
-
return [key, value * 2];
|
|
13
|
-
})
|
|
14
|
-
);
|
|
15
|
-
};
|
|
16
|
-
const result = traverse(definition, transform);
|
|
17
|
-
expect(result).toEqual({ a: 2, b: 4 });
|
|
18
|
-
});
|
|
19
|
-
it("applies transform function to nested objects", () => {
|
|
20
|
-
const definition = { a: { b: 2, c: 3 }, d: 4 };
|
|
21
|
-
const transform = (schema) => {
|
|
22
|
-
return Object.fromEntries(
|
|
23
|
-
Object.entries(schema).map(([key, value]) => {
|
|
24
|
-
if (typeof value === "object" && value !== null) {
|
|
25
|
-
return [key, value];
|
|
26
|
-
}
|
|
27
|
-
if (typeof value !== "number") {
|
|
28
|
-
return [key, value];
|
|
29
|
-
}
|
|
30
|
-
return [key, value * 2];
|
|
31
|
-
})
|
|
32
|
-
);
|
|
33
|
-
};
|
|
34
|
-
const result = traverse(definition, transform);
|
|
35
|
-
expect(result).toEqual({ a: { b: 4, c: 6 }, d: 8 });
|
|
36
|
-
});
|
|
37
|
-
it("applies transform function to arrays within objects", () => {
|
|
38
|
-
const definition = { a: [1, 2, { b: 3 }], c: 4 };
|
|
39
|
-
const transform = (schema) => {
|
|
40
|
-
return Object.fromEntries(
|
|
41
|
-
Object.entries(schema).map(([key, value]) => {
|
|
42
|
-
if (Array.isArray(value)) {
|
|
43
|
-
return [key, value.map((v) => typeof v === "number" ? v * 2 : v)];
|
|
44
|
-
}
|
|
45
|
-
if (typeof value !== "number") {
|
|
46
|
-
return [key, value];
|
|
47
|
-
}
|
|
48
|
-
return [key, value * 2];
|
|
49
|
-
})
|
|
50
|
-
);
|
|
51
|
-
};
|
|
52
|
-
const result = traverse(definition, transform);
|
|
53
|
-
expect(result).toEqual({ a: [2, 4, { b: 6 }], c: 8 });
|
|
54
|
-
});
|
|
55
|
-
it("handles empty objects", () => {
|
|
56
|
-
const definition = {};
|
|
57
|
-
const transform = (schema) => schema;
|
|
58
|
-
const result = traverse(definition, transform);
|
|
59
|
-
expect(result).toEqual({});
|
|
60
|
-
});
|
|
61
|
-
it("handles objects with null values", () => {
|
|
62
|
-
const definition = { a: null, b: 2 };
|
|
63
|
-
const transform = (schema) => schema;
|
|
64
|
-
const result = traverse(definition, transform);
|
|
65
|
-
expect(result).toEqual({ a: null, b: 2 });
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
//# sourceMappingURL=traverse.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/traverse.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { traverse } from './traverse'\n\ndescribe('traverse', () => {\n it('applies transform function to a flat object', () => {\n const definition = { a: 1, b: 2 }\n const transform = (schema: any) => {\n return Object.fromEntries(\n Object.entries(schema).map(([key, value]) => {\n if (typeof value !== 'number') {\n return [key, value]\n }\n\n return [key, value * 2]\n }),\n )\n }\n\n const result = traverse(definition, transform)\n expect(result).toEqual({ a: 2, b: 4 })\n })\n\n it('applies transform function to nested objects', () => {\n const definition = { a: { b: 2, c: 3 }, d: 4 }\n const transform = (schema: any) => {\n return Object.fromEntries(\n Object.entries(schema).map(([key, value]) => {\n if (typeof value === 'object' && value !== null) {\n return [key, value]\n }\n\n if (typeof value !== 'number') {\n return [key, value]\n }\n\n return [key, value * 2]\n }),\n )\n }\n const result = traverse(definition, transform)\n expect(result).toEqual({ a: { b: 4, c: 6 }, d: 8 })\n })\n\n it('applies transform function to arrays within objects', () => {\n const definition = { a: [1, 2, { b: 3 }], c: 4 }\n const transform = (schema: any) => {\n return Object.fromEntries(\n Object.entries(schema).map(([key, value]) => {\n if (Array.isArray(value)) {\n return [key, value.map((v: any) => (typeof v === 'number' ? v * 2 : v))]\n }\n\n if (typeof value !== 'number') {\n return [key, value]\n }\n\n return [key, value * 2]\n }),\n )\n }\n\n const result = traverse(definition, transform)\n\n expect(result).toEqual({ a: [2, 4, { b: 6 }], c: 8 })\n })\n\n it('handles empty objects', () => {\n const definition = {}\n const transform = (schema: any) => schema\n const result = traverse(definition, transform)\n\n expect(result).toEqual({})\n })\n\n it('handles objects with null values', () => {\n const definition = { a: null, b: 2 }\n const transform = (schema: any) => schema\n const result = traverse(definition, transform)\n\n expect(result).toEqual({ a: null, b: 2 })\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,gBAAgB;AAEzB,SAAS,YAAY,MAAM;AACzB,KAAG,+CAA+C,MAAM;AACtD,UAAM,aAAa,EAAE,GAAG,GAAG,GAAG,EAAE;AAChC,UAAM,YAAY,CAAC,WAAgB;AACjC,aAAO,OAAO;AAAA,QACZ,OAAO,QAAQ,MAAM,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAC3C,cAAI,OAAO,UAAU,UAAU;AAC7B,mBAAO,CAAC,KAAK,KAAK;AAAA,UACpB;AAEA,iBAAO,CAAC,KAAK,QAAQ,CAAC;AAAA,QACxB,CAAC;AAAA,MACH;AAAA,IACF;AAEA,UAAM,SAAS,SAAS,YAAY,SAAS;AAC7C,WAAO,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,GAAG,EAAE,CAAC;AAAA,EACvC,CAAC;AAED,KAAG,gDAAgD,MAAM;AACvD,UAAM,aAAa,EAAE,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,GAAG,EAAE;AAC7C,UAAM,YAAY,CAAC,WAAgB;AACjC,aAAO,OAAO;AAAA,QACZ,OAAO,QAAQ,MAAM,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAC3C,cAAI,O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,CAAC;AAAA,EAC3B,CAAC;AAED,KAAG,oCAAoC,MAAM;AAC3C,UAAM,aAAa,EAAE,GAAG,MAAM,GAAG,EAAE;AACnC,UAAM,YAAY,CAAC,WAAgB;AACnC,UAAM,SAAS,SAAS,YAAY,SAAS;AAE7C,WAAO,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,GAAG,EAAE,CAAC;AAAA,EAC1C,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { unescapeJsonPointer } from "./unescape-json-pointer.js";
|
|
3
|
-
describe("unescapeJsonPointer", async () => {
|
|
4
|
-
it("unescapes a slash", () => {
|
|
5
|
-
expect(unescapeJsonPointer("/foo~1bar~1baz")).toBe("/foo/bar/baz");
|
|
6
|
-
});
|
|
7
|
-
it("unescapes multiple slashes", () => {
|
|
8
|
-
expect(unescapeJsonPointer("#/paths/~1upload/post/responses/401/content/application~1problem+json/schema")).toBe(
|
|
9
|
-
"#/paths//upload/post/responses/401/content/application/problem+json/schema"
|
|
10
|
-
);
|
|
11
|
-
});
|
|
12
|
-
it("unescapes a tilde", () => {
|
|
13
|
-
expect(unescapeJsonPointer("/foo~0bar~0baz")).toBe("/foo~bar~baz");
|
|
14
|
-
});
|
|
15
|
-
it("unescapes a space", () => {
|
|
16
|
-
expect(unescapeJsonPointer("foo%20bar")).toBe("foo bar");
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
//# sourceMappingURL=unescape-json-pointer.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/unescape-json-pointer.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { unescapeJsonPointer } from './unescape-json-pointer'\n\ndescribe('unescapeJsonPointer', async () => {\n it('unescapes a slash', () => {\n expect(unescapeJsonPointer('/foo~1bar~1baz')).toBe('/foo/bar/baz')\n })\n\n it('unescapes multiple slashes', () => {\n expect(unescapeJsonPointer('#/paths/~1upload/post/responses/401/content/application~1problem+json/schema')).toBe(\n '#/paths//upload/post/responses/401/content/application/problem+json/schema',\n )\n })\n\n it('unescapes a tilde', () => {\n expect(unescapeJsonPointer('/foo~0bar~0baz')).toBe('/foo~bar~baz')\n })\n\n it('unescapes a space', () => {\n expect(unescapeJsonPointer('foo%20bar')).toBe('foo bar')\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,2BAA2B;AAEpC,SAAS,uBAAuB,YAAY;AAC1C,KAAG,qBAAqB,MAAM;AAC5B,WAAO,oBAAoB,gBAAgB,CAAC,EAAE,KAAK,cAAc;AAAA,EACnE,CAAC;AAED,KAAG,8BAA8B,MAAM;AACrC,WAAO,oBAAoB,8EAA8E,CAAC,EAAE;AAAA,MAC1G;AAAA,IACF;AAAA,EACF,CAAC;AAED,KAAG,qBAAqB,MAAM;AAC5B,WAAO,oBAAoB,gBAAgB,CAAC,EAAE,KAAK,cAAc;AAAA,EACnE,CAAC;AAED,KAAG,qBAAqB,MAAM;AAC5B,WAAO,oBAAoB,WAAW,CAAC,EAAE,KAAK,SAAS;AAAA,EACzD,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|