@gitbook/react-openapi 1.1.9 → 1.2.0
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/InteractiveSection.d.ts +4 -0
- package/dist/InteractiveSection.jsx +14 -13
- package/dist/OpenAPICodeSample.d.ts +3 -2
- package/dist/OpenAPICodeSample.jsx +8 -12
- package/dist/OpenAPICodeSampleInteractive.d.ts +3 -0
- package/dist/OpenAPICodeSampleInteractive.jsx +37 -49
- package/dist/OpenAPICodeSampleSelector.d.ts +14 -0
- package/dist/OpenAPICodeSampleSelector.jsx +44 -0
- package/dist/OpenAPICopyButton.d.ts +2 -0
- package/dist/OpenAPICopyButton.jsx +5 -2
- package/dist/OpenAPIDisclosure.d.ts +4 -3
- package/dist/OpenAPIDisclosure.jsx +8 -11
- package/dist/OpenAPIDisclosureGroup.d.ts +7 -3
- package/dist/OpenAPIDisclosureGroup.jsx +18 -18
- package/dist/OpenAPIExample.d.ts +16 -0
- package/dist/OpenAPIExample.jsx +36 -0
- package/dist/OpenAPIMediaType.d.ts +21 -0
- package/dist/OpenAPIMediaType.jsx +61 -0
- package/dist/OpenAPIOperation.d.ts +3 -2
- package/dist/OpenAPIOperation.jsx +9 -72
- package/dist/OpenAPIOperationDescription.d.ts +9 -0
- package/dist/OpenAPIOperationDescription.jsx +22 -0
- package/dist/OpenAPIOperationStability.d.ts +9 -0
- package/dist/OpenAPIOperationStability.jsx +27 -0
- package/dist/OpenAPIPath.d.ts +12 -2
- package/dist/OpenAPIPath.jsx +10 -4
- package/dist/OpenAPIRequestBody.d.ts +3 -1
- package/dist/OpenAPIRequestBody.jsx +4 -3
- package/dist/OpenAPIResponse.d.ts +1 -1
- package/dist/OpenAPIResponse.jsx +1 -1
- package/dist/OpenAPIResponseExample.d.ts +4 -3
- package/dist/OpenAPIResponseExample.jsx +24 -154
- package/dist/OpenAPIResponseExampleContent.d.ts +19 -0
- package/dist/OpenAPIResponseExampleContent.jsx +57 -0
- package/dist/OpenAPIResponses.d.ts +1 -1
- package/dist/OpenAPIResponses.jsx +49 -36
- package/dist/OpenAPISchema.d.ts +1 -1
- package/dist/OpenAPISchema.jsx +121 -20
- package/dist/OpenAPISchemaName.d.ts +2 -0
- package/dist/OpenAPISchemaName.jsx +21 -17
- package/dist/OpenAPISchemaServer.d.ts +1 -1
- package/dist/OpenAPISecurities.d.ts +2 -1
- package/dist/OpenAPISecurities.jsx +11 -10
- package/dist/OpenAPISelect.d.ts +22 -0
- package/dist/OpenAPISelect.jsx +43 -0
- package/dist/OpenAPISpec.d.ts +3 -2
- package/dist/OpenAPISpec.jsx +11 -9
- package/dist/OpenAPITabs.jsx +9 -9
- package/dist/OpenAPIWebhook.d.ts +10 -0
- package/dist/OpenAPIWebhook.jsx +23 -0
- package/dist/OpenAPIWebhookExample.d.ts +6 -0
- package/dist/OpenAPIWebhookExample.jsx +41 -0
- package/dist/ScalarApiButton.d.ts +2 -0
- package/dist/ScalarApiButton.jsx +4 -3
- package/dist/StaticSection.d.ts +4 -1
- package/dist/StaticSection.jsx +13 -4
- package/dist/code-samples.js +57 -39
- package/dist/common/OpenAPIColumnSpec.d.ts +6 -0
- package/dist/common/OpenAPIColumnSpec.jsx +20 -0
- package/dist/common/OpenAPIOperationDescription.d.ts +6 -0
- package/dist/common/OpenAPIOperationDescription.jsx +19 -0
- package/dist/common/OpenAPIStability.d.ts +4 -0
- package/dist/common/OpenAPIStability.jsx +15 -0
- package/dist/common/OpenAPISummary.d.ts +6 -0
- package/dist/common/OpenAPISummary.jsx +30 -0
- package/dist/context.d.ts +75 -0
- package/dist/context.js +43 -0
- package/dist/generateSchemaExample.js +4 -0
- package/dist/getOrCreateStoreByKey.d.ts +10 -0
- package/dist/getOrCreateStoreByKey.js +19 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +3 -0
- package/dist/resolveOpenAPIOperation.js +10 -5
- package/dist/resolveOpenAPIWebhook.d.ts +11 -0
- package/dist/resolveOpenAPIWebhook.js +127 -0
- package/dist/schemas/OpenAPISchemas.d.ts +5 -6
- package/dist/schemas/OpenAPISchemas.jsx +52 -49
- package/dist/schemas/resolveOpenAPISchemas.d.ts +4 -3
- package/dist/schemas/resolveOpenAPISchemas.js +0 -1
- package/dist/stringifyOpenAPI.d.ts +1 -1
- package/dist/stringifyOpenAPI.js +6 -3
- package/dist/translate.d.ts +10 -0
- package/dist/translate.jsx +75 -0
- package/dist/translations/de.d.ts +37 -0
- package/dist/translations/de.js +37 -0
- package/dist/translations/en.d.ts +37 -0
- package/dist/translations/en.js +37 -0
- package/dist/translations/es.d.ts +37 -0
- package/dist/translations/es.js +37 -0
- package/dist/translations/fr.d.ts +37 -0
- package/dist/translations/fr.js +37 -0
- package/dist/translations/index.d.ts +341 -0
- package/dist/translations/index.js +27 -0
- package/dist/translations/ja.d.ts +37 -0
- package/dist/translations/ja.js +37 -0
- package/dist/translations/nl.d.ts +37 -0
- package/dist/translations/nl.js +37 -0
- package/dist/translations/no.d.ts +37 -0
- package/dist/translations/no.js +37 -0
- package/dist/translations/pt-br.d.ts +37 -0
- package/dist/translations/pt-br.js +37 -0
- package/dist/translations/types.d.ts +5 -0
- package/dist/translations/types.js +1 -0
- package/dist/translations/zh.d.ts +37 -0
- package/dist/translations/zh.js +37 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types.d.ts +12 -48
- package/dist/util/example.d.ts +35 -0
- package/dist/util/example.jsx +103 -0
- package/dist/utils.d.ts +18 -0
- package/dist/utils.js +57 -0
- package/package.json +3 -3
- package/src/InteractiveSection.tsx +22 -18
- package/src/OpenAPICodeSample.tsx +26 -15
- package/src/OpenAPICodeSampleInteractive.tsx +67 -70
- package/src/OpenAPICodeSampleSelector.tsx +94 -0
- package/src/OpenAPICopyButton.tsx +7 -2
- package/src/OpenAPIDisclosure.tsx +20 -22
- package/src/OpenAPIDisclosureGroup.tsx +40 -22
- package/src/OpenAPIExample.tsx +55 -0
- package/src/OpenAPIMediaType.tsx +139 -0
- package/src/OpenAPIOperation.tsx +11 -104
- package/src/OpenAPIOperationDescription.tsx +34 -0
- package/src/OpenAPIOperationStability.tsx +39 -0
- package/src/OpenAPIPath.tsx +26 -6
- package/src/OpenAPIRequestBody.tsx +9 -4
- package/src/OpenAPIResponse.tsx +2 -2
- package/src/OpenAPIResponseExample.tsx +41 -215
- package/src/OpenAPIResponseExampleContent.tsx +123 -0
- package/src/OpenAPIResponses.tsx +83 -62
- package/src/OpenAPISchema.test.ts +80 -0
- package/src/OpenAPISchema.tsx +149 -25
- package/src/OpenAPISchemaName.tsx +28 -19
- package/src/OpenAPISchemaServer.tsx +1 -1
- package/src/OpenAPISecurities.tsx +46 -12
- package/src/OpenAPISelect.tsx +96 -0
- package/src/OpenAPISpec.tsx +21 -10
- package/src/OpenAPITabs.tsx +9 -9
- package/src/OpenAPIWebhook.tsx +33 -0
- package/src/OpenAPIWebhookExample.tsx +60 -0
- package/src/ScalarApiButton.tsx +6 -6
- package/src/StaticSection.tsx +37 -5
- package/src/code-samples.test.ts +3 -1
- package/src/code-samples.ts +67 -54
- package/src/common/OpenAPIColumnSpec.tsx +31 -0
- package/src/common/OpenAPIOperationDescription.tsx +31 -0
- package/src/common/OpenAPIStability.tsx +23 -0
- package/src/common/OpenAPISummary.tsx +45 -0
- package/src/context.ts +99 -0
- package/src/generateSchemaExample.test.ts +1020 -0
- package/src/generateSchemaExample.ts +5 -0
- package/src/getOrCreateStoreByKey.ts +33 -0
- package/src/index.ts +5 -1
- package/src/resolveOpenAPIOperation.ts +14 -3
- package/src/resolveOpenAPIWebhook.ts +99 -0
- package/src/schemas/OpenAPISchemas.tsx +76 -71
- package/src/schemas/resolveOpenAPISchemas.ts +4 -5
- package/src/stringifyOpenAPI.ts +11 -3
- package/src/translate.tsx +80 -0
- package/src/translations/de.ts +37 -0
- package/src/translations/en.ts +37 -0
- package/src/translations/es.ts +37 -0
- package/src/translations/fr.ts +37 -0
- package/src/translations/index.ts +33 -0
- package/src/translations/ja.ts +37 -0
- package/src/translations/nl.ts +37 -0
- package/src/translations/no.ts +37 -0
- package/src/translations/pt-br.ts +37 -0
- package/src/translations/types.ts +7 -0
- package/src/translations/zh.ts +37 -0
- package/src/types.ts +11 -46
- package/src/util/example.tsx +129 -0
- package/src/utils.ts +67 -0
- package/dist/useSyncedTabsGlobalState.d.ts +0 -10
- package/dist/useSyncedTabsGlobalState.js +0 -20
- package/src/useSyncedTabsGlobalState.ts +0 -35
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { de } from './de';
|
|
2
|
+
import { en } from './en';
|
|
3
|
+
import { es } from './es';
|
|
4
|
+
import { fr } from './fr';
|
|
5
|
+
import { ja } from './ja';
|
|
6
|
+
import { nl } from './nl';
|
|
7
|
+
import { no } from './no';
|
|
8
|
+
import { pt_br } from './pt-br';
|
|
9
|
+
import type { Translation } from './types';
|
|
10
|
+
import { zh } from './zh';
|
|
11
|
+
|
|
12
|
+
export * from './types';
|
|
13
|
+
|
|
14
|
+
export const translations = {
|
|
15
|
+
en,
|
|
16
|
+
de,
|
|
17
|
+
es,
|
|
18
|
+
fr,
|
|
19
|
+
ja,
|
|
20
|
+
nl,
|
|
21
|
+
no,
|
|
22
|
+
'pt-br': pt_br,
|
|
23
|
+
zh,
|
|
24
|
+
} satisfies Record<string, Translation>;
|
|
25
|
+
|
|
26
|
+
export type TranslationLocale = keyof typeof translations;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Check if the locale is valid.
|
|
30
|
+
*/
|
|
31
|
+
export function checkIsValidLocale(locale: string): locale is TranslationLocale {
|
|
32
|
+
return Object.prototype.hasOwnProperty.call(translations, locale);
|
|
33
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const ja = {
|
|
2
|
+
required: '必須',
|
|
3
|
+
deprecated: '非推奨',
|
|
4
|
+
deprecated_and_sunset_on: 'この操作は非推奨であり、${1}に廃止されます。',
|
|
5
|
+
stability_experimental: '実験的',
|
|
6
|
+
stability_alpha: 'アルファ',
|
|
7
|
+
stability_beta: 'ベータ',
|
|
8
|
+
copy_to_clipboard: 'クリップボードにコピー',
|
|
9
|
+
copied: 'コピー済み',
|
|
10
|
+
no_content: 'コンテンツなし',
|
|
11
|
+
unresolved_reference: '未解決の参照',
|
|
12
|
+
circular_reference: '循環参照',
|
|
13
|
+
read_only: '読み取り専用',
|
|
14
|
+
write_only: '書き込み専用',
|
|
15
|
+
optional: 'オプション',
|
|
16
|
+
min: '最小',
|
|
17
|
+
max: '最大',
|
|
18
|
+
nullable: 'ヌル許容',
|
|
19
|
+
body: '本文',
|
|
20
|
+
payload: 'ペイロード',
|
|
21
|
+
headers: 'ヘッダー',
|
|
22
|
+
authorizations: '認可',
|
|
23
|
+
responses: 'レスポンス',
|
|
24
|
+
path_parameters: 'パスパラメータ',
|
|
25
|
+
query_parameters: 'クエリパラメータ',
|
|
26
|
+
header_parameters: 'ヘッダーパラメータ',
|
|
27
|
+
attributes: '属性',
|
|
28
|
+
test_it: 'テストする',
|
|
29
|
+
information: '情報',
|
|
30
|
+
success: '成功',
|
|
31
|
+
redirect: 'リダイレクト',
|
|
32
|
+
error: 'エラー',
|
|
33
|
+
show: '表示',
|
|
34
|
+
hide: '非表示',
|
|
35
|
+
available_items: '利用可能なアイテム',
|
|
36
|
+
child_attributes: '子属性',
|
|
37
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const nl = {
|
|
2
|
+
required: 'Vereist',
|
|
3
|
+
deprecated: 'Verouderd',
|
|
4
|
+
deprecated_and_sunset_on: 'Deze bewerking is verouderd en wordt op ${1} beëindigd.',
|
|
5
|
+
stability_experimental: 'Experimenteel',
|
|
6
|
+
stability_alpha: 'Alfa',
|
|
7
|
+
stability_beta: 'Bèta',
|
|
8
|
+
copy_to_clipboard: 'Kopiëren naar klembord',
|
|
9
|
+
copied: 'Gekopieerd',
|
|
10
|
+
no_content: 'Geen inhoud',
|
|
11
|
+
unresolved_reference: 'Onopgeloste verwijzing',
|
|
12
|
+
circular_reference: 'Circulaire verwijzing',
|
|
13
|
+
read_only: 'Alleen lezen',
|
|
14
|
+
write_only: 'Alleen schrijven',
|
|
15
|
+
optional: 'Optioneel',
|
|
16
|
+
min: 'Min',
|
|
17
|
+
max: 'Max',
|
|
18
|
+
nullable: 'Null toegestaan',
|
|
19
|
+
body: 'Body',
|
|
20
|
+
payload: 'Payload',
|
|
21
|
+
headers: 'Headers',
|
|
22
|
+
authorizations: 'Autorisaties',
|
|
23
|
+
responses: 'Reacties',
|
|
24
|
+
path_parameters: 'Padparameters',
|
|
25
|
+
query_parameters: 'Queryparameters',
|
|
26
|
+
header_parameters: 'Headerparameters',
|
|
27
|
+
attributes: 'Attributen',
|
|
28
|
+
test_it: 'Test het',
|
|
29
|
+
information: 'Informatie',
|
|
30
|
+
success: 'Succes',
|
|
31
|
+
redirect: 'Omleiding',
|
|
32
|
+
error: 'Fout',
|
|
33
|
+
show: 'Toon',
|
|
34
|
+
hide: 'Verbergen',
|
|
35
|
+
available_items: 'Beschikbare items',
|
|
36
|
+
child_attributes: 'Kindattributen',
|
|
37
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const no = {
|
|
2
|
+
required: 'Påkrevd',
|
|
3
|
+
deprecated: 'Foreldet',
|
|
4
|
+
deprecated_and_sunset_on: 'Denne operasjonen er foreldet og vil bli avviklet den ${1}.',
|
|
5
|
+
stability_experimental: 'Eksperimentell',
|
|
6
|
+
stability_alpha: 'Alfa',
|
|
7
|
+
stability_beta: 'Beta',
|
|
8
|
+
copy_to_clipboard: 'Kopier til utklippstavle',
|
|
9
|
+
copied: 'Kopiert',
|
|
10
|
+
no_content: 'Ingen innhold',
|
|
11
|
+
unresolved_reference: 'Uavklart referanse',
|
|
12
|
+
circular_reference: 'Sirkulær referanse',
|
|
13
|
+
read_only: 'Skrivebeskyttet',
|
|
14
|
+
write_only: 'Kun skriving',
|
|
15
|
+
optional: 'Valgfri',
|
|
16
|
+
min: 'Min',
|
|
17
|
+
max: 'Maks',
|
|
18
|
+
nullable: 'Kan være null',
|
|
19
|
+
body: 'Brødtekst',
|
|
20
|
+
payload: 'Nyttelast',
|
|
21
|
+
headers: 'Overskrifter',
|
|
22
|
+
authorizations: 'Autorisasjoner',
|
|
23
|
+
responses: 'Responser',
|
|
24
|
+
path_parameters: 'Sti-parametere',
|
|
25
|
+
query_parameters: 'Forespørselsparametere',
|
|
26
|
+
header_parameters: 'Header-parametere',
|
|
27
|
+
attributes: 'Attributter',
|
|
28
|
+
test_it: 'Test det',
|
|
29
|
+
information: 'Informasjon',
|
|
30
|
+
success: 'Suksess',
|
|
31
|
+
redirect: 'Viderekobling',
|
|
32
|
+
error: 'Feil',
|
|
33
|
+
show: 'Vis',
|
|
34
|
+
hide: 'Skjul',
|
|
35
|
+
available_items: 'Tilgjengelige elementer',
|
|
36
|
+
child_attributes: 'Barneattributter',
|
|
37
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const pt_br = {
|
|
2
|
+
required: 'Obrigatório',
|
|
3
|
+
deprecated: 'Obsoleto',
|
|
4
|
+
deprecated_and_sunset_on: 'Esta operação está obsoleta e será descontinuada em ${1}.',
|
|
5
|
+
stability_experimental: 'Experimental',
|
|
6
|
+
stability_alpha: 'Alfa',
|
|
7
|
+
stability_beta: 'Beta',
|
|
8
|
+
copy_to_clipboard: 'Copiar para a área de transferência',
|
|
9
|
+
copied: 'Copiado',
|
|
10
|
+
no_content: 'Sem conteúdo',
|
|
11
|
+
unresolved_reference: 'Referência não resolvida',
|
|
12
|
+
circular_reference: 'Referência circular',
|
|
13
|
+
read_only: 'Somente leitura',
|
|
14
|
+
write_only: 'Somente escrita',
|
|
15
|
+
optional: 'Opcional',
|
|
16
|
+
min: 'Mín',
|
|
17
|
+
max: 'Máx',
|
|
18
|
+
nullable: 'Nulo',
|
|
19
|
+
body: 'Corpo',
|
|
20
|
+
payload: 'Carga útil',
|
|
21
|
+
headers: 'Cabeçalhos',
|
|
22
|
+
authorizations: 'Autorizações',
|
|
23
|
+
responses: 'Respostas',
|
|
24
|
+
path_parameters: 'Parâmetros de rota',
|
|
25
|
+
query_parameters: 'Parâmetros de consulta',
|
|
26
|
+
header_parameters: 'Parâmetros de cabeçalho',
|
|
27
|
+
attributes: 'Atributos',
|
|
28
|
+
test_it: 'Testar',
|
|
29
|
+
information: 'Informação',
|
|
30
|
+
success: 'Sucesso',
|
|
31
|
+
redirect: 'Redirecionamento',
|
|
32
|
+
error: 'Erro',
|
|
33
|
+
show: 'Mostrar',
|
|
34
|
+
hide: 'Ocultar',
|
|
35
|
+
available_items: 'Itens disponíveis',
|
|
36
|
+
child_attributes: 'Atributos filhos',
|
|
37
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const zh = {
|
|
2
|
+
required: '必填',
|
|
3
|
+
deprecated: '已弃用',
|
|
4
|
+
deprecated_and_sunset_on: '此操作已弃用,将于 ${1} 停止使用。',
|
|
5
|
+
stability_experimental: '实验性',
|
|
6
|
+
stability_alpha: 'Alpha',
|
|
7
|
+
stability_beta: 'Beta',
|
|
8
|
+
copy_to_clipboard: '复制到剪贴板',
|
|
9
|
+
copied: '已复制',
|
|
10
|
+
no_content: '无内容',
|
|
11
|
+
unresolved_reference: '未解析的引用',
|
|
12
|
+
circular_reference: '循环引用',
|
|
13
|
+
read_only: '只读',
|
|
14
|
+
write_only: '只写',
|
|
15
|
+
optional: '可选',
|
|
16
|
+
min: '最小值',
|
|
17
|
+
max: '最大值',
|
|
18
|
+
nullable: '可为 null',
|
|
19
|
+
body: '请求体',
|
|
20
|
+
payload: '有效载荷',
|
|
21
|
+
headers: '头部信息',
|
|
22
|
+
authorizations: '授权',
|
|
23
|
+
responses: '响应',
|
|
24
|
+
path_parameters: '路径参数',
|
|
25
|
+
query_parameters: '查询参数',
|
|
26
|
+
header_parameters: '头参数',
|
|
27
|
+
attributes: '属性',
|
|
28
|
+
test_it: '测试一下',
|
|
29
|
+
information: '信息',
|
|
30
|
+
success: '成功',
|
|
31
|
+
redirect: '重定向',
|
|
32
|
+
error: '错误',
|
|
33
|
+
show: '显示',
|
|
34
|
+
hide: '隐藏',
|
|
35
|
+
available_items: '可用项',
|
|
36
|
+
child_attributes: '子属性',
|
|
37
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -1,51 +1,10 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
OpenAPICustomOperationProperties,
|
|
3
3
|
OpenAPICustomSpecProperties,
|
|
4
|
-
OpenAPISchema,
|
|
5
4
|
OpenAPIV3,
|
|
6
5
|
} from '@gitbook/openapi-parser';
|
|
7
6
|
|
|
8
|
-
export
|
|
9
|
-
/**
|
|
10
|
-
* Render a code block.
|
|
11
|
-
*/
|
|
12
|
-
renderCodeBlock: (props: { code: string; syntax: string }) => React.ReactNode;
|
|
13
|
-
/**
|
|
14
|
-
* Render the heading of the operation.
|
|
15
|
-
*/
|
|
16
|
-
renderHeading: (props: {
|
|
17
|
-
deprecated: boolean;
|
|
18
|
-
title: string;
|
|
19
|
-
stability?: string;
|
|
20
|
-
}) => React.ReactNode;
|
|
21
|
-
/**
|
|
22
|
-
* Render the document of the operation.
|
|
23
|
-
*/
|
|
24
|
-
renderDocument: (props: { document: object }) => React.ReactNode;
|
|
25
|
-
|
|
26
|
-
/** Spec url for the Scalar Api Client */
|
|
27
|
-
specUrl: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface OpenAPIClientContext {
|
|
31
|
-
icons: {
|
|
32
|
-
chevronDown: React.ReactNode;
|
|
33
|
-
chevronRight: React.ReactNode;
|
|
34
|
-
plus: React.ReactNode;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Force all sections to be opened by default.
|
|
39
|
-
* @default false
|
|
40
|
-
*/
|
|
41
|
-
defaultInteractiveOpened?: boolean;
|
|
42
|
-
/**
|
|
43
|
-
* The key of the block
|
|
44
|
-
*/
|
|
45
|
-
blockKey?: string;
|
|
46
|
-
/** Optional id attached to the OpenAPI Operation heading and used as an anchor */
|
|
47
|
-
id?: string;
|
|
48
|
-
}
|
|
7
|
+
export type OpenAPISecurityWithRequired = OpenAPIV3.SecuritySchemeObject & { required?: boolean };
|
|
49
8
|
|
|
50
9
|
export interface OpenAPIOperationData extends OpenAPICustomSpecProperties {
|
|
51
10
|
path: string;
|
|
@@ -58,10 +17,16 @@ export interface OpenAPIOperationData extends OpenAPICustomSpecProperties {
|
|
|
58
17
|
operation: OpenAPIV3.OperationObject<OpenAPICustomOperationProperties>;
|
|
59
18
|
|
|
60
19
|
/** Securities that should be used for this operation */
|
|
61
|
-
securities: [string,
|
|
20
|
+
securities: [string, OpenAPISecurityWithRequired][];
|
|
62
21
|
}
|
|
63
22
|
|
|
64
|
-
export interface
|
|
65
|
-
|
|
66
|
-
|
|
23
|
+
export interface OpenAPIWebhookData extends OpenAPICustomSpecProperties {
|
|
24
|
+
name: string;
|
|
25
|
+
method: string;
|
|
26
|
+
|
|
27
|
+
/** Servers to be used for this operation */
|
|
28
|
+
servers: OpenAPIV3.ServerObject[];
|
|
29
|
+
|
|
30
|
+
/** Spec of the webhook */
|
|
31
|
+
operation: OpenAPIV3.OperationObject<OpenAPICustomOperationProperties>;
|
|
67
32
|
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
+
import { OpenAPIExample } from '../OpenAPIExample';
|
|
3
|
+
import type { OpenAPIContext } from '../context';
|
|
4
|
+
import { generateSchemaExample } from '../generateSchemaExample';
|
|
5
|
+
import { tString } from '../translate';
|
|
6
|
+
import { checkIsReference } from '../utils';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Generate an example from a reference object.
|
|
10
|
+
*/
|
|
11
|
+
export function getExampleFromReference(
|
|
12
|
+
ref: OpenAPIV3.ReferenceObject,
|
|
13
|
+
context: OpenAPIContext
|
|
14
|
+
): OpenAPIV3.ExampleObject {
|
|
15
|
+
return {
|
|
16
|
+
summary: tString(context.translation, 'unresolved_reference'),
|
|
17
|
+
value: { $ref: ref.$ref },
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get examples from a media type object.
|
|
23
|
+
*/
|
|
24
|
+
export function getExamplesFromMediaTypeObject(args: {
|
|
25
|
+
mediaType: string;
|
|
26
|
+
mediaTypeObject: OpenAPIV3.MediaTypeObject;
|
|
27
|
+
context: OpenAPIContext;
|
|
28
|
+
}): { key: string; example: OpenAPIV3.ExampleObject }[] {
|
|
29
|
+
const { mediaTypeObject, mediaType, context } = args;
|
|
30
|
+
if (mediaTypeObject.examples) {
|
|
31
|
+
return Object.entries(mediaTypeObject.examples).map(([key, example]) => {
|
|
32
|
+
return {
|
|
33
|
+
key,
|
|
34
|
+
example: checkIsReference(example)
|
|
35
|
+
? getExampleFromReference(example, context)
|
|
36
|
+
: example,
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (mediaTypeObject.example) {
|
|
42
|
+
return [{ key: 'default', example: { value: mediaTypeObject.example } }];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (mediaTypeObject.schema) {
|
|
46
|
+
if (mediaType === 'application/xml') {
|
|
47
|
+
// @TODO normally we should use the name of the schema but we don't have it
|
|
48
|
+
// fix it when we got the reference name
|
|
49
|
+
const root = mediaTypeObject.schema.xml?.name ?? 'object';
|
|
50
|
+
return [
|
|
51
|
+
{
|
|
52
|
+
key: 'default',
|
|
53
|
+
example: {
|
|
54
|
+
value: {
|
|
55
|
+
[root]: generateSchemaExample(mediaTypeObject.schema, {
|
|
56
|
+
xml: mediaType === 'application/xml',
|
|
57
|
+
mode: 'read',
|
|
58
|
+
}),
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
return [
|
|
65
|
+
{
|
|
66
|
+
key: 'default',
|
|
67
|
+
example: {
|
|
68
|
+
value: generateSchemaExample(mediaTypeObject.schema, {
|
|
69
|
+
mode: 'read',
|
|
70
|
+
}),
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Get example from a schema object.
|
|
80
|
+
*/
|
|
81
|
+
export function getExampleFromSchema(args: {
|
|
82
|
+
schema: OpenAPIV3.SchemaObject;
|
|
83
|
+
}): OpenAPIV3.ExampleObject {
|
|
84
|
+
const { schema } = args;
|
|
85
|
+
|
|
86
|
+
if (schema.example) {
|
|
87
|
+
return { value: schema.example };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return { value: generateSchemaExample(schema, { mode: 'read' }) };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Get the examples from a media type object.
|
|
95
|
+
*/
|
|
96
|
+
export function getExamples(props: {
|
|
97
|
+
mediaTypeObject: OpenAPIV3.MediaTypeObject;
|
|
98
|
+
mediaType: string;
|
|
99
|
+
context: OpenAPIContext;
|
|
100
|
+
}) {
|
|
101
|
+
const { mediaTypeObject, mediaType, context } = props;
|
|
102
|
+
const examples = getExamplesFromMediaTypeObject({ mediaTypeObject, mediaType, context });
|
|
103
|
+
const syntax = getSyntaxFromMediaType(mediaType);
|
|
104
|
+
|
|
105
|
+
return examples.map((example) => {
|
|
106
|
+
return {
|
|
107
|
+
key: example.key,
|
|
108
|
+
label: example.example.summary || example.key,
|
|
109
|
+
body: (
|
|
110
|
+
<OpenAPIExample example={example.example} context={props.context} syntax={syntax} />
|
|
111
|
+
),
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Get the syntax from a media type.
|
|
118
|
+
*/
|
|
119
|
+
function getSyntaxFromMediaType(mediaType: string): string {
|
|
120
|
+
if (mediaType.includes('json')) {
|
|
121
|
+
return 'json';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (mediaType === 'application/xml') {
|
|
125
|
+
return 'xml';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return 'text';
|
|
129
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { AnyObject, OpenAPIV3, OpenAPIV3_1 } from '@gitbook/openapi-parser';
|
|
2
|
+
import type { OpenAPIUniversalContext } from './context';
|
|
2
3
|
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
|
4
|
+
import { tString } from './translate';
|
|
3
5
|
|
|
4
6
|
export function checkIsReference(input: unknown): input is OpenAPIV3.ReferenceObject {
|
|
5
7
|
return typeof input === 'object' && !!input && '$ref' in input;
|
|
@@ -149,3 +151,68 @@ function shouldDisplayExample(schema: OpenAPIV3.SchemaObject): boolean {
|
|
|
149
151
|
Object.keys(schema.example).length > 0)
|
|
150
152
|
);
|
|
151
153
|
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Get the class name for a status code.
|
|
157
|
+
* 1xx: informational
|
|
158
|
+
* 2xx: success
|
|
159
|
+
* 3xx: redirect
|
|
160
|
+
* 4xx, 5xx: error
|
|
161
|
+
*/
|
|
162
|
+
export function getStatusCodeClassName(statusCode: number | string): string {
|
|
163
|
+
const category = getStatusCodeCategory(statusCode);
|
|
164
|
+
switch (category) {
|
|
165
|
+
case 1:
|
|
166
|
+
return 'informational';
|
|
167
|
+
case 2:
|
|
168
|
+
return 'success';
|
|
169
|
+
case 3:
|
|
170
|
+
return 'redirect';
|
|
171
|
+
case 4:
|
|
172
|
+
case 5:
|
|
173
|
+
return 'error';
|
|
174
|
+
default:
|
|
175
|
+
return 'unknown';
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Get a default label for a status code.
|
|
181
|
+
* This is used when there is no label provided in the OpenAPI spec.
|
|
182
|
+
* 1xx: Information
|
|
183
|
+
* 2xx: Success
|
|
184
|
+
* 3xx: Redirect
|
|
185
|
+
* 4xx, 5xx: Error
|
|
186
|
+
*/
|
|
187
|
+
export function getStatusCodeDefaultLabel(
|
|
188
|
+
statusCode: number | string,
|
|
189
|
+
context: OpenAPIUniversalContext
|
|
190
|
+
): string {
|
|
191
|
+
const category = getStatusCodeCategory(statusCode);
|
|
192
|
+
switch (category) {
|
|
193
|
+
case 1:
|
|
194
|
+
return tString(context.translation, 'information');
|
|
195
|
+
case 2:
|
|
196
|
+
return tString(context.translation, 'success');
|
|
197
|
+
case 3:
|
|
198
|
+
return tString(context.translation, 'redirect');
|
|
199
|
+
case 4:
|
|
200
|
+
case 5:
|
|
201
|
+
return tString(context.translation, 'error');
|
|
202
|
+
default:
|
|
203
|
+
return '';
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function getStatusCodeCategory(statusCode: number | string): number | string {
|
|
208
|
+
const code = typeof statusCode === 'string' ? Number.parseInt(statusCode, 10) : statusCode;
|
|
209
|
+
|
|
210
|
+
if (Number.isNaN(code) || code < 100 || code >= 600) {
|
|
211
|
+
return 'unknown';
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Determine the category of the status code based on the first digit
|
|
215
|
+
const category = Math.floor(code / 100);
|
|
216
|
+
|
|
217
|
+
return category;
|
|
218
|
+
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
type Key = string | number;
|
|
2
|
-
type TabState = {
|
|
3
|
-
tabKey: Key | null;
|
|
4
|
-
};
|
|
5
|
-
type TabActions = {
|
|
6
|
-
setTabKey: (tab: Key | null) => void;
|
|
7
|
-
};
|
|
8
|
-
type TabStore = TabState & TabActions;
|
|
9
|
-
export declare const getOrCreateTabStoreByKey: (storeKey: string, initialKey?: Key) => import("zustand").StoreApi<TabStore>;
|
|
10
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { createStore } from 'zustand';
|
|
3
|
-
var createTabStore = function (initialTab) {
|
|
4
|
-
return createStore()(function (set) { return ({
|
|
5
|
-
tabKey: initialTab !== null && initialTab !== void 0 ? initialTab : null,
|
|
6
|
-
setTabKey: function (tabKey) {
|
|
7
|
-
set(function () { return ({ tabKey: tabKey }); });
|
|
8
|
-
},
|
|
9
|
-
}); });
|
|
10
|
-
};
|
|
11
|
-
var defaultTabStores = new Map();
|
|
12
|
-
var createTabStoreFactory = function (stores) {
|
|
13
|
-
return function (storeKey, initialKey) {
|
|
14
|
-
if (!stores.has(storeKey)) {
|
|
15
|
-
stores.set(storeKey, createTabStore(initialKey));
|
|
16
|
-
}
|
|
17
|
-
return stores.get(storeKey);
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
export var getOrCreateTabStoreByKey = createTabStoreFactory(defaultTabStores);
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { createStore } from 'zustand';
|
|
4
|
-
|
|
5
|
-
type Key = string | number;
|
|
6
|
-
|
|
7
|
-
type TabState = {
|
|
8
|
-
tabKey: Key | null;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
type TabActions = { setTabKey: (tab: Key | null) => void };
|
|
12
|
-
|
|
13
|
-
type TabStore = TabState & TabActions;
|
|
14
|
-
|
|
15
|
-
const createTabStore = (initialTab?: Key) => {
|
|
16
|
-
return createStore<TabStore>()((set) => ({
|
|
17
|
-
tabKey: initialTab ?? null,
|
|
18
|
-
setTabKey: (tabKey) => {
|
|
19
|
-
set(() => ({ tabKey }));
|
|
20
|
-
},
|
|
21
|
-
}));
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const defaultTabStores = new Map<string, ReturnType<typeof createTabStore>>();
|
|
25
|
-
|
|
26
|
-
const createTabStoreFactory = (stores: typeof defaultTabStores) => {
|
|
27
|
-
return (storeKey: string, initialKey?: Key) => {
|
|
28
|
-
if (!stores.has(storeKey)) {
|
|
29
|
-
stores.set(storeKey, createTabStore(initialKey));
|
|
30
|
-
}
|
|
31
|
-
return stores.get(storeKey)!;
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export const getOrCreateTabStoreByKey = createTabStoreFactory(defaultTabStores);
|