@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
|
@@ -166,6 +166,11 @@ const getExampleFromSchema = (
|
|
|
166
166
|
// But if `emptyString` is set, we do want to see some values.
|
|
167
167
|
const makeUpRandomData = !!options?.emptyString;
|
|
168
168
|
|
|
169
|
+
// If the property is deprecated we don't show it in examples.
|
|
170
|
+
if (schema.deprecated) {
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
|
|
169
174
|
// Check if the property is read-only/write-only
|
|
170
175
|
if (
|
|
171
176
|
(options?.mode === 'write' && schema.readOnly) ||
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createStore } from 'zustand';
|
|
2
|
+
|
|
3
|
+
type Key = string | number;
|
|
4
|
+
|
|
5
|
+
type State = {
|
|
6
|
+
key: Key | null;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type Actions = { setKey: (key: Key | null) => void };
|
|
10
|
+
|
|
11
|
+
export type Store = State & Actions;
|
|
12
|
+
|
|
13
|
+
const createStateStore = (initial?: Key) => {
|
|
14
|
+
return createStore<Store>()((set) => ({
|
|
15
|
+
key: initial ?? null,
|
|
16
|
+
setKey: (key) => {
|
|
17
|
+
set(() => ({ key }));
|
|
18
|
+
},
|
|
19
|
+
}));
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const defaultStores = new Map<string, ReturnType<typeof createStateStore>>();
|
|
23
|
+
|
|
24
|
+
const createStateStoreFactory = (stores: typeof defaultStores) => {
|
|
25
|
+
return (storeKey: string, initialKey?: Key) => {
|
|
26
|
+
if (!stores.has(storeKey)) {
|
|
27
|
+
stores.set(storeKey, createStateStore(initialKey));
|
|
28
|
+
}
|
|
29
|
+
return stores.get(storeKey)!;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const getOrCreateStoreByKey = createStateStoreFactory(defaultStores);
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export * from './schemas';
|
|
2
2
|
export * from './OpenAPIOperation';
|
|
3
|
+
export * from './OpenAPIWebhook';
|
|
3
4
|
export * from './OpenAPIOperationContext';
|
|
4
5
|
export * from './resolveOpenAPIOperation';
|
|
5
|
-
export
|
|
6
|
+
export * from './resolveOpenAPIWebhook';
|
|
7
|
+
export type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
|
|
8
|
+
export type { OpenAPIContextInput } from './context';
|
|
9
|
+
export { checkIsValidLocale } from './translations';
|
|
@@ -40,16 +40,27 @@ export async function resolveOpenAPIOperation(
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
const servers = 'servers' in schema ? (schema.servers ?? []) : [];
|
|
43
|
-
const security
|
|
43
|
+
const security: OpenAPIV3_1.SecurityRequirementObject[] =
|
|
44
|
+
operation.security ?? schema.security ?? [];
|
|
45
|
+
|
|
46
|
+
// If security includes an empty object, it means that the security is optional
|
|
47
|
+
const isOptionalSecurity = security.some((entry) => Object.keys(entry).length === 0);
|
|
48
|
+
const flatSecurities = flattenSecurities(security);
|
|
44
49
|
|
|
45
50
|
// Resolve securities
|
|
46
51
|
const securities: OpenAPIOperationData['securities'] = [];
|
|
47
|
-
for (const entry of
|
|
52
|
+
for (const entry of flatSecurities) {
|
|
48
53
|
const securityKey = Object.keys(entry)[0];
|
|
49
54
|
if (securityKey) {
|
|
50
55
|
const securityScheme = schema.components?.securitySchemes?.[securityKey];
|
|
51
56
|
if (securityScheme && !checkIsReference(securityScheme)) {
|
|
52
|
-
securities.push([
|
|
57
|
+
securities.push([
|
|
58
|
+
securityKey,
|
|
59
|
+
{
|
|
60
|
+
...securityScheme,
|
|
61
|
+
required: !isOptionalSecurity,
|
|
62
|
+
},
|
|
63
|
+
]);
|
|
53
64
|
}
|
|
54
65
|
}
|
|
55
66
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { fromJSON, toJSON } from 'flatted';
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
Filesystem,
|
|
5
|
+
OpenAPIV3,
|
|
6
|
+
OpenAPIV3_1,
|
|
7
|
+
OpenAPIV3xDocument,
|
|
8
|
+
} from '@gitbook/openapi-parser';
|
|
9
|
+
import { dereferenceFilesystem } from './dereference';
|
|
10
|
+
import type { OpenAPIWebhookData } from './types';
|
|
11
|
+
|
|
12
|
+
export { fromJSON, toJSON };
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Resolve an OpenAPI webhook in a file and compile it to a more usable format.
|
|
16
|
+
*/
|
|
17
|
+
export async function resolveOpenAPIWebhook(
|
|
18
|
+
filesystem: Filesystem<OpenAPIV3xDocument>,
|
|
19
|
+
webhookDescriptor: {
|
|
20
|
+
name: string;
|
|
21
|
+
method: string;
|
|
22
|
+
}
|
|
23
|
+
): Promise<OpenAPIWebhookData | null> {
|
|
24
|
+
const { name, method } = webhookDescriptor;
|
|
25
|
+
const schema = await dereferenceFilesystem(filesystem);
|
|
26
|
+
let operation = getWebhookByNameAndMethod(schema, name, method);
|
|
27
|
+
|
|
28
|
+
if (!operation) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Resolve common parameters
|
|
33
|
+
const commonParameters = getPathObjectParameter(schema, name);
|
|
34
|
+
if (commonParameters) {
|
|
35
|
+
operation = {
|
|
36
|
+
...operation,
|
|
37
|
+
parameters: [...commonParameters, ...(operation.parameters ?? [])],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const servers = 'servers' in schema ? (schema.servers ?? []) : [];
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
servers,
|
|
45
|
+
operation,
|
|
46
|
+
method,
|
|
47
|
+
name,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get a path object from its path.
|
|
53
|
+
*/
|
|
54
|
+
function getPathObject(
|
|
55
|
+
schema: OpenAPIV3.Document | OpenAPIV3_1.Document,
|
|
56
|
+
name: string
|
|
57
|
+
): OpenAPIV3.PathItemObject | OpenAPIV3_1.PathItemObject | null {
|
|
58
|
+
if (schema.webhooks?.[name]) {
|
|
59
|
+
return schema.webhooks[name];
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Resolve parameters from a path in an OpenAPI schema.
|
|
66
|
+
*/
|
|
67
|
+
function getPathObjectParameter(
|
|
68
|
+
schema: OpenAPIV3.Document | OpenAPIV3_1.Document,
|
|
69
|
+
path: string
|
|
70
|
+
):
|
|
71
|
+
| (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[]
|
|
72
|
+
| (OpenAPIV3.ParameterObject | OpenAPIV3_1.ReferenceObject)[]
|
|
73
|
+
| null {
|
|
74
|
+
const pathObject = getPathObject(schema, path);
|
|
75
|
+
if (pathObject?.parameters) {
|
|
76
|
+
return pathObject.parameters;
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Get an operation by its path and method.
|
|
83
|
+
*/
|
|
84
|
+
function getWebhookByNameAndMethod(
|
|
85
|
+
schema: OpenAPIV3.Document | OpenAPIV3_1.Document,
|
|
86
|
+
name: string,
|
|
87
|
+
method: string
|
|
88
|
+
): OpenAPIV3.OperationObject | null {
|
|
89
|
+
// Types are buffy for OpenAPIV3_1.OperationObject, so we use v3
|
|
90
|
+
const pathObject = getPathObject(schema, name);
|
|
91
|
+
if (!pathObject) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
const normalizedMethod = method.toLowerCase();
|
|
95
|
+
if (!pathObject[normalizedMethod]) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
return pathObject[normalizedMethod];
|
|
99
|
+
}
|
|
@@ -1,99 +1,104 @@
|
|
|
1
|
+
import type { OpenAPISchema } from '@gitbook/openapi-parser';
|
|
1
2
|
import clsx from 'clsx';
|
|
2
|
-
import {
|
|
3
|
+
import { OpenAPIDisclosure } from '../OpenAPIDisclosure';
|
|
4
|
+
import { OpenAPIExample } from '../OpenAPIExample';
|
|
3
5
|
import { OpenAPIRootSchema } from '../OpenAPISchemaServer';
|
|
4
|
-
import { Section, SectionBody } from '../StaticSection';
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
import { Section, SectionBody, StaticSection } from '../StaticSection';
|
|
7
|
+
import {
|
|
8
|
+
type OpenAPIContextInput,
|
|
9
|
+
getOpenAPIClientContext,
|
|
10
|
+
resolveOpenAPIContext,
|
|
11
|
+
} from '../context';
|
|
12
|
+
import { t } from '../translate';
|
|
13
|
+
import { getExampleFromSchema } from '../util/example';
|
|
11
14
|
|
|
12
15
|
/**
|
|
13
|
-
*
|
|
16
|
+
* OpenAPI Schemas component.
|
|
14
17
|
*/
|
|
15
18
|
export function OpenAPISchemas(props: {
|
|
16
19
|
className?: string;
|
|
17
|
-
|
|
18
|
-
context:
|
|
20
|
+
schemas: OpenAPISchema[];
|
|
21
|
+
context: OpenAPIContextInput;
|
|
19
22
|
/**
|
|
20
23
|
* Whether to show the schema directly if there is only one.
|
|
21
24
|
*/
|
|
22
25
|
grouped?: boolean;
|
|
23
26
|
}) {
|
|
24
|
-
const {
|
|
25
|
-
const { schemas } = data;
|
|
27
|
+
const { schemas, context: contextInput, grouped, className } = props;
|
|
26
28
|
|
|
27
|
-
const
|
|
28
|
-
defaultInteractiveOpened: context.defaultInteractiveOpened,
|
|
29
|
-
icons: context.icons,
|
|
30
|
-
blockKey: context.blockKey,
|
|
31
|
-
};
|
|
29
|
+
const firstSchema = schemas[0];
|
|
32
30
|
|
|
33
|
-
if (!
|
|
31
|
+
if (!firstSchema) {
|
|
34
32
|
return null;
|
|
35
33
|
}
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
<OpenAPIRootSchemasSchema grouped={grouped} schemas={schemas} context={clientContext} />
|
|
40
|
-
</div>
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Root schema for OpenAPI schemas.
|
|
46
|
-
* It displays a single model or a disclosure group for multiple schemas.
|
|
47
|
-
*/
|
|
48
|
-
function OpenAPIRootSchemasSchema(props: {
|
|
49
|
-
schemas: OpenAPISchemasData['schemas'];
|
|
50
|
-
context: OpenAPIClientContext;
|
|
51
|
-
grouped?: boolean;
|
|
52
|
-
}) {
|
|
53
|
-
const { schemas, context, grouped } = props;
|
|
35
|
+
const context = resolveOpenAPIContext(contextInput);
|
|
36
|
+
const clientContext = getOpenAPIClientContext(context);
|
|
54
37
|
|
|
55
38
|
// If there is only one model and we are not grouping, we show it directly.
|
|
56
39
|
if (schemas.length === 1 && !grouped) {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
if (!schema) {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
|
|
40
|
+
const title = `The ${firstSchema.name} object`;
|
|
63
41
|
return (
|
|
64
|
-
<
|
|
65
|
-
<
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
42
|
+
<div className={clsx('openapi-schemas', className)}>
|
|
43
|
+
<div className="openapi-summary" id={context.id}>
|
|
44
|
+
{context.renderHeading({
|
|
45
|
+
title,
|
|
46
|
+
deprecated: Boolean(firstSchema.schema.deprecated),
|
|
47
|
+
stability: firstSchema.schema['x-stability'],
|
|
48
|
+
})}
|
|
49
|
+
</div>
|
|
50
|
+
<div className="openapi-columns">
|
|
51
|
+
<div className="openapi-column-spec">
|
|
52
|
+
<StaticSection
|
|
53
|
+
className="openapi-parameters"
|
|
54
|
+
header={t(context.translation, 'attributes')}
|
|
55
|
+
>
|
|
56
|
+
<OpenAPIRootSchema
|
|
57
|
+
schema={firstSchema.schema}
|
|
58
|
+
context={clientContext}
|
|
59
|
+
/>
|
|
60
|
+
</StaticSection>
|
|
61
|
+
</div>
|
|
62
|
+
<div className="openapi-column-preview">
|
|
63
|
+
<div className="openapi-column-preview-body">
|
|
64
|
+
<div className="openapi-panel">
|
|
65
|
+
<h4 className="openapi-panel-heading">{title}</h4>
|
|
66
|
+
<div className="openapi-panel-body">
|
|
67
|
+
<OpenAPIExample
|
|
68
|
+
example={getExampleFromSchema({
|
|
69
|
+
schema: firstSchema.schema,
|
|
70
|
+
})}
|
|
71
|
+
context={context}
|
|
72
|
+
syntax="json"
|
|
73
|
+
/>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
</div>
|
|
69
80
|
);
|
|
70
81
|
}
|
|
71
82
|
|
|
72
83
|
// If there are multiple schemas, we use a disclosure group to show them all.
|
|
73
84
|
return (
|
|
74
|
-
<
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
</Section>
|
|
93
|
-
),
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
}))}
|
|
97
|
-
/>
|
|
85
|
+
<div className={clsx('openapi-schemas', className)}>
|
|
86
|
+
{schemas.map(({ name, schema }) => {
|
|
87
|
+
return (
|
|
88
|
+
<OpenAPIDisclosure
|
|
89
|
+
className="openapi-schemas-disclosure"
|
|
90
|
+
key={name}
|
|
91
|
+
icon={context.icons.chevronRight}
|
|
92
|
+
label={name}
|
|
93
|
+
>
|
|
94
|
+
<Section className="openapi-section-schemas">
|
|
95
|
+
<SectionBody>
|
|
96
|
+
<OpenAPIRootSchema schema={schema} context={clientContext} />
|
|
97
|
+
</SectionBody>
|
|
98
|
+
</Section>
|
|
99
|
+
</OpenAPIDisclosure>
|
|
100
|
+
);
|
|
101
|
+
})}
|
|
102
|
+
</div>
|
|
98
103
|
);
|
|
99
104
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import type { Filesystem, OpenAPIV3xDocument } from '@gitbook/openapi-parser';
|
|
1
|
+
import type { Filesystem, OpenAPISchema, OpenAPIV3xDocument } from '@gitbook/openapi-parser';
|
|
2
2
|
import { filterSelectedOpenAPISchemas } from '@gitbook/openapi-parser';
|
|
3
3
|
import { dereferenceFilesystem } from '../dereference';
|
|
4
|
-
import type { OpenAPISchemasData } from '../types';
|
|
5
|
-
|
|
6
|
-
//!!TODO: We should return only the schemas that are used in the block. Still a WIP awaiting future work.
|
|
7
4
|
|
|
8
5
|
/**
|
|
9
6
|
* Resolve an OpenAPI schemas from a file and compile it to a more usable format.
|
|
@@ -14,7 +11,9 @@ export async function resolveOpenAPISchemas(
|
|
|
14
11
|
options: {
|
|
15
12
|
schemas: string[];
|
|
16
13
|
}
|
|
17
|
-
): Promise<
|
|
14
|
+
): Promise<{
|
|
15
|
+
schemas: OpenAPISchema[];
|
|
16
|
+
} | null> {
|
|
18
17
|
const { schemas: selectedSchemas } = options;
|
|
19
18
|
|
|
20
19
|
const schema = await dereferenceFilesystem(filesystem);
|
package/src/stringifyOpenAPI.ts
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Stringify an OpenAPI object. Same API as JSON.stringify.
|
|
3
3
|
*/
|
|
4
|
-
export function stringifyOpenAPI(
|
|
4
|
+
export function stringifyOpenAPI(
|
|
5
|
+
value: any,
|
|
6
|
+
replacer?: ((this: any, key: string, value: any) => any) | null,
|
|
7
|
+
space?: string | number
|
|
8
|
+
): string {
|
|
5
9
|
return JSON.stringify(
|
|
6
|
-
|
|
10
|
+
value,
|
|
7
11
|
(key, value) => {
|
|
8
12
|
// Ignore internal keys
|
|
9
13
|
if (key.startsWith('x-gitbook-')) {
|
|
10
14
|
return undefined;
|
|
11
15
|
}
|
|
12
16
|
|
|
17
|
+
if (replacer) {
|
|
18
|
+
return replacer(key, value);
|
|
19
|
+
}
|
|
20
|
+
|
|
13
21
|
return value;
|
|
14
22
|
},
|
|
15
|
-
|
|
23
|
+
space
|
|
16
24
|
);
|
|
17
25
|
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import type { Translation, TranslationKey } from './translations';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Translate a string.
|
|
7
|
+
*/
|
|
8
|
+
export function t(
|
|
9
|
+
translation: Translation,
|
|
10
|
+
id: TranslationKey,
|
|
11
|
+
...args: React.ReactNode[]
|
|
12
|
+
): React.ReactNode {
|
|
13
|
+
const string = translation[id];
|
|
14
|
+
if (!string) {
|
|
15
|
+
throw new Error(`Translation not found for "${id}"`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Now we are going to replace the arguments
|
|
19
|
+
// but we want to return a string as long as it's possible
|
|
20
|
+
// (eg. if there isn't any argument that is a ReactNode)
|
|
21
|
+
const parts: React.ReactNode[] = [];
|
|
22
|
+
let currentStringToReplace: string = string;
|
|
23
|
+
|
|
24
|
+
args.forEach((arg, i) => {
|
|
25
|
+
if (typeof arg === 'string') {
|
|
26
|
+
currentStringToReplace = currentStringToReplace.replace(`\${${i + 1}}`, arg);
|
|
27
|
+
} else {
|
|
28
|
+
const [partToPush, partToReplace] = currentStringToReplace.split(`\${${i + 1}}`);
|
|
29
|
+
if (partToPush === undefined || partToReplace === undefined) {
|
|
30
|
+
throw new Error(`Invalid translation "${id}"`);
|
|
31
|
+
}
|
|
32
|
+
parts.push(<React.Fragment key={`string-${i}`}>{partToPush}</React.Fragment>);
|
|
33
|
+
parts.push(<React.Fragment key={`arg-${i}`}>{arg}</React.Fragment>);
|
|
34
|
+
currentStringToReplace = partToReplace;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (!parts.length) {
|
|
39
|
+
return currentStringToReplace;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<>
|
|
44
|
+
{parts}
|
|
45
|
+
{currentStringToReplace}
|
|
46
|
+
</>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Version of `t` that returns a string.
|
|
52
|
+
*/
|
|
53
|
+
export function tString(
|
|
54
|
+
translation: Translation,
|
|
55
|
+
id: TranslationKey,
|
|
56
|
+
...args: React.ReactNode[]
|
|
57
|
+
): string {
|
|
58
|
+
const result = t(translation, id, ...args);
|
|
59
|
+
return reactToString(result);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function reactToString(el: React.ReactNode): string {
|
|
63
|
+
if (typeof el === 'string' || typeof el === 'number' || typeof el === 'boolean') {
|
|
64
|
+
return `${el}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (el === null || el === undefined) {
|
|
68
|
+
return '';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (Array.isArray(el)) {
|
|
72
|
+
return el.map(reactToString).join('');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (typeof el === 'object' && 'props' in el) {
|
|
76
|
+
return el.props.children.map(reactToString).join('');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
throw new Error(`Unsupported type ${typeof el}`);
|
|
80
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const de = {
|
|
2
|
+
required: 'Erforderlich',
|
|
3
|
+
deprecated: 'Veraltet',
|
|
4
|
+
deprecated_and_sunset_on: 'Diese Operation ist veraltet und wird am ${1} eingestellt.',
|
|
5
|
+
stability_experimental: 'Experimentell',
|
|
6
|
+
stability_alpha: 'Alpha',
|
|
7
|
+
stability_beta: 'Beta',
|
|
8
|
+
copy_to_clipboard: 'In die Zwischenablage kopieren',
|
|
9
|
+
copied: 'Kopiert',
|
|
10
|
+
no_content: 'Kein Inhalt',
|
|
11
|
+
unresolved_reference: 'Nicht aufgelöste Referenz',
|
|
12
|
+
circular_reference: 'Zirkuläre Referenz',
|
|
13
|
+
read_only: 'Nur lesen',
|
|
14
|
+
write_only: 'Nur schreiben',
|
|
15
|
+
optional: 'Optional',
|
|
16
|
+
min: 'Min',
|
|
17
|
+
max: 'Max',
|
|
18
|
+
nullable: 'Nullfähig',
|
|
19
|
+
body: 'Rumpf',
|
|
20
|
+
payload: 'Nutzlast',
|
|
21
|
+
headers: 'Kopfzeilen',
|
|
22
|
+
authorizations: 'Autorisierungen',
|
|
23
|
+
responses: 'Antworten',
|
|
24
|
+
path_parameters: 'Pfadparameter',
|
|
25
|
+
query_parameters: 'Abfrageparameter',
|
|
26
|
+
header_parameters: 'Header-Parameter',
|
|
27
|
+
attributes: 'Attribute',
|
|
28
|
+
test_it: 'Teste es',
|
|
29
|
+
information: 'Information',
|
|
30
|
+
success: 'Erfolg',
|
|
31
|
+
redirect: 'Umleitung',
|
|
32
|
+
error: 'Fehler',
|
|
33
|
+
show: 'Anzeigen',
|
|
34
|
+
hide: 'Verstecken',
|
|
35
|
+
available_items: 'Verfügbare Elemente',
|
|
36
|
+
child_attributes: 'Unterattribute',
|
|
37
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const en = {
|
|
2
|
+
required: 'Required',
|
|
3
|
+
deprecated: 'Deprecated',
|
|
4
|
+
deprecated_and_sunset_on: 'This operation is deprecated and will be sunset on ${1}.',
|
|
5
|
+
stability_experimental: 'Experimental',
|
|
6
|
+
stability_alpha: 'Alpha',
|
|
7
|
+
stability_beta: 'Beta',
|
|
8
|
+
copy_to_clipboard: 'Copy to clipboard',
|
|
9
|
+
copied: 'Copied',
|
|
10
|
+
no_content: 'No content',
|
|
11
|
+
unresolved_reference: 'Unresolved reference',
|
|
12
|
+
circular_reference: 'Circular reference',
|
|
13
|
+
read_only: 'Read-only',
|
|
14
|
+
write_only: 'Write-only',
|
|
15
|
+
optional: 'Optional',
|
|
16
|
+
min: 'Min',
|
|
17
|
+
max: 'Max',
|
|
18
|
+
nullable: 'Nullable',
|
|
19
|
+
body: 'Body',
|
|
20
|
+
payload: 'Payload',
|
|
21
|
+
headers: 'Headers',
|
|
22
|
+
authorizations: 'Authorizations',
|
|
23
|
+
responses: 'Responses',
|
|
24
|
+
path_parameters: 'Path parameters',
|
|
25
|
+
query_parameters: 'Query parameters',
|
|
26
|
+
header_parameters: 'Header parameters',
|
|
27
|
+
attributes: 'Attributes',
|
|
28
|
+
test_it: 'Test it',
|
|
29
|
+
information: 'Information',
|
|
30
|
+
success: 'Success',
|
|
31
|
+
redirect: 'Redirect',
|
|
32
|
+
error: 'Error',
|
|
33
|
+
show: 'Show',
|
|
34
|
+
hide: 'Hide',
|
|
35
|
+
available_items: 'Available items',
|
|
36
|
+
child_attributes: 'Child attributes',
|
|
37
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const es = {
|
|
2
|
+
required: 'Requerido',
|
|
3
|
+
deprecated: 'Obsoleto',
|
|
4
|
+
deprecated_and_sunset_on: 'Esta operación está obsoleta y se retirará el ${1}.',
|
|
5
|
+
stability_experimental: 'Experimental',
|
|
6
|
+
stability_alpha: 'Alfa',
|
|
7
|
+
stability_beta: 'Beta',
|
|
8
|
+
copy_to_clipboard: 'Copiar al portapapeles',
|
|
9
|
+
copied: 'Copiado',
|
|
10
|
+
no_content: 'Sin contenido',
|
|
11
|
+
unresolved_reference: 'Referencia no resuelta',
|
|
12
|
+
circular_reference: 'Referencia circular',
|
|
13
|
+
read_only: 'Solo lectura',
|
|
14
|
+
write_only: 'Solo escritura',
|
|
15
|
+
optional: 'Opcional',
|
|
16
|
+
min: 'Mín',
|
|
17
|
+
max: 'Máx',
|
|
18
|
+
nullable: 'Nulo',
|
|
19
|
+
body: 'Cuerpo',
|
|
20
|
+
payload: 'Caga útil',
|
|
21
|
+
headers: 'Encabezados',
|
|
22
|
+
authorizations: 'Autorizaciones',
|
|
23
|
+
responses: 'Respuestas',
|
|
24
|
+
path_parameters: 'Parámetros de ruta',
|
|
25
|
+
query_parameters: 'Parámetros de consulta',
|
|
26
|
+
header_parameters: 'Parámetros de encabezado',
|
|
27
|
+
attributes: 'Atributos',
|
|
28
|
+
test_it: 'Pruébalo',
|
|
29
|
+
information: 'Información',
|
|
30
|
+
success: 'Éxito',
|
|
31
|
+
redirect: 'Redirección',
|
|
32
|
+
error: 'Error',
|
|
33
|
+
show: 'Mostrar',
|
|
34
|
+
hide: 'Ocultar',
|
|
35
|
+
available_items: 'Elementos disponibles',
|
|
36
|
+
child_attributes: 'Atributos secundarios',
|
|
37
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const fr = {
|
|
2
|
+
required: 'Requis',
|
|
3
|
+
deprecated: 'Obsolète',
|
|
4
|
+
deprecated_and_sunset_on: 'Cette opération est obsolète et sera supprimée le ${1}.',
|
|
5
|
+
stability_experimental: 'Expérimental',
|
|
6
|
+
stability_alpha: 'Alpha',
|
|
7
|
+
stability_beta: 'Bêta',
|
|
8
|
+
copy_to_clipboard: 'Copier dans le presse-papiers',
|
|
9
|
+
copied: 'Copié',
|
|
10
|
+
no_content: 'Aucun contenu',
|
|
11
|
+
unresolved_reference: 'Référence non résolue',
|
|
12
|
+
circular_reference: 'Référence circulaire',
|
|
13
|
+
read_only: 'Lecture seule',
|
|
14
|
+
write_only: 'Écriture seule',
|
|
15
|
+
optional: 'Optionnel',
|
|
16
|
+
min: 'Min',
|
|
17
|
+
max: 'Max',
|
|
18
|
+
nullable: 'Nullable',
|
|
19
|
+
body: 'Corps',
|
|
20
|
+
payload: 'Charge utile',
|
|
21
|
+
headers: 'En-têtes',
|
|
22
|
+
authorizations: 'Autorisations',
|
|
23
|
+
responses: 'Réponses',
|
|
24
|
+
path_parameters: 'Paramètres de chemin',
|
|
25
|
+
query_parameters: 'Paramètres de requête',
|
|
26
|
+
header_parameters: 'Paramètres d’en-tête',
|
|
27
|
+
attributes: 'Attributs',
|
|
28
|
+
test_it: 'Tester',
|
|
29
|
+
information: 'Information',
|
|
30
|
+
success: 'Succès',
|
|
31
|
+
redirect: 'Redirection',
|
|
32
|
+
error: 'Erreur',
|
|
33
|
+
show: 'Afficher',
|
|
34
|
+
hide: 'Masquer',
|
|
35
|
+
available_items: 'Éléments disponibles',
|
|
36
|
+
child_attributes: 'Attributs enfants',
|
|
37
|
+
};
|