@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
package/dist/utils.js
CHANGED
|
@@ -1,224 +1,163 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
|
13
|
-
import { tString } from './translate';
|
|
14
|
-
export function checkIsReference(input) {
|
|
15
|
-
return typeof input === 'object' && !!input && '$ref' in input;
|
|
1
|
+
import { stringifyOpenAPI } from "./stringifyOpenAPI.js";
|
|
2
|
+
import { tString } from "./translate.js";
|
|
3
|
+
|
|
4
|
+
//#region src/utils.ts
|
|
5
|
+
function checkIsReference(input) {
|
|
6
|
+
return typeof input === "object" && !!input && "$ref" in input;
|
|
16
7
|
}
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
function createStateKey(key, scope) {
|
|
9
|
+
return scope ? `${scope}_${key}` : key;
|
|
19
10
|
}
|
|
20
11
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
* Check if an object has a description. Either at the root level or in items.
|
|
13
|
+
*/
|
|
23
14
|
function hasDescription(object) {
|
|
24
|
-
|
|
15
|
+
return "description" in object || "x-gitbook-description-html" in object;
|
|
25
16
|
}
|
|
26
17
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return 'x-gitbook-description-html' in object &&
|
|
33
|
-
typeof object['x-gitbook-description-html'] === 'string'
|
|
34
|
-
? object['x-gitbook-description-html'].trim()
|
|
35
|
-
: typeof object.description === 'string'
|
|
36
|
-
? object.description.trim()
|
|
37
|
-
: undefined;
|
|
38
|
-
}
|
|
39
|
-
// If the object has no description, try to resolve it from the items
|
|
40
|
-
if ('items' in object && typeof object.items === 'object' && hasDescription(object.items)) {
|
|
41
|
-
return resolveDescription(object.items);
|
|
42
|
-
}
|
|
43
|
-
return undefined;
|
|
18
|
+
* Resolve the description of an object.
|
|
19
|
+
*/
|
|
20
|
+
function resolveDescription(object) {
|
|
21
|
+
if (hasDescription(object)) return "x-gitbook-description-html" in object && typeof object["x-gitbook-description-html"] === "string" ? object["x-gitbook-description-html"].trim() : typeof object.description === "string" ? object.description.trim() : void 0;
|
|
22
|
+
if ("items" in object && typeof object.items === "object" && hasDescription(object.items)) return resolveDescription(object.items);
|
|
44
23
|
}
|
|
45
24
|
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
: undefined,
|
|
54
|
-
};
|
|
25
|
+
* Extract descriptions from an object.
|
|
26
|
+
*/
|
|
27
|
+
function extractDescriptions(object) {
|
|
28
|
+
return {
|
|
29
|
+
description: object.description,
|
|
30
|
+
"x-gitbook-description-html": "x-gitbook-description-html" in object ? object["x-gitbook-description-html"] : void 0
|
|
31
|
+
};
|
|
55
32
|
}
|
|
56
33
|
/**
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
// Resolve top level example first
|
|
68
|
-
if (shouldDisplayExample(object)) {
|
|
69
|
-
return formatExample(object.example);
|
|
70
|
-
}
|
|
71
|
-
// Resolve example from items if it exists
|
|
72
|
-
if (object.items && typeof object.items === 'object') {
|
|
73
|
-
return formatExample(object.items.example);
|
|
74
|
-
}
|
|
75
|
-
return undefined;
|
|
34
|
+
* Resolve the first example from an object.
|
|
35
|
+
*/
|
|
36
|
+
function resolveFirstExample(object) {
|
|
37
|
+
if ("examples" in object && typeof object.examples === "object" && object.examples) {
|
|
38
|
+
const firstKey = Object.keys(object.examples)[0];
|
|
39
|
+
if (firstKey && object.examples[firstKey]) return formatExample(object.examples[firstKey]);
|
|
40
|
+
}
|
|
41
|
+
if (shouldDisplayExample(object)) return formatExample(object.example);
|
|
42
|
+
if (object.items && typeof object.items === "object") return formatExample(object.items.example);
|
|
76
43
|
}
|
|
77
44
|
/**
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
45
|
+
* Resolve the schema of a parameter.
|
|
46
|
+
* Extract the description, example and deprecated from parameter.
|
|
47
|
+
*/
|
|
48
|
+
function resolveParameterSchema(parameter) {
|
|
49
|
+
const schema = checkIsReference(parameter.schema) ? void 0 : parameter.schema;
|
|
50
|
+
return {
|
|
51
|
+
...extractDescriptions(parameter),
|
|
52
|
+
example: resolveFirstExample(parameter),
|
|
53
|
+
deprecated: parameter.deprecated,
|
|
54
|
+
...schema
|
|
55
|
+
};
|
|
86
56
|
}
|
|
87
57
|
/**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
schema: resolveParameterSchema(parameter),
|
|
102
|
-
required: parameter.required,
|
|
103
|
-
};
|
|
58
|
+
* Transform a parameter object to a property object.
|
|
59
|
+
*/
|
|
60
|
+
function parameterToProperty(parameter) {
|
|
61
|
+
if (checkIsReference(parameter)) return {
|
|
62
|
+
propertyName: parameter.$ref ?? "Unknown ref",
|
|
63
|
+
schema: {},
|
|
64
|
+
required: void 0
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
propertyName: parameter.name,
|
|
68
|
+
schema: resolveParameterSchema(parameter),
|
|
69
|
+
required: parameter.required
|
|
70
|
+
};
|
|
104
71
|
}
|
|
105
72
|
/**
|
|
106
|
-
|
|
107
|
-
|
|
73
|
+
* Format the example of a schema.
|
|
74
|
+
*/
|
|
108
75
|
function formatExample(example) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
.replace(/\n/g, ' ') // Replace newlines with spaces
|
|
112
|
-
.replace(/\s+/g, ' ') // Collapse multiple spaces/newlines into a single space
|
|
113
|
-
.replace(/([\{\}:,])\s+/g, '$1 ') // Ensure a space after {, }, :, and ,
|
|
114
|
-
.replace(/\s+([\{\}:,])/g, ' $1') // Ensure a space before {, }, :, and ,
|
|
115
|
-
.trim();
|
|
116
|
-
}
|
|
117
|
-
return stringifyOpenAPI(example);
|
|
76
|
+
if (typeof example === "string") return example.replace(/\n/g, " ").replace(/\s+/g, " ").replace(/([\{\}:,])\s+/g, "$1 ").replace(/\s+([\{\}:,])/g, " $1").trim();
|
|
77
|
+
return stringifyOpenAPI(example);
|
|
118
78
|
}
|
|
119
79
|
/**
|
|
120
|
-
|
|
121
|
-
|
|
80
|
+
* Check if an example should be displayed.
|
|
81
|
+
*/
|
|
122
82
|
function shouldDisplayExample(schema) {
|
|
123
|
-
|
|
124
|
-
typeof schema.example === 'number' ||
|
|
125
|
-
typeof schema.example === 'boolean' ||
|
|
126
|
-
(Array.isArray(schema.example) && schema.example.length > 0) ||
|
|
127
|
-
(typeof schema.example === 'object' &&
|
|
128
|
-
schema.example !== null &&
|
|
129
|
-
Object.keys(schema.example).length > 0));
|
|
83
|
+
return typeof schema.example === "string" && !!schema.example || typeof schema.example === "number" || typeof schema.example === "boolean" || Array.isArray(schema.example) && schema.example.length > 0 || typeof schema.example === "object" && schema.example !== null && Object.keys(schema.example).length > 0;
|
|
130
84
|
}
|
|
131
85
|
/**
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
case 4:
|
|
148
|
-
case 5:
|
|
149
|
-
return 'error';
|
|
150
|
-
default:
|
|
151
|
-
return 'unknown';
|
|
152
|
-
}
|
|
86
|
+
* Get the class name for a status code.
|
|
87
|
+
* 1xx: informational
|
|
88
|
+
* 2xx: success
|
|
89
|
+
* 3xx: redirect
|
|
90
|
+
* 4xx, 5xx: error
|
|
91
|
+
*/
|
|
92
|
+
function getStatusCodeClassName(statusCode) {
|
|
93
|
+
switch (getStatusCodeCategory(statusCode)) {
|
|
94
|
+
case 1: return "informational";
|
|
95
|
+
case 2: return "success";
|
|
96
|
+
case 3: return "redirect";
|
|
97
|
+
case 4:
|
|
98
|
+
case 5: return "error";
|
|
99
|
+
default: return "unknown";
|
|
100
|
+
}
|
|
153
101
|
}
|
|
154
102
|
/**
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
case 4:
|
|
172
|
-
case 5:
|
|
173
|
-
return tString(context.translation, 'error');
|
|
174
|
-
default:
|
|
175
|
-
return '';
|
|
176
|
-
}
|
|
103
|
+
* Get a default label for a status code.
|
|
104
|
+
* This is used when there is no label provided in the OpenAPI spec.
|
|
105
|
+
* 1xx: Information
|
|
106
|
+
* 2xx: Success
|
|
107
|
+
* 3xx: Redirect
|
|
108
|
+
* 4xx, 5xx: Error
|
|
109
|
+
*/
|
|
110
|
+
function getStatusCodeDefaultLabel(statusCode, context) {
|
|
111
|
+
switch (getStatusCodeCategory(statusCode)) {
|
|
112
|
+
case 1: return tString(context.translation, "information");
|
|
113
|
+
case 2: return tString(context.translation, "success");
|
|
114
|
+
case 3: return tString(context.translation, "redirect");
|
|
115
|
+
case 4:
|
|
116
|
+
case 5: return tString(context.translation, "error");
|
|
117
|
+
default: return "";
|
|
118
|
+
}
|
|
177
119
|
}
|
|
178
120
|
function getStatusCodeCategory(statusCode) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
// Determine the category of the status code based on the first digit
|
|
184
|
-
var category = Math.floor(code / 100);
|
|
185
|
-
return category;
|
|
121
|
+
const code = typeof statusCode === "string" ? Number.parseInt(statusCode, 10) : statusCode;
|
|
122
|
+
if (Number.isNaN(code) || code < 100 || code >= 600) return "unknown";
|
|
123
|
+
return Math.floor(code / 100);
|
|
186
124
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
type = (_a = schema.type) !== null && _a !== void 0 ? _a : 'object';
|
|
203
|
-
if (schema.format) {
|
|
204
|
-
type += " \u00B7 ".concat(schema.format);
|
|
205
|
-
}
|
|
206
|
-
// Only add the title if it's an object (no need for the title of a string, number, etc.)
|
|
207
|
-
if (type === 'object' && schema.title) {
|
|
208
|
-
type += " \u00B7 ".concat(schema.title.replaceAll(' ', ''));
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
if ('anyOf' in schema) {
|
|
212
|
-
type = 'any of';
|
|
213
|
-
}
|
|
214
|
-
else if ('oneOf' in schema) {
|
|
215
|
-
type = 'one of';
|
|
216
|
-
}
|
|
217
|
-
else if ('allOf' in schema) {
|
|
218
|
-
type = 'all of';
|
|
219
|
-
}
|
|
220
|
-
else if ('not' in schema) {
|
|
221
|
-
type = 'not';
|
|
222
|
-
}
|
|
223
|
-
return type;
|
|
125
|
+
function getSchemaTitle(schema) {
|
|
126
|
+
let type = "any";
|
|
127
|
+
if (schema.enum || schema["x-enumDescriptions"] || schema["x-gitbook-enum"]) type = `${schema.type} · enum`;
|
|
128
|
+
else if (schema.type === "array" && !!schema.items) type = `${getSchemaTitle(schema.items)}[]`;
|
|
129
|
+
else if (Array.isArray(schema.type)) type = schema.type.join(" | ");
|
|
130
|
+
else if (schema.type || schema.properties) {
|
|
131
|
+
type = schema.type ?? "object";
|
|
132
|
+
if (schema.format) type += ` · ${schema.format}`;
|
|
133
|
+
if (type === "object" && schema.title) type += ` · ${schema.title.replaceAll(" ", "")}`;
|
|
134
|
+
}
|
|
135
|
+
if ("anyOf" in schema) type = "any of";
|
|
136
|
+
else if ("oneOf" in schema) type = "one of";
|
|
137
|
+
else if ("allOf" in schema) type = "all of";
|
|
138
|
+
else if ("not" in schema) type = "not";
|
|
139
|
+
return type;
|
|
224
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Extract security information for an operation based on its security requirements and the spec security schemes.
|
|
143
|
+
*/
|
|
144
|
+
function extractOperationSecurityInfo(args) {
|
|
145
|
+
const { securityRequirement, securities } = args;
|
|
146
|
+
const securitiesMap = new Map(securities);
|
|
147
|
+
if (!securityRequirement || securityRequirement.length === 0) return securities.map(([key, security]) => ({
|
|
148
|
+
key,
|
|
149
|
+
label: key,
|
|
150
|
+
schemes: [security]
|
|
151
|
+
}));
|
|
152
|
+
return securityRequirement.map((requirement, idx) => {
|
|
153
|
+
const schemeKeys = Object.keys(requirement);
|
|
154
|
+
return {
|
|
155
|
+
key: `security-${idx}`,
|
|
156
|
+
label: schemeKeys.join(" & "),
|
|
157
|
+
schemes: schemeKeys.map((schemeKey) => securitiesMap.get(schemeKey)).filter((s) => s !== void 0)
|
|
158
|
+
};
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
//#endregion
|
|
163
|
+
export { checkIsReference, createStateKey, extractOperationSecurityInfo, getSchemaTitle, getStatusCodeClassName, getStatusCodeDefaultLabel, parameterToProperty, resolveDescription, resolveFirstExample };
|
package/package.json
CHANGED
|
@@ -4,23 +4,22 @@
|
|
|
4
4
|
"exports": {
|
|
5
5
|
".": {
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
|
-
"development": "./src/index.ts",
|
|
8
7
|
"default": "./dist/index.js"
|
|
9
8
|
}
|
|
10
9
|
},
|
|
11
|
-
"version": "1.
|
|
10
|
+
"version": "1.5.2",
|
|
12
11
|
"sideEffects": false,
|
|
13
12
|
"dependencies": {
|
|
14
|
-
"@gitbook/expr": "
|
|
15
|
-
"@gitbook/openapi-parser": "
|
|
13
|
+
"@gitbook/expr": "1.2.3",
|
|
14
|
+
"@gitbook/openapi-parser": "3.0.4",
|
|
16
15
|
"@scalar/api-client-react": "^1.3.16",
|
|
17
16
|
"@scalar/oas-utils": "^0.2.130",
|
|
18
17
|
"@scalar/types": "^0.1.9",
|
|
19
|
-
"
|
|
18
|
+
"classnames": "^2.5.1",
|
|
20
19
|
"flatted": "^3.2.9",
|
|
21
20
|
"json-xml-parse": "^1.3.0",
|
|
22
|
-
"react-aria-components": "^1.
|
|
23
|
-
"react-aria": "^3.
|
|
21
|
+
"react-aria-components": "^1.13.0",
|
|
22
|
+
"react-aria": "^3.44.0",
|
|
24
23
|
"usehooks-ts": "^3.1.0",
|
|
25
24
|
"zustand": "^5.0.3",
|
|
26
25
|
"js-yaml": "^4.1.0"
|
|
@@ -28,17 +27,25 @@
|
|
|
28
27
|
"devDependencies": {
|
|
29
28
|
"@types/js-yaml": "^4.0.9",
|
|
30
29
|
"bun-types": "^1.1.20",
|
|
30
|
+
"react": "^19.0.0",
|
|
31
|
+
"react-dom": "^19.0.0",
|
|
32
|
+
"tsdown": "^0.15.6",
|
|
31
33
|
"typescript": "^5.5.3"
|
|
32
34
|
},
|
|
33
35
|
"peerDependencies": {
|
|
34
|
-
"react": "*"
|
|
36
|
+
"react": "*",
|
|
37
|
+
"react-dom": "*"
|
|
35
38
|
},
|
|
36
39
|
"scripts": {
|
|
37
|
-
"build": "
|
|
40
|
+
"build": "tsdown",
|
|
38
41
|
"typecheck": "tsc --noEmit",
|
|
39
42
|
"unit": "bun test",
|
|
40
|
-
"dev": "bun run build -- --watch",
|
|
43
|
+
"dev": "bun run build -- --watch ./src",
|
|
41
44
|
"clean": "rm -rf ./dist"
|
|
42
45
|
},
|
|
43
|
-
"files": ["dist", "
|
|
46
|
+
"files": ["dist", "README.md", "CHANGELOG.md"],
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public",
|
|
49
|
+
"registry": "https://registry.npmjs.org/"
|
|
50
|
+
}
|
|
44
51
|
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
interface InteractiveSectionTab {
|
|
2
|
-
key: string;
|
|
3
|
-
label: string;
|
|
4
|
-
body: React.ReactNode;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* To optimize rendering, most of the components are server-components,
|
|
8
|
-
* and the interactiveness is mainly handled by a few key components like this one.
|
|
9
|
-
*/
|
|
10
|
-
export declare function InteractiveSection(props: {
|
|
11
|
-
id?: string;
|
|
12
|
-
/** Class name to be set on the section, sub-elements will use it as prefix */
|
|
13
|
-
className: string;
|
|
14
|
-
/** If true, the content can be toggeable */
|
|
15
|
-
toggeable?: boolean;
|
|
16
|
-
/** Default state of the toggle */
|
|
17
|
-
defaultOpened?: boolean;
|
|
18
|
-
/** Icon to display for the toggle */
|
|
19
|
-
toggleIcon?: React.ReactNode;
|
|
20
|
-
/** Tabs of content to display */
|
|
21
|
-
tabs?: Array<InteractiveSectionTab>;
|
|
22
|
-
/** Default tab to have opened */
|
|
23
|
-
defaultTab?: string;
|
|
24
|
-
/** Content of the header */
|
|
25
|
-
header?: React.ReactNode;
|
|
26
|
-
/** Children to display within the container */
|
|
27
|
-
overlay?: React.ReactNode;
|
|
28
|
-
/** State key to use with a store */
|
|
29
|
-
stateKey?: string;
|
|
30
|
-
/** Icon for the tabs select */
|
|
31
|
-
selectIcon?: React.ReactNode;
|
|
32
|
-
}): import("react").JSX.Element;
|
|
33
|
-
export {};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import clsx from 'clsx';
|
|
3
|
-
import { useRef } from 'react';
|
|
4
|
-
import { mergeProps, useButton, useDisclosure, useFocusRing } from 'react-aria';
|
|
5
|
-
import { useDisclosureState } from 'react-stately';
|
|
6
|
-
import { OpenAPISelect, OpenAPISelectItem, useSelectState } from './OpenAPISelect';
|
|
7
|
-
import { Section, SectionBody, SectionHeader, SectionHeaderContent } from './StaticSection';
|
|
8
|
-
/**
|
|
9
|
-
* To optimize rendering, most of the components are server-components,
|
|
10
|
-
* and the interactiveness is mainly handled by a few key components like this one.
|
|
11
|
-
*/
|
|
12
|
-
export function InteractiveSection(props) {
|
|
13
|
-
var _a, _b;
|
|
14
|
-
var id = props.id, className = props.className, _c = props.toggeable, toggeable = _c === void 0 ? false : _c, _d = props.defaultOpened, defaultOpened = _d === void 0 ? true : _d, _e = props.tabs, tabs = _e === void 0 ? [] : _e, _f = props.defaultTab, defaultTab = _f === void 0 ? (_a = tabs[0]) === null || _a === void 0 ? void 0 : _a.key : _f, header = props.header, overlay = props.overlay, _g = props.toggleIcon, toggleIcon = _g === void 0 ? '▶' : _g, selectIcon = props.selectIcon, _h = props.stateKey, stateKey = _h === void 0 ? 'interactive-section' : _h;
|
|
15
|
-
var state = useDisclosureState({
|
|
16
|
-
defaultExpanded: defaultOpened,
|
|
17
|
-
});
|
|
18
|
-
var panelRef = useRef(null);
|
|
19
|
-
var triggerRef = useRef(null);
|
|
20
|
-
var _j = useDisclosure({}, state, panelRef), triggerProps = _j.buttonProps, panelProps = _j.panelProps;
|
|
21
|
-
var buttonProps = useButton(triggerProps, triggerRef).buttonProps;
|
|
22
|
-
var _k = useFocusRing(), isFocusVisible = _k.isFocusVisible, focusProps = _k.focusProps;
|
|
23
|
-
var store = useSelectState(stateKey, defaultTab);
|
|
24
|
-
var selectedTab = (_b = tabs.find(function (tab) { return tab.key === store.key; })) !== null && _b !== void 0 ? _b : tabs[0];
|
|
25
|
-
return (<Section id={id} className={clsx('openapi-section', toggeable ? 'openapi-section-toggeable' : null, className, toggeable ? "".concat(className, "-").concat(state.isExpanded ? 'opened' : 'closed') : null)}>
|
|
26
|
-
{header ? (<SectionHeader onClick={function () {
|
|
27
|
-
if (toggeable) {
|
|
28
|
-
state.toggle();
|
|
29
|
-
}
|
|
30
|
-
}} className={className}>
|
|
31
|
-
<SectionHeaderContent className={className}>
|
|
32
|
-
{(selectedTab === null || selectedTab === void 0 ? void 0 : selectedTab.body) && toggeable ? (<button {...mergeProps(buttonProps, focusProps)} ref={triggerRef} className={clsx('openapi-section-toggle', "".concat(className, "-toggle"))} style={{
|
|
33
|
-
outline: isFocusVisible
|
|
34
|
-
? '2px solid rgb(var(--primary-color-500) / 0.4)'
|
|
35
|
-
: 'none',
|
|
36
|
-
}}>
|
|
37
|
-
{toggleIcon}
|
|
38
|
-
</button>) : null}
|
|
39
|
-
{header}
|
|
40
|
-
</SectionHeaderContent>
|
|
41
|
-
{/* biome-ignore lint/a11y/useKeyWithClickEvents: we prevent default here */}
|
|
42
|
-
<div className={clsx('openapi-section-header-controls', "".concat(className, "-header-controls"))} onClick={function (event) {
|
|
43
|
-
event.stopPropagation();
|
|
44
|
-
}}>
|
|
45
|
-
{tabs.length > 0 ? (<OpenAPISelect stateKey={stateKey} items={tabs} onSelectionChange={function () {
|
|
46
|
-
state.expand();
|
|
47
|
-
}} icon={selectIcon} placement="bottom end">
|
|
48
|
-
{tabs.map(function (tab) { return (<OpenAPISelectItem key={tab.key} id={tab.key} value={tab}>
|
|
49
|
-
{tab.label}
|
|
50
|
-
</OpenAPISelectItem>); })}
|
|
51
|
-
</OpenAPISelect>) : null}
|
|
52
|
-
</div>
|
|
53
|
-
</SectionHeader>) : null}
|
|
54
|
-
{(!toggeable || state.isExpanded) && (selectedTab === null || selectedTab === void 0 ? void 0 : selectedTab.body) ? (<SectionBody ref={panelRef} {...panelProps} className={className}>
|
|
55
|
-
{selectedTab === null || selectedTab === void 0 ? void 0 : selectedTab.body}
|
|
56
|
-
</SectionBody>) : null}
|
|
57
|
-
{overlay ? (<div className={clsx('openapi-section-overlay', "".concat(className, "-overlay"))}>
|
|
58
|
-
{overlay}
|
|
59
|
-
</div>) : null}
|
|
60
|
-
</Section>);
|
|
61
|
-
}
|
package/dist/Markdown.d.ts
DELETED
package/dist/Markdown.jsx
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
-
import { type OpenAPIContext } from './context';
|
|
3
|
-
import type { OpenAPIOperationData } from './types';
|
|
4
|
-
/**
|
|
5
|
-
* Display code samples to execute the operation.
|
|
6
|
-
* It supports the Redocly custom syntax as well (https://redocly.com/docs/api-reference-docs/specification-extensions/x-code-samples/)
|
|
7
|
-
*/
|
|
8
|
-
export declare function OpenAPICodeSample(props: {
|
|
9
|
-
data: OpenAPIOperationData;
|
|
10
|
-
context: OpenAPIContext;
|
|
11
|
-
}): import("react").JSX.Element | null;
|
|
12
|
-
export interface MediaTypeRenderer {
|
|
13
|
-
mediaType: string;
|
|
14
|
-
element: React.ReactNode;
|
|
15
|
-
examples: Array<{
|
|
16
|
-
example: OpenAPIV3.ExampleObject;
|
|
17
|
-
element: React.ReactNode;
|
|
18
|
-
}>;
|
|
19
|
-
}
|