@scalar/oas-utils 0.2.140 → 0.2.141
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/dist/entities/cookie/cookie.js +14 -13
- package/dist/entities/cookie/cookie.js.map +7 -0
- package/dist/entities/cookie/index.d.ts +1 -1
- package/dist/entities/cookie/index.d.ts.map +1 -1
- package/dist/entities/cookie/index.js +5 -1
- package/dist/entities/cookie/index.js.map +7 -0
- package/dist/entities/environment/environment.js +10 -9
- package/dist/entities/environment/environment.js.map +7 -0
- package/dist/entities/environment/index.d.ts +1 -1
- package/dist/entities/environment/index.d.ts.map +1 -1
- package/dist/entities/environment/index.js +5 -1
- package/dist/entities/environment/index.js.map +7 -0
- package/dist/entities/hotkeys/hotkeys.js +109 -116
- package/dist/entities/hotkeys/hotkeys.js.map +7 -0
- package/dist/entities/hotkeys/index.d.ts +1 -1
- package/dist/entities/hotkeys/index.d.ts.map +1 -1
- package/dist/entities/hotkeys/index.js +6 -1
- package/dist/entities/hotkeys/index.js.map +7 -0
- package/dist/entities/shared/index.d.ts +1 -1
- package/dist/entities/shared/index.d.ts.map +1 -1
- package/dist/entities/shared/index.js +7 -1
- package/dist/entities/shared/index.js.map +7 -0
- package/dist/entities/shared/utility.js +9 -12
- package/dist/entities/shared/utility.js.map +7 -0
- package/dist/entities/spec/collection.d.ts.map +1 -1
- package/dist/entities/spec/collection.js +91 -94
- package/dist/entities/spec/collection.js.map +7 -0
- package/dist/entities/spec/index.d.ts +8 -8
- package/dist/entities/spec/index.d.ts.map +1 -1
- package/dist/entities/spec/index.js +59 -9
- package/dist/entities/spec/index.js.map +7 -0
- package/dist/entities/spec/operation.d.ts +1 -1
- package/dist/entities/spec/operation.d.ts.map +1 -1
- package/dist/entities/spec/operation.js +5 -8
- package/dist/entities/spec/operation.js.map +7 -0
- package/dist/entities/spec/operation.test.js +43 -0
- package/dist/entities/spec/operation.test.js.map +7 -0
- package/dist/entities/spec/parameters.d.ts +1 -1
- package/dist/entities/spec/parameters.d.ts.map +1 -1
- package/dist/entities/spec/parameters.js +40 -38
- package/dist/entities/spec/parameters.js.map +7 -0
- package/dist/entities/spec/parameters.test.js +71 -0
- package/dist/entities/spec/parameters.test.js.map +7 -0
- package/dist/entities/spec/request-example.test.js +637 -0
- package/dist/entities/spec/request-example.test.js.map +7 -0
- package/dist/entities/spec/request-examples.d.ts +3 -3
- package/dist/entities/spec/request-examples.d.ts.map +1 -1
- package/dist/entities/spec/request-examples.js +323 -338
- package/dist/entities/spec/request-examples.js.map +7 -0
- package/dist/entities/spec/requests.d.ts +6 -8
- package/dist/entities/spec/requests.d.ts.map +1 -1
- package/dist/entities/spec/requests.js +80 -101
- package/dist/entities/spec/requests.js.map +7 -0
- package/dist/entities/spec/server.js +47 -63
- package/dist/entities/spec/server.js.map +7 -0
- package/dist/entities/spec/server.test.js +120 -0
- package/dist/entities/spec/server.test.js.map +7 -0
- package/dist/entities/spec/spec-objects.d.ts.map +1 -1
- package/dist/entities/spec/spec-objects.js +77 -121
- package/dist/entities/spec/spec-objects.js.map +7 -0
- package/dist/entities/spec/spec-objects.test.js +205 -0
- package/dist/entities/spec/spec-objects.test.js.map +7 -0
- package/dist/entities/spec/x-scalar-environments.js +21 -18
- package/dist/entities/spec/x-scalar-environments.js.map +7 -0
- package/dist/entities/spec/x-scalar-environments.test.js +11 -0
- package/dist/entities/spec/x-scalar-environments.test.js.map +7 -0
- package/dist/entities/spec/x-scalar-secrets.js +8 -6
- package/dist/entities/spec/x-scalar-secrets.js.map +7 -0
- package/dist/entities/spec/x-scalar-secrets.test.js +11 -0
- package/dist/entities/spec/x-scalar-secrets.test.js.map +7 -0
- package/dist/entities/workspace/index.d.ts +1 -1
- package/dist/entities/workspace/index.d.ts.map +1 -1
- package/dist/entities/workspace/index.js +7 -1
- package/dist/entities/workspace/index.js.map +7 -0
- package/dist/entities/workspace/workspace.js +46 -50
- package/dist/entities/workspace/workspace.js.map +7 -0
- package/dist/helpers/create-hash.js +15 -18
- package/dist/helpers/create-hash.js.map +7 -0
- package/dist/helpers/ensure-protocol.js +9 -10
- package/dist/helpers/ensure-protocol.js.map +7 -0
- package/dist/helpers/ensure-protocol.test.js +70 -0
- package/dist/helpers/ensure-protocol.test.js.map +7 -0
- package/dist/helpers/fetch-document.js +24 -32
- package/dist/helpers/fetch-document.js.map +7 -0
- package/dist/helpers/fetch-document.test.js +63 -0
- package/dist/helpers/fetch-document.test.js.map +7 -0
- package/dist/helpers/fetch-with-proxy-fallback.js +20 -28
- package/dist/helpers/fetch-with-proxy-fallback.js.map +7 -0
- package/dist/helpers/find-variables.d.ts +1 -1
- package/dist/helpers/find-variables.d.ts.map +1 -1
- package/dist/helpers/find-variables.js +6 -8
- package/dist/helpers/find-variables.js.map +7 -0
- package/dist/helpers/find-variables.test.js +20 -0
- package/dist/helpers/find-variables.test.js.map +7 -0
- package/dist/helpers/http-methods.d.ts +1 -1
- package/dist/helpers/http-methods.d.ts.map +1 -1
- package/dist/helpers/http-methods.js +60 -66
- package/dist/helpers/http-methods.js.map +7 -0
- package/dist/helpers/http-status-codes.js +319 -317
- package/dist/helpers/http-status-codes.js.map +7 -0
- package/dist/helpers/index.d.ts +27 -27
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +73 -27
- package/dist/helpers/index.js.map +7 -0
- package/dist/helpers/is-defined.js +5 -14
- package/dist/helpers/is-defined.js.map +7 -0
- package/dist/helpers/is-defined.test.js +37 -0
- package/dist/helpers/is-defined.test.js.map +7 -0
- package/dist/helpers/is-local-url.js +11 -16
- package/dist/helpers/is-local-url.js.map +7 -0
- package/dist/helpers/is-local-url.test.js +40 -0
- package/dist/helpers/is-local-url.test.js.map +7 -0
- package/dist/helpers/is-valid-url.js +9 -18
- package/dist/helpers/is-valid-url.js.map +7 -0
- package/dist/helpers/is-valid-url.test.js +17 -0
- package/dist/helpers/is-valid-url.test.js.map +7 -0
- package/dist/helpers/iterate-title.js +11 -15
- package/dist/helpers/iterate-title.js.map +7 -0
- package/dist/helpers/json2xml.js +40 -47
- package/dist/helpers/json2xml.js.map +7 -0
- package/dist/helpers/json2xml.test.js +19 -0
- package/dist/helpers/json2xml.test.js.map +7 -0
- package/dist/helpers/local-storage.js +13 -15
- package/dist/helpers/local-storage.js.map +7 -0
- package/dist/helpers/make-url-absolute.js +11 -17
- package/dist/helpers/make-url-absolute.js.map +7 -0
- package/dist/helpers/make-url-absolute.test.js +61 -0
- package/dist/helpers/make-url-absolute.test.js.map +7 -0
- package/dist/helpers/merge-urls.js +50 -75
- package/dist/helpers/merge-urls.js.map +7 -0
- package/dist/helpers/merge-urls.test.js +339 -0
- package/dist/helpers/merge-urls.test.js.map +7 -0
- package/dist/helpers/normalize-mime-type-object.js +21 -31
- package/dist/helpers/normalize-mime-type-object.js.map +7 -0
- package/dist/helpers/normalize-mime-type-object.test.js +53 -0
- package/dist/helpers/normalize-mime-type-object.test.js.map +7 -0
- package/dist/helpers/normalize-mime-type.js +8 -18
- package/dist/helpers/normalize-mime-type.js.map +7 -0
- package/dist/helpers/normalize-mime-type.test.js +33 -0
- package/dist/helpers/normalize-mime-type.test.js.map +7 -0
- package/dist/helpers/object.js +12 -18
- package/dist/helpers/object.js.map +7 -0
- package/dist/helpers/omit-undefined-values.js +17 -19
- package/dist/helpers/omit-undefined-values.js.map +7 -0
- package/dist/helpers/omit-undefined-values.test.js +89 -0
- package/dist/helpers/omit-undefined-values.test.js.map +7 -0
- package/dist/helpers/parse.js +71 -83
- package/dist/helpers/parse.js.map +7 -0
- package/dist/helpers/parse.test.js +45 -0
- package/dist/helpers/parse.test.js.map +7 -0
- package/dist/helpers/pretty-print-json.js +31 -35
- package/dist/helpers/pretty-print-json.js.map +7 -0
- package/dist/helpers/pretty-print-json.test.js +28 -0
- package/dist/helpers/pretty-print-json.test.js.map +7 -0
- package/dist/helpers/redirect-to-proxy.js +46 -83
- package/dist/helpers/redirect-to-proxy.js.map +7 -0
- package/dist/helpers/redirect-to-proxy.test.js +54 -0
- package/dist/helpers/redirect-to-proxy.test.js.map +7 -0
- package/dist/helpers/regex-helpers.js +11 -9
- package/dist/helpers/regex-helpers.js.map +7 -0
- package/dist/helpers/regex-helpers.test.js +154 -0
- package/dist/helpers/regex-helpers.test.js.map +7 -0
- package/dist/helpers/replace-variables.js +13 -16
- package/dist/helpers/replace-variables.js.map +7 -0
- package/dist/helpers/replace-variables.test.js +30 -0
- package/dist/helpers/replace-variables.test.js.map +7 -0
- package/dist/helpers/schema-model.js +15 -14
- package/dist/helpers/schema-model.js.map +7 -0
- package/dist/helpers/security/get-schemes.d.ts +1 -1
- package/dist/helpers/security/get-schemes.d.ts.map +1 -1
- package/dist/helpers/security/get-schemes.js +7 -9
- package/dist/helpers/security/get-schemes.js.map +7 -0
- package/dist/helpers/security/get-schemes.test.js +71 -0
- package/dist/helpers/security/get-schemes.test.js.map +7 -0
- package/dist/helpers/security/has-token.js +18 -19
- package/dist/helpers/security/has-token.js.map +7 -0
- package/dist/helpers/security/has-token.test.js +157 -0
- package/dist/helpers/security/has-token.test.js.map +7 -0
- package/dist/helpers/security/index.d.ts +2 -2
- package/dist/helpers/security/index.d.ts.map +1 -1
- package/dist/helpers/security/index.js +7 -2
- package/dist/helpers/security/index.js.map +7 -0
- package/dist/helpers/should-ignore-entity.d.ts +2 -2
- package/dist/helpers/should-ignore-entity.d.ts.map +1 -1
- package/dist/helpers/should-ignore-entity.js +5 -6
- package/dist/helpers/should-ignore-entity.js.map +7 -0
- package/dist/helpers/ssr-state.js +6 -6
- package/dist/helpers/ssr-state.js.map +7 -0
- package/dist/helpers/string.js +6 -18
- package/dist/helpers/string.js.map +7 -0
- package/dist/migrations/data-version.js +7 -17
- package/dist/migrations/data-version.js.map +7 -0
- package/dist/migrations/generate-types.js +56 -0
- package/dist/migrations/generate-types.js.map +7 -0
- package/dist/migrations/index.d.ts +3 -3
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +10 -3
- package/dist/migrations/index.js.map +7 -0
- package/dist/migrations/local-storage.d.ts +1 -1
- package/dist/migrations/local-storage.d.ts.map +1 -1
- package/dist/migrations/local-storage.js +27 -32
- package/dist/migrations/local-storage.js.map +7 -0
- package/dist/migrations/migrator.d.ts +1 -1
- package/dist/migrations/migrator.d.ts.map +1 -1
- package/dist/migrations/migrator.js +51 -58
- package/dist/migrations/migrator.js.map +7 -0
- package/dist/migrations/semver.js +23 -25
- package/dist/migrations/semver.js.map +7 -0
- package/dist/migrations/semver.test.js +21 -0
- package/dist/migrations/semver.test.js.map +7 -0
- package/dist/migrations/v-0.0.0/types.generated.js +1 -0
- package/dist/migrations/v-0.0.0/types.generated.js.map +7 -0
- package/dist/migrations/v-2.1.0/migration.d.ts +2 -2
- package/dist/migrations/v-2.1.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.1.0/migration.js +256 -273
- package/dist/migrations/v-2.1.0/migration.js.map +7 -0
- package/dist/migrations/v-2.1.0/types.generated.js +1 -0
- package/dist/migrations/v-2.1.0/types.generated.js.map +7 -0
- package/dist/migrations/v-2.2.0/migration.d.ts +2 -2
- package/dist/migrations/v-2.2.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.2.0/migration.js +95 -100
- package/dist/migrations/v-2.2.0/migration.js.map +7 -0
- package/dist/migrations/v-2.2.0/types.generated.js +1 -0
- package/dist/migrations/v-2.2.0/types.generated.js.map +7 -0
- package/dist/migrations/v-2.3.0/migration.d.ts +2 -2
- package/dist/migrations/v-2.3.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.3.0/migration.js +47 -46
- package/dist/migrations/v-2.3.0/migration.js.map +7 -0
- package/dist/migrations/v-2.3.0/types.generated.js +1 -0
- package/dist/migrations/v-2.3.0/types.generated.js.map +7 -0
- package/dist/migrations/v-2.4.0/migration.d.ts +2 -2
- package/dist/migrations/v-2.4.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.4.0/migration.js +24 -26
- package/dist/migrations/v-2.4.0/migration.js.map +7 -0
- package/dist/migrations/v-2.4.0/migration.test.js +90 -0
- package/dist/migrations/v-2.4.0/migration.test.js.map +7 -0
- package/dist/migrations/v-2.4.0/types.generated.js +1 -0
- package/dist/migrations/v-2.4.0/types.generated.js.map +7 -0
- package/dist/migrations/v-2.5.0/migration.d.ts +2 -2
- package/dist/migrations/v-2.5.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.5.0/migration.js +135 -119
- package/dist/migrations/v-2.5.0/migration.js.map +7 -0
- package/dist/migrations/v-2.5.0/migration.test.js +108 -0
- package/dist/migrations/v-2.5.0/migration.test.js.map +7 -0
- package/dist/migrations/v-2.5.0/types.generated.d.ts +8 -8
- package/dist/migrations/v-2.5.0/types.generated.d.ts.map +1 -1
- package/dist/migrations/v-2.5.0/types.generated.js +1 -0
- package/dist/migrations/v-2.5.0/types.generated.js.map +7 -0
- package/dist/spec-getters/get-example-from-schema.js +206 -268
- package/dist/spec-getters/get-example-from-schema.js.map +7 -0
- package/dist/spec-getters/get-example-from-schema.test.js +1092 -0
- package/dist/spec-getters/get-example-from-schema.test.js.map +7 -0
- package/dist/spec-getters/get-parameters-from-operation.js +22 -42
- package/dist/spec-getters/get-parameters-from-operation.js.map +7 -0
- package/dist/spec-getters/get-parameters-from-operation.test.js +178 -0
- package/dist/spec-getters/get-parameters-from-operation.test.js.map +7 -0
- package/dist/spec-getters/get-request-body-from-operation.js +110 -162
- package/dist/spec-getters/get-request-body-from-operation.js.map +7 -0
- package/dist/spec-getters/get-request-body-from-operation.test.js +289 -0
- package/dist/spec-getters/get-request-body-from-operation.test.js.map +7 -0
- package/dist/spec-getters/get-server-variable-examples.d.ts +1 -1
- package/dist/spec-getters/get-server-variable-examples.d.ts.map +1 -1
- package/dist/spec-getters/get-server-variable-examples.js +12 -11
- package/dist/spec-getters/get-server-variable-examples.js.map +7 -0
- package/dist/spec-getters/index.d.ts +4 -4
- package/dist/spec-getters/index.d.ts.map +1 -1
- package/dist/spec-getters/index.js +11 -4
- package/dist/spec-getters/index.js.map +7 -0
- package/dist/transforms/import-spec.d.ts +6 -6
- package/dist/transforms/import-spec.d.ts.map +1 -1
- package/dist/transforms/import-spec.js +313 -425
- package/dist/transforms/import-spec.js.map +7 -0
- package/dist/transforms/import-spec.test.js +1124 -0
- package/dist/transforms/import-spec.test.js.map +7 -0
- package/dist/transforms/index.d.ts +1 -1
- package/dist/transforms/index.d.ts.map +1 -1
- package/dist/transforms/index.js +7 -1
- package/dist/transforms/index.js.map +7 -0
- package/package.json +9 -10
|
@@ -1,282 +1,220 @@
|
|
|
1
|
-
/** Hard limit for rendering circular references */
|
|
2
1
|
const MAX_LEVELS_DEEP = 5;
|
|
3
|
-
/** Sets the max number of properties after the third level to prevent exponential horizontal growth */
|
|
4
2
|
const MAX_PROPERTIES = 10;
|
|
5
3
|
const genericExampleValues = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
4
|
+
// 'date-time': '1970-01-01T00:00:00Z',
|
|
5
|
+
"date-time": (/* @__PURE__ */ new Date()).toISOString(),
|
|
6
|
+
// 'date': '1970-01-01',
|
|
7
|
+
"date": (/* @__PURE__ */ new Date()).toISOString().split("T")[0],
|
|
8
|
+
"email": "hello@example.com",
|
|
9
|
+
"hostname": "example.com",
|
|
10
|
+
// https://tools.ietf.org/html/rfc6531#section-3.3
|
|
11
|
+
"idn-email": "jane.doe@example.com",
|
|
12
|
+
// https://tools.ietf.org/html/rfc5890#section-2.3.2.3
|
|
13
|
+
"idn-hostname": "example.com",
|
|
14
|
+
"ipv4": "127.0.0.1",
|
|
15
|
+
"ipv6": "51d4:7fab:bfbf:b7d7:b2cb:d4b4:3dad:d998",
|
|
16
|
+
"iri-reference": "/entitiy/1",
|
|
17
|
+
// https://tools.ietf.org/html/rfc3987
|
|
18
|
+
"iri": "https://example.com/entity/123",
|
|
19
|
+
"json-pointer": "/nested/objects",
|
|
20
|
+
"password": "super-secret",
|
|
21
|
+
"regex": "/[a-z]/",
|
|
22
|
+
// https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01
|
|
23
|
+
"relative-json-pointer": "1/nested/objects",
|
|
24
|
+
// full-time in https://tools.ietf.org/html/rfc3339#section-5.6
|
|
25
|
+
// 'time': '00:00:00Z',
|
|
26
|
+
"time": (/* @__PURE__ */ new Date()).toISOString().split("T")[1].split(".")[0],
|
|
27
|
+
// either a URI or relative-reference https://tools.ietf.org/html/rfc3986#section-4.1
|
|
28
|
+
"uri-reference": "../folder",
|
|
29
|
+
"uri-template": "https://example.com/{id}",
|
|
30
|
+
"uri": "https://example.com",
|
|
31
|
+
"uuid": "123e4567-e89b-12d3-a456-426614174000",
|
|
32
|
+
"object-id": "6592008029c8c3e4dc76256c"
|
|
35
33
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
*/
|
|
39
|
-
function guessFromFormat(schema, fallback = '') {
|
|
40
|
-
return genericExampleValues[schema.format] ?? fallback;
|
|
34
|
+
function guessFromFormat(schema, fallback = "") {
|
|
35
|
+
return genericExampleValues[schema.format] ?? fallback;
|
|
41
36
|
}
|
|
42
|
-
|
|
43
|
-
const resultCache = new WeakMap();
|
|
44
|
-
/** Store result in the cache, and return the result */
|
|
37
|
+
const resultCache = /* @__PURE__ */ new WeakMap();
|
|
45
38
|
function cache(schema, result) {
|
|
46
|
-
|
|
47
|
-
if (typeof result !== 'object' || result === null) {
|
|
48
|
-
return result;
|
|
49
|
-
}
|
|
50
|
-
resultCache.set(schema, result);
|
|
39
|
+
if (typeof result !== "object" || result === null) {
|
|
51
40
|
return result;
|
|
41
|
+
}
|
|
42
|
+
resultCache.set(schema, result);
|
|
43
|
+
return result;
|
|
52
44
|
}
|
|
53
|
-
/**
|
|
54
|
-
* This function takes an OpenAPI schema and generates an example from it
|
|
55
|
-
*/
|
|
56
45
|
const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
parentSchema?.required?.includes(name ?? schema.name);
|
|
120
|
-
if (!isRequired) {
|
|
121
|
-
return undefined;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
// Object
|
|
125
|
-
if (schema.type === 'object' || schema.properties !== undefined) {
|
|
126
|
-
const response = {};
|
|
127
|
-
let propertyCount = 0;
|
|
128
|
-
// Regular properties
|
|
129
|
-
if (schema.properties !== undefined) {
|
|
130
|
-
for (const propertyName in schema.properties) {
|
|
131
|
-
if (Object.prototype.hasOwnProperty.call(schema.properties, propertyName)) {
|
|
132
|
-
// Only apply property limit for nested levels (level > 0)
|
|
133
|
-
if (level > 3 && propertyCount >= MAX_PROPERTIES) {
|
|
134
|
-
response['...'] = '[Additional Properties Truncated]';
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
const property = schema.properties[propertyName];
|
|
138
|
-
const propertyXmlTagName = options?.xml ? property.xml?.name : undefined;
|
|
139
|
-
const value = getExampleFromSchema(property, options, level + 1, schema, propertyName);
|
|
140
|
-
if (typeof value !== 'undefined') {
|
|
141
|
-
response[propertyXmlTagName ?? propertyName] = value;
|
|
142
|
-
propertyCount++;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
46
|
+
if (resultCache.has(schema)) {
|
|
47
|
+
return resultCache.get(schema);
|
|
48
|
+
}
|
|
49
|
+
if (level === MAX_LEVELS_DEEP + 1) {
|
|
50
|
+
try {
|
|
51
|
+
JSON.stringify(schema);
|
|
52
|
+
} catch {
|
|
53
|
+
return "[Circular Reference]";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const makeUpRandomData = !!options?.emptyString;
|
|
57
|
+
if (schema.deprecated) {
|
|
58
|
+
return void 0;
|
|
59
|
+
}
|
|
60
|
+
if (options?.mode === "write" && schema.readOnly || options?.mode === "read" && schema.writeOnly) {
|
|
61
|
+
return void 0;
|
|
62
|
+
}
|
|
63
|
+
if (schema["x-variable"]) {
|
|
64
|
+
const value = options?.variables?.[schema["x-variable"]];
|
|
65
|
+
if (value !== void 0) {
|
|
66
|
+
if (schema.type === "number" || schema.type === "integer") {
|
|
67
|
+
return Number.parseInt(value, 10);
|
|
68
|
+
}
|
|
69
|
+
return cache(schema, value);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (Array.isArray(schema.examples) && schema.examples.length > 0) {
|
|
73
|
+
return cache(schema, schema.examples[0]);
|
|
74
|
+
}
|
|
75
|
+
if (schema.example !== void 0) {
|
|
76
|
+
return cache(schema, schema.example);
|
|
77
|
+
}
|
|
78
|
+
if (schema.default !== void 0) {
|
|
79
|
+
return cache(schema, schema.default);
|
|
80
|
+
}
|
|
81
|
+
if (Array.isArray(schema.enum) && schema.enum.length > 0) {
|
|
82
|
+
return cache(schema, schema.enum[0]);
|
|
83
|
+
}
|
|
84
|
+
const isObjectOrArray = schema.type === "object" || schema.type === "array" || !!schema.allOf?.at?.(0) || !!schema.anyOf?.at?.(0) || !!schema.oneOf?.at?.(0);
|
|
85
|
+
if (!isObjectOrArray && options?.omitEmptyAndOptionalProperties === true) {
|
|
86
|
+
const isRequired = schema.required === true || parentSchema?.required === true || parentSchema?.required?.includes(name ?? schema.name);
|
|
87
|
+
if (!isRequired) {
|
|
88
|
+
return void 0;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (schema.type === "object" || schema.properties !== void 0) {
|
|
92
|
+
const response = {};
|
|
93
|
+
let propertyCount = 0;
|
|
94
|
+
if (schema.properties !== void 0) {
|
|
95
|
+
for (const propertyName in schema.properties) {
|
|
96
|
+
if (Object.prototype.hasOwnProperty.call(schema.properties, propertyName)) {
|
|
97
|
+
if (level > 3 && propertyCount >= MAX_PROPERTIES) {
|
|
98
|
+
response["..."] = "[Additional Properties Truncated]";
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
const property = schema.properties[propertyName];
|
|
102
|
+
const propertyXmlTagName = options?.xml ? property.xml?.name : void 0;
|
|
103
|
+
const value = getExampleFromSchema(property, options, level + 1, schema, propertyName);
|
|
104
|
+
if (typeof value !== "undefined") {
|
|
105
|
+
response[propertyXmlTagName ?? propertyName] = value;
|
|
106
|
+
propertyCount++;
|
|
107
|
+
}
|
|
146
108
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (schema.patternProperties !== void 0) {
|
|
112
|
+
for (const pattern in schema.patternProperties) {
|
|
113
|
+
if (Object.prototype.hasOwnProperty.call(schema.patternProperties, pattern)) {
|
|
114
|
+
const property = schema.patternProperties[pattern];
|
|
115
|
+
const exampleKey = pattern;
|
|
116
|
+
response[exampleKey] = getExampleFromSchema(property, options, level + 1, schema, exampleKey);
|
|
157
117
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (schema.additionalProperties !== void 0) {
|
|
121
|
+
const anyTypeIsValid = (
|
|
122
|
+
// true
|
|
123
|
+
schema.additionalProperties === true || // or an empty object {}
|
|
124
|
+
typeof schema.additionalProperties === "object" && !Object.keys(schema.additionalProperties).length
|
|
125
|
+
);
|
|
126
|
+
if (anyTypeIsValid) {
|
|
127
|
+
response["ANY_ADDITIONAL_PROPERTY"] = "anything";
|
|
128
|
+
} else if (schema.additionalProperties !== false) {
|
|
129
|
+
response["ANY_ADDITIONAL_PROPERTY"] = getExampleFromSchema(schema.additionalProperties, options, level + 1);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (schema.anyOf !== void 0) {
|
|
133
|
+
Object.assign(response, getExampleFromSchema(schema.anyOf[0], options, level + 1));
|
|
134
|
+
} else if (schema.oneOf !== void 0) {
|
|
135
|
+
Object.assign(response, getExampleFromSchema(schema.oneOf[0], options, level + 1));
|
|
136
|
+
} else if (schema.allOf !== void 0) {
|
|
137
|
+
Object.assign(
|
|
138
|
+
response,
|
|
139
|
+
...schema.allOf.map((item) => getExampleFromSchema(item, options, level + 1, schema)).filter((item) => item !== void 0)
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
return cache(schema, response);
|
|
143
|
+
}
|
|
144
|
+
if (schema.type === "array" || schema.items !== void 0) {
|
|
145
|
+
const itemsXmlTagName = schema?.items?.xml?.name;
|
|
146
|
+
const wrapItems = !!(options?.xml && schema.xml?.wrapped && itemsXmlTagName);
|
|
147
|
+
if (schema.example !== void 0) {
|
|
148
|
+
return cache(schema, wrapItems ? { [itemsXmlTagName]: schema.example } : schema.example);
|
|
149
|
+
}
|
|
150
|
+
if (schema.items) {
|
|
151
|
+
if (schema.items.allOf) {
|
|
152
|
+
if (schema.items.allOf[0].type === "object") {
|
|
153
|
+
const mergedExample = getExampleFromSchema(
|
|
154
|
+
{ type: "object", allOf: schema.items.allOf },
|
|
155
|
+
options,
|
|
156
|
+
level + 1,
|
|
157
|
+
schema
|
|
158
|
+
);
|
|
159
|
+
return cache(schema, wrapItems ? [{ [itemsXmlTagName]: mergedExample }] : [mergedExample]);
|
|
171
160
|
}
|
|
172
|
-
|
|
173
|
-
|
|
161
|
+
const examples = schema.items.allOf.map((item) => getExampleFromSchema(item, options, level + 1, schema)).filter((item) => item !== void 0);
|
|
162
|
+
return cache(schema, wrapItems ? examples.map((example) => ({ [itemsXmlTagName]: example })) : examples);
|
|
163
|
+
}
|
|
164
|
+
const rules = ["anyOf", "oneOf"];
|
|
165
|
+
for (const rule of rules) {
|
|
166
|
+
if (!schema.items[rule]) {
|
|
167
|
+
continue;
|
|
174
168
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
const exampleValues = {
|
|
227
|
-
string: makeUpRandomData ? guessFromFormat(schema, options?.emptyString) : '',
|
|
228
|
-
boolean: true,
|
|
229
|
-
integer: schema.min ?? 1,
|
|
230
|
-
number: schema.min ?? 1,
|
|
231
|
-
array: [],
|
|
232
|
-
};
|
|
233
|
-
if (schema.type !== undefined && exampleValues[schema.type] !== undefined) {
|
|
234
|
-
return cache(schema, exampleValues[schema.type]);
|
|
235
|
-
}
|
|
236
|
-
const discriminateSchema = schema.oneOf || schema.anyOf;
|
|
237
|
-
// Check if property has the `oneOf` | `anyOf` key
|
|
238
|
-
if (Array.isArray(discriminateSchema) && discriminateSchema.length > 0) {
|
|
239
|
-
// Get the first item from the `oneOf` | `anyOf` array
|
|
240
|
-
const firstOneOfItem = discriminateSchema[0];
|
|
241
|
-
// Return an example for the first item
|
|
242
|
-
return getExampleFromSchema(firstOneOfItem, options, level + 1);
|
|
243
|
-
}
|
|
244
|
-
// Check if schema has the `allOf` key
|
|
245
|
-
if (Array.isArray(schema.allOf)) {
|
|
246
|
-
let example = null;
|
|
247
|
-
// Loop through all `allOf` schemas
|
|
248
|
-
schema.allOf.forEach((allOfItem) => {
|
|
249
|
-
// Return an example from the schema
|
|
250
|
-
const newExample = getExampleFromSchema(allOfItem, options, level + 1);
|
|
251
|
-
// Merge or overwrite the example
|
|
252
|
-
example =
|
|
253
|
-
typeof newExample === 'object' && typeof example === 'object'
|
|
254
|
-
? {
|
|
255
|
-
...(example ?? {}),
|
|
256
|
-
...newExample,
|
|
257
|
-
}
|
|
258
|
-
: Array.isArray(newExample) && Array.isArray(example)
|
|
259
|
-
? [...(example ?? {}), ...newExample]
|
|
260
|
-
: newExample;
|
|
261
|
-
});
|
|
262
|
-
return cache(schema, example);
|
|
263
|
-
}
|
|
264
|
-
// Check if schema is a union type
|
|
265
|
-
if (Array.isArray(schema.type)) {
|
|
266
|
-
// Return null if the type is nullable
|
|
267
|
-
if (schema.type.includes('null')) {
|
|
268
|
-
return null;
|
|
269
|
-
}
|
|
270
|
-
// Return an example for the first type in the union
|
|
271
|
-
const exampleValue = exampleValues[schema.type[0]];
|
|
272
|
-
if (exampleValue !== undefined) {
|
|
273
|
-
return cache(schema, exampleValue);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
// Warn if the type is unknown …
|
|
277
|
-
// console.warn(`[getExampleFromSchema] Unknown property type "${schema.type}".`)
|
|
278
|
-
// … and just return null for now.
|
|
279
|
-
return null;
|
|
169
|
+
const schemas = schema.items[rule].slice(0, 1);
|
|
170
|
+
const exampleFromRule = schemas.map((item) => getExampleFromSchema(item, options, level + 1, schema)).filter((item) => item !== void 0);
|
|
171
|
+
return cache(schema, wrapItems ? [{ [itemsXmlTagName]: exampleFromRule }] : exampleFromRule);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (schema.items?.type) {
|
|
175
|
+
const exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1);
|
|
176
|
+
return wrapItems ? [{ [itemsXmlTagName]: exampleFromSchema }] : [exampleFromSchema];
|
|
177
|
+
}
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
180
|
+
const exampleValues = {
|
|
181
|
+
string: makeUpRandomData ? guessFromFormat(schema, options?.emptyString) : "",
|
|
182
|
+
boolean: true,
|
|
183
|
+
integer: schema.min ?? 1,
|
|
184
|
+
number: schema.min ?? 1,
|
|
185
|
+
array: []
|
|
186
|
+
};
|
|
187
|
+
if (schema.type !== void 0 && exampleValues[schema.type] !== void 0) {
|
|
188
|
+
return cache(schema, exampleValues[schema.type]);
|
|
189
|
+
}
|
|
190
|
+
const discriminateSchema = schema.oneOf || schema.anyOf;
|
|
191
|
+
if (Array.isArray(discriminateSchema) && discriminateSchema.length > 0) {
|
|
192
|
+
const firstOneOfItem = discriminateSchema[0];
|
|
193
|
+
return getExampleFromSchema(firstOneOfItem, options, level + 1);
|
|
194
|
+
}
|
|
195
|
+
if (Array.isArray(schema.allOf)) {
|
|
196
|
+
let example = null;
|
|
197
|
+
schema.allOf.forEach((allOfItem) => {
|
|
198
|
+
const newExample = getExampleFromSchema(allOfItem, options, level + 1);
|
|
199
|
+
example = typeof newExample === "object" && typeof example === "object" ? {
|
|
200
|
+
...example ?? {},
|
|
201
|
+
...newExample
|
|
202
|
+
} : Array.isArray(newExample) && Array.isArray(example) ? [...example ?? {}, ...newExample] : newExample;
|
|
203
|
+
});
|
|
204
|
+
return cache(schema, example);
|
|
205
|
+
}
|
|
206
|
+
if (Array.isArray(schema.type)) {
|
|
207
|
+
if (schema.type.includes("null")) {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
const exampleValue = exampleValues[schema.type[0]];
|
|
211
|
+
if (exampleValue !== void 0) {
|
|
212
|
+
return cache(schema, exampleValue);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return null;
|
|
216
|
+
};
|
|
217
|
+
export {
|
|
218
|
+
getExampleFromSchema
|
|
280
219
|
};
|
|
281
|
-
|
|
282
|
-
export { getExampleFromSchema };
|
|
220
|
+
//# sourceMappingURL=get-example-from-schema.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/spec-getters/get-example-from-schema.ts"],
|
|
4
|
+
"sourcesContent": ["/** Hard limit for rendering circular references */\nconst MAX_LEVELS_DEEP = 5\n/** Sets the max number of properties after the third level to prevent exponential horizontal growth */\nconst MAX_PROPERTIES = 10\n\nconst genericExampleValues: Record<string, string> = {\n // 'date-time': '1970-01-01T00:00:00Z',\n 'date-time': new Date().toISOString(),\n // 'date': '1970-01-01',\n 'date': new Date().toISOString().split('T')[0]!,\n 'email': 'hello@example.com',\n 'hostname': 'example.com',\n // https://tools.ietf.org/html/rfc6531#section-3.3\n 'idn-email': 'jane.doe@example.com',\n // https://tools.ietf.org/html/rfc5890#section-2.3.2.3\n 'idn-hostname': 'example.com',\n 'ipv4': '127.0.0.1',\n 'ipv6': '51d4:7fab:bfbf:b7d7:b2cb:d4b4:3dad:d998',\n 'iri-reference': '/entitiy/1',\n // https://tools.ietf.org/html/rfc3987\n 'iri': 'https://example.com/entity/123',\n 'json-pointer': '/nested/objects',\n 'password': 'super-secret',\n 'regex': '/[a-z]/',\n // https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01\n 'relative-json-pointer': '1/nested/objects',\n // full-time in https://tools.ietf.org/html/rfc3339#section-5.6\n // 'time': '00:00:00Z',\n 'time': new Date().toISOString().split('T')[1]!.split('.')[0]!,\n // either a URI or relative-reference https://tools.ietf.org/html/rfc3986#section-4.1\n 'uri-reference': '../folder',\n 'uri-template': 'https://example.com/{id}',\n 'uri': 'https://example.com',\n 'uuid': '123e4567-e89b-12d3-a456-426614174000',\n 'object-id': '6592008029c8c3e4dc76256c',\n}\n\n/**\n * We can use the `format` to generate some random values.\n */\nfunction guessFromFormat(schema: Record<string, any>, fallback: string = '') {\n return genericExampleValues[schema.format] ?? fallback\n}\n\n/** Map of all the results */\nconst resultCache = new WeakMap<Record<string, any>, any>()\n\n/** Store result in the cache, and return the result */\nfunction cache(schema: Record<string, any>, result: unknown) {\n // Avoid unnecessary WeakMap operations for primitive values\n if (typeof result !== 'object' || result === null) {\n return result\n }\n\n resultCache.set(schema, result)\n\n return result\n}\n\n/**\n * This function takes an OpenAPI schema and generates an example from it\n */\nexport const getExampleFromSchema = (\n schema: Record<string, any>,\n options?: {\n /**\n * The fallback string for empty string values.\n * @default ''\n */\n emptyString?: string\n /**\n * Whether to use the XML tag names as keys\n * @default false\n */\n xml?: boolean\n /**\n * Whether to show read-only/write-only properties. Otherwise all properties are shown.\n * @default undefined\n */\n mode?: 'read' | 'write'\n /**\n * Dynamic values to add to the example.\n */\n variables?: Record<string, any>\n /**\n * Whether to omit empty and optional properties.\n * @default false\n */\n omitEmptyAndOptionalProperties?: boolean\n },\n level: number = 0,\n parentSchema?: Record<string, any>,\n name?: string,\n): any => {\n // Check if the result is already cached\n if (resultCache.has(schema)) {\n return resultCache.get(schema)\n }\n\n // Check whether it\u2019s a circular reference\n if (level === MAX_LEVELS_DEEP + 1) {\n try {\n // Fails if it contains a circular reference\n JSON.stringify(schema)\n } catch {\n return '[Circular Reference]'\n }\n }\n\n // Sometimes, we just want the structure and no values.\n // But if `emptyString` is set, we do want to see some values.\n const makeUpRandomData = !!options?.emptyString\n\n // If the property is deprecated anyway, we don\u2019t want to show it.\n if (schema.deprecated) {\n return undefined\n }\n\n // Check if the property is read-only/write-only\n if ((options?.mode === 'write' && schema.readOnly) || (options?.mode === 'read' && schema.writeOnly)) {\n return undefined\n }\n\n // Use given variables as values\n if (schema['x-variable']) {\n const value = options?.variables?.[schema['x-variable']]\n\n // Return the value if it\u2019s defined\n if (value !== undefined) {\n // Type-casting\n if (schema.type === 'number' || schema.type === 'integer') {\n return Number.parseInt(value, 10)\n }\n\n return cache(schema, value)\n }\n }\n\n // Use the first example, if there\u2019s an array\n if (Array.isArray(schema.examples) && schema.examples.length > 0) {\n return cache(schema, schema.examples[0])\n }\n\n // Use an example, if there\u2019s one\n if (schema.example !== undefined) {\n return cache(schema, schema.example)\n }\n\n // Use a default value, if there\u2019s one\n if (schema.default !== undefined) {\n return cache(schema, schema.default)\n }\n\n // enum: [ 'available', 'pending', 'sold' ]\n if (Array.isArray(schema.enum) && schema.enum.length > 0) {\n return cache(schema, schema.enum[0])\n }\n\n // Check if the property is required\n const isObjectOrArray =\n schema.type === 'object' ||\n schema.type === 'array' ||\n !!schema.allOf?.at?.(0) ||\n !!schema.anyOf?.at?.(0) ||\n !!schema.oneOf?.at?.(0)\n if (!isObjectOrArray && options?.omitEmptyAndOptionalProperties === true) {\n const isRequired =\n schema.required === true ||\n parentSchema?.required === true ||\n parentSchema?.required?.includes(name ?? schema.name)\n\n if (!isRequired) {\n return undefined\n }\n }\n\n // Object\n if (schema.type === 'object' || schema.properties !== undefined) {\n const response: Record<string, any> = {}\n let propertyCount = 0\n\n // Regular properties\n if (schema.properties !== undefined) {\n for (const propertyName in schema.properties) {\n if (Object.prototype.hasOwnProperty.call(schema.properties, propertyName)) {\n // Only apply property limit for nested levels (level > 0)\n if (level > 3 && propertyCount >= MAX_PROPERTIES) {\n response['...'] = '[Additional Properties Truncated]'\n break\n }\n\n const property = schema.properties[propertyName]\n const propertyXmlTagName = options?.xml ? property.xml?.name : undefined\n\n const value = getExampleFromSchema(property, options, level + 1, schema, propertyName)\n\n if (typeof value !== 'undefined') {\n response[propertyXmlTagName ?? propertyName] = value\n propertyCount++\n }\n }\n }\n }\n\n // Pattern properties (regex)\n if (schema.patternProperties !== undefined) {\n for (const pattern in schema.patternProperties) {\n if (Object.prototype.hasOwnProperty.call(schema.patternProperties, pattern)) {\n const property = schema.patternProperties[pattern]\n\n // Use the regex pattern as an example key\n const exampleKey = pattern\n\n response[exampleKey] = getExampleFromSchema(property, options, level + 1, schema, exampleKey)\n }\n }\n }\n\n // Additional properties\n if (schema.additionalProperties !== undefined) {\n const anyTypeIsValid =\n // true\n schema.additionalProperties === true ||\n // or an empty object {}\n (typeof schema.additionalProperties === 'object' && !Object.keys(schema.additionalProperties).length)\n\n if (anyTypeIsValid) {\n response['ANY_ADDITIONAL_PROPERTY'] = 'anything'\n } else if (schema.additionalProperties !== false) {\n response['ANY_ADDITIONAL_PROPERTY'] = getExampleFromSchema(schema.additionalProperties, options, level + 1)\n }\n }\n\n if (schema.anyOf !== undefined) {\n Object.assign(response, getExampleFromSchema(schema.anyOf[0], options, level + 1))\n } else if (schema.oneOf !== undefined) {\n Object.assign(response, getExampleFromSchema(schema.oneOf[0], options, level + 1))\n } else if (schema.allOf !== undefined) {\n Object.assign(\n response,\n ...schema.allOf\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined),\n )\n }\n\n return cache(schema, response)\n }\n\n // Array\n if (schema.type === 'array' || schema.items !== undefined) {\n const itemsXmlTagName = schema?.items?.xml?.name\n const wrapItems = !!(options?.xml && schema.xml?.wrapped && itemsXmlTagName)\n\n if (schema.example !== undefined) {\n return cache(schema, wrapItems ? { [itemsXmlTagName]: schema.example } : schema.example)\n }\n\n // Check whether the array has a anyOf, oneOf, or allOf rule\n if (schema.items) {\n // First handle allOf separately since it needs special handling\n if (schema.items.allOf) {\n // If the first item is an object type, merge all schemas\n if (schema.items.allOf[0].type === 'object') {\n const mergedExample = getExampleFromSchema(\n { type: 'object', allOf: schema.items.allOf },\n options,\n level + 1,\n schema,\n )\n\n return cache(schema, wrapItems ? [{ [itemsXmlTagName]: mergedExample }] : [mergedExample])\n }\n // For non-objects (like strings), collect all examples\n const examples = schema.items.allOf\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined)\n\n return cache(schema, wrapItems ? examples.map((example: any) => ({ [itemsXmlTagName]: example })) : examples)\n }\n\n // Handle other rules (anyOf, oneOf)\n const rules = ['anyOf', 'oneOf']\n for (const rule of rules) {\n if (!schema.items[rule]) {\n continue\n }\n\n const schemas = schema.items[rule].slice(0, 1)\n const exampleFromRule = schemas\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined)\n\n return cache(schema, wrapItems ? [{ [itemsXmlTagName]: exampleFromRule }] : exampleFromRule)\n }\n }\n\n if (schema.items?.type) {\n const exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1)\n\n return wrapItems ? [{ [itemsXmlTagName]: exampleFromSchema }] : [exampleFromSchema]\n }\n\n return []\n }\n\n const exampleValues: Record<any, any> = {\n string: makeUpRandomData ? guessFromFormat(schema, options?.emptyString) : '',\n boolean: true,\n integer: schema.min ?? 1,\n number: schema.min ?? 1,\n array: [],\n }\n\n if (schema.type !== undefined && exampleValues[schema.type] !== undefined) {\n return cache(schema, exampleValues[schema.type])\n }\n\n const discriminateSchema = schema.oneOf || schema.anyOf\n // Check if property has the `oneOf` | `anyOf` key\n if (Array.isArray(discriminateSchema) && discriminateSchema.length > 0) {\n // Get the first item from the `oneOf` | `anyOf` array\n const firstOneOfItem = discriminateSchema[0]\n\n // Return an example for the first item\n return getExampleFromSchema(firstOneOfItem, options, level + 1)\n }\n\n // Check if schema has the `allOf` key\n if (Array.isArray(schema.allOf)) {\n let example: any = null\n\n // Loop through all `allOf` schemas\n schema.allOf.forEach((allOfItem: Record<string, any>) => {\n // Return an example from the schema\n const newExample = getExampleFromSchema(allOfItem, options, level + 1)\n\n // Merge or overwrite the example\n example =\n typeof newExample === 'object' && typeof example === 'object'\n ? {\n ...(example ?? {}),\n ...newExample,\n }\n : Array.isArray(newExample) && Array.isArray(example)\n ? [...(example ?? {}), ...newExample]\n : newExample\n })\n\n return cache(schema, example)\n }\n\n // Check if schema is a union type\n if (Array.isArray(schema.type)) {\n // Return null if the type is nullable\n if (schema.type.includes('null')) {\n return null\n }\n // Return an example for the first type in the union\n const exampleValue = exampleValues[schema.type[0]]\n if (exampleValue !== undefined) {\n return cache(schema, exampleValue)\n }\n }\n\n // Warn if the type is unknown \u2026\n // console.warn(`[getExampleFromSchema] Unknown property type \"${schema.type}\".`)\n\n // \u2026 and just return null for now.\n return null\n}\n"],
|
|
5
|
+
"mappings": "AACA,MAAM,kBAAkB;AAExB,MAAM,iBAAiB;AAEvB,MAAM,uBAA+C;AAAA;AAAA,EAEnD,cAAa,oBAAI,KAAK,GAAE,YAAY;AAAA;AAAA,EAEpC,SAAQ,oBAAI,KAAK,GAAE,YAAY,EAAE,MAAM,GAAG,EAAE,CAAC;AAAA,EAC7C,SAAS;AAAA,EACT,YAAY;AAAA;AAAA,EAEZ,aAAa;AAAA;AAAA,EAEb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