@gitbook/react-openapi 1.4.3 → 1.5.2
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 +36 -0
- package/dist/InteractiveSection.js +59 -0
- package/dist/Markdown.js +10 -0
- package/dist/OpenAPICodeSample.js +219 -0
- package/dist/OpenAPICodeSampleInteractive.js +66 -0
- package/dist/OpenAPICodeSampleSelector.js +45 -0
- package/dist/OpenAPICopyButton.js +39 -0
- package/dist/OpenAPIDisclosure.js +30 -0
- package/dist/OpenAPIDisclosureGroup.js +75 -0
- package/dist/OpenAPIExample.js +41 -0
- package/dist/OpenAPIMediaType.js +58 -0
- package/dist/OpenAPIOperation.d.ts +12 -7
- package/dist/OpenAPIOperation.js +30 -0
- package/dist/OpenAPIOperationContext.d.ts +10 -6
- package/dist/OpenAPIOperationContext.js +30 -0
- package/dist/OpenAPIPath.js +51 -0
- package/dist/OpenAPIPrefillContextProvider.d.ts +11 -7
- package/dist/OpenAPIPrefillContextProvider.js +25 -0
- package/dist/OpenAPIRequestBody.js +28 -0
- package/dist/OpenAPIRequestBodyHeaderType.js +23 -0
- package/dist/OpenAPIResponse.js +39 -0
- package/dist/OpenAPIResponseExample.js +75 -0
- package/dist/OpenAPIResponseExampleContent.js +61 -0
- package/dist/OpenAPIResponses.js +61 -0
- package/dist/OpenAPISchema.js +373 -0
- package/dist/OpenAPISchemaName.js +45 -0
- package/dist/OpenAPISchemaServer.js +13 -0
- package/dist/OpenAPISecurities.js +124 -0
- package/dist/OpenAPISelect.js +45 -0
- package/dist/OpenAPISpec.js +73 -0
- package/dist/OpenAPIWebhook.d.ts +12 -7
- package/dist/OpenAPIWebhook.js +28 -0
- package/dist/OpenAPIWebhookExample.js +40 -0
- package/dist/ScalarApiButton.js +87 -0
- package/dist/StaticSection.js +37 -0
- package/dist/code-samples.js +267 -419
- package/dist/common/OpenAPIColumnSpec.js +23 -0
- package/dist/common/OpenAPIOperationDescription.js +18 -0
- package/dist/common/OpenAPIStability.js +17 -0
- package/dist/common/OpenAPISummary.js +27 -0
- package/dist/contentTypeChecks.js +24 -20
- package/dist/context.d.ts +68 -72
- package/dist/context.js +25 -39
- package/dist/decycle.js +39 -68
- package/dist/dereference.js +20 -64
- package/dist/generateSchemaExample.js +188 -332
- package/dist/getDisclosureLabel.js +15 -16
- package/dist/getOrCreateStoreByKey.js +20 -17
- package/dist/index.d.ts +12 -10
- package/dist/index.js +11 -8
- package/dist/json2xml.js +10 -5
- package/dist/resolveOpenAPIOperation.d.ts +11 -7
- package/dist/resolveOpenAPIOperation.js +88 -159
- package/dist/resolveOpenAPIWebhook.d.ts +11 -7
- package/dist/resolveOpenAPIWebhook.js +41 -116
- package/dist/schemas/OpenAPISchemaItem.js +26 -0
- package/dist/schemas/OpenAPISchemas.d.ts +16 -11
- package/dist/schemas/OpenAPISchemas.js +57 -0
- package/dist/schemas/resolveOpenAPISchemas.d.ts +9 -4
- package/dist/schemas/resolveOpenAPISchemas.js +15 -59
- package/dist/stringifyOpenAPI.js +12 -13
- package/dist/translate.js +43 -0
- package/dist/translations/de.js +47 -42
- package/dist/translations/en.d.ts +46 -42
- package/dist/translations/en.js +47 -42
- package/dist/translations/es.js +47 -42
- package/dist/translations/fr.js +47 -42
- package/dist/translations/index.d.ts +404 -391
- package/dist/translations/index.js +28 -24
- package/dist/translations/ja.js +47 -42
- package/dist/translations/nl.js +47 -42
- package/dist/translations/no.js +47 -42
- package/dist/translations/pt-br.js +47 -42
- package/dist/translations/types.d.ts +7 -5
- package/dist/translations/zh.js +47 -42
- package/dist/types.d.ts +30 -24
- package/dist/util/example.js +84 -0
- package/dist/util/server.js +32 -38
- package/dist/util/tryit-prefill.js +135 -121
- package/dist/utils.js +135 -196
- package/package.json +18 -11
- package/dist/InteractiveSection.d.ts +0 -33
- package/dist/InteractiveSection.jsx +0 -61
- package/dist/Markdown.d.ts +0 -4
- package/dist/Markdown.jsx +0 -5
- package/dist/OpenAPICodeSample.d.ts +0 -19
- package/dist/OpenAPICodeSample.jsx +0 -230
- package/dist/OpenAPICodeSampleInteractive.d.ts +0 -14
- package/dist/OpenAPICodeSampleInteractive.jsx +0 -73
- package/dist/OpenAPICodeSampleSelector.d.ts +0 -14
- package/dist/OpenAPICodeSampleSelector.jsx +0 -44
- package/dist/OpenAPICopyButton.d.ts +0 -13
- package/dist/OpenAPICopyButton.jsx +0 -35
- package/dist/OpenAPIDisclosure.d.ts +0 -11
- package/dist/OpenAPIDisclosure.jsx +0 -30
- package/dist/OpenAPIDisclosureGroup.d.ts +0 -23
- package/dist/OpenAPIDisclosureGroup.jsx +0 -83
- package/dist/OpenAPIExample.d.ts +0 -16
- package/dist/OpenAPIExample.jsx +0 -36
- package/dist/OpenAPIMediaType.d.ts +0 -21
- package/dist/OpenAPIMediaType.jsx +0 -61
- package/dist/OpenAPIOperation.jsx +0 -25
- package/dist/OpenAPIOperationContext.jsx +0 -26
- package/dist/OpenAPIOperationDescription.d.ts +0 -9
- package/dist/OpenAPIOperationDescription.jsx +0 -22
- package/dist/OpenAPIOperationStability.d.ts +0 -9
- package/dist/OpenAPIOperationStability.jsx +0 -27
- package/dist/OpenAPIPath.d.ts +0 -18
- package/dist/OpenAPIPath.jsx +0 -55
- package/dist/OpenAPIPrefillContextProvider.jsx +0 -19
- package/dist/OpenAPIRequestBody.d.ts +0 -11
- package/dist/OpenAPIRequestBody.jsx +0 -28
- package/dist/OpenAPIRequestBodyHeaderType.d.ts +0 -8
- package/dist/OpenAPIRequestBodyHeaderType.jsx +0 -25
- package/dist/OpenAPIResponse.d.ts +0 -10
- package/dist/OpenAPIResponse.jsx +0 -57
- package/dist/OpenAPIResponseExample.d.ts +0 -9
- package/dist/OpenAPIResponseExample.jsx +0 -105
- package/dist/OpenAPIResponseExampleContent.d.ts +0 -22
- package/dist/OpenAPIResponseExampleContent.jsx +0 -60
- package/dist/OpenAPIResponses.d.ts +0 -9
- package/dist/OpenAPIResponses.jsx +0 -77
- package/dist/OpenAPISchema.d.ts +0 -27
- package/dist/OpenAPISchema.jsx +0 -400
- package/dist/OpenAPISchemaName.d.ts +0 -16
- package/dist/OpenAPISchemaName.jsx +0 -43
- package/dist/OpenAPISchemaServer.d.ts +0 -12
- package/dist/OpenAPISchemaServer.jsx +0 -8
- package/dist/OpenAPISecurities.d.ts +0 -9
- package/dist/OpenAPISecurities.jsx +0 -114
- package/dist/OpenAPISelect.d.ts +0 -22
- package/dist/OpenAPISelect.jsx +0 -44
- package/dist/OpenAPISpec.d.ts +0 -6
- package/dist/OpenAPISpec.jsx +0 -80
- package/dist/OpenAPITabs.d.ts +0 -26
- package/dist/OpenAPITabs.jsx +0 -109
- package/dist/OpenAPIWebhook.jsx +0 -23
- package/dist/OpenAPIWebhookExample.d.ts +0 -6
- package/dist/OpenAPIWebhookExample.jsx +0 -41
- package/dist/ScalarApiButton.d.ts +0 -14
- package/dist/ScalarApiButton.jsx +0 -81
- package/dist/StaticSection.d.ts +0 -13
- package/dist/StaticSection.jsx +0 -32
- package/dist/code-samples.d.ts +0 -17
- package/dist/common/OpenAPIColumnSpec.d.ts +0 -6
- package/dist/common/OpenAPIColumnSpec.jsx +0 -20
- package/dist/common/OpenAPIOperationDescription.d.ts +0 -6
- package/dist/common/OpenAPIOperationDescription.jsx +0 -19
- package/dist/common/OpenAPIStability.d.ts +0 -4
- package/dist/common/OpenAPIStability.jsx +0 -15
- package/dist/common/OpenAPISummary.d.ts +0 -6
- package/dist/common/OpenAPISummary.jsx +0 -30
- package/dist/contentTypeChecks.d.ts +0 -10
- package/dist/decycle.d.ts +0 -2
- package/dist/dereference.d.ts +0 -5
- package/dist/generateSchemaExample.d.ts +0 -45
- package/dist/getDisclosureLabel.d.ts +0 -7
- package/dist/getOrCreateStoreByKey.d.ts +0 -10
- package/dist/json2xml.d.ts +0 -4
- package/dist/schemas/OpenAPISchemaItem.d.ts +0 -7
- package/dist/schemas/OpenAPISchemaItem.jsx +0 -16
- package/dist/schemas/OpenAPISchemas.jsx +0 -59
- package/dist/schemas/index.d.ts +0 -2
- package/dist/schemas/index.js +0 -2
- package/dist/stringifyOpenAPI.d.ts +0 -4
- package/dist/translate.d.ts +0 -10
- package/dist/translate.jsx +0 -75
- package/dist/translations/de.d.ts +0 -43
- package/dist/translations/es.d.ts +0 -43
- package/dist/translations/fr.d.ts +0 -43
- package/dist/translations/ja.d.ts +0 -43
- package/dist/translations/nl.d.ts +0 -43
- package/dist/translations/no.d.ts +0 -43
- package/dist/translations/pt-br.d.ts +0 -43
- package/dist/translations/types.js +0 -1
- package/dist/translations/zh.d.ts +0 -43
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types.js +0 -1
- package/dist/util/example.d.ts +0 -35
- package/dist/util/example.jsx +0 -103
- package/dist/util/server.d.ts +0 -9
- package/dist/util/tryit-prefill.d.ts +0 -20
- package/dist/utils.d.ts +0 -50
- package/src/InteractiveSection.tsx +0 -147
- package/src/Markdown.tsx +0 -12
- package/src/OpenAPICodeSample.tsx +0 -330
- package/src/OpenAPICodeSampleInteractive.tsx +0 -136
- package/src/OpenAPICodeSampleSelector.tsx +0 -94
- package/src/OpenAPICopyButton.tsx +0 -72
- package/src/OpenAPIDisclosure.tsx +0 -46
- package/src/OpenAPIDisclosureGroup.tsx +0 -158
- package/src/OpenAPIExample.tsx +0 -55
- package/src/OpenAPIMediaType.tsx +0 -139
- package/src/OpenAPIOperation.tsx +0 -35
- package/src/OpenAPIOperationContext.tsx +0 -45
- package/src/OpenAPIOperationDescription.tsx +0 -34
- package/src/OpenAPIOperationStability.tsx +0 -39
- package/src/OpenAPIPath.tsx +0 -90
- package/src/OpenAPIPrefillContextProvider.tsx +0 -40
- package/src/OpenAPIRequestBody.tsx +0 -54
- package/src/OpenAPIRequestBodyHeaderType.tsx +0 -36
- package/src/OpenAPIResponse.tsx +0 -82
- package/src/OpenAPIResponseExample.tsx +0 -151
- package/src/OpenAPIResponseExampleContent.tsx +0 -125
- package/src/OpenAPIResponses.tsx +0 -125
- package/src/OpenAPISchema.test.ts +0 -172
- package/src/OpenAPISchema.tsx +0 -654
- package/src/OpenAPISchemaName.tsx +0 -80
- package/src/OpenAPISchemaServer.tsx +0 -34
- package/src/OpenAPISecurities.tsx +0 -231
- package/src/OpenAPISelect.tsx +0 -96
- package/src/OpenAPISpec.tsx +0 -138
- package/src/OpenAPITabs.tsx +0 -147
- package/src/OpenAPIWebhook.tsx +0 -33
- package/src/OpenAPIWebhookExample.tsx +0 -60
- package/src/ScalarApiButton.tsx +0 -132
- package/src/StaticSection.tsx +0 -91
- package/src/__snapshots__/json2xml.test.ts.snap +0 -18
- package/src/code-samples.test.ts +0 -714
- package/src/code-samples.ts +0 -448
- package/src/common/OpenAPIColumnSpec.tsx +0 -31
- package/src/common/OpenAPIOperationDescription.tsx +0 -31
- package/src/common/OpenAPIStability.tsx +0 -23
- package/src/common/OpenAPISummary.tsx +0 -45
- package/src/contentTypeChecks.ts +0 -39
- package/src/context.ts +0 -99
- package/src/decycle.ts +0 -68
- package/src/dereference.ts +0 -29
- package/src/generateSchemaExample.test.ts +0 -1040
- package/src/generateSchemaExample.ts +0 -530
- package/src/getDisclosureLabel.ts +0 -25
- package/src/getOrCreateStoreByKey.ts +0 -33
- package/src/index.ts +0 -10
- package/src/json2xml.test.ts +0 -46
- package/src/json2xml.ts +0 -8
- package/src/resolveOpenAPIOperation.test.ts +0 -177
- package/src/resolveOpenAPIOperation.ts +0 -151
- package/src/resolveOpenAPIWebhook.ts +0 -99
- package/src/schemas/OpenAPISchemaItem.tsx +0 -34
- package/src/schemas/OpenAPISchemas.tsx +0 -98
- package/src/schemas/index.ts +0 -2
- package/src/schemas/resolveOpenAPISchemas.test.ts +0 -174
- package/src/schemas/resolveOpenAPISchemas.ts +0 -28
- package/src/stringifyOpenAPI.ts +0 -25
- package/src/translate.tsx +0 -80
- package/src/translations/de.ts +0 -43
- package/src/translations/en.ts +0 -43
- package/src/translations/es.ts +0 -43
- package/src/translations/fr.ts +0 -43
- package/src/translations/index.ts +0 -33
- package/src/translations/ja.ts +0 -43
- package/src/translations/nl.ts +0 -43
- package/src/translations/no.ts +0 -43
- package/src/translations/pt-br.ts +0 -43
- package/src/translations/types.ts +0 -7
- package/src/translations/zh.ts +0 -43
- package/src/types.ts +0 -46
- package/src/util/example.tsx +0 -129
- package/src/util/server.test.ts +0 -58
- package/src/util/server.ts +0 -47
- package/src/util/tryit-prefill.test.ts +0 -311
- package/src/util/tryit-prefill.ts +0 -160
- package/src/utils.ts +0 -255
|
@@ -1,342 +1,198 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
-
if (ar || !(i in from)) {
|
|
15
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
-
ar[i] = from[i];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
-
};
|
|
21
|
-
var _a, _b, _c;
|
|
22
|
-
import { checkIsReference } from './utils';
|
|
1
|
+
import { checkIsReference } from "./utils.js";
|
|
2
|
+
|
|
3
|
+
//#region src/generateSchemaExample.ts
|
|
23
4
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
5
|
+
* Generate a JSON example from a schema
|
|
6
|
+
*/
|
|
7
|
+
function generateSchemaExample(schema, options) {
|
|
8
|
+
return getExampleFromSchema(schema, {
|
|
9
|
+
emptyString: "text",
|
|
10
|
+
...options
|
|
11
|
+
});
|
|
28
12
|
}
|
|
29
13
|
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
return [];
|
|
14
|
+
* Generate an example for a media type.
|
|
15
|
+
*/
|
|
16
|
+
function generateMediaTypeExamples(mediaType, options) {
|
|
17
|
+
if (mediaType.example) return [{
|
|
18
|
+
summary: "default",
|
|
19
|
+
value: mediaType.example
|
|
20
|
+
}];
|
|
21
|
+
if (mediaType.examples) {
|
|
22
|
+
const { examples } = mediaType;
|
|
23
|
+
const keys = Object.keys(examples);
|
|
24
|
+
if (keys.length > 0) return keys.reduce((result, key) => {
|
|
25
|
+
const example = examples[key];
|
|
26
|
+
if (!example || checkIsReference(example)) return result;
|
|
27
|
+
result.push({
|
|
28
|
+
summary: example.summary || key,
|
|
29
|
+
value: example.value,
|
|
30
|
+
description: example.description,
|
|
31
|
+
externalValue: example.externalValue
|
|
32
|
+
});
|
|
33
|
+
return result;
|
|
34
|
+
}, []);
|
|
35
|
+
}
|
|
36
|
+
if (mediaType.schema) return [{
|
|
37
|
+
summary: "default",
|
|
38
|
+
value: generateSchemaExample(mediaType.schema, options)
|
|
39
|
+
}];
|
|
40
|
+
return [];
|
|
59
41
|
}
|
|
60
42
|
/** Hard limit for rendering circular references */
|
|
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
|
-
// either a URI or relative-reference https://tools.ietf.org/html/rfc3986#section-4.1
|
|
86
|
-
'uri-reference': '../folder',
|
|
87
|
-
'uri-template': 'https://example.com/{id}',
|
|
88
|
-
'object-id': '6592008029c8c3e4dc76256c',
|
|
43
|
+
const MAX_LEVELS_DEEP = 5;
|
|
44
|
+
const genericExampleValues = {
|
|
45
|
+
"date-time": (/* @__PURE__ */ new Date()).toISOString(),
|
|
46
|
+
date: (/* @__PURE__ */ new Date()).toISOString().split("T")[0] ?? "1970-01-01",
|
|
47
|
+
email: "name@gmail.com",
|
|
48
|
+
hostname: "example.com",
|
|
49
|
+
ipv4: "0.0.0.0",
|
|
50
|
+
ipv6: "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
|
|
51
|
+
uri: "https://example.com",
|
|
52
|
+
uuid: "123e4567-e89b-12d3-a456-426614174000",
|
|
53
|
+
binary: "binary",
|
|
54
|
+
byte: "Ynl0ZXM=",
|
|
55
|
+
password: "password",
|
|
56
|
+
"idn-email": "jane.doe@example.com",
|
|
57
|
+
"idn-hostname": "example.com",
|
|
58
|
+
"iri-reference": "/entitiy/1",
|
|
59
|
+
iri: "https://example.com/entity/123",
|
|
60
|
+
"json-pointer": "/nested/objects",
|
|
61
|
+
regex: "/[a-z]/",
|
|
62
|
+
"relative-json-pointer": "1/nested/objects",
|
|
63
|
+
time: (/* @__PURE__ */ new Date()).toISOString().split("T")[1]?.split(".")[0] ?? "00:00:00Z",
|
|
64
|
+
"uri-reference": "../folder",
|
|
65
|
+
"uri-template": "https://example.com/{id}",
|
|
66
|
+
"object-id": "6592008029c8c3e4dc76256c"
|
|
89
67
|
};
|
|
90
68
|
/**
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
function guessFromFormat(schema, fallback) {
|
|
94
|
-
|
|
95
|
-
if (fallback === void 0) { fallback = ''; }
|
|
96
|
-
return (_a = genericExampleValues[schema.format]) !== null && _a !== void 0 ? _a : fallback;
|
|
69
|
+
* We can use the `format` to generate some random values.
|
|
70
|
+
*/
|
|
71
|
+
function guessFromFormat(schema, fallback = "") {
|
|
72
|
+
return genericExampleValues[schema.format] ?? fallback;
|
|
97
73
|
}
|
|
98
74
|
/**
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
!Object.keys(schema.additionalProperties).length);
|
|
220
|
-
if (anyTypeIsValid) {
|
|
221
|
-
response.ANY_ADDITIONAL_PROPERTY = 'anything';
|
|
222
|
-
}
|
|
223
|
-
else if (schema.additionalProperties !== false) {
|
|
224
|
-
response.ANY_ADDITIONAL_PROPERTY = getExampleFromSchema(schema.additionalProperties, options, level + 1, undefined, undefined, resultCache);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
if (schema.anyOf !== undefined) {
|
|
228
|
-
Object.assign(response, getExampleFromSchema(schema.anyOf[0], options, level + 1, undefined, undefined, resultCache));
|
|
229
|
-
}
|
|
230
|
-
else if (schema.oneOf !== undefined) {
|
|
231
|
-
Object.assign(response, getExampleFromSchema(schema.oneOf[0], options, level + 1, undefined, undefined, resultCache));
|
|
232
|
-
}
|
|
233
|
-
else if (schema.allOf !== undefined) {
|
|
234
|
-
Object.assign.apply(Object, __spreadArray([response], schema.allOf
|
|
235
|
-
.map(function (item) {
|
|
236
|
-
return getExampleFromSchema(item, options, level + 1, schema, undefined, resultCache);
|
|
237
|
-
})
|
|
238
|
-
.filter(function (item) { return item !== undefined; }), false));
|
|
239
|
-
}
|
|
240
|
-
return cache(schema, response);
|
|
241
|
-
}
|
|
242
|
-
// Array
|
|
243
|
-
if (schema.type === 'array' || schema.items !== undefined) {
|
|
244
|
-
var itemsXmlTagName_1 = (_r = (_q = schema === null || schema === void 0 ? void 0 : schema.items) === null || _q === void 0 ? void 0 : _q.xml) === null || _r === void 0 ? void 0 : _r.name;
|
|
245
|
-
var wrapItems = !!((options === null || options === void 0 ? void 0 : options.xml) && ((_s = schema.xml) === null || _s === void 0 ? void 0 : _s.wrapped) && itemsXmlTagName_1);
|
|
246
|
-
if (schema.example !== undefined) {
|
|
247
|
-
return cache(schema, wrapItems ? (_a = {}, _a[itemsXmlTagName_1] = schema.example, _a) : schema.example);
|
|
248
|
-
}
|
|
249
|
-
// Check whether the array has a anyOf, oneOf, or allOf rule
|
|
250
|
-
if (schema.items) {
|
|
251
|
-
// First handle allOf separately since it needs special handling
|
|
252
|
-
if (schema.items.allOf) {
|
|
253
|
-
// If the first item is an object type, merge all schemas
|
|
254
|
-
if (schema.items.allOf[0].type === 'object') {
|
|
255
|
-
var mergedExample = getExampleFromSchema({ type: 'object', allOf: schema.items.allOf }, options, level + 1, schema, undefined, resultCache);
|
|
256
|
-
return cache(schema, wrapItems ? [(_b = {}, _b[itemsXmlTagName_1] = mergedExample, _b)] : [mergedExample]);
|
|
257
|
-
}
|
|
258
|
-
// For non-objects (like strings), collect all examples
|
|
259
|
-
var examples = schema.items.allOf
|
|
260
|
-
.map(function (item) {
|
|
261
|
-
return getExampleFromSchema(item, options, level + 1, schema, undefined, resultCache);
|
|
262
|
-
})
|
|
263
|
-
.filter(function (item) { return item !== undefined; });
|
|
264
|
-
return cache(schema, wrapItems
|
|
265
|
-
? examples.map(function (example) {
|
|
266
|
-
var _a;
|
|
267
|
-
return (_a = {}, _a[itemsXmlTagName_1] = example, _a);
|
|
268
|
-
})
|
|
269
|
-
: examples);
|
|
270
|
-
}
|
|
271
|
-
// Handle other rules (anyOf, oneOf)
|
|
272
|
-
var rules = ['anyOf', 'oneOf'];
|
|
273
|
-
for (var _i = 0, rules_1 = rules; _i < rules_1.length; _i++) {
|
|
274
|
-
var rule = rules_1[_i];
|
|
275
|
-
if (!schema.items[rule]) {
|
|
276
|
-
continue;
|
|
277
|
-
}
|
|
278
|
-
var schemas = schema.items[rule].slice(0, 1);
|
|
279
|
-
var exampleFromRule = schemas
|
|
280
|
-
.map(function (item) {
|
|
281
|
-
return getExampleFromSchema(item, options, level + 1, schema, undefined, resultCache);
|
|
282
|
-
})
|
|
283
|
-
.filter(function (item) { return item !== undefined; });
|
|
284
|
-
return cache(schema, wrapItems ? [(_c = {}, _c[itemsXmlTagName_1] = exampleFromRule, _c)] : exampleFromRule);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
if ((_t = schema.items) === null || _t === void 0 ? void 0 : _t.type) {
|
|
288
|
-
var exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1, undefined, undefined, resultCache);
|
|
289
|
-
return wrapItems ? [(_d = {}, _d[itemsXmlTagName_1] = exampleFromSchema, _d)] : [exampleFromSchema];
|
|
290
|
-
}
|
|
291
|
-
return [];
|
|
292
|
-
}
|
|
293
|
-
var exampleValues = {
|
|
294
|
-
string: makeUpRandomData ? guessFromFormat(schema, options === null || options === void 0 ? void 0 : options.emptyString) : '',
|
|
295
|
-
boolean: true,
|
|
296
|
-
integer: (_u = schema.min) !== null && _u !== void 0 ? _u : 1,
|
|
297
|
-
number: (_v = schema.min) !== null && _v !== void 0 ? _v : 1,
|
|
298
|
-
array: [],
|
|
299
|
-
};
|
|
300
|
-
if (schema.type !== undefined && exampleValues[schema.type] !== undefined) {
|
|
301
|
-
return cache(schema, exampleValues[schema.type]);
|
|
302
|
-
}
|
|
303
|
-
var discriminateSchema = schema.oneOf || schema.anyOf;
|
|
304
|
-
// Check if property has the `oneOf` | `anyOf` key
|
|
305
|
-
if (Array.isArray(discriminateSchema) && discriminateSchema.length > 0) {
|
|
306
|
-
// Get the first item from the `oneOf` | `anyOf` array
|
|
307
|
-
var firstOneOfItem = discriminateSchema[0];
|
|
308
|
-
// Return an example for the first item
|
|
309
|
-
return getExampleFromSchema(firstOneOfItem, options, level + 1, undefined, undefined, resultCache);
|
|
310
|
-
}
|
|
311
|
-
// Check if schema has the `allOf` key
|
|
312
|
-
if (Array.isArray(schema.allOf)) {
|
|
313
|
-
var example_1 = null;
|
|
314
|
-
// Loop through all `allOf` schemas
|
|
315
|
-
schema.allOf.forEach(function (allOfItem) {
|
|
316
|
-
// Return an example from the schema
|
|
317
|
-
var newExample = getExampleFromSchema(allOfItem, options, level + 1, undefined, undefined, resultCache);
|
|
318
|
-
// Merge or overwrite the example
|
|
319
|
-
example_1 =
|
|
320
|
-
typeof newExample === 'object' && typeof example_1 === 'object'
|
|
321
|
-
? __assign(__assign({}, (example_1 !== null && example_1 !== void 0 ? example_1 : {})), newExample) : Array.isArray(newExample) && Array.isArray(example_1)
|
|
322
|
-
? __spreadArray(__spreadArray([], (example_1 !== null && example_1 !== void 0 ? example_1 : {}), true), newExample, true) : newExample;
|
|
323
|
-
});
|
|
324
|
-
return cache(schema, example_1);
|
|
325
|
-
}
|
|
326
|
-
// Check if schema is a union type
|
|
327
|
-
if (Array.isArray(schema.type)) {
|
|
328
|
-
// Return null if the type is nullable
|
|
329
|
-
if (schema.type.includes('null')) {
|
|
330
|
-
return null;
|
|
331
|
-
}
|
|
332
|
-
// Return an example for the first type in the union
|
|
333
|
-
var exampleValue = exampleValues[schema.type[0]];
|
|
334
|
-
if (exampleValue !== undefined) {
|
|
335
|
-
return cache(schema, exampleValue);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
// Warn if the type is unknown …
|
|
339
|
-
// console.warn(`[getExampleFromSchema] Unknown property type "${schema.type}".`)
|
|
340
|
-
// … and just return null for now.
|
|
341
|
-
return null;
|
|
75
|
+
* This function takes an OpenAPI schema and generates an example from it
|
|
76
|
+
* Forked from : https://github.com/scalar/scalar/blob/main/packages/oas-utils/src/spec-getters/getExampleFromSchema.ts
|
|
77
|
+
*/
|
|
78
|
+
const getExampleFromSchema = (schema, options, level = 0, parentSchema, name, resultCache = /* @__PURE__ */ new WeakMap()) => {
|
|
79
|
+
function cache(schema$1, result) {
|
|
80
|
+
if (typeof result !== "object" || result === null) return result;
|
|
81
|
+
resultCache.set(schema$1, result);
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
if (resultCache.has(schema)) return resultCache.get(schema);
|
|
85
|
+
if (level === MAX_LEVELS_DEEP + 1) try {
|
|
86
|
+
JSON.stringify(schema);
|
|
87
|
+
} catch {
|
|
88
|
+
return "[Circular Reference]";
|
|
89
|
+
}
|
|
90
|
+
const makeUpRandomData = !!options?.emptyString;
|
|
91
|
+
if (schema.deprecated || schema.type === "array" && schema.items?.deprecated) return;
|
|
92
|
+
if (options?.mode === "write" && schema.readOnly || options?.mode === "read" && schema.writeOnly) return;
|
|
93
|
+
if (schema["x-variable"]) {
|
|
94
|
+
const value = options?.variables?.[schema["x-variable"]];
|
|
95
|
+
if (value !== void 0) {
|
|
96
|
+
if (schema.type === "number" || schema.type === "integer") return Number.parseInt(value, 10);
|
|
97
|
+
return cache(schema, value);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (Array.isArray(schema.examples) && schema.examples.length > 0) return cache(schema, schema.examples[0]);
|
|
101
|
+
if (schema.example !== void 0) return cache(schema, schema.example);
|
|
102
|
+
if (schema.default !== void 0 && [
|
|
103
|
+
"string",
|
|
104
|
+
"number",
|
|
105
|
+
"boolean"
|
|
106
|
+
].includes(typeof schema.default)) return cache(schema, schema.default);
|
|
107
|
+
if (Array.isArray(schema.enum) && schema.enum.length > 0) return cache(schema, schema.enum[0]);
|
|
108
|
+
if (!(schema.type === "object" || schema.type === "array" || !!schema.allOf?.at?.(0) || !!schema.anyOf?.at?.(0) || !!schema.oneOf?.at?.(0)) && options?.omitEmptyAndOptionalProperties === true) {
|
|
109
|
+
if (!(schema.required === true || parentSchema?.required === true || parentSchema?.required?.includes(name ?? schema.name))) return;
|
|
110
|
+
}
|
|
111
|
+
if (schema.type === "object" || schema.properties !== void 0) {
|
|
112
|
+
const response = {};
|
|
113
|
+
if (schema.properties !== void 0) {
|
|
114
|
+
for (const propertyName in schema.properties) if (Object.prototype.hasOwnProperty.call(schema.properties, propertyName)) {
|
|
115
|
+
const property = schema.properties[propertyName];
|
|
116
|
+
const propertyXmlTagName = options?.xml ? property.xml?.name : void 0;
|
|
117
|
+
response[propertyXmlTagName ?? propertyName] = getExampleFromSchema(property, options, level + 1, schema, propertyName, resultCache);
|
|
118
|
+
if (typeof response[propertyXmlTagName ?? propertyName] === "undefined") delete response[propertyXmlTagName ?? propertyName];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (schema.patternProperties !== void 0) {
|
|
122
|
+
for (const pattern in schema.patternProperties) if (Object.prototype.hasOwnProperty.call(schema.patternProperties, pattern)) {
|
|
123
|
+
const property = schema.patternProperties[pattern];
|
|
124
|
+
const exampleKey = pattern;
|
|
125
|
+
response[exampleKey] = getExampleFromSchema(property, options, level + 1, schema, exampleKey, resultCache);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (schema.additionalProperties !== void 0) {
|
|
129
|
+
if (schema.additionalProperties === true || typeof schema.additionalProperties === "object" && !Object.keys(schema.additionalProperties).length) response.ANY_ADDITIONAL_PROPERTY = "anything";
|
|
130
|
+
else if (schema.additionalProperties !== false) response.ANY_ADDITIONAL_PROPERTY = getExampleFromSchema(schema.additionalProperties, options, level + 1, void 0, void 0, resultCache);
|
|
131
|
+
}
|
|
132
|
+
if (schema.anyOf !== void 0) Object.assign(response, getExampleFromSchema(schema.anyOf[0], options, level + 1, void 0, void 0, resultCache));
|
|
133
|
+
else if (schema.oneOf !== void 0) Object.assign(response, getExampleFromSchema(schema.oneOf[0], options, level + 1, void 0, void 0, resultCache));
|
|
134
|
+
else if (schema.allOf !== void 0) Object.assign(response, ...schema.allOf.map((item) => getExampleFromSchema(item, options, level + 1, schema, void 0, resultCache)).filter((item) => item !== void 0));
|
|
135
|
+
return cache(schema, response);
|
|
136
|
+
}
|
|
137
|
+
if (schema.type === "array" || schema.items !== void 0) {
|
|
138
|
+
const itemsXmlTagName = schema?.items?.xml?.name;
|
|
139
|
+
const wrapItems = !!(options?.xml && schema.xml?.wrapped && itemsXmlTagName);
|
|
140
|
+
if (schema.example !== void 0) return cache(schema, wrapItems ? { [itemsXmlTagName]: schema.example } : schema.example);
|
|
141
|
+
if (schema.items) {
|
|
142
|
+
if (schema.items.allOf) {
|
|
143
|
+
if (schema.items.allOf[0].type === "object") {
|
|
144
|
+
const mergedExample = getExampleFromSchema({
|
|
145
|
+
type: "object",
|
|
146
|
+
allOf: schema.items.allOf
|
|
147
|
+
}, options, level + 1, schema, void 0, resultCache);
|
|
148
|
+
return cache(schema, wrapItems ? [{ [itemsXmlTagName]: mergedExample }] : [mergedExample]);
|
|
149
|
+
}
|
|
150
|
+
const examples = schema.items.allOf.map((item) => getExampleFromSchema(item, options, level + 1, schema, void 0, resultCache)).filter((item) => item !== void 0);
|
|
151
|
+
return cache(schema, wrapItems ? examples.map((example) => ({ [itemsXmlTagName]: example })) : examples);
|
|
152
|
+
}
|
|
153
|
+
for (const rule of ["anyOf", "oneOf"]) {
|
|
154
|
+
if (!schema.items[rule]) continue;
|
|
155
|
+
const exampleFromRule = schema.items[rule].slice(0, 1).map((item) => getExampleFromSchema(item, options, level + 1, schema, void 0, resultCache)).filter((item) => item !== void 0);
|
|
156
|
+
return cache(schema, wrapItems ? [{ [itemsXmlTagName]: exampleFromRule }] : exampleFromRule);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (schema.items?.type) {
|
|
160
|
+
const exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1, void 0, void 0, resultCache);
|
|
161
|
+
return wrapItems ? [{ [itemsXmlTagName]: exampleFromSchema }] : [exampleFromSchema];
|
|
162
|
+
}
|
|
163
|
+
return [];
|
|
164
|
+
}
|
|
165
|
+
const exampleValues = {
|
|
166
|
+
string: makeUpRandomData ? guessFromFormat(schema, options?.emptyString) : "",
|
|
167
|
+
boolean: true,
|
|
168
|
+
integer: schema.min ?? 1,
|
|
169
|
+
number: schema.min ?? 1,
|
|
170
|
+
array: []
|
|
171
|
+
};
|
|
172
|
+
if (schema.type !== void 0 && exampleValues[schema.type] !== void 0) return cache(schema, exampleValues[schema.type]);
|
|
173
|
+
const discriminateSchema = schema.oneOf || schema.anyOf;
|
|
174
|
+
if (Array.isArray(discriminateSchema) && discriminateSchema.length > 0) {
|
|
175
|
+
const firstOneOfItem = discriminateSchema[0];
|
|
176
|
+
return getExampleFromSchema(firstOneOfItem, options, level + 1, void 0, void 0, resultCache);
|
|
177
|
+
}
|
|
178
|
+
if (Array.isArray(schema.allOf)) {
|
|
179
|
+
let example = null;
|
|
180
|
+
schema.allOf.forEach((allOfItem) => {
|
|
181
|
+
const newExample = getExampleFromSchema(allOfItem, options, level + 1, void 0, void 0, resultCache);
|
|
182
|
+
example = typeof newExample === "object" && typeof example === "object" ? {
|
|
183
|
+
...example ?? {},
|
|
184
|
+
...newExample
|
|
185
|
+
} : Array.isArray(newExample) && Array.isArray(example) ? [...example ?? {}, ...newExample] : newExample;
|
|
186
|
+
});
|
|
187
|
+
return cache(schema, example);
|
|
188
|
+
}
|
|
189
|
+
if (Array.isArray(schema.type)) {
|
|
190
|
+
if (schema.type.includes("null")) return null;
|
|
191
|
+
const exampleValue = exampleValues[schema.type[0]];
|
|
192
|
+
if (exampleValue !== void 0) return cache(schema, exampleValue);
|
|
193
|
+
}
|
|
194
|
+
return null;
|
|
342
195
|
};
|
|
196
|
+
|
|
197
|
+
//#endregion
|
|
198
|
+
export { generateMediaTypeExamples, generateSchemaExample };
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
else {
|
|
15
|
-
label = tString(context.translation, 'properties').toLowerCase();
|
|
16
|
-
}
|
|
17
|
-
return tString(context.translation, isExpanded ? 'hide' : 'show', label);
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { tString } from "./translate.js";
|
|
5
|
+
|
|
6
|
+
//#region src/getDisclosureLabel.ts
|
|
7
|
+
function getDisclosureLabel(props) {
|
|
8
|
+
const { schema, isExpanded, context } = props;
|
|
9
|
+
let label;
|
|
10
|
+
if (schema.type === "array" && !!schema.items) if (schema.items.oneOf) label = tString(context.translation, "available_items").toLowerCase();
|
|
11
|
+
else label = tString(context.translation, "properties").toLowerCase();
|
|
12
|
+
else label = tString(context.translation, "properties").toLowerCase();
|
|
13
|
+
return tString(context.translation, isExpanded ? "hide" : "show", label);
|
|
18
14
|
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { getDisclosureLabel };
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import { createStore } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { createStore } from "zustand";
|
|
2
|
+
|
|
3
|
+
//#region src/getOrCreateStoreByKey.ts
|
|
4
|
+
const createStateStore = (initial) => {
|
|
5
|
+
return createStore()((set) => ({
|
|
6
|
+
key: initial ?? null,
|
|
7
|
+
setKey: (key) => {
|
|
8
|
+
set(() => ({ key }));
|
|
9
|
+
}
|
|
10
|
+
}));
|
|
9
11
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return stores.get(storeKey);
|
|
17
|
-
};
|
|
12
|
+
const defaultStores = /* @__PURE__ */ new Map();
|
|
13
|
+
const createStateStoreFactory = (stores) => {
|
|
14
|
+
return (storeKey, initialKey) => {
|
|
15
|
+
if (!stores.has(storeKey)) stores.set(storeKey, createStateStore(initialKey));
|
|
16
|
+
return stores.get(storeKey);
|
|
17
|
+
};
|
|
18
18
|
};
|
|
19
|
-
|
|
19
|
+
const getOrCreateStoreByKey = createStateStoreFactory(defaultStores);
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { getOrCreateStoreByKey };
|