@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.
Files changed (225) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/index.d.ts +663 -10
  3. package/dist/index.js +3873 -8
  4. package/package.json +11 -7
  5. package/dist/InteractiveSection.d.ts +0 -33
  6. package/dist/InteractiveSection.jsx +0 -61
  7. package/dist/Markdown.d.ts +0 -4
  8. package/dist/Markdown.jsx +0 -5
  9. package/dist/OpenAPICodeSample.d.ts +0 -19
  10. package/dist/OpenAPICodeSample.jsx +0 -230
  11. package/dist/OpenAPICodeSampleInteractive.d.ts +0 -14
  12. package/dist/OpenAPICodeSampleInteractive.jsx +0 -73
  13. package/dist/OpenAPICodeSampleSelector.d.ts +0 -14
  14. package/dist/OpenAPICodeSampleSelector.jsx +0 -44
  15. package/dist/OpenAPICopyButton.d.ts +0 -13
  16. package/dist/OpenAPICopyButton.jsx +0 -35
  17. package/dist/OpenAPIDisclosure.d.ts +0 -11
  18. package/dist/OpenAPIDisclosure.jsx +0 -30
  19. package/dist/OpenAPIDisclosureGroup.d.ts +0 -23
  20. package/dist/OpenAPIDisclosureGroup.jsx +0 -83
  21. package/dist/OpenAPIExample.d.ts +0 -16
  22. package/dist/OpenAPIExample.jsx +0 -36
  23. package/dist/OpenAPIMediaType.d.ts +0 -21
  24. package/dist/OpenAPIMediaType.jsx +0 -61
  25. package/dist/OpenAPIOperation.d.ts +0 -10
  26. package/dist/OpenAPIOperation.jsx +0 -25
  27. package/dist/OpenAPIOperationContext.d.ts +0 -16
  28. package/dist/OpenAPIOperationContext.jsx +0 -26
  29. package/dist/OpenAPIOperationDescription.d.ts +0 -9
  30. package/dist/OpenAPIOperationDescription.jsx +0 -22
  31. package/dist/OpenAPIOperationStability.d.ts +0 -9
  32. package/dist/OpenAPIOperationStability.jsx +0 -27
  33. package/dist/OpenAPIPath.d.ts +0 -18
  34. package/dist/OpenAPIPath.jsx +0 -55
  35. package/dist/OpenAPIPrefillContextProvider.d.ts +0 -22
  36. package/dist/OpenAPIPrefillContextProvider.jsx +0 -19
  37. package/dist/OpenAPIRequestBody.d.ts +0 -11
  38. package/dist/OpenAPIRequestBody.jsx +0 -28
  39. package/dist/OpenAPIRequestBodyHeaderType.d.ts +0 -8
  40. package/dist/OpenAPIRequestBodyHeaderType.jsx +0 -25
  41. package/dist/OpenAPIResponse.d.ts +0 -10
  42. package/dist/OpenAPIResponse.jsx +0 -57
  43. package/dist/OpenAPIResponseExample.d.ts +0 -9
  44. package/dist/OpenAPIResponseExample.jsx +0 -105
  45. package/dist/OpenAPIResponseExampleContent.d.ts +0 -22
  46. package/dist/OpenAPIResponseExampleContent.jsx +0 -60
  47. package/dist/OpenAPIResponses.d.ts +0 -9
  48. package/dist/OpenAPIResponses.jsx +0 -77
  49. package/dist/OpenAPISchema.d.ts +0 -27
  50. package/dist/OpenAPISchema.jsx +0 -400
  51. package/dist/OpenAPISchemaName.d.ts +0 -16
  52. package/dist/OpenAPISchemaName.jsx +0 -43
  53. package/dist/OpenAPISchemaServer.d.ts +0 -12
  54. package/dist/OpenAPISchemaServer.jsx +0 -8
  55. package/dist/OpenAPISecurities.d.ts +0 -9
  56. package/dist/OpenAPISecurities.jsx +0 -114
  57. package/dist/OpenAPISelect.d.ts +0 -22
  58. package/dist/OpenAPISelect.jsx +0 -44
  59. package/dist/OpenAPISpec.d.ts +0 -6
  60. package/dist/OpenAPISpec.jsx +0 -80
  61. package/dist/OpenAPITabs.d.ts +0 -26
  62. package/dist/OpenAPITabs.jsx +0 -109
  63. package/dist/OpenAPIWebhook.d.ts +0 -10
  64. package/dist/OpenAPIWebhook.jsx +0 -23
  65. package/dist/OpenAPIWebhookExample.d.ts +0 -6
  66. package/dist/OpenAPIWebhookExample.jsx +0 -41
  67. package/dist/ScalarApiButton.d.ts +0 -14
  68. package/dist/ScalarApiButton.jsx +0 -81
  69. package/dist/StaticSection.d.ts +0 -13
  70. package/dist/StaticSection.jsx +0 -32
  71. package/dist/code-samples.d.ts +0 -17
  72. package/dist/code-samples.js +0 -427
  73. package/dist/common/OpenAPIColumnSpec.d.ts +0 -6
  74. package/dist/common/OpenAPIColumnSpec.jsx +0 -20
  75. package/dist/common/OpenAPIOperationDescription.d.ts +0 -6
  76. package/dist/common/OpenAPIOperationDescription.jsx +0 -19
  77. package/dist/common/OpenAPIStability.d.ts +0 -4
  78. package/dist/common/OpenAPIStability.jsx +0 -15
  79. package/dist/common/OpenAPISummary.d.ts +0 -6
  80. package/dist/common/OpenAPISummary.jsx +0 -30
  81. package/dist/contentTypeChecks.d.ts +0 -10
  82. package/dist/contentTypeChecks.js +0 -30
  83. package/dist/context.d.ts +0 -75
  84. package/dist/context.js +0 -43
  85. package/dist/decycle.d.ts +0 -2
  86. package/dist/decycle.js +0 -70
  87. package/dist/dereference.d.ts +0 -5
  88. package/dist/dereference.js +0 -68
  89. package/dist/generateSchemaExample.d.ts +0 -45
  90. package/dist/generateSchemaExample.js +0 -342
  91. package/dist/getDisclosureLabel.d.ts +0 -7
  92. package/dist/getDisclosureLabel.js +0 -18
  93. package/dist/getOrCreateStoreByKey.d.ts +0 -10
  94. package/dist/getOrCreateStoreByKey.js +0 -19
  95. package/dist/json2xml.d.ts +0 -4
  96. package/dist/json2xml.js +0 -7
  97. package/dist/resolveOpenAPIOperation.d.ts +0 -11
  98. package/dist/resolveOpenAPIOperation.js +0 -173
  99. package/dist/resolveOpenAPIWebhook.d.ts +0 -11
  100. package/dist/resolveOpenAPIWebhook.js +0 -127
  101. package/dist/schemas/OpenAPISchemaItem.d.ts +0 -7
  102. package/dist/schemas/OpenAPISchemaItem.jsx +0 -16
  103. package/dist/schemas/OpenAPISchemas.d.ts +0 -14
  104. package/dist/schemas/OpenAPISchemas.jsx +0 -59
  105. package/dist/schemas/index.d.ts +0 -2
  106. package/dist/schemas/index.js +0 -2
  107. package/dist/schemas/resolveOpenAPISchemas.d.ts +0 -10
  108. package/dist/schemas/resolveOpenAPISchemas.js +0 -61
  109. package/dist/stringifyOpenAPI.d.ts +0 -4
  110. package/dist/stringifyOpenAPI.js +0 -15
  111. package/dist/translate.d.ts +0 -10
  112. package/dist/translate.jsx +0 -75
  113. package/dist/translations/de.d.ts +0 -43
  114. package/dist/translations/de.js +0 -43
  115. package/dist/translations/en.d.ts +0 -43
  116. package/dist/translations/en.js +0 -43
  117. package/dist/translations/es.d.ts +0 -43
  118. package/dist/translations/es.js +0 -43
  119. package/dist/translations/fr.d.ts +0 -43
  120. package/dist/translations/fr.js +0 -43
  121. package/dist/translations/index.d.ts +0 -395
  122. package/dist/translations/index.js +0 -27
  123. package/dist/translations/ja.d.ts +0 -43
  124. package/dist/translations/ja.js +0 -43
  125. package/dist/translations/nl.d.ts +0 -43
  126. package/dist/translations/nl.js +0 -43
  127. package/dist/translations/no.d.ts +0 -43
  128. package/dist/translations/no.js +0 -43
  129. package/dist/translations/pt-br.d.ts +0 -43
  130. package/dist/translations/pt-br.js +0 -43
  131. package/dist/translations/types.d.ts +0 -5
  132. package/dist/translations/types.js +0 -1
  133. package/dist/translations/zh.d.ts +0 -43
  134. package/dist/translations/zh.js +0 -43
  135. package/dist/tsconfig.build.tsbuildinfo +0 -1
  136. package/dist/types.d.ts +0 -31
  137. package/dist/types.js +0 -1
  138. package/dist/util/example.d.ts +0 -35
  139. package/dist/util/example.jsx +0 -103
  140. package/dist/util/server.d.ts +0 -9
  141. package/dist/util/server.js +0 -44
  142. package/dist/util/tryit-prefill.d.ts +0 -20
  143. package/dist/util/tryit-prefill.js +0 -129
  144. package/dist/utils.d.ts +0 -50
  145. package/dist/utils.js +0 -224
  146. package/src/InteractiveSection.tsx +0 -147
  147. package/src/Markdown.tsx +0 -12
  148. package/src/OpenAPICodeSample.tsx +0 -330
  149. package/src/OpenAPICodeSampleInteractive.tsx +0 -136
  150. package/src/OpenAPICodeSampleSelector.tsx +0 -94
  151. package/src/OpenAPICopyButton.tsx +0 -72
  152. package/src/OpenAPIDisclosure.tsx +0 -46
  153. package/src/OpenAPIDisclosureGroup.tsx +0 -158
  154. package/src/OpenAPIExample.tsx +0 -55
  155. package/src/OpenAPIMediaType.tsx +0 -139
  156. package/src/OpenAPIOperation.tsx +0 -35
  157. package/src/OpenAPIOperationContext.tsx +0 -45
  158. package/src/OpenAPIOperationDescription.tsx +0 -34
  159. package/src/OpenAPIOperationStability.tsx +0 -39
  160. package/src/OpenAPIPath.tsx +0 -90
  161. package/src/OpenAPIPrefillContextProvider.tsx +0 -40
  162. package/src/OpenAPIRequestBody.tsx +0 -54
  163. package/src/OpenAPIRequestBodyHeaderType.tsx +0 -36
  164. package/src/OpenAPIResponse.tsx +0 -82
  165. package/src/OpenAPIResponseExample.tsx +0 -151
  166. package/src/OpenAPIResponseExampleContent.tsx +0 -125
  167. package/src/OpenAPIResponses.tsx +0 -125
  168. package/src/OpenAPISchema.test.ts +0 -172
  169. package/src/OpenAPISchema.tsx +0 -654
  170. package/src/OpenAPISchemaName.tsx +0 -80
  171. package/src/OpenAPISchemaServer.tsx +0 -34
  172. package/src/OpenAPISecurities.tsx +0 -231
  173. package/src/OpenAPISelect.tsx +0 -96
  174. package/src/OpenAPISpec.tsx +0 -138
  175. package/src/OpenAPITabs.tsx +0 -147
  176. package/src/OpenAPIWebhook.tsx +0 -33
  177. package/src/OpenAPIWebhookExample.tsx +0 -60
  178. package/src/ScalarApiButton.tsx +0 -132
  179. package/src/StaticSection.tsx +0 -91
  180. package/src/__snapshots__/json2xml.test.ts.snap +0 -18
  181. package/src/code-samples.test.ts +0 -714
  182. package/src/code-samples.ts +0 -448
  183. package/src/common/OpenAPIColumnSpec.tsx +0 -31
  184. package/src/common/OpenAPIOperationDescription.tsx +0 -31
  185. package/src/common/OpenAPIStability.tsx +0 -23
  186. package/src/common/OpenAPISummary.tsx +0 -45
  187. package/src/contentTypeChecks.ts +0 -39
  188. package/src/context.ts +0 -99
  189. package/src/decycle.ts +0 -68
  190. package/src/dereference.ts +0 -29
  191. package/src/generateSchemaExample.test.ts +0 -1040
  192. package/src/generateSchemaExample.ts +0 -530
  193. package/src/getDisclosureLabel.ts +0 -25
  194. package/src/getOrCreateStoreByKey.ts +0 -33
  195. package/src/index.ts +0 -10
  196. package/src/json2xml.test.ts +0 -46
  197. package/src/json2xml.ts +0 -8
  198. package/src/resolveOpenAPIOperation.test.ts +0 -177
  199. package/src/resolveOpenAPIOperation.ts +0 -151
  200. package/src/resolveOpenAPIWebhook.ts +0 -99
  201. package/src/schemas/OpenAPISchemaItem.tsx +0 -34
  202. package/src/schemas/OpenAPISchemas.tsx +0 -98
  203. package/src/schemas/index.ts +0 -2
  204. package/src/schemas/resolveOpenAPISchemas.test.ts +0 -174
  205. package/src/schemas/resolveOpenAPISchemas.ts +0 -28
  206. package/src/stringifyOpenAPI.ts +0 -25
  207. package/src/translate.tsx +0 -80
  208. package/src/translations/de.ts +0 -43
  209. package/src/translations/en.ts +0 -43
  210. package/src/translations/es.ts +0 -43
  211. package/src/translations/fr.ts +0 -43
  212. package/src/translations/index.ts +0 -33
  213. package/src/translations/ja.ts +0 -43
  214. package/src/translations/nl.ts +0 -43
  215. package/src/translations/no.ts +0 -43
  216. package/src/translations/pt-br.ts +0 -43
  217. package/src/translations/types.ts +0 -7
  218. package/src/translations/zh.ts +0 -43
  219. package/src/types.ts +0 -46
  220. package/src/util/example.tsx +0 -129
  221. package/src/util/server.test.ts +0 -58
  222. package/src/util/server.ts +0 -47
  223. package/src/util/tryit-prefill.test.ts +0 -311
  224. package/src/util/tryit-prefill.ts +0 -160
  225. package/src/utils.ts +0 -255
