@gitbook/react-openapi 1.4.3 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/dist/index.d.ts +663 -10
- package/dist/index.js +3873 -8
- package/package.json +11 -7
- 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.d.ts +0 -10
- package/dist/OpenAPIOperation.jsx +0 -25
- package/dist/OpenAPIOperationContext.d.ts +0 -16
- 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.d.ts +0 -22
- 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.d.ts +0 -10
- 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/code-samples.js +0 -427
- 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/contentTypeChecks.js +0 -30
- package/dist/context.d.ts +0 -75
- package/dist/context.js +0 -43
- package/dist/decycle.d.ts +0 -2
- package/dist/decycle.js +0 -70
- package/dist/dereference.d.ts +0 -5
- package/dist/dereference.js +0 -68
- package/dist/generateSchemaExample.d.ts +0 -45
- package/dist/generateSchemaExample.js +0 -342
- package/dist/getDisclosureLabel.d.ts +0 -7
- package/dist/getDisclosureLabel.js +0 -18
- package/dist/getOrCreateStoreByKey.d.ts +0 -10
- package/dist/getOrCreateStoreByKey.js +0 -19
- package/dist/json2xml.d.ts +0 -4
- package/dist/json2xml.js +0 -7
- package/dist/resolveOpenAPIOperation.d.ts +0 -11
- package/dist/resolveOpenAPIOperation.js +0 -173
- package/dist/resolveOpenAPIWebhook.d.ts +0 -11
- package/dist/resolveOpenAPIWebhook.js +0 -127
- package/dist/schemas/OpenAPISchemaItem.d.ts +0 -7
- package/dist/schemas/OpenAPISchemaItem.jsx +0 -16
- package/dist/schemas/OpenAPISchemas.d.ts +0 -14
- package/dist/schemas/OpenAPISchemas.jsx +0 -59
- package/dist/schemas/index.d.ts +0 -2
- package/dist/schemas/index.js +0 -2
- package/dist/schemas/resolveOpenAPISchemas.d.ts +0 -10
- package/dist/schemas/resolveOpenAPISchemas.js +0 -61
- package/dist/stringifyOpenAPI.d.ts +0 -4
- package/dist/stringifyOpenAPI.js +0 -15
- package/dist/translate.d.ts +0 -10
- package/dist/translate.jsx +0 -75
- package/dist/translations/de.d.ts +0 -43
- package/dist/translations/de.js +0 -43
- package/dist/translations/en.d.ts +0 -43
- package/dist/translations/en.js +0 -43
- package/dist/translations/es.d.ts +0 -43
- package/dist/translations/es.js +0 -43
- package/dist/translations/fr.d.ts +0 -43
- package/dist/translations/fr.js +0 -43
- package/dist/translations/index.d.ts +0 -395
- package/dist/translations/index.js +0 -27
- package/dist/translations/ja.d.ts +0 -43
- package/dist/translations/ja.js +0 -43
- package/dist/translations/nl.d.ts +0 -43
- package/dist/translations/nl.js +0 -43
- package/dist/translations/no.d.ts +0 -43
- package/dist/translations/no.js +0 -43
- package/dist/translations/pt-br.d.ts +0 -43
- package/dist/translations/pt-br.js +0 -43
- package/dist/translations/types.d.ts +0 -5
- package/dist/translations/types.js +0 -1
- package/dist/translations/zh.d.ts +0 -43
- package/dist/translations/zh.js +0 -43
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types.d.ts +0 -31
- 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/server.js +0 -44
- package/dist/util/tryit-prefill.d.ts +0 -20
- package/dist/util/tryit-prefill.js +0 -129
- package/dist/utils.d.ts +0 -50
- package/dist/utils.js +0 -224
- 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/OpenAPIResponse.jsx
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
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
|
-
import { OpenAPIDisclosure } from './OpenAPIDisclosure';
|
|
13
|
-
import { OpenAPISchemaPresentation } from './OpenAPISchema';
|
|
14
|
-
import { OpenAPISchemaProperties } from './OpenAPISchemaServer';
|
|
15
|
-
import { tString } from './translate';
|
|
16
|
-
import { parameterToProperty, resolveDescription } from './utils';
|
|
17
|
-
/**
|
|
18
|
-
* Display an interactive response body.
|
|
19
|
-
*/
|
|
20
|
-
export function OpenAPIResponse(props) {
|
|
21
|
-
var _a, _b;
|
|
22
|
-
var response = props.response, context = props.context, mediaType = props.mediaType;
|
|
23
|
-
var headers = Object.entries((_a = response.headers) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
|
|
24
|
-
var name = _a[0], header = _a[1];
|
|
25
|
-
return [name, header !== null && header !== void 0 ? header : {}];
|
|
26
|
-
});
|
|
27
|
-
var content = Object.entries((_b = mediaType === null || mediaType === void 0 ? void 0 : mediaType.schema) !== null && _b !== void 0 ? _b : {});
|
|
28
|
-
var description = resolveDescription(response);
|
|
29
|
-
if (content.length === 0 && !description && headers.length === 0) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
return (<div className="openapi-response-body">
|
|
33
|
-
{headers.length > 0 ? (<OpenAPIDisclosure header={<OpenAPISchemaPresentation context={context} property={{
|
|
34
|
-
propertyName: tString(context.translation, 'headers'),
|
|
35
|
-
schema: {
|
|
36
|
-
type: 'object',
|
|
37
|
-
},
|
|
38
|
-
required: null,
|
|
39
|
-
}}/>} icon={context.icons.plus} label={function (isExpanded) {
|
|
40
|
-
return tString(context.translation, isExpanded ? 'hide' : 'show', tString(context.translation, headers.length === 1 ? 'header' : 'headers'));
|
|
41
|
-
}}>
|
|
42
|
-
<OpenAPISchemaProperties properties={headers.map(function (_a) {
|
|
43
|
-
var name = _a[0], header = _a[1];
|
|
44
|
-
return parameterToProperty(__assign({ name: name }, header));
|
|
45
|
-
})} context={context}/>
|
|
46
|
-
</OpenAPIDisclosure>) : null}
|
|
47
|
-
{(mediaType === null || mediaType === void 0 ? void 0 : mediaType.schema) && (<div className="openapi-responsebody">
|
|
48
|
-
<OpenAPISchemaProperties id={"response-".concat(context.blockKey)} properties={[
|
|
49
|
-
{
|
|
50
|
-
schema: mediaType.schema,
|
|
51
|
-
propertyName: tString(context.translation, 'response'),
|
|
52
|
-
required: null,
|
|
53
|
-
},
|
|
54
|
-
]} context={context}/>
|
|
55
|
-
</div>)}
|
|
56
|
-
</div>);
|
|
57
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type OpenAPIContext } from './context';
|
|
2
|
-
import type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Display an example of the response content.
|
|
5
|
-
*/
|
|
6
|
-
export declare function OpenAPIResponseExample(props: {
|
|
7
|
-
data: OpenAPIOperationData | OpenAPIWebhookData;
|
|
8
|
-
context: OpenAPIContext;
|
|
9
|
-
}): import("react").JSX.Element | null;
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { Markdown } from './Markdown';
|
|
2
|
-
import { OpenAPIEmptyExample, OpenAPIExample } from './OpenAPIExample';
|
|
3
|
-
import { OpenAPIMediaTypeContent } from './OpenAPIMediaType';
|
|
4
|
-
import { OpenAPIResponseExampleContent } from './OpenAPIResponseExampleContent';
|
|
5
|
-
import { getOpenAPIClientContext } from './context';
|
|
6
|
-
import { getExampleFromReference, getExamples } from './util/example';
|
|
7
|
-
import { createStateKey, getStatusCodeDefaultLabel, resolveDescription } from './utils';
|
|
8
|
-
import { checkIsReference } from './utils';
|
|
9
|
-
/**
|
|
10
|
-
* Display an example of the response content.
|
|
11
|
-
*/
|
|
12
|
-
export function OpenAPIResponseExample(props) {
|
|
13
|
-
var data = props.data, context = props.context;
|
|
14
|
-
// if there are no responses defined for the operation
|
|
15
|
-
if (!data.operation.responses) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
var responses = Object.entries(data.operation.responses);
|
|
19
|
-
// Sort response to get 200, and 2xx first
|
|
20
|
-
responses.sort(function (_a, _b) {
|
|
21
|
-
var a = _a[0];
|
|
22
|
-
var b = _b[0];
|
|
23
|
-
if (a === 'default') {
|
|
24
|
-
return 1;
|
|
25
|
-
}
|
|
26
|
-
if (b === 'default') {
|
|
27
|
-
return -1;
|
|
28
|
-
}
|
|
29
|
-
if (a === '200') {
|
|
30
|
-
return -1;
|
|
31
|
-
}
|
|
32
|
-
if (b === '200') {
|
|
33
|
-
return 1;
|
|
34
|
-
}
|
|
35
|
-
return Number(a) - Number(b);
|
|
36
|
-
});
|
|
37
|
-
var tabs = responses
|
|
38
|
-
.filter(function (_a) {
|
|
39
|
-
var _ = _a[0], responseObject = _a[1];
|
|
40
|
-
return responseObject &&
|
|
41
|
-
typeof responseObject === 'object' &&
|
|
42
|
-
// Make sure the response is not hidden
|
|
43
|
-
!responseObject['x-hideSample'];
|
|
44
|
-
})
|
|
45
|
-
.map(function (_a) {
|
|
46
|
-
var key = _a[0], responseObject = _a[1];
|
|
47
|
-
var description = resolveDescription(responseObject);
|
|
48
|
-
var label = description ? (<Markdown key={"response-description-".concat(key)} source={description}/>) : (getStatusCodeDefaultLabel(key, context));
|
|
49
|
-
if (checkIsReference(responseObject)) {
|
|
50
|
-
return {
|
|
51
|
-
key: key,
|
|
52
|
-
label: label,
|
|
53
|
-
statusCode: key,
|
|
54
|
-
body: (<OpenAPIExample example={getExampleFromReference(responseObject, context)} context={context} syntax="json"/>),
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
if (!responseObject.content || Object.keys(responseObject.content).length === 0) {
|
|
58
|
-
return {
|
|
59
|
-
key: key,
|
|
60
|
-
label: label,
|
|
61
|
-
statusCode: key,
|
|
62
|
-
body: <OpenAPIEmptyExample context={context}/>,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
key: key,
|
|
67
|
-
label: label,
|
|
68
|
-
statusCode: key,
|
|
69
|
-
body: <OpenAPIResponse context={context} content={responseObject.content}/>,
|
|
70
|
-
};
|
|
71
|
-
});
|
|
72
|
-
if (tabs.length === 0) {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
return (<OpenAPIResponseExampleContent selectIcon={context.icons.chevronDown} blockKey={context.blockKey} items={tabs}/>);
|
|
76
|
-
}
|
|
77
|
-
function OpenAPIResponse(props) {
|
|
78
|
-
var context = props.context, content = props.content;
|
|
79
|
-
var entries = Object.entries(content);
|
|
80
|
-
var firstEntry = entries[0];
|
|
81
|
-
if (!firstEntry) {
|
|
82
|
-
throw new Error('One media type is required');
|
|
83
|
-
}
|
|
84
|
-
var tabs = entries.map(function (entry) {
|
|
85
|
-
var mediaType = entry[0], mediaTypeObject = entry[1];
|
|
86
|
-
if (!mediaTypeObject) {
|
|
87
|
-
return {
|
|
88
|
-
key: mediaType,
|
|
89
|
-
label: mediaType,
|
|
90
|
-
body: <OpenAPIEmptyExample context={context}/>,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
key: mediaType,
|
|
95
|
-
label: mediaType,
|
|
96
|
-
body: <></>,
|
|
97
|
-
examples: getExamples({
|
|
98
|
-
mediaTypeObject: mediaTypeObject,
|
|
99
|
-
mediaType: mediaType,
|
|
100
|
-
context: context,
|
|
101
|
-
}),
|
|
102
|
-
};
|
|
103
|
-
});
|
|
104
|
-
return (<OpenAPIMediaTypeContent selectIcon={context.icons.chevronDown} stateKey={createStateKey('response-media-types', context.blockKey)} items={tabs} context={getOpenAPIClientContext(context)}/>);
|
|
105
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Key } from 'react-aria';
|
|
2
|
-
import { OpenAPISelectItem } from './OpenAPISelect';
|
|
3
|
-
type OpenAPIResponseExampleItem = OpenAPISelectItem & {
|
|
4
|
-
statusCode: string;
|
|
5
|
-
body: React.ReactNode;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Get the state of the response examples select.
|
|
9
|
-
*/
|
|
10
|
-
export declare function useResponseExamplesState(blockKey: string | undefined, initialKey?: Key): {
|
|
11
|
-
key: (string | number) | null;
|
|
12
|
-
setKey: (key: Key | null) => void;
|
|
13
|
-
};
|
|
14
|
-
export declare function OpenAPIResponseExampleContent(props: {
|
|
15
|
-
items: OpenAPIResponseExampleItem[];
|
|
16
|
-
blockKey?: string;
|
|
17
|
-
selectIcon?: React.ReactNode;
|
|
18
|
-
}): import("react").JSX.Element;
|
|
19
|
-
declare function OpenAPIResponseExampleItem(props: {
|
|
20
|
-
item: OpenAPIResponseExampleItem;
|
|
21
|
-
}): import("react").JSX.Element;
|
|
22
|
-
export {};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import clsx from 'clsx';
|
|
3
|
-
import { OpenAPISelect, OpenAPISelectItem, useSelectState } from './OpenAPISelect';
|
|
4
|
-
import { StaticSection } from './StaticSection';
|
|
5
|
-
import { createStateKey, getStatusCodeClassName } from './utils';
|
|
6
|
-
/**
|
|
7
|
-
* Get the state of the response examples select.
|
|
8
|
-
*/
|
|
9
|
-
export function useResponseExamplesState(blockKey, initialKey) {
|
|
10
|
-
if (initialKey === void 0) { initialKey = 'default'; }
|
|
11
|
-
return useSelectState(getResponseExampleStateKey(blockKey), initialKey);
|
|
12
|
-
}
|
|
13
|
-
export function OpenAPIResponseExampleContent(props) {
|
|
14
|
-
var blockKey = props.blockKey, items = props.items, selectIcon = props.selectIcon;
|
|
15
|
-
return (<StaticSection header={<OpenAPIResponseExampleHeader selectIcon={selectIcon} blockKey={blockKey} items={items}/>} className="openapi-response-examples">
|
|
16
|
-
<OpenAPIResponseExampleBody blockKey={blockKey} items={items}/>
|
|
17
|
-
</StaticSection>);
|
|
18
|
-
}
|
|
19
|
-
function OpenAPIResponseExampleHeader(props) {
|
|
20
|
-
var items = props.items, blockKey = props.blockKey, selectIcon = props.selectIcon;
|
|
21
|
-
if (items.length === 1) {
|
|
22
|
-
var item = items[0];
|
|
23
|
-
if (!item) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
return (<span className="openapi-response-examples-statuscode-title">
|
|
27
|
-
<OpenAPIResponseExampleItem item={item}/>
|
|
28
|
-
</span>);
|
|
29
|
-
}
|
|
30
|
-
return (<OpenAPISelect items={items} icon={selectIcon} stateKey={getResponseExampleStateKey(blockKey)} placement="bottom start">
|
|
31
|
-
{items.map(function (item) { return (<OpenAPISelectItem key={item.key} id={item.key} value={item}>
|
|
32
|
-
<OpenAPIResponseExampleItem item={item}/>
|
|
33
|
-
</OpenAPISelectItem>); })}
|
|
34
|
-
</OpenAPISelect>);
|
|
35
|
-
}
|
|
36
|
-
function OpenAPIResponseExampleItem(props) {
|
|
37
|
-
var item = props.item;
|
|
38
|
-
return (<>
|
|
39
|
-
<span className={clsx('openapi-statuscode', "openapi-statuscode-".concat(getStatusCodeClassName(item.statusCode)), 'openapi-response-examples-statuscode')}>
|
|
40
|
-
{item.statusCode}
|
|
41
|
-
</span>
|
|
42
|
-
<span className="openapi-response-examples-statuscode-label">{item.label}</span>
|
|
43
|
-
</>);
|
|
44
|
-
}
|
|
45
|
-
function OpenAPIResponseExampleBody(props) {
|
|
46
|
-
var _a, _b;
|
|
47
|
-
var blockKey = props.blockKey, items = props.items;
|
|
48
|
-
var state = useResponseExamplesState(blockKey, (_a = items[0]) === null || _a === void 0 ? void 0 : _a.key);
|
|
49
|
-
var selectedItem = (_b = items.find(function (item) { return item.key === state.key; })) !== null && _b !== void 0 ? _b : items[0];
|
|
50
|
-
if (!selectedItem) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
return <div className="openapi-response-examples-panel">{selectedItem.body}</div>;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Return the state key for the response examples.
|
|
57
|
-
*/
|
|
58
|
-
function getResponseExampleStateKey(blockKey) {
|
|
59
|
-
return createStateKey('openapi-responses', blockKey);
|
|
60
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { OpenAPIV3, OpenAPIV3_1 } from '@gitbook/openapi-parser';
|
|
2
|
-
import type { OpenAPIClientContext } from './context';
|
|
3
|
-
/**
|
|
4
|
-
* Display an interactive response body.
|
|
5
|
-
*/
|
|
6
|
-
export declare function OpenAPIResponses(props: {
|
|
7
|
-
responses: OpenAPIV3.ResponsesObject | OpenAPIV3_1.ResponsesObject;
|
|
8
|
-
context: OpenAPIClientContext;
|
|
9
|
-
}): import("react").JSX.Element;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import clsx from 'clsx';
|
|
3
|
-
import { Markdown } from './Markdown';
|
|
4
|
-
import { OpenAPIDisclosureGroup } from './OpenAPIDisclosureGroup';
|
|
5
|
-
import { OpenAPIResponse } from './OpenAPIResponse';
|
|
6
|
-
import { useResponseExamplesState } from './OpenAPIResponseExampleContent';
|
|
7
|
-
import { StaticSection } from './StaticSection';
|
|
8
|
-
import { t } from './translate';
|
|
9
|
-
import { createStateKey, getStatusCodeClassName, getStatusCodeDefaultLabel, resolveDescription, } from './utils';
|
|
10
|
-
/**
|
|
11
|
-
* Display an interactive response body.
|
|
12
|
-
*/
|
|
13
|
-
export function OpenAPIResponses(props) {
|
|
14
|
-
var _a;
|
|
15
|
-
var responses = props.responses, context = props.context;
|
|
16
|
-
var groups = Object.entries(responses)
|
|
17
|
-
.filter(function (_a) {
|
|
18
|
-
var _ = _a[0], response = _a[1];
|
|
19
|
-
return response && typeof response === 'object';
|
|
20
|
-
})
|
|
21
|
-
.map(function (_a) {
|
|
22
|
-
var statusCode = _a[0], response = _a[1];
|
|
23
|
-
var tabs = (function () {
|
|
24
|
-
var _a;
|
|
25
|
-
// If there is no content, but there are headers, we need to show the headers
|
|
26
|
-
if ((!response.content || !Object.keys(response.content).length) &&
|
|
27
|
-
response.headers &&
|
|
28
|
-
Object.keys(response.headers).length) {
|
|
29
|
-
return [
|
|
30
|
-
{
|
|
31
|
-
key: 'default',
|
|
32
|
-
label: '',
|
|
33
|
-
body: (<OpenAPIResponse response={response} mediaType={{}} context={context}/>),
|
|
34
|
-
},
|
|
35
|
-
];
|
|
36
|
-
}
|
|
37
|
-
if (!response.content) {
|
|
38
|
-
return [
|
|
39
|
-
{
|
|
40
|
-
key: 'default',
|
|
41
|
-
label: '',
|
|
42
|
-
body: (<pre className="openapi-example-empty">
|
|
43
|
-
<p>{t(context.translation, 'no_content')}</p>
|
|
44
|
-
</pre>),
|
|
45
|
-
},
|
|
46
|
-
];
|
|
47
|
-
}
|
|
48
|
-
return Object.entries((_a = response.content) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
|
|
49
|
-
var contentType = _a[0], mediaType = _a[1];
|
|
50
|
-
return ({
|
|
51
|
-
key: contentType,
|
|
52
|
-
label: contentType,
|
|
53
|
-
body: (<OpenAPIResponse response={response} mediaType={mediaType} context={context}/>),
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
})();
|
|
57
|
-
var description = resolveDescription(response);
|
|
58
|
-
return {
|
|
59
|
-
key: statusCode,
|
|
60
|
-
label: (<div className="openapi-response-tab-content">
|
|
61
|
-
<span className={clsx('openapi-statuscode', "openapi-statuscode-".concat(getStatusCodeClassName(statusCode)))}>
|
|
62
|
-
{statusCode}
|
|
63
|
-
</span>
|
|
64
|
-
{description ? (<Markdown source={description} className="openapi-response-description"/>) : (getStatusCodeDefaultLabel(statusCode, context))}
|
|
65
|
-
</div>),
|
|
66
|
-
tabs: tabs,
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
var state = useResponseExamplesState(context.blockKey, (_a = groups[0]) === null || _a === void 0 ? void 0 : _a.key);
|
|
70
|
-
return (<StaticSection header={t(context.translation, 'responses')} className="openapi-responses">
|
|
71
|
-
<OpenAPIDisclosureGroup icon={context.icons.chevronRight} expandedKeys={state.key ? new Set([state.key]) : new Set()} onExpandedChange={function (keys) {
|
|
72
|
-
var _a;
|
|
73
|
-
var key = (_a = keys.values().next().value) !== null && _a !== void 0 ? _a : null;
|
|
74
|
-
state.setKey(key);
|
|
75
|
-
}} groups={groups} selectIcon={context.icons.chevronDown} selectStateKey={createStateKey('response-media-types', context.blockKey)}/>
|
|
76
|
-
</StaticSection>);
|
|
77
|
-
}
|
package/dist/OpenAPISchema.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
-
import type { OpenAPIClientContext } from './context';
|
|
3
|
-
export interface OpenAPISchemaPropertyEntry {
|
|
4
|
-
propertyName?: string;
|
|
5
|
-
required?: boolean | null;
|
|
6
|
-
schema: OpenAPIV3.SchemaObject;
|
|
7
|
-
}
|
|
8
|
-
export declare function OpenAPISchemaPropertiesFromServer(props: {
|
|
9
|
-
id?: string;
|
|
10
|
-
properties: string;
|
|
11
|
-
context: OpenAPIClientContext;
|
|
12
|
-
}): import("react").JSX.Element;
|
|
13
|
-
export declare function OpenAPIRootSchemaFromServer(props: {
|
|
14
|
-
schema: string;
|
|
15
|
-
context: OpenAPIClientContext;
|
|
16
|
-
}): import("react").JSX.Element;
|
|
17
|
-
/**
|
|
18
|
-
* Render the top row of a schema. e.g: name, type, and required status.
|
|
19
|
-
*/
|
|
20
|
-
export declare function OpenAPISchemaPresentation(props: {
|
|
21
|
-
property: OpenAPISchemaPropertyEntry;
|
|
22
|
-
context: OpenAPIClientContext;
|
|
23
|
-
}): import("react").JSX.Element;
|
|
24
|
-
/**
|
|
25
|
-
* Get the alternatives to display for a schema.
|
|
26
|
-
*/
|
|
27
|
-
export declare function getSchemaAlternatives(schema: OpenAPIV3.SchemaObject, ancestors?: Set<OpenAPIV3.SchemaObject>): OpenAPIV3.SchemaObject[] | null;
|