@gitbook/react-openapi 1.4.2 → 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 +34 -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,43 +0,0 @@
|
|
|
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: 'Headers',
|
|
22
|
-
header: 'Header',
|
|
23
|
-
authorizations: 'Autorizações',
|
|
24
|
-
responses: 'Respostas',
|
|
25
|
-
response: 'Resposta',
|
|
26
|
-
path_parameters: 'Parâmetros de rota',
|
|
27
|
-
query_parameters: 'Parâmetros de consulta',
|
|
28
|
-
header_parameters: 'Parâmetros de cabeçalho',
|
|
29
|
-
attributes: 'Atributos',
|
|
30
|
-
test_it: 'Testar',
|
|
31
|
-
information: 'Informação',
|
|
32
|
-
success: 'Sucesso',
|
|
33
|
-
redirect: 'Redirecionamento',
|
|
34
|
-
error: 'Erro',
|
|
35
|
-
show: 'Mostrar ${1}',
|
|
36
|
-
hide: 'Ocultar ${1}',
|
|
37
|
-
available_items: 'Itens disponíveis',
|
|
38
|
-
available_scopes: 'Scopes disponíveis',
|
|
39
|
-
properties: 'Propriedades',
|
|
40
|
-
or: 'ou',
|
|
41
|
-
and: 'e',
|
|
42
|
-
possible_values: 'Valores possíveis',
|
|
43
|
-
};
|
package/src/translations/zh.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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
|
-
header: '头部',
|
|
23
|
-
authorizations: '授权',
|
|
24
|
-
responses: '响应',
|
|
25
|
-
response: '响应',
|
|
26
|
-
path_parameters: '路径参数',
|
|
27
|
-
query_parameters: '查询参数',
|
|
28
|
-
header_parameters: '头参数',
|
|
29
|
-
attributes: '属性',
|
|
30
|
-
test_it: '测试一下',
|
|
31
|
-
information: '信息',
|
|
32
|
-
success: '成功',
|
|
33
|
-
redirect: '重定向',
|
|
34
|
-
error: '错误',
|
|
35
|
-
show: '显示${1}',
|
|
36
|
-
hide: '隐藏${1}',
|
|
37
|
-
available_items: '可用项',
|
|
38
|
-
available_scopes: '可用范围',
|
|
39
|
-
properties: '属性',
|
|
40
|
-
or: '或',
|
|
41
|
-
and: '和',
|
|
42
|
-
possible_values: '可能的值',
|
|
43
|
-
};
|
package/src/types.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
OpenAPICustomOperationProperties,
|
|
3
|
-
OpenAPICustomPrefillProperties,
|
|
4
|
-
OpenAPICustomSpecProperties,
|
|
5
|
-
OpenAPIV3,
|
|
6
|
-
} from '@gitbook/openapi-parser';
|
|
7
|
-
|
|
8
|
-
export type OpenAPIServerVariableWithCustomProperties = OpenAPIV3.ServerVariableObject &
|
|
9
|
-
OpenAPICustomPrefillProperties;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* OpenAPI ServerObject type extended to provide x-gitbook prefill custom properties at the variable level.
|
|
13
|
-
*/
|
|
14
|
-
export type OpenAPIServerWithCustomProperties = Omit<OpenAPIV3.ServerObject, 'variables'> & {
|
|
15
|
-
variables?: {
|
|
16
|
-
[variable: string]: OpenAPIServerVariableWithCustomProperties;
|
|
17
|
-
};
|
|
18
|
-
} & OpenAPICustomPrefillProperties;
|
|
19
|
-
|
|
20
|
-
export type OpenAPISecurityWithRequired = OpenAPIV3.SecuritySchemeObject &
|
|
21
|
-
OpenAPICustomPrefillProperties & { required?: boolean };
|
|
22
|
-
|
|
23
|
-
export interface OpenAPIOperationData extends OpenAPICustomSpecProperties {
|
|
24
|
-
path: string;
|
|
25
|
-
method: string;
|
|
26
|
-
|
|
27
|
-
/** Servers to be used for this operation */
|
|
28
|
-
servers: OpenAPIServerWithCustomProperties[];
|
|
29
|
-
|
|
30
|
-
/** Spec of the operation */
|
|
31
|
-
operation: OpenAPIV3.OperationObject<OpenAPICustomOperationProperties>;
|
|
32
|
-
|
|
33
|
-
/** Securities that should be used for this operation */
|
|
34
|
-
securities: [string, OpenAPISecurityWithRequired][];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface OpenAPIWebhookData extends OpenAPICustomSpecProperties {
|
|
38
|
-
name: string;
|
|
39
|
-
method: string;
|
|
40
|
-
|
|
41
|
-
/** Servers to be used for this operation */
|
|
42
|
-
servers: OpenAPIV3.ServerObject[];
|
|
43
|
-
|
|
44
|
-
/** Spec of the webhook */
|
|
45
|
-
operation: OpenAPIV3.OperationObject<OpenAPICustomOperationProperties>;
|
|
46
|
-
}
|
package/src/util/example.tsx
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
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/util/server.test.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'bun:test';
|
|
2
|
-
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
3
|
-
import { getDefaultServerURL, interpolateServerURL } from './server';
|
|
4
|
-
|
|
5
|
-
describe('#interpolateServerURL', () => {
|
|
6
|
-
it('interpolates the server URL with the default values of the variables', () => {
|
|
7
|
-
const server: OpenAPIV3.ServerObject = {
|
|
8
|
-
url: 'https://{username}.example.com/{basePath}',
|
|
9
|
-
variables: {
|
|
10
|
-
username: { default: 'user' },
|
|
11
|
-
basePath: { default: 'v1' },
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
const result = interpolateServerURL(server);
|
|
15
|
-
expect(result).toBe('https://user.example.com/v1');
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('returns the URL with placeholders if no variables are provided', () => {
|
|
19
|
-
const server: OpenAPIV3.ServerObject = {
|
|
20
|
-
url: 'https://{username}.example.com/{basePath}',
|
|
21
|
-
};
|
|
22
|
-
const result = interpolateServerURL(server);
|
|
23
|
-
expect(result).toBe('https://{username}.example.com/{basePath}');
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('returns the URL with mixed placeholders and default values', () => {
|
|
27
|
-
const server: OpenAPIV3.ServerObject = {
|
|
28
|
-
url: 'https://{username}.example.com/{basePath}',
|
|
29
|
-
variables: {
|
|
30
|
-
basePath: { default: 'v1' },
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
const result = interpolateServerURL(server);
|
|
34
|
-
expect(result).toBe('https://{username}.example.com/v1');
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
describe('#getDefaultServerURL', () => {
|
|
39
|
-
it('returns the default server URL', () => {
|
|
40
|
-
const servers: OpenAPIV3.ServerObject[] = [
|
|
41
|
-
{
|
|
42
|
-
url: 'https://{username}.example.com/{basePath}',
|
|
43
|
-
variables: {
|
|
44
|
-
username: { default: 'user' },
|
|
45
|
-
basePath: { default: 'v1' },
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
];
|
|
49
|
-
const result = getDefaultServerURL(servers);
|
|
50
|
-
expect(result).toBe('https://user.example.com/v1');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('returns empty string if no servers are provided', () => {
|
|
54
|
-
const servers: OpenAPIV3.ServerObject[] = [];
|
|
55
|
-
const result = getDefaultServerURL(servers);
|
|
56
|
-
expect(result).toBe('');
|
|
57
|
-
});
|
|
58
|
-
});
|
package/src/util/server.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Get the default URL for the server.
|
|
5
|
-
*/
|
|
6
|
-
export function getDefaultServerURL(servers: OpenAPIV3.ServerObject[]): string {
|
|
7
|
-
const server = servers[0];
|
|
8
|
-
if (!server) {
|
|
9
|
-
// Return empty string if no server is found to display nothing
|
|
10
|
-
return '';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return interpolateServerURL(server);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Interpolate the server URL with the default values of the variables.
|
|
18
|
-
*/
|
|
19
|
-
export function interpolateServerURL(server: OpenAPIV3.ServerObject) {
|
|
20
|
-
const parts = parseServerURL(server?.url ?? '');
|
|
21
|
-
|
|
22
|
-
return parts
|
|
23
|
-
.map((part) => {
|
|
24
|
-
if (part.kind === 'text') {
|
|
25
|
-
return part.text;
|
|
26
|
-
}
|
|
27
|
-
return server.variables?.[part.name]?.default ?? `{${part.name}}`;
|
|
28
|
-
})
|
|
29
|
-
.join('');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function parseServerURL(url: string) {
|
|
33
|
-
const parts = url.split(/{([^}]+)}/g);
|
|
34
|
-
const result: Array<{ kind: 'variable'; name: string } | { kind: 'text'; text: string }> = [];
|
|
35
|
-
for (let i = 0; i < parts.length; i++) {
|
|
36
|
-
const part = parts[i];
|
|
37
|
-
if (!part) {
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
if (i % 2 === 0) {
|
|
41
|
-
result.push({ kind: 'text', text: part });
|
|
42
|
-
} else {
|
|
43
|
-
result.push({ kind: 'variable', name: part });
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return result;
|
|
47
|
-
}
|
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'bun:test';
|
|
2
|
-
import type { PrefillInputContextData } from '../OpenAPIPrefillContextProvider';
|
|
3
|
-
import type { OpenAPIOperationData } from '../types';
|
|
4
|
-
import { resolveTryItPrefillForOperation } from './tryit-prefill';
|
|
5
|
-
|
|
6
|
-
describe('resolveTryItPrefillForOperation', () => {
|
|
7
|
-
describe('prefill authentication info', () => {
|
|
8
|
-
it('should resolve prefill for bearer token scheme', () => {
|
|
9
|
-
const operation: OpenAPIOperationData = {
|
|
10
|
-
path: '/orgs/<orgId>/spaces/<spaceId>',
|
|
11
|
-
method: 'GET',
|
|
12
|
-
operation: { summary: 'Get space by ID' },
|
|
13
|
-
servers: [{ url: 'https://api.gitbook.com/v1/' }],
|
|
14
|
-
securities: [
|
|
15
|
-
[
|
|
16
|
-
'apiTokenScheme',
|
|
17
|
-
{
|
|
18
|
-
type: 'http',
|
|
19
|
-
scheme: 'bearer',
|
|
20
|
-
'x-gitbook-prefill': '{{ visitor.claims.apiToken }}',
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
],
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const prefillInputContext: PrefillInputContextData = {
|
|
27
|
-
visitor: { claims: { apiToken: 'gb_api_testToken' } },
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const result = resolveTryItPrefillForOperation({
|
|
31
|
-
operation,
|
|
32
|
-
prefillInputContext,
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
expect(result).toEqual({
|
|
36
|
-
authentication: {
|
|
37
|
-
securitySchemes: {
|
|
38
|
-
apiTokenScheme: { token: 'gb_api_testToken' },
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should resolve prefill for basic auth scheme', () => {
|
|
45
|
-
const operation: OpenAPIOperationData = {
|
|
46
|
-
path: '/orgs/<orgId>/spaces',
|
|
47
|
-
method: 'PUT',
|
|
48
|
-
operation: { summary: 'Create space in an org' },
|
|
49
|
-
servers: [{ url: 'https://api.gitbook.com/v1/' }],
|
|
50
|
-
securities: [
|
|
51
|
-
[
|
|
52
|
-
'basicAuthScheme',
|
|
53
|
-
{
|
|
54
|
-
type: 'http',
|
|
55
|
-
scheme: 'basic',
|
|
56
|
-
'x-gitbook-prefill': '{{ visitor.claims.basicAuth }}',
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
],
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const prefillInputContext: PrefillInputContextData = {
|
|
63
|
-
visitor: { claims: { basicAuth: 'testuser:testpassword' } },
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const result = resolveTryItPrefillForOperation({
|
|
67
|
-
operation,
|
|
68
|
-
prefillInputContext,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
expect(result).toEqual({
|
|
72
|
-
authentication: {
|
|
73
|
-
securitySchemes: {
|
|
74
|
-
basicAuthScheme: { username: 'testuser', password: 'testpassword' },
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('should resolve prefill for apiKey scheme', () => {
|
|
81
|
-
const operation: OpenAPIOperationData = {
|
|
82
|
-
path: '/orgs/<orgId>/spaces/<spaceId>',
|
|
83
|
-
method: 'POST',
|
|
84
|
-
operation: { summary: 'Update space by ID' },
|
|
85
|
-
servers: [{ url: 'https://api.gitbook.com/v1/' }],
|
|
86
|
-
securities: [
|
|
87
|
-
[
|
|
88
|
-
'apiKeyHeader',
|
|
89
|
-
{
|
|
90
|
-
type: 'apiKey',
|
|
91
|
-
in: 'header',
|
|
92
|
-
name: 'X-API-KEY',
|
|
93
|
-
'x-gitbook-prefill': '{{ visitor.claims.apiKey }}',
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
],
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const prefillInputContext: PrefillInputContextData = {
|
|
100
|
-
visitor: { claims: { apiKey: 'key-123' } },
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const result = resolveTryItPrefillForOperation({
|
|
104
|
-
operation,
|
|
105
|
-
prefillInputContext,
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
expect(result).toEqual({
|
|
109
|
-
authentication: {
|
|
110
|
-
securitySchemes: {
|
|
111
|
-
apiKeyHeader: { name: 'X-API-KEY', in: 'header', value: 'key-123' },
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('should return empty object if no visitor data matches prefill expression', () => {
|
|
118
|
-
const operation: OpenAPIOperationData = {
|
|
119
|
-
path: '/orgs/<orgId>/spaces',
|
|
120
|
-
method: 'GET',
|
|
121
|
-
operation: { summary: 'List all spaces in an org' },
|
|
122
|
-
servers: [{ url: 'https://api.gitbook.com/v1/' }],
|
|
123
|
-
securities: [
|
|
124
|
-
[
|
|
125
|
-
'bearer',
|
|
126
|
-
{
|
|
127
|
-
type: 'http',
|
|
128
|
-
scheme: 'bearer',
|
|
129
|
-
'x-gitbook-prefill': '{{ visitor.claims.missing }}',
|
|
130
|
-
},
|
|
131
|
-
],
|
|
132
|
-
],
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const prefillInputContext: PrefillInputContextData = {
|
|
136
|
-
visitor: { claims: {} },
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
const result = resolveTryItPrefillForOperation({
|
|
140
|
-
operation,
|
|
141
|
-
prefillInputContext,
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
expect(result).toEqual({});
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
describe('prefill server info', () => {
|
|
149
|
-
it('should prefill server at url level', () => {
|
|
150
|
-
const operation: OpenAPIOperationData = {
|
|
151
|
-
path: '/orgs/<orgId>/spaces',
|
|
152
|
-
method: 'GET',
|
|
153
|
-
operation: { summary: 'List spaces in an org' },
|
|
154
|
-
servers: [
|
|
155
|
-
{
|
|
156
|
-
url: 'https://api.gitbook.com/v1/',
|
|
157
|
-
description: 'GitBook API endpoint',
|
|
158
|
-
'x-gitbook-prefill': '{{ visitor.claims.api.endpointUrl }}',
|
|
159
|
-
},
|
|
160
|
-
],
|
|
161
|
-
securities: [],
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
const prefillInputContext: PrefillInputContextData = {
|
|
165
|
-
visitor: {
|
|
166
|
-
claims: { api: { endpointUrl: 'https://api.gitbook-staging.com/v1/' } },
|
|
167
|
-
},
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
const result = resolveTryItPrefillForOperation({
|
|
171
|
-
operation,
|
|
172
|
-
prefillInputContext,
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
expect(result).toEqual({
|
|
176
|
-
servers: [
|
|
177
|
-
{
|
|
178
|
-
url: 'https://api.gitbook-staging.com/v1/',
|
|
179
|
-
description: 'GitBook API endpoint',
|
|
180
|
-
},
|
|
181
|
-
],
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it('should prefill server at variables level', () => {
|
|
186
|
-
const operation: OpenAPIOperationData = {
|
|
187
|
-
path: '/orgs/<orgId>/spaces',
|
|
188
|
-
method: 'GET',
|
|
189
|
-
operation: { summary: 'List spaces in an org' },
|
|
190
|
-
servers: [
|
|
191
|
-
{
|
|
192
|
-
url: 'https://api.{domain}/{version}/',
|
|
193
|
-
description: 'Versioned API endpoint by environment',
|
|
194
|
-
variables: {
|
|
195
|
-
domain: {
|
|
196
|
-
default: 'gitbook.com',
|
|
197
|
-
'x-gitbook-prefill':
|
|
198
|
-
'{{ visitor.claims.api.env === "staging" ? "gitbook-staging.com" : "gitbook.com" }}',
|
|
199
|
-
},
|
|
200
|
-
version: {
|
|
201
|
-
default: 'v1',
|
|
202
|
-
'x-gitbook-prefill': '{{ visitor.claims.api.version }}',
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
],
|
|
207
|
-
securities: [],
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
// Override env
|
|
211
|
-
const overrideEnvResult = resolveTryItPrefillForOperation({
|
|
212
|
-
operation,
|
|
213
|
-
prefillInputContext: { visitor: { claims: { api: { env: 'staging' } } } },
|
|
214
|
-
});
|
|
215
|
-
expect(overrideEnvResult).toEqual({
|
|
216
|
-
servers: [
|
|
217
|
-
{
|
|
218
|
-
url: 'https://api.{domain}/{version}/',
|
|
219
|
-
description: 'Versioned API endpoint by environment',
|
|
220
|
-
variables: {
|
|
221
|
-
domain: { default: 'gitbook-staging.com' },
|
|
222
|
-
version: { default: 'v1' },
|
|
223
|
-
},
|
|
224
|
-
},
|
|
225
|
-
],
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
// Override version
|
|
229
|
-
const overrideVersionResult = resolveTryItPrefillForOperation({
|
|
230
|
-
operation,
|
|
231
|
-
prefillInputContext: { visitor: { claims: { api: { version: 'v2' } } } },
|
|
232
|
-
});
|
|
233
|
-
expect(overrideVersionResult).toEqual({
|
|
234
|
-
servers: [
|
|
235
|
-
{
|
|
236
|
-
url: 'https://api.{domain}/{version}/',
|
|
237
|
-
description: 'Versioned API endpoint by environment',
|
|
238
|
-
variables: {
|
|
239
|
-
domain: { default: 'gitbook.com' },
|
|
240
|
-
version: { default: 'v2' },
|
|
241
|
-
},
|
|
242
|
-
},
|
|
243
|
-
],
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
// Override both
|
|
247
|
-
const overrideBoth = resolveTryItPrefillForOperation({
|
|
248
|
-
operation,
|
|
249
|
-
prefillInputContext: {
|
|
250
|
-
visitor: { claims: { api: { env: 'staging', version: 'v2' } } },
|
|
251
|
-
},
|
|
252
|
-
});
|
|
253
|
-
expect(overrideBoth).toEqual({
|
|
254
|
-
servers: [
|
|
255
|
-
{
|
|
256
|
-
url: 'https://api.{domain}/{version}/',
|
|
257
|
-
description: 'Versioned API endpoint by environment',
|
|
258
|
-
variables: {
|
|
259
|
-
domain: { default: 'gitbook-staging.com' },
|
|
260
|
-
version: { default: 'v2' },
|
|
261
|
-
},
|
|
262
|
-
},
|
|
263
|
-
],
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
it('should ignore server prefill when no matching visitor data', () => {
|
|
268
|
-
const operation: OpenAPIOperationData = {
|
|
269
|
-
path: '/orgs/<orgId>/spaces',
|
|
270
|
-
method: 'GET',
|
|
271
|
-
operation: { summary: 'List spaces in an org' },
|
|
272
|
-
servers: [
|
|
273
|
-
{
|
|
274
|
-
url: 'https://api.{domain}/{version}/',
|
|
275
|
-
description: 'Versioned API endpoint by environment',
|
|
276
|
-
variables: {
|
|
277
|
-
domain: {
|
|
278
|
-
default: 'gitbook.com',
|
|
279
|
-
'x-gitbook-prefill':
|
|
280
|
-
'{{ visitor.claims.api.env === "staging" ? "gitbook-staging.com" : "gitbook.com" }}',
|
|
281
|
-
},
|
|
282
|
-
version: {
|
|
283
|
-
default: 'v1',
|
|
284
|
-
'x-gitbook-prefill': '{{ visitor.claims.api.version }}',
|
|
285
|
-
},
|
|
286
|
-
},
|
|
287
|
-
},
|
|
288
|
-
],
|
|
289
|
-
securities: [],
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
const result = resolveTryItPrefillForOperation({
|
|
293
|
-
operation,
|
|
294
|
-
prefillInputContext: { visitor: { claims: { isBetaUser: true } } },
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
expect(result).toEqual({
|
|
298
|
-
servers: [
|
|
299
|
-
{
|
|
300
|
-
url: 'https://api.{domain}/{version}/',
|
|
301
|
-
description: 'Versioned API endpoint by environment',
|
|
302
|
-
variables: {
|
|
303
|
-
domain: { default: 'gitbook.com' },
|
|
304
|
-
version: { default: 'v1' },
|
|
305
|
-
},
|
|
306
|
-
},
|
|
307
|
-
],
|
|
308
|
-
});
|
|
309
|
-
});
|
|
310
|
-
});
|
|
311
|
-
});
|