@@ -1,80 +0,0 @@
1
- import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
- import type React from 'react';
3
- import type { OpenAPIClientContext } from './context';
4
- import { t, tString } from './translate';
5
-
6
- interface OpenAPISchemaNameProps {
7
- schema?: OpenAPIV3.SchemaObject;
8
- propertyName?: string | React.JSX.Element;
9
- required?: boolean | null;
10
- type?: string;
11
- context: OpenAPIClientContext;
12
- }
13
-
14
- /**
15
- * Display the schema name row.
16
- * It includes the property name, type, required and deprecated status.
17
- */
18
- export function OpenAPISchemaName(props: OpenAPISchemaNameProps) {
19
- const { schema, type, propertyName, required, context } = props;
20
-
21
- const additionalItems = schema && getAdditionalItems(schema, context);
22
-
23
- return (
24
- <span className="openapi-schema-name">
25
- {propertyName ? (
26
- <span data-deprecated={schema?.deprecated} className="openapi-schema-propertyname">
27
- {propertyName}
28
- </span>
29
- ) : null}
30
- {type || additionalItems ? (
31
- <span>
32
- {type ? <span className="openapi-schema-type">{type}</span> : null}
33
- {additionalItems ? (
34
- <span className="openapi-schema-type">{additionalItems}</span>
35
- ) : null}
36
- </span>
37
- ) : null}
38
- {schema?.readOnly ? (
39
- <span className="openapi-schema-readonly">
40
- {t(context.translation, 'read_only')}
41
- </span>
42
- ) : null}
43
- {schema?.writeOnly ? (
44
- <span className="openapi-schema-writeonly">
45
- {t(context.translation, 'write_only')}
46
- </span>
47
- ) : null}
48
- {required === null ? null : required ? (
49
- <span className="openapi-schema-required">
50
- {t(context.translation, 'required')}
51
- </span>
52
- ) : (
53
- <span className="openapi-schema-optional">
54
- {t(context.translation, 'optional')}
55
- </span>
56
- )}
57
- {schema?.deprecated ? (
58
- <span className="openapi-deprecated">{t(context.translation, 'deprecated')}</span>
59
- ) : null}
60
- </span>
61
- );
62
- }
63
-
64
- function getAdditionalItems(schema: OpenAPIV3.SchemaObject, context: OpenAPIClientContext): string {
65
- let additionalItems = '';
66
-
67
- if (schema.minimum || schema.minLength || schema.minItems) {
68
- additionalItems += ` · ${tString(context.translation, 'min').toLowerCase()}: ${schema.minimum || schema.minLength || schema.minItems}`;
69
- }
70
-
71
- if (schema.maximum || schema.maxLength || schema.maxItems) {
72
- additionalItems += ` · ${tString(context.translation, 'max').toLowerCase()}: ${schema.maximum || schema.maxLength || schema.maxItems}`;
73
- }
74
-
75
- if (schema.nullable) {
76
- additionalItems = ` | ${tString(context.translation, 'nullable').toLowerCase()}`;
77
- }
78
-
79
- return additionalItems;
80
- }
@@ -1,34 +0,0 @@
1
- import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
- import {
3
- OpenAPIRootSchemaFromServer,
4
- OpenAPISchemaPropertiesFromServer,
5
- type OpenAPISchemaPropertyEntry,
6
- } from './OpenAPISchema';
7
- import type { OpenAPIClientContext } from './context';
8
- import { decycle } from './decycle';
9
-
10
- export function OpenAPISchemaProperties(props: {
11
- id?: string;
12
- properties: OpenAPISchemaPropertyEntry[];
13
- context: OpenAPIClientContext;
14
- }) {
15
- return (
16
- <OpenAPISchemaPropertiesFromServer
17
- id={props.id}
18
- properties={JSON.stringify(props.properties, decycle())}
19
- context={props.context}
20
- />
21
- );
22
- }
23
-
24
- export function OpenAPIRootSchema(props: {
25
- schema: OpenAPIV3.SchemaObject;
26
- context: OpenAPIClientContext;
27
- }) {
28
- return (
29
- <OpenAPIRootSchemaFromServer
30
- schema={JSON.stringify(props.schema, decycle())}
31
- context={props.context}
32
- />
33
- );
34
- }
@@ -1,231 +0,0 @@
1
- import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
- import { InteractiveSection } from './InteractiveSection';
3
- import { Markdown } from './Markdown';
4
- import { OpenAPICopyButton } from './OpenAPICopyButton';
5
- import { OpenAPISchemaName } from './OpenAPISchemaName';
6
- import type { OpenAPIClientContext } from './context';
7
- import { t } from './translate';
8
- import type { OpenAPIOperationData, OpenAPISecurityWithRequired } from './types';
9
- import { createStateKey, resolveDescription } from './utils';
10
-
11
- /**
12
- * Present securities authorization that can be used for this operation.
13
- */
14
- export function OpenAPISecurities(props: {
15
- securities: OpenAPIOperationData['securities'];
16
- context: OpenAPIClientContext;
17
- }) {
18
- const { securities, context } = props;
19
-
20
- if (securities.length === 0) {
21
- return null;
22
- }
23
-
24
- return (
25
- <InteractiveSection
26
- header={t(context.translation, 'authorizations')}
27
- stateKey={createStateKey('securities', context.blockKey)}
28
- toggeable
29
- defaultOpened={false}
30
- toggleIcon={context.icons.chevronRight}
31
- selectIcon={context.icons.chevronDown}
32
- className="openapi-securities"
33
- tabs={securities.map(([key, security]) => {
34
- const description = resolveDescription(security);
35
- return {
36
- key: key,
37
- label: key,
38
- body: (
39
- <div className="openapi-schema">
40
- <div className="openapi-schema-presentation">
41
- {getLabelForType(security, context)}
42
-
43
- {description ? (
44
- <Markdown
45
- source={description}
46
- className="openapi-securities-description"
47
- />
48
- ) : null}
49
- </div>
50
- </div>
51
- ),
52
- };
53
- })}
54
- />
55
- );
56
- }
57
-
58
- function getLabelForType(security: OpenAPISecurityWithRequired, context: OpenAPIClientContext) {
59
- switch (security.type) {
60
- case 'apiKey':
61
- return (
62
- <OpenAPISchemaName
63
- context={context}
64
- propertyName={security.name ?? 'apiKey'}
65
- type="string"
66
- required={security.required}
67
- />
68
- );
69
- case 'http':
70
- if (security.scheme === 'basic') {
71
- return (
72
- <OpenAPISchemaName
73
- context={context}
74
- propertyName="Authorization"
75
- type="string"
76
- required={security.required}
77
- />
78
- );
79
- }
80
-
81
- if (security.scheme === 'bearer') {
82
- const description = resolveDescription(security);
83
- return (
84
- <>
85
- <OpenAPISchemaName
86
- context={context}
87
- propertyName="Authorization"
88
- type="string"
89
- required={security.required}
90
- />
91
- {/** Show a default description if none is provided */}
92
- {!description ? (
93
- <Markdown
94
- source={`Bearer authentication header of the form Bearer ${'&lt;token&gt;'}.`}
95
- className="openapi-securities-description"
96
- />
97
- ) : null}
98
- </>
99
- );
100
- }
101
-
102
- return (
103
- <OpenAPISchemaName
104
- context={context}
105
- propertyName="HTTP"
106
- required={security.required}
107
- />
108
- );
109
- case 'oauth2':
110
- return <OpenAPISchemaOAuth2Flows context={context} security={security} />;
111
- case 'openIdConnect':
112
- return (
113
- <OpenAPISchemaName
114
- context={context}
115
- propertyName="OpenID Connect"
116
- required={security.required}
117
- />
118
- );
119
- default:
120
- // @ts-ignore
121
- return security.type;
122
- }
123
- }
124
-
125
- function OpenAPISchemaOAuth2Flows(props: {
126
- context: OpenAPIClientContext;
127
- security: OpenAPIV3.OAuth2SecurityScheme & { required?: boolean };
128
- }) {
129
- const { context, security } = props;
130
-
131
- const flows = Object.entries(security.flows ?? {});
132
-
133
- return (
134
- <div className="openapi-securities-oauth-flows">
135
- {flows.map(([name, flow], index) => (
136
- <OpenAPISchemaOAuth2Item
137
- key={index}
138
- flow={flow}
139
- name={name}
140
- context={context}
141
- security={security}
142
- />
143
- ))}
144
- </div>
145
- );
146
- }
147
-
148
- function OpenAPISchemaOAuth2Item(props: {
149
- flow: NonNullable<OpenAPIV3.OAuth2SecurityScheme['flows']>[keyof NonNullable<
150
- OpenAPIV3.OAuth2SecurityScheme['flows']
151
- >];
152
- name: string;
153
- context: OpenAPIClientContext;
154
- security: OpenAPIV3.OAuth2SecurityScheme & { required?: boolean };
155
- }) {
156
- const { flow, context, security, name } = props;
157
-
158
- if (!flow) {
159
- return null;
160
- }
161
-
162
- const scopes = Object.entries(flow?.scopes ?? {});
163
-
164
- return (
165
- <div>
166
- <OpenAPISchemaName
167
- context={context}
168
- propertyName="OAuth2"
169
- type={name}
170
- required={security.required}
171
- />
172
- <div className="openapi-securities-oauth-content openapi-markdown">
173
- {security.description ? <Markdown source={security.description} /> : null}
174
- {'authorizationUrl' in flow && flow.authorizationUrl ? (
175
- <span>
176
- Authorization URL:{' '}
177
- <OpenAPICopyButton
178
- value={flow.authorizationUrl}
179
- context={context}
180
- className="openapi-securities-url"
181
- withTooltip
182
- >
183
- {flow.authorizationUrl}
184
- </OpenAPICopyButton>
185
- </span>
186
- ) : null}
187
- {'tokenUrl' in flow && flow.tokenUrl ? (
188
- <span>
189
- Token URL:{' '}
190
- <OpenAPICopyButton
191
- value={flow.tokenUrl}
192
- context={context}
193
- className="openapi-securities-url"
194
- withTooltip
195
- >
196
- {flow.tokenUrl}
197
- </OpenAPICopyButton>
198
- </span>
199
- ) : null}
200
- {'refreshUrl' in flow && flow.refreshUrl ? (
201
- <span>
202
- Refresh URL:{' '}
203
- <OpenAPICopyButton
204
- value={flow.refreshUrl}
205
- context={context}
206
- className="openapi-securities-url"
207
- withTooltip
208
- >
209
- {flow.refreshUrl}
210
- </OpenAPICopyButton>
211
- </span>
212
- ) : null}
213
- {scopes.length ? (
214
- <div>
215
- {t(context.translation, 'available_scopes')}:{' '}
216
- <ul>
217
- {scopes.map(([key, value]) => (
218
- <li key={key}>
219
- <OpenAPICopyButton value={key} context={context} withTooltip>
220
- <code>{key}</code>
221
- </OpenAPICopyButton>
222
- : {value}
223
- </li>
224
- ))}
225
- </ul>
226
- </div>
227
- ) : null}
228
- </div>
229
- </div>
230
- );
231
- }
@@ -1,96 +0,0 @@
1
- 'use client';
2
-
3
- import clsx from 'clsx';
4
- import { useCallback } from 'react';
5
- import {
6
- Button,
7
- type Key,
8
- ListBox,
9
- ListBoxItem,
10
- type ListBoxItemProps,
11
- Popover,
12
- type PopoverProps,
13
- Select,
14
- type SelectProps,
15
- SelectValue,
16
- } from 'react-aria-components';
17
- import { useStore } from 'zustand';
18
- import { getOrCreateStoreByKey } from './getOrCreateStoreByKey';
19
-
20
- export type OpenAPISelectItem = {
21
- key: Key;
22
- label: string | React.ReactNode;
23
- };
24
-
25
- interface OpenAPISelectProps<T extends OpenAPISelectItem> extends Omit<SelectProps<T>, 'children'> {
26
- items: T[];
27
- children: React.ReactNode | ((item: T) => React.ReactNode);
28
- placement?: PopoverProps['placement'];
29
- stateKey?: string;
30
- /**
31
- * Icon to display in the select button.
32
- */
33
- icon?: React.ReactNode;
34
- }
35
-
36
- export function useSelectState(stateKey = 'select-state', initialKey: Key = 'default') {
37
- const store = useStore(getOrCreateStoreByKey(stateKey, initialKey));
38
- return {
39
- key: store.key,
40
- setKey: useCallback((key: Key | null) => store.setKey(key), [store.setKey]),
41
- };
42
- }
43
-
44
- export function OpenAPISelect<T extends OpenAPISelectItem>(props: OpenAPISelectProps<T>) {
45
- const {
46
- icon = '▼',
47
- items,
48
- children,
49
- className,
50
- placement,
51
- stateKey,
52
- selectedKey,
53
- onSelectionChange,
54
- } = props;
55
-
56
- const state = useSelectState(stateKey, items[0]?.key);
57
-
58
- const selected = items.find((item) => item.key === state.key) || items[0];
59
-
60
- return (
61
- <Select
62
- aria-label="OpenAPI Select"
63
- {...props}
64
- selectedKey={selectedKey || selected?.key}
65
- onSelectionChange={(key) => {
66
- onSelectionChange?.(key);
67
- state.setKey(key);
68
- }}
69
- className={clsx('openapi-select', className)}
70
- >
71
- <Button>
72
- <SelectValue />
73
- {icon}
74
- </Button>
75
- <Popover placement={placement} className="openapi-select-popover">
76
- <ListBox className="openapi-select-listbox" items={items}>
77
- {children}
78
- </ListBox>
79
- </Popover>
80
- </Select>
81
- );
82
- }
83
-
84
- export function OpenAPISelectItem(props: ListBoxItemProps) {
85
- return (
86
- <ListBoxItem
87
- {...props}
88
- className={({ isFocused, isSelected }) =>
89
- clsx('openapi-select-item', {
90
- 'openapi-select-item-focused': isFocused,
91
- 'openapi-select-item-selected': isSelected,
92
- })
93
- }
94
- />
95
- );
96
- }
@@ -1,138 +0,0 @@
1
- import type { OpenAPI } from '@gitbook/openapi-parser';
2
-
3
- import { OpenAPIRequestBody } from './OpenAPIRequestBody';
4
- import { OpenAPIResponses } from './OpenAPIResponses';
5
- import { OpenAPISchemaProperties } from './OpenAPISchemaServer';
6
- import { OpenAPISecurities } from './OpenAPISecurities';
7
- import { StaticSection } from './StaticSection';
8
- import type { OpenAPIClientContext } from './context';
9
- import { tString } from './translate';
10
- import type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
11
- import { parameterToProperty } from './utils';
12
-
13
- export function OpenAPISpec(props: {
14
- data: OpenAPIOperationData | OpenAPIWebhookData;
15
- context: OpenAPIClientContext;
16
- }) {
17
- const { data, context } = props;
18
-
19
- const { operation } = data;
20
-
21
- const parameters = deduplicateParameters(operation.parameters ?? []);
22
- const parameterGroups = groupParameters(parameters, context);
23
-
24
- const securities = 'securities' in data ? data.securities : [];
25
-
26
- return (
27
- <>
28
- {securities.length > 0 ? (
29
- <OpenAPISecurities key="securities" securities={securities} context={context} />
30
- ) : null}
31
-
32
- {parameterGroups.map((group) => {
33
- return (
34
- <StaticSection
35
- key={`parameter-${group.key}`}
36
- className="openapi-parameters"
37
- header={group.label}
38
- >
39
- <OpenAPISchemaProperties
40
- properties={group.parameters.map(parameterToProperty)}
41
- context={context}
42
- />
43
- </StaticSection>
44
- );
45
- })}
46
-
47
- {operation.requestBody ? (
48
- <OpenAPIRequestBody
49
- key="body"
50
- requestBody={operation.requestBody}
51
- context={context}
52
- data={data}
53
- />
54
- ) : null}
55
- {operation.responses ? (
56
- <OpenAPIResponses
57
- key="responses"
58
- responses={operation.responses}
59
- context={context}
60
- />
61
- ) : null}
62
- </>
63
- );
64
- }
65
-
66
- function groupParameters(
67
- parameters: OpenAPI.Parameters,
68
- context: OpenAPIClientContext
69
- ): Array<{
70
- key: string;
71
- label: string;
72
- parameters: OpenAPI.Parameters;
73
- }> {
74
- const sorted = ['path', 'query', 'header'];
75
-
76
- const groups: Array<{
77
- key: string;
78
- label: string;
79
- parameters: OpenAPI.Parameters;
80
- }> = [];
81
-
82
- parameters
83
- .filter((parameter) => parameter.in)
84
- .forEach((parameter) => {
85
- const key = parameter.in;
86
- const label = getParameterGroupName(parameter.in, context);
87
- const group = groups.find((group) => group.key === key);
88
- if (group) {
89
- group.parameters.push(parameter);
90
- } else {
91
- groups.push({
92
- key,
93
- label,
94
- parameters: [parameter],
95
- });
96
- }
97
- });
98
-
99
- groups.sort((a, b) => sorted.indexOf(a.key) - sorted.indexOf(b.key));
100
-
101
- return groups;
102
- }
103
-
104
- function getParameterGroupName(paramIn: string, context: OpenAPIClientContext): string {
105
- switch (paramIn) {
106
- case 'path':
107
- return tString(context.translation, 'path_parameters');
108
- case 'query':
109
- return tString(context.translation, 'query_parameters');
110
- case 'header':
111
- return tString(context.translation, 'header_parameters');
112
- default:
113
- return paramIn;
114
- }
115
- }
116
-
117
- /** Deduplicate parameters by name and in.
118
- * Some specs have both parameters define at path and operation level.
119
- * We only want to display one of them.
120
- * Parameters can have the wrong type (object instead of array) sometimes, we just return an empty array in that case.
121
- */
122
- function deduplicateParameters(parameters: OpenAPI.Parameters): OpenAPI.Parameters {
123
- const seen = new Set();
124
-
125
- return Array.isArray(parameters)
126
- ? parameters.filter((param) => {
127
- const key = `${param.name}:${param.in}`;
128
-
129
- if (seen.has(key)) {
130
- return false;
131
- }
132
-
133
- seen.add(key);
134
-
135
- return true;
136
- })
137
- : [];
138
- }