@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
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { createContext, useContext, useRef } from 'react';
|
|
4
|
-
import { mergeProps, useButton, useDisclosure, useFocusRing, useId } from 'react-aria';
|
|
5
|
-
import {
|
|
6
|
-
type DisclosureGroupProps,
|
|
7
|
-
type DisclosureGroupState,
|
|
8
|
-
useDisclosureGroupState,
|
|
9
|
-
useDisclosureState,
|
|
10
|
-
} from 'react-stately';
|
|
11
|
-
import { OpenAPISelect, OpenAPISelectItem, useSelectState } from './OpenAPISelect';
|
|
12
|
-
|
|
13
|
-
interface Props {
|
|
14
|
-
groups: TDisclosureGroup[];
|
|
15
|
-
icon?: React.ReactNode;
|
|
16
|
-
/** State key to use with a store */
|
|
17
|
-
selectStateKey?: string;
|
|
18
|
-
/** Icon to display for the select */
|
|
19
|
-
selectIcon?: React.ReactNode;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
type TDisclosureGroup = {
|
|
23
|
-
key: string;
|
|
24
|
-
label: string | React.ReactNode;
|
|
25
|
-
tabs?: {
|
|
26
|
-
key: string;
|
|
27
|
-
label: string | React.ReactNode;
|
|
28
|
-
body?: React.ReactNode;
|
|
29
|
-
}[];
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const DisclosureGroupStateContext = createContext<DisclosureGroupState | null>(null);
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Display an interactive OpenAPI disclosure group.
|
|
36
|
-
*/
|
|
37
|
-
export function OpenAPIDisclosureGroup(props: DisclosureGroupProps & Props) {
|
|
38
|
-
const { icon, groups, selectStateKey, selectIcon } = props;
|
|
39
|
-
|
|
40
|
-
const state = useDisclosureGroupState(props);
|
|
41
|
-
|
|
42
|
-
return (
|
|
43
|
-
<DisclosureGroupStateContext.Provider value={state}>
|
|
44
|
-
{groups.map((group) => (
|
|
45
|
-
<DisclosureItem
|
|
46
|
-
selectStateKey={selectStateKey}
|
|
47
|
-
selectIcon={selectIcon}
|
|
48
|
-
icon={icon}
|
|
49
|
-
key={group.key}
|
|
50
|
-
group={group}
|
|
51
|
-
/>
|
|
52
|
-
))}
|
|
53
|
-
</DisclosureGroupStateContext.Provider>
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function DisclosureItem(props: {
|
|
58
|
-
group: TDisclosureGroup;
|
|
59
|
-
icon?: React.ReactNode;
|
|
60
|
-
selectStateKey?: string;
|
|
61
|
-
selectIcon?: React.ReactNode;
|
|
62
|
-
}) {
|
|
63
|
-
const { icon, group, selectStateKey, selectIcon } = props;
|
|
64
|
-
|
|
65
|
-
const defaultId = useId();
|
|
66
|
-
const id = group.key || defaultId;
|
|
67
|
-
const groupState = useContext(DisclosureGroupStateContext);
|
|
68
|
-
const isExpanded = groupState?.expandedKeys.has(id) || false;
|
|
69
|
-
const state = useDisclosureState({
|
|
70
|
-
isExpanded,
|
|
71
|
-
onExpandedChange() {
|
|
72
|
-
if (groupState) {
|
|
73
|
-
groupState.toggleKey(id);
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const panelRef = useRef<HTMLDivElement | null>(null);
|
|
79
|
-
const triggerRef = useRef<HTMLDivElement | null>(null);
|
|
80
|
-
const isDisabled = groupState?.isDisabled || !group.tabs?.length || false;
|
|
81
|
-
const { buttonProps: triggerProps, panelProps } = useDisclosure(
|
|
82
|
-
{
|
|
83
|
-
...props,
|
|
84
|
-
isExpanded,
|
|
85
|
-
isDisabled,
|
|
86
|
-
},
|
|
87
|
-
state,
|
|
88
|
-
panelRef
|
|
89
|
-
);
|
|
90
|
-
const { buttonProps } = useButton(triggerProps, triggerRef);
|
|
91
|
-
const { isFocusVisible, focusProps } = useFocusRing();
|
|
92
|
-
|
|
93
|
-
const defaultTab = group.tabs?.[0]?.key || '';
|
|
94
|
-
const store = useSelectState(selectStateKey, defaultTab);
|
|
95
|
-
const selectedTab = group.tabs?.find((tab) => tab.key === store.key) || group.tabs?.[0];
|
|
96
|
-
|
|
97
|
-
return (
|
|
98
|
-
<div className="openapi-disclosure-group" aria-expanded={state.isExpanded}>
|
|
99
|
-
<div
|
|
100
|
-
slot="trigger"
|
|
101
|
-
ref={triggerRef}
|
|
102
|
-
{...mergeProps(buttonProps, focusProps)}
|
|
103
|
-
aria-disabled={isDisabled}
|
|
104
|
-
style={{
|
|
105
|
-
outline: isFocusVisible
|
|
106
|
-
? '2px solid rgb(var(--primary-color-500)/0.4)'
|
|
107
|
-
: 'none',
|
|
108
|
-
}}
|
|
109
|
-
className="openapi-disclosure-group-trigger"
|
|
110
|
-
>
|
|
111
|
-
<div className="openapi-disclosure-group-icon">
|
|
112
|
-
{icon || (
|
|
113
|
-
<svg viewBox="0 0 24 24" className="openapi-disclosure-group-icon">
|
|
114
|
-
<path d="m8.25 4.5 7.5 7.5-7.5 7.5" />
|
|
115
|
-
</svg>
|
|
116
|
-
)}
|
|
117
|
-
</div>
|
|
118
|
-
|
|
119
|
-
<div className="openapi-disclosure-group-label">
|
|
120
|
-
{group.label}
|
|
121
|
-
|
|
122
|
-
{group.tabs ? (
|
|
123
|
-
<div
|
|
124
|
-
className="openapi-disclosure-group-mediatype"
|
|
125
|
-
onClick={(e) => e.stopPropagation()}
|
|
126
|
-
>
|
|
127
|
-
{group.tabs?.length > 1 ? (
|
|
128
|
-
<OpenAPISelect
|
|
129
|
-
icon={selectIcon}
|
|
130
|
-
stateKey={selectStateKey}
|
|
131
|
-
onSelectionChange={() => {
|
|
132
|
-
state.expand();
|
|
133
|
-
}}
|
|
134
|
-
items={group.tabs}
|
|
135
|
-
placement="bottom end"
|
|
136
|
-
>
|
|
137
|
-
{group.tabs.map((tab) => (
|
|
138
|
-
<OpenAPISelectItem key={tab.key} id={tab.key} value={tab}>
|
|
139
|
-
{tab.label}
|
|
140
|
-
</OpenAPISelectItem>
|
|
141
|
-
))}
|
|
142
|
-
</OpenAPISelect>
|
|
143
|
-
) : group.tabs[0]?.label ? (
|
|
144
|
-
<span>{group.tabs[0].label}</span>
|
|
145
|
-
) : null}
|
|
146
|
-
</div>
|
|
147
|
-
) : null}
|
|
148
|
-
</div>
|
|
149
|
-
</div>
|
|
150
|
-
|
|
151
|
-
{state.isExpanded && selectedTab && (
|
|
152
|
-
<div className="openapi-disclosure-group-panel" ref={panelRef} {...panelProps}>
|
|
153
|
-
{selectedTab.body}
|
|
154
|
-
</div>
|
|
155
|
-
)}
|
|
156
|
-
</div>
|
|
157
|
-
);
|
|
158
|
-
}
|
package/src/OpenAPIExample.tsx
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
-
import type { OpenAPIContext, OpenAPIUniversalContext } from './context';
|
|
3
|
-
import { json2xml } from './json2xml';
|
|
4
|
-
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
|
5
|
-
import { t } from './translate';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Display an example.
|
|
9
|
-
*/
|
|
10
|
-
export function OpenAPIExample(props: {
|
|
11
|
-
example: OpenAPIV3.ExampleObject;
|
|
12
|
-
context: OpenAPIContext;
|
|
13
|
-
syntax: string;
|
|
14
|
-
}) {
|
|
15
|
-
const { example, context, syntax } = props;
|
|
16
|
-
const code = stringifyExample({ example, xml: syntax === 'xml' });
|
|
17
|
-
|
|
18
|
-
if (code === null) {
|
|
19
|
-
return <OpenAPIEmptyExample context={context} />;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return context.renderCodeBlock({ code, syntax });
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function stringifyExample(args: { example: OpenAPIV3.ExampleObject; xml: boolean }): string | null {
|
|
26
|
-
const { example, xml } = args;
|
|
27
|
-
|
|
28
|
-
if (!example.value) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (typeof example.value === 'string') {
|
|
33
|
-
return example.value;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (xml) {
|
|
37
|
-
return json2xml(example.value);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return stringifyOpenAPI(example.value, null, 2);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Empty response example.
|
|
45
|
-
*/
|
|
46
|
-
export function OpenAPIEmptyExample(props: {
|
|
47
|
-
context: OpenAPIUniversalContext;
|
|
48
|
-
}) {
|
|
49
|
-
const { context } = props;
|
|
50
|
-
return (
|
|
51
|
-
<pre className="openapi-example-empty">
|
|
52
|
-
<p>{t(context.translation, 'no_content')}</p>
|
|
53
|
-
</pre>
|
|
54
|
-
);
|
|
55
|
-
}
|
package/src/OpenAPIMediaType.tsx
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import type { Key } from 'react-aria';
|
|
4
|
-
import { OpenAPIEmptyExample } from './OpenAPIExample';
|
|
5
|
-
import { OpenAPISelect, OpenAPISelectItem, useSelectState } from './OpenAPISelect';
|
|
6
|
-
import { StaticSection } from './StaticSection';
|
|
7
|
-
import type { OpenAPIClientContext } from './context';
|
|
8
|
-
|
|
9
|
-
type OpenAPIMediaTypeItem = OpenAPISelectItem & {
|
|
10
|
-
body: React.ReactNode;
|
|
11
|
-
examples?: OpenAPIMediaTypeItem[];
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Get the state of the response examples select.
|
|
16
|
-
*/
|
|
17
|
-
export function useMediaTypesState(stateKey: string | undefined, initialKey: Key = 'default') {
|
|
18
|
-
return useSelectState(stateKey, initialKey);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function useMediaTypeExamplesState(stateKey: string | undefined, initialKey: Key = 'default') {
|
|
22
|
-
return useSelectState(stateKey, initialKey);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function OpenAPIMediaTypeContent(props: {
|
|
26
|
-
items: OpenAPIMediaTypeItem[];
|
|
27
|
-
selectIcon?: React.ReactNode;
|
|
28
|
-
stateKey: string;
|
|
29
|
-
context: OpenAPIClientContext;
|
|
30
|
-
}) {
|
|
31
|
-
const { stateKey, items, selectIcon, context } = props;
|
|
32
|
-
const state = useMediaTypesState(stateKey, items[0]?.key);
|
|
33
|
-
|
|
34
|
-
const examples = items.find((item) => item.key === state.key)?.examples ?? [];
|
|
35
|
-
|
|
36
|
-
if (!items.length && !examples.length) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return (
|
|
41
|
-
<StaticSection
|
|
42
|
-
footer={
|
|
43
|
-
items.length > 1 || examples.length > 1 ? (
|
|
44
|
-
<OpenAPIMediaTypeFooter
|
|
45
|
-
items={items}
|
|
46
|
-
examples={examples}
|
|
47
|
-
selectIcon={selectIcon}
|
|
48
|
-
stateKey={stateKey}
|
|
49
|
-
/>
|
|
50
|
-
) : null
|
|
51
|
-
}
|
|
52
|
-
className="openapi-response-media-types-examples"
|
|
53
|
-
>
|
|
54
|
-
<OpenAPIMediaTypeBody
|
|
55
|
-
context={context}
|
|
56
|
-
stateKey={stateKey}
|
|
57
|
-
items={items}
|
|
58
|
-
examples={examples}
|
|
59
|
-
/>
|
|
60
|
-
</StaticSection>
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function OpenAPIMediaTypeFooter(props: {
|
|
65
|
-
items: OpenAPIMediaTypeItem[];
|
|
66
|
-
examples?: OpenAPIMediaTypeItem[];
|
|
67
|
-
selectIcon?: React.ReactNode;
|
|
68
|
-
stateKey: string;
|
|
69
|
-
}) {
|
|
70
|
-
const { items, examples, stateKey, selectIcon } = props;
|
|
71
|
-
|
|
72
|
-
return (
|
|
73
|
-
<>
|
|
74
|
-
{items.length > 1 && (
|
|
75
|
-
<OpenAPISelect
|
|
76
|
-
icon={selectIcon}
|
|
77
|
-
items={items}
|
|
78
|
-
stateKey={stateKey}
|
|
79
|
-
placement="bottom start"
|
|
80
|
-
>
|
|
81
|
-
{items.map((item) => (
|
|
82
|
-
<OpenAPISelectItem key={item.key} id={item.key} value={item}>
|
|
83
|
-
<span>{item.label}</span>
|
|
84
|
-
</OpenAPISelectItem>
|
|
85
|
-
))}
|
|
86
|
-
</OpenAPISelect>
|
|
87
|
-
)}
|
|
88
|
-
|
|
89
|
-
{examples && examples.length > 1 ? (
|
|
90
|
-
<OpenAPISelect
|
|
91
|
-
icon={selectIcon}
|
|
92
|
-
items={examples}
|
|
93
|
-
stateKey={`${stateKey}-examples`}
|
|
94
|
-
placement="bottom start"
|
|
95
|
-
>
|
|
96
|
-
{examples.map((example) => (
|
|
97
|
-
<OpenAPISelectItem key={example.key} id={example.key} value={example}>
|
|
98
|
-
<span>{example.label}</span>
|
|
99
|
-
</OpenAPISelectItem>
|
|
100
|
-
))}
|
|
101
|
-
</OpenAPISelect>
|
|
102
|
-
) : null}
|
|
103
|
-
</>
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function OpenAPIMediaTypeBody(props: {
|
|
108
|
-
items: OpenAPIMediaTypeItem[];
|
|
109
|
-
examples?: OpenAPIMediaTypeItem[];
|
|
110
|
-
stateKey: string;
|
|
111
|
-
context: OpenAPIClientContext;
|
|
112
|
-
}) {
|
|
113
|
-
const { stateKey, items, examples, context } = props;
|
|
114
|
-
const state = useMediaTypesState(stateKey, items[0]?.key);
|
|
115
|
-
|
|
116
|
-
const selectedItem = items.find((item) => item.key === state.key) ?? items[0];
|
|
117
|
-
|
|
118
|
-
const exampleState = useMediaTypeExamplesState(
|
|
119
|
-
`${stateKey}-examples`,
|
|
120
|
-
selectedItem?.examples?.[0]?.key
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
if (!selectedItem) {
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (examples) {
|
|
128
|
-
const selectedExample =
|
|
129
|
-
examples.find((example) => example.key === exampleState.key) ?? examples[0];
|
|
130
|
-
|
|
131
|
-
if (!selectedExample) {
|
|
132
|
-
return <OpenAPIEmptyExample context={context} />;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return selectedExample.body;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return selectedItem.body;
|
|
139
|
-
}
|
package/src/OpenAPIOperation.tsx
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import clsx from 'clsx';
|
|
2
|
-
import { OpenAPICodeSample } from './OpenAPICodeSample';
|
|
3
|
-
import { OpenAPIResponseExample } from './OpenAPIResponseExample';
|
|
4
|
-
import { OpenAPIColumnSpec } from './common/OpenAPIColumnSpec';
|
|
5
|
-
import { OpenAPISummary } from './common/OpenAPISummary';
|
|
6
|
-
import { type OpenAPIContextInput, resolveOpenAPIContext } from './context';
|
|
7
|
-
import type { OpenAPIOperationData } from './types';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Display an interactive OpenAPI operation.
|
|
11
|
-
*/
|
|
12
|
-
export function OpenAPIOperation(props: {
|
|
13
|
-
className?: string;
|
|
14
|
-
data: OpenAPIOperationData;
|
|
15
|
-
context: OpenAPIContextInput;
|
|
16
|
-
}) {
|
|
17
|
-
const { className, data, context: contextInput } = props;
|
|
18
|
-
|
|
19
|
-
const context = resolveOpenAPIContext(contextInput);
|
|
20
|
-
|
|
21
|
-
return (
|
|
22
|
-
<div className={clsx('openapi-operation', className)}>
|
|
23
|
-
<OpenAPISummary data={data} context={context} />
|
|
24
|
-
<div className="openapi-columns">
|
|
25
|
-
<OpenAPIColumnSpec data={data} context={context} />
|
|
26
|
-
<div className="openapi-column-preview">
|
|
27
|
-
<div className="openapi-column-preview-body">
|
|
28
|
-
<OpenAPICodeSample data={data} context={context} />
|
|
29
|
-
<OpenAPIResponseExample data={data} context={context} />
|
|
30
|
-
</div>
|
|
31
|
-
</div>
|
|
32
|
-
</div>
|
|
33
|
-
</div>
|
|
34
|
-
);
|
|
35
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { createContext, useContext, useMemo } from 'react';
|
|
4
|
-
import { useEventCallback } from 'usehooks-ts';
|
|
5
|
-
|
|
6
|
-
interface OpenAPIOperationPointer {
|
|
7
|
-
path: string;
|
|
8
|
-
method: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface OpenAPIOperationContextValue {
|
|
12
|
-
onOpenClient: (pointer: OpenAPIOperationPointer) => void;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const OpenAPIOperationContext = createContext<OpenAPIOperationContextValue>({
|
|
16
|
-
onOpenClient: () => {},
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Provider for the OpenAPIOperationContext.
|
|
21
|
-
*/
|
|
22
|
-
export function OpenAPIOperationContextProvider(
|
|
23
|
-
props: React.PropsWithChildren<Partial<OpenAPIOperationContextValue>>
|
|
24
|
-
) {
|
|
25
|
-
const { children } = props;
|
|
26
|
-
|
|
27
|
-
const onOpenClient = useEventCallback((pointer: OpenAPIOperationPointer) => {
|
|
28
|
-
props.onOpenClient?.(pointer);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const value = useMemo(() => ({ onOpenClient }), [onOpenClient]);
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<OpenAPIOperationContext.Provider value={value}>
|
|
35
|
-
{children}
|
|
36
|
-
</OpenAPIOperationContext.Provider>
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Hook to access the OpenAPIOperationContext.
|
|
42
|
-
*/
|
|
43
|
-
export function useOpenAPIOperationContext() {
|
|
44
|
-
return useContext(OpenAPIOperationContext);
|
|
45
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { OpenAPICustomOperationProperties, OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
-
import { Markdown } from './Markdown';
|
|
3
|
-
import type { OpenAPIContext } from './context';
|
|
4
|
-
import { resolveDescription } from './utils';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Display the description of an OpenAPI operation.
|
|
8
|
-
*/
|
|
9
|
-
export function OpenAPIOperationDescription(props: {
|
|
10
|
-
operation: OpenAPIV3.OperationObject<OpenAPICustomOperationProperties>;
|
|
11
|
-
context: OpenAPIContext;
|
|
12
|
-
}) {
|
|
13
|
-
const { operation } = props;
|
|
14
|
-
if (operation['x-gitbook-description-document']) {
|
|
15
|
-
return (
|
|
16
|
-
<div className="openapi-intro">
|
|
17
|
-
{props.context.renderDocument({
|
|
18
|
-
document: operation['x-gitbook-description-document'],
|
|
19
|
-
})}
|
|
20
|
-
</div>
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const description = resolveDescription(operation);
|
|
25
|
-
if (!description) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<div className="openapi-intro">
|
|
31
|
-
<Markdown className="openapi-description" source={description} />
|
|
32
|
-
</div>
|
|
33
|
-
);
|
|
34
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { OpenAPIStability } from '@gitbook/openapi-parser';
|
|
2
|
-
import type { OpenAPIContext } from './context';
|
|
3
|
-
import { t } from './translate';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Display the stability of an OpenAPI operation.
|
|
7
|
-
*/
|
|
8
|
-
export function OpenAPIOperationStability(props: {
|
|
9
|
-
stability: OpenAPIStability;
|
|
10
|
-
context: OpenAPIContext;
|
|
11
|
-
}) {
|
|
12
|
-
const { stability, context } = props;
|
|
13
|
-
|
|
14
|
-
const stabilityLabel = getStabilityLabel(stability, context);
|
|
15
|
-
|
|
16
|
-
if (!stabilityLabel) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<div className={`openapi-stability openapi-stability-${stability}`}>{stabilityLabel}</div>
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Get the stability label for the given stability level.
|
|
27
|
-
*/
|
|
28
|
-
function getStabilityLabel(stability: OpenAPIStability, context: OpenAPIContext) {
|
|
29
|
-
switch (stability) {
|
|
30
|
-
case 'experimental':
|
|
31
|
-
return t(context.translation, 'stability_experimental');
|
|
32
|
-
case 'alpha':
|
|
33
|
-
return t(context.translation, 'stability_alpha');
|
|
34
|
-
case 'beta':
|
|
35
|
-
return t(context.translation, 'stability_beta');
|
|
36
|
-
default:
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
}
|
package/src/OpenAPIPath.tsx
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { OpenAPICopyButton } from './OpenAPICopyButton';
|
|
2
|
-
import { type OpenAPIUniversalContext, getOpenAPIClientContext } from './context';
|
|
3
|
-
import type { OpenAPIOperationData } from './types';
|
|
4
|
-
import { getDefaultServerURL } from './util/server';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Display the path of an operation.
|
|
8
|
-
*/
|
|
9
|
-
export function OpenAPIPath(props: {
|
|
10
|
-
data: OpenAPIOperationData;
|
|
11
|
-
context: OpenAPIUniversalContext;
|
|
12
|
-
/** Whether to show the server URL.
|
|
13
|
-
* @default true
|
|
14
|
-
*/
|
|
15
|
-
withServer?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Whether the path is copyable.
|
|
18
|
-
* @default true
|
|
19
|
-
*/
|
|
20
|
-
canCopy?: boolean;
|
|
21
|
-
}) {
|
|
22
|
-
const { data, context, withServer = true, canCopy = true } = props;
|
|
23
|
-
const { method, path, operation } = data;
|
|
24
|
-
|
|
25
|
-
const server = getDefaultServerURL(data.servers);
|
|
26
|
-
const formattedPath = formatPath(path);
|
|
27
|
-
|
|
28
|
-
const element = (() => {
|
|
29
|
-
return (
|
|
30
|
-
<>
|
|
31
|
-
{withServer ? <span className="openapi-path-server">{server}</span> : null}
|
|
32
|
-
{formattedPath}
|
|
33
|
-
</>
|
|
34
|
-
);
|
|
35
|
-
})();
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<div className="openapi-path">
|
|
39
|
-
<div className={`openapi-method openapi-method-${method}`}>{method}</div>
|
|
40
|
-
|
|
41
|
-
<OpenAPICopyButton
|
|
42
|
-
value={`${withServer ? server : ''}${path}`}
|
|
43
|
-
className="openapi-path-title"
|
|
44
|
-
data-deprecated={operation.deprecated}
|
|
45
|
-
isDisabled={!canCopy}
|
|
46
|
-
context={getOpenAPIClientContext(context)}
|
|
47
|
-
>
|
|
48
|
-
{element}
|
|
49
|
-
</OpenAPICopyButton>
|
|
50
|
-
</div>
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Format the path by wrapping placeholders in <span> tags.
|
|
56
|
-
*/
|
|
57
|
-
function formatPath(path: string) {
|
|
58
|
-
// Matches placeholders like {id}, {userId}, etc.
|
|
59
|
-
const regex = /\{\s*(\w+)\s*\}|:\w+/g;
|
|
60
|
-
|
|
61
|
-
const parts: (string | React.JSX.Element)[] = [];
|
|
62
|
-
let lastIndex = 0;
|
|
63
|
-
|
|
64
|
-
//Wrap the variables in <span> tags and maintain either {variable} or :variable
|
|
65
|
-
path.replace(regex, (match, _, offset) => {
|
|
66
|
-
if (offset > lastIndex) {
|
|
67
|
-
parts.push(path.slice(lastIndex, offset));
|
|
68
|
-
}
|
|
69
|
-
parts.push(
|
|
70
|
-
<span key={`offset-${offset}`} className="openapi-path-variable">
|
|
71
|
-
{match}
|
|
72
|
-
</span>
|
|
73
|
-
);
|
|
74
|
-
lastIndex = offset + match.length;
|
|
75
|
-
return match;
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
if (lastIndex < path.length) {
|
|
79
|
-
parts.push(path.slice(lastIndex));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const formattedPath = parts.map((part, index) => {
|
|
83
|
-
if (typeof part === 'string') {
|
|
84
|
-
return <span key={`part-${index}`}>{part}</span>;
|
|
85
|
-
}
|
|
86
|
-
return part;
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
return formattedPath;
|
|
90
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Prefill data that can be used to dynamically inject info into OpenAPI operation blocks.
|
|
7
|
-
*
|
|
8
|
-
* This is typically dynamic input context, such as visitor data or environment info.
|
|
9
|
-
*/
|
|
10
|
-
export type PrefillInputContextData = Record<string, unknown>;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Context value is function that returns prefill data.
|
|
14
|
-
*/
|
|
15
|
-
type PrefillContextValue = () => PrefillInputContextData | null;
|
|
16
|
-
|
|
17
|
-
const OpenAPIPrefillContext = React.createContext<PrefillContextValue | null>(null);
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Provide context to help prefill dynamic info like visitor data in OpenAPI blocks.
|
|
21
|
-
*/
|
|
22
|
-
export function OpenAPIPrefillContextProvider(
|
|
23
|
-
props: React.PropsWithChildren<{
|
|
24
|
-
getPrefillInputContextData: () => PrefillInputContextData | null;
|
|
25
|
-
}>
|
|
26
|
-
) {
|
|
27
|
-
const { getPrefillInputContextData, children } = props;
|
|
28
|
-
return (
|
|
29
|
-
<OpenAPIPrefillContext.Provider value={getPrefillInputContextData}>
|
|
30
|
-
{children}
|
|
31
|
-
</OpenAPIPrefillContext.Provider>
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Hook to access the prefill context function.
|
|
37
|
-
*/
|
|
38
|
-
export function useOpenAPIPrefillContext(): PrefillContextValue {
|
|
39
|
-
return React.useContext(OpenAPIPrefillContext) ?? (() => null);
|
|
40
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
-
import { InteractiveSection } from './InteractiveSection';
|
|
3
|
-
import { OpenAPIRequestBodyHeaderType } from './OpenAPIRequestBodyHeaderType';
|
|
4
|
-
import { OpenAPIRootSchema } from './OpenAPISchemaServer';
|
|
5
|
-
import type { OpenAPIClientContext } from './context';
|
|
6
|
-
import { t } from './translate';
|
|
7
|
-
import type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
|
|
8
|
-
import { checkIsReference, createStateKey } from './utils';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Display an interactive request body.
|
|
12
|
-
*/
|
|
13
|
-
export function OpenAPIRequestBody(props: {
|
|
14
|
-
requestBody: OpenAPIV3.RequestBodyObject | OpenAPIV3.ReferenceObject;
|
|
15
|
-
context: OpenAPIClientContext;
|
|
16
|
-
data: OpenAPIOperationData | OpenAPIWebhookData;
|
|
17
|
-
}) {
|
|
18
|
-
const { requestBody, context, data } = props;
|
|
19
|
-
|
|
20
|
-
if (checkIsReference(requestBody)) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const stateKey = createStateKey('request-body-media-type', context.blockKey);
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<InteractiveSection
|
|
28
|
-
header={
|
|
29
|
-
<>
|
|
30
|
-
<span>{t(context.translation, 'name' in data ? 'payload' : 'body')}</span>
|
|
31
|
-
<OpenAPIRequestBodyHeaderType requestBody={requestBody} stateKey={stateKey} />
|
|
32
|
-
</>
|
|
33
|
-
}
|
|
34
|
-
className="openapi-requestbody"
|
|
35
|
-
stateKey={stateKey}
|
|
36
|
-
selectIcon={context.icons.chevronDown}
|
|
37
|
-
tabs={Object.entries(requestBody.content ?? {}).map(
|
|
38
|
-
([contentType, mediaTypeObject]) => {
|
|
39
|
-
return {
|
|
40
|
-
key: contentType,
|
|
41
|
-
label: contentType,
|
|
42
|
-
body: (
|
|
43
|
-
<OpenAPIRootSchema
|
|
44
|
-
schema={mediaTypeObject.schema ?? {}}
|
|
45
|
-
context={context}
|
|
46
|
-
key={contentType}
|
|
47
|
-
/>
|
|
48
|
-
),
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
)}
|
|
52
|
-
/>
|
|
53
|
-
);
|
|
54
|
-
}
|