@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
package/src/context.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { type Translation, type TranslationLocale, translations } from './translations';
|
|
2
|
-
|
|
3
|
-
export interface OpenAPIClientContext {
|
|
4
|
-
/**
|
|
5
|
-
* The translation language to use.
|
|
6
|
-
*/
|
|
7
|
-
translation: Translation;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Icons used in the block.
|
|
11
|
-
*/
|
|
12
|
-
icons: {
|
|
13
|
-
chevronDown: React.ReactNode;
|
|
14
|
-
chevronRight: React.ReactNode;
|
|
15
|
-
plus: React.ReactNode;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Force all sections to be opened by default.
|
|
20
|
-
* @default false
|
|
21
|
-
*/
|
|
22
|
-
defaultInteractiveOpened?: boolean;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The key of the block
|
|
26
|
-
*/
|
|
27
|
-
blockKey?: string;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Optional id attached to the heading and used as an anchor.
|
|
31
|
-
*/
|
|
32
|
-
id?: string;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Mark the context as a client context.
|
|
36
|
-
*/
|
|
37
|
-
$$isClientContext$$: true;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface OpenAPIContext extends Omit<OpenAPIClientContext, '$$isClientContext$$'> {
|
|
41
|
-
/**
|
|
42
|
-
* Render a code block.
|
|
43
|
-
*/
|
|
44
|
-
renderCodeBlock: (props: { code: string; syntax: string }) => React.ReactNode;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Render the heading of the operation.
|
|
48
|
-
*/
|
|
49
|
-
renderHeading: (props: {
|
|
50
|
-
deprecated: boolean;
|
|
51
|
-
title: string;
|
|
52
|
-
stability?: string;
|
|
53
|
-
}) => React.ReactNode;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Render the document of the operation.
|
|
57
|
-
*/
|
|
58
|
-
renderDocument: (props: { document: object }) => React.ReactNode;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Specification URL.
|
|
62
|
-
*/
|
|
63
|
-
specUrl: string;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export type OpenAPIUniversalContext = OpenAPIClientContext | OpenAPIContext;
|
|
67
|
-
|
|
68
|
-
export interface OpenAPIContextInput extends Omit<OpenAPIContext, 'translation'> {
|
|
69
|
-
/**
|
|
70
|
-
* The translation language to use.
|
|
71
|
-
* @default 'en'
|
|
72
|
-
*/
|
|
73
|
-
locale?: TranslationLocale | undefined;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Resolve OpenAPI context from the input.
|
|
78
|
-
*/
|
|
79
|
-
export function resolveOpenAPIContext(context: OpenAPIContextInput): OpenAPIContext {
|
|
80
|
-
const { locale, ...rest } = context;
|
|
81
|
-
return {
|
|
82
|
-
...rest,
|
|
83
|
-
translation: translations[locale ?? 'en'],
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Get the client context from the OpenAPI context.
|
|
89
|
-
*/
|
|
90
|
-
export function getOpenAPIClientContext(context: OpenAPIUniversalContext): OpenAPIClientContext {
|
|
91
|
-
return {
|
|
92
|
-
translation: context.translation,
|
|
93
|
-
icons: context.icons,
|
|
94
|
-
defaultInteractiveOpened: context.defaultInteractiveOpened,
|
|
95
|
-
blockKey: context.blockKey,
|
|
96
|
-
id: context.id,
|
|
97
|
-
$$isClientContext$$: true,
|
|
98
|
-
};
|
|
99
|
-
}
|
package/src/decycle.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
// Forked from: https://github.com/YChebotaev/json-decycle/blob/master/src/index.ts
|
|
2
|
-
// Replaced `$ref` with `$reference` to avoid conflicts with OpenAPI
|
|
3
|
-
|
|
4
|
-
const isObject = (value: any): value is object =>
|
|
5
|
-
typeof value === 'object' &&
|
|
6
|
-
value != null &&
|
|
7
|
-
!(value instanceof Boolean) &&
|
|
8
|
-
!(value instanceof Date) &&
|
|
9
|
-
!(value instanceof Number) &&
|
|
10
|
-
!(value instanceof RegExp) &&
|
|
11
|
-
!(value instanceof String);
|
|
12
|
-
|
|
13
|
-
const toPointer = (parts: string[]) =>
|
|
14
|
-
`#${parts.map((part) => String(part).replace(/~/g, '~0').replace(/\//g, '~1')).join('/')}`;
|
|
15
|
-
|
|
16
|
-
export const decycle = () => {
|
|
17
|
-
const paths = new WeakMap();
|
|
18
|
-
|
|
19
|
-
return function replacer(this: any, key: string | symbol, value: any) {
|
|
20
|
-
if (key !== '$reference' && isObject(value)) {
|
|
21
|
-
const seen = paths.has(value);
|
|
22
|
-
|
|
23
|
-
if (seen) {
|
|
24
|
-
return { $reference: toPointer(paths.get(value)) };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
paths.set(value, [...(paths.get(this) ?? []), key]);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return value;
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export function retrocycle() {
|
|
35
|
-
const parents = new WeakMap();
|
|
36
|
-
const keys = new WeakMap();
|
|
37
|
-
const refs = new Set();
|
|
38
|
-
|
|
39
|
-
function dereference(this: { [k: string]: any }, ref: { $reference: string }) {
|
|
40
|
-
const parts = ref.$reference.slice(1).split('/');
|
|
41
|
-
let key: any;
|
|
42
|
-
let value = this;
|
|
43
|
-
|
|
44
|
-
for (let i = 0; i < parts.length; i++) {
|
|
45
|
-
key = parts[i]?.replace(/~1/g, '/').replace(/~0/g, '~');
|
|
46
|
-
value = value[key];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const parent = parents.get(ref);
|
|
50
|
-
parent[keys.get(ref)] = value;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return function reviver(this: object, key: string | symbol, value: any) {
|
|
54
|
-
if (key === '$reference') {
|
|
55
|
-
refs.add(this);
|
|
56
|
-
} else if (isObject(value)) {
|
|
57
|
-
const isRoot = key === '' && Object.keys(this).length === 1;
|
|
58
|
-
if (isRoot) {
|
|
59
|
-
refs.forEach(dereference as any, this);
|
|
60
|
-
} else {
|
|
61
|
-
parents.set(value, this);
|
|
62
|
-
keys.set(value, key);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return value;
|
|
67
|
-
};
|
|
68
|
-
}
|
package/src/dereference.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { type Filesystem, type OpenAPIV3xDocument, dereference } from '@gitbook/openapi-parser';
|
|
2
|
-
|
|
3
|
-
const dereferenceCache = new WeakMap<Filesystem, Promise<OpenAPIV3xDocument>>();
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Memoized version of `dereferenceSchema`.
|
|
7
|
-
*/
|
|
8
|
-
export function dereferenceFilesystem(filesystem: Filesystem): Promise<OpenAPIV3xDocument> {
|
|
9
|
-
if (dereferenceCache.has(filesystem)) {
|
|
10
|
-
return dereferenceCache.get(filesystem) as Promise<OpenAPIV3xDocument>;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const promise = baseDereferenceFilesystem(filesystem);
|
|
14
|
-
dereferenceCache.set(filesystem, promise);
|
|
15
|
-
return promise;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Dereference an OpenAPI schema.
|
|
20
|
-
*/
|
|
21
|
-
async function baseDereferenceFilesystem(filesystem: Filesystem): Promise<OpenAPIV3xDocument> {
|
|
22
|
-
const result = await dereference(filesystem);
|
|
23
|
-
|
|
24
|
-
if (!result.schema) {
|
|
25
|
-
throw new Error('Failed to dereference OpenAPI document');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return result.schema as OpenAPIV3xDocument;
|
|
29
|
-
}
|