@gitbook/react-openapi 0.7.1 → 1.0.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 +49 -0
- package/dist/InteractiveSection.d.ts +4 -8
- package/dist/InteractiveSection.jsx +60 -0
- package/dist/Markdown.d.ts +1 -2
- package/dist/Markdown.jsx +5 -0
- package/dist/OpenAPICodeSample.d.ts +2 -4
- package/dist/OpenAPICodeSample.jsx +141 -0
- package/dist/OpenAPIDisclosure.d.ts +12 -0
- package/dist/OpenAPIDisclosure.jsx +32 -0
- package/dist/OpenAPIDisclosureGroup.d.ts +19 -0
- package/dist/OpenAPIDisclosureGroup.jsx +81 -0
- package/dist/OpenAPIOperation.d.ts +2 -4
- package/dist/OpenAPIOperation.jsx +51 -0
- package/dist/OpenAPIOperationContext.d.ts +16 -0
- package/dist/OpenAPIOperationContext.jsx +26 -0
- package/dist/OpenAPIPath.d.ts +8 -0
- package/dist/OpenAPIPath.jsx +54 -0
- package/dist/OpenAPIRequestBody.d.ts +4 -5
- package/dist/OpenAPIRequestBody.jsx +22 -0
- package/dist/OpenAPIResponse.d.ts +4 -4
- package/dist/OpenAPIResponse.jsx +39 -0
- package/dist/OpenAPIResponseExample.d.ts +2 -4
- package/dist/OpenAPIResponseExample.jsx +108 -0
- package/dist/OpenAPIResponses.d.ts +3 -4
- package/dist/OpenAPIResponses.jsx +35 -0
- package/dist/OpenAPISchema.d.ts +11 -8
- package/dist/OpenAPISchema.jsx +285 -0
- package/dist/OpenAPISchemaName.d.ts +12 -0
- package/dist/OpenAPISchemaName.jsx +15 -0
- package/dist/OpenAPISecurities.d.ts +2 -4
- package/dist/OpenAPISecurities.jsx +55 -0
- package/dist/OpenAPIServerURL.d.ts +2 -3
- package/dist/OpenAPIServerURL.jsx +67 -0
- package/dist/OpenAPIServerURLVariable.d.ts +2 -3
- package/dist/OpenAPIServerURLVariable.jsx +8 -0
- package/dist/OpenAPISpec.d.ts +3 -4
- package/dist/OpenAPISpec.jsx +91 -0
- package/dist/OpenAPITabs.d.ts +26 -0
- package/dist/OpenAPITabs.jsx +103 -0
- package/dist/ScalarApiButton.d.ts +3 -3
- package/dist/ScalarApiButton.jsx +51 -0
- package/dist/code-samples.d.ts +4 -0
- package/dist/code-samples.js +103 -38
- package/dist/generateSchemaExample.d.ts +2 -2
- package/dist/generateSchemaExample.js +29 -102
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/resolveOpenAPIOperation.d.ts +11 -0
- package/dist/resolveOpenAPIOperation.js +194 -0
- package/dist/stringifyOpenAPI.d.ts +4 -0
- package/dist/stringifyOpenAPI.js +6 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types.d.ts +11 -12
- package/dist/useSyncedTabsGlobalState.d.ts +1 -0
- package/dist/useSyncedTabsGlobalState.js +16 -0
- package/dist/utils.d.ts +6 -2
- package/dist/utils.js +13 -6
- package/package.json +12 -10
- package/src/InteractiveSection.tsx +90 -86
- package/src/Markdown.tsx +2 -3
- package/src/OpenAPICodeSample.tsx +43 -31
- package/src/OpenAPIDisclosure.tsx +50 -0
- package/src/OpenAPIDisclosureGroup.tsx +136 -0
- package/src/OpenAPIOperation.tsx +36 -42
- package/src/OpenAPIOperationContext.tsx +45 -0
- package/src/OpenAPIPath.tsx +65 -0
- package/src/OpenAPIRequestBody.tsx +10 -17
- package/src/OpenAPIResponse.tsx +27 -45
- package/src/OpenAPIResponseExample.tsx +89 -31
- package/src/OpenAPIResponses.tsx +48 -17
- package/src/OpenAPISchema.test.ts +1 -1
- package/src/OpenAPISchema.tsx +129 -108
- package/src/OpenAPISchemaName.tsx +27 -0
- package/src/OpenAPISecurities.tsx +45 -24
- package/src/OpenAPIServerURL.tsx +17 -10
- package/src/OpenAPIServerURLVariable.tsx +2 -4
- package/src/OpenAPISpec.tsx +58 -58
- package/src/OpenAPITabs.tsx +153 -0
- package/src/ScalarApiButton.tsx +84 -7
- package/src/code-samples.test.ts +51 -0
- package/src/code-samples.ts +95 -31
- package/src/generateSchemaExample.ts +26 -153
- package/src/index.ts +3 -2
- package/src/resolveOpenAPIOperation.test.ts +177 -0
- package/src/resolveOpenAPIOperation.ts +164 -0
- package/src/stringifyOpenAPI.ts +6 -0
- package/src/types.ts +17 -10
- package/src/useSyncedTabsGlobalState.ts +23 -0
- package/src/utils.ts +14 -7
- package/dist/InteractiveSection.js +0 -47
- package/dist/Markdown.js +0 -6
- package/dist/OpenAPICodeSample.js +0 -110
- package/dist/OpenAPIOperation.js +0 -38
- package/dist/OpenAPIRequestBody.js +0 -18
- package/dist/OpenAPIResponse.js +0 -32
- package/dist/OpenAPIResponseExample.js +0 -54
- package/dist/OpenAPIResponses.js +0 -18
- package/dist/OpenAPISchema.js +0 -235
- package/dist/OpenAPISchema.test.d.ts +0 -1
- package/dist/OpenAPISchema.test.js +0 -91
- package/dist/OpenAPISecurities.js +0 -42
- package/dist/OpenAPIServerURL.js +0 -51
- package/dist/OpenAPIServerURLVariable.js +0 -10
- package/dist/OpenAPISpec.js +0 -70
- package/dist/ScalarApiButton.js +0 -14
- package/dist/fetchOpenAPIOperation.d.ts +0 -72
- package/dist/fetchOpenAPIOperation.js +0 -124
- package/dist/fetchOpenAPIOperation.test.d.ts +0 -1
- package/dist/fetchOpenAPIOperation.test.js +0 -152
- package/dist/resolveOpenAPIPath.d.ts +0 -7
- package/dist/resolveOpenAPIPath.js +0 -112
- package/dist/resolveOpenAPIPath.test.d.ts +0 -1
- package/dist/resolveOpenAPIPath.test.js +0 -39
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/fetchOpenAPIOperation.test.ts +0 -185
- package/src/fetchOpenAPIOperation.ts +0 -230
- package/src/resolveOpenAPIPath.test.ts +0 -60
- package/src/resolveOpenAPIPath.ts +0 -145
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { OpenAPIRootSchema } from './OpenAPISchema';
|
|
2
|
+
import { InteractiveSection } from './InteractiveSection';
|
|
3
|
+
import { checkIsReference } from './utils';
|
|
4
|
+
/**
|
|
5
|
+
* Display an interactive request body.
|
|
6
|
+
*/
|
|
7
|
+
export function OpenAPIRequestBody(props) {
|
|
8
|
+
var _a;
|
|
9
|
+
var requestBody = props.requestBody, context = props.context;
|
|
10
|
+
if (checkIsReference(requestBody)) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
return (<InteractiveSection header="Body" className="openapi-requestbody" tabs={Object.entries((_a = requestBody.content) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
|
|
14
|
+
var _b;
|
|
15
|
+
var contentType = _a[0], mediaTypeObject = _a[1];
|
|
16
|
+
return {
|
|
17
|
+
key: contentType,
|
|
18
|
+
label: contentType,
|
|
19
|
+
body: (<OpenAPIRootSchema schema={(_b = mediaTypeObject.schema) !== null && _b !== void 0 ? _b : {}} context={context}/>),
|
|
20
|
+
};
|
|
21
|
+
})}/>);
|
|
22
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { OpenAPIClientContext } from './types';
|
|
1
|
+
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
+
import type { OpenAPIClientContext } from './types';
|
|
4
3
|
/**
|
|
5
4
|
* Display an interactive response body.
|
|
6
5
|
*/
|
|
7
6
|
export declare function OpenAPIResponse(props: {
|
|
8
7
|
response: OpenAPIV3.ResponseObject;
|
|
8
|
+
mediaType: OpenAPIV3.MediaTypeObject;
|
|
9
9
|
context: OpenAPIClientContext;
|
|
10
|
-
}):
|
|
10
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { OpenAPISchemaProperties } from './OpenAPISchema';
|
|
2
|
+
import { resolveDescription } from './utils';
|
|
3
|
+
import { OpenAPIDisclosure } from './OpenAPIDisclosure';
|
|
4
|
+
/**
|
|
5
|
+
* Display an interactive response body.
|
|
6
|
+
*/
|
|
7
|
+
export function OpenAPIResponse(props) {
|
|
8
|
+
var _a, _b, _c;
|
|
9
|
+
var response = props.response, context = props.context, mediaType = props.mediaType;
|
|
10
|
+
var headers = Object.entries((_a = response.headers) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
|
|
11
|
+
var name = _a[0], header = _a[1];
|
|
12
|
+
return [name, header !== null && header !== void 0 ? header : {}];
|
|
13
|
+
});
|
|
14
|
+
var content = Object.entries((_b = mediaType.schema) !== null && _b !== void 0 ? _b : {});
|
|
15
|
+
var description = resolveDescription(response);
|
|
16
|
+
if (content.length === 0 && !description && headers.length === 0) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return (<div className="openapi-response-body">
|
|
20
|
+
{headers.length > 0 ? (<OpenAPIDisclosure context={context} label={'Headers'}>
|
|
21
|
+
<OpenAPISchemaProperties properties={headers.map(function (_a) {
|
|
22
|
+
var _b;
|
|
23
|
+
var name = _a[0], header = _a[1];
|
|
24
|
+
return ({
|
|
25
|
+
propertyName: name,
|
|
26
|
+
schema: (_b = header.schema) !== null && _b !== void 0 ? _b : {},
|
|
27
|
+
required: header.required,
|
|
28
|
+
});
|
|
29
|
+
})} context={context}/>
|
|
30
|
+
</OpenAPIDisclosure>) : null}
|
|
31
|
+
<div className="openapi-responsebody">
|
|
32
|
+
<OpenAPISchemaProperties id={"response-".concat(context.blockKey)} properties={[
|
|
33
|
+
{
|
|
34
|
+
schema: (_c = mediaType.schema) !== null && _c !== void 0 ? _c : {},
|
|
35
|
+
},
|
|
36
|
+
]} context={context}/>
|
|
37
|
+
</div>
|
|
38
|
+
</div>);
|
|
39
|
+
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { OpenAPIOperationData } from './fetchOpenAPIOperation';
|
|
3
|
-
import { OpenAPIContextProps } from './types';
|
|
1
|
+
import type { OpenAPIContextProps, OpenAPIOperationData } from './types';
|
|
4
2
|
/**
|
|
5
3
|
* Display an example of the response content.
|
|
6
4
|
*/
|
|
7
5
|
export declare function OpenAPIResponseExample(props: {
|
|
8
6
|
data: OpenAPIOperationData;
|
|
9
7
|
context: OpenAPIContextProps;
|
|
10
|
-
}):
|
|
8
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { generateSchemaExample } from './generateSchemaExample';
|
|
2
|
+
import { checkIsReference, createStateKey, resolveDescription } from './utils';
|
|
3
|
+
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
|
4
|
+
import { OpenAPITabs, OpenAPITabsList, OpenAPITabsPanels } from './OpenAPITabs';
|
|
5
|
+
import { InteractiveSection } from './InteractiveSection';
|
|
6
|
+
/**
|
|
7
|
+
* Display an example of the response content.
|
|
8
|
+
*/
|
|
9
|
+
export function OpenAPIResponseExample(props) {
|
|
10
|
+
var data = props.data, context = props.context;
|
|
11
|
+
// if there are no responses defined for the operation
|
|
12
|
+
if (!data.operation.responses) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
var responses = Object.entries(data.operation.responses);
|
|
16
|
+
// Sort response to get 200, and 2xx first
|
|
17
|
+
responses.sort(function (_a, _b) {
|
|
18
|
+
var a = _a[0];
|
|
19
|
+
var b = _b[0];
|
|
20
|
+
if (a === 'default') {
|
|
21
|
+
return 1;
|
|
22
|
+
}
|
|
23
|
+
if (b === 'default') {
|
|
24
|
+
return -1;
|
|
25
|
+
}
|
|
26
|
+
if (a === '200') {
|
|
27
|
+
return -1;
|
|
28
|
+
}
|
|
29
|
+
if (b === '200') {
|
|
30
|
+
return 1;
|
|
31
|
+
}
|
|
32
|
+
return Number(a) - Number(b);
|
|
33
|
+
});
|
|
34
|
+
var examples = responses
|
|
35
|
+
.map(function (_a) {
|
|
36
|
+
var key = _a[0], value = _a[1];
|
|
37
|
+
var responseObject = value;
|
|
38
|
+
var mediaTypeObject = (function () {
|
|
39
|
+
var _a;
|
|
40
|
+
if (!responseObject.content) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
var key = Object.keys(responseObject.content)[0];
|
|
44
|
+
return ((_a = responseObject.content['application/json']) !== null && _a !== void 0 ? _a : (key ? responseObject.content[key] : null));
|
|
45
|
+
})();
|
|
46
|
+
if (!mediaTypeObject) {
|
|
47
|
+
return {
|
|
48
|
+
key: key,
|
|
49
|
+
label: key,
|
|
50
|
+
description: resolveDescription(responseObject),
|
|
51
|
+
body: <OpenAPIEmptyResponseExample />,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
var example = handleUnresolvedReference((function () {
|
|
55
|
+
var examples = mediaTypeObject.examples, example = mediaTypeObject.example;
|
|
56
|
+
if (examples) {
|
|
57
|
+
var key_1 = Object.keys(examples)[0];
|
|
58
|
+
if (key_1) {
|
|
59
|
+
// @TODO handle multiple examples
|
|
60
|
+
var firstExample = examples[key_1];
|
|
61
|
+
if (firstExample) {
|
|
62
|
+
return firstExample;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (example) {
|
|
67
|
+
return { value: example };
|
|
68
|
+
}
|
|
69
|
+
var schema = mediaTypeObject.schema;
|
|
70
|
+
if (!schema) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
return { value: generateSchemaExample(schema) };
|
|
74
|
+
})());
|
|
75
|
+
return {
|
|
76
|
+
key: key,
|
|
77
|
+
label: key,
|
|
78
|
+
description: resolveDescription(responseObject),
|
|
79
|
+
body: (example === null || example === void 0 ? void 0 : example.value) ? (<context.CodeBlock code={typeof example.value === 'string'
|
|
80
|
+
? example.value
|
|
81
|
+
: stringifyOpenAPI(example.value, null, 2)} syntax="json"/>) : (<OpenAPIEmptyResponseExample />),
|
|
82
|
+
};
|
|
83
|
+
})
|
|
84
|
+
.filter(function (val) {
|
|
85
|
+
return Boolean(val);
|
|
86
|
+
});
|
|
87
|
+
if (examples.length === 0) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
return (<OpenAPITabs stateKey={createStateKey('response-example')} items={examples}>
|
|
91
|
+
<InteractiveSection header={<OpenAPITabsList />} className="openapi-response-example">
|
|
92
|
+
<OpenAPITabsPanels />
|
|
93
|
+
</InteractiveSection>
|
|
94
|
+
</OpenAPITabs>);
|
|
95
|
+
}
|
|
96
|
+
function OpenAPIEmptyResponseExample() {
|
|
97
|
+
return (<pre className="openapi-response-example-empty">
|
|
98
|
+
<p>No body</p>
|
|
99
|
+
</pre>);
|
|
100
|
+
}
|
|
101
|
+
function handleUnresolvedReference(input) {
|
|
102
|
+
var isReference = checkIsReference(input === null || input === void 0 ? void 0 : input.value);
|
|
103
|
+
if (isReference) {
|
|
104
|
+
// If we find a reference that wasn't resolved or needed to be resolved externally, render out the URL
|
|
105
|
+
return { value: input.value.$ref };
|
|
106
|
+
}
|
|
107
|
+
return input;
|
|
108
|
+
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { OpenAPIV3 } from 'openapi-types';
|
|
1
|
+
import type { OpenAPIV3, OpenAPIV3_1 } from '@gitbook/openapi-parser';
|
|
3
2
|
import { OpenAPIClientContext } from './types';
|
|
4
3
|
/**
|
|
5
4
|
* Display an interactive response body.
|
|
6
5
|
*/
|
|
7
6
|
export declare function OpenAPIResponses(props: {
|
|
8
|
-
responses: OpenAPIV3.ResponsesObject;
|
|
7
|
+
responses: OpenAPIV3.ResponsesObject | OpenAPIV3_1.ResponsesObject;
|
|
9
8
|
context: OpenAPIClientContext;
|
|
10
|
-
}):
|
|
9
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { OpenAPIResponse } from './OpenAPIResponse';
|
|
2
|
+
import { InteractiveSection } from './InteractiveSection';
|
|
3
|
+
import { OpenAPIDisclosureGroup } from './OpenAPIDisclosureGroup';
|
|
4
|
+
import { Markdown } from './Markdown';
|
|
5
|
+
/**
|
|
6
|
+
* Display an interactive response body.
|
|
7
|
+
*/
|
|
8
|
+
export function OpenAPIResponses(props) {
|
|
9
|
+
var responses = props.responses, context = props.context;
|
|
10
|
+
return (<InteractiveSection header="Responses" className="openapi-responses">
|
|
11
|
+
<OpenAPIDisclosureGroup allowsMultipleExpanded icon={context.icons.chevronRight} groups={Object.entries(responses).map(function (_a) {
|
|
12
|
+
var _b;
|
|
13
|
+
var statusCode = _a[0], response = _a[1];
|
|
14
|
+
var content = Object.entries((_b = response.content) !== null && _b !== void 0 ? _b : {});
|
|
15
|
+
var description = response.description;
|
|
16
|
+
return {
|
|
17
|
+
id: statusCode,
|
|
18
|
+
label: (<div className="openapi-response-tab-content" key={"response-".concat(statusCode)}>
|
|
19
|
+
<span className="openapi-response-statuscode">
|
|
20
|
+
{statusCode}
|
|
21
|
+
</span>
|
|
22
|
+
{description ? (<Markdown source={description} className="openapi-response-description"/>) : null}
|
|
23
|
+
</div>),
|
|
24
|
+
tabs: content.map(function (_a) {
|
|
25
|
+
var contentType = _a[0], mediaType = _a[1];
|
|
26
|
+
return ({
|
|
27
|
+
id: contentType,
|
|
28
|
+
label: contentType,
|
|
29
|
+
body: (<OpenAPIResponse key={"$response-".concat(statusCode, "-").concat(contentType)} response={response} mediaType={mediaType} context={context}/>),
|
|
30
|
+
});
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
})}/>
|
|
34
|
+
</InteractiveSection>);
|
|
35
|
+
}
|
package/dist/OpenAPISchema.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { OpenAPIV3 } from 'openapi-
|
|
2
|
-
import
|
|
3
|
-
import { OpenAPIClientContext } from './types';
|
|
1
|
+
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
+
import type { OpenAPIClientContext } from './types';
|
|
4
3
|
type CircularRefsIds = Map<OpenAPIV3.SchemaObject, string>;
|
|
5
|
-
interface OpenAPISchemaPropertyEntry {
|
|
4
|
+
export interface OpenAPISchemaPropertyEntry {
|
|
6
5
|
propertyName?: string;
|
|
7
6
|
required?: boolean;
|
|
8
7
|
schema: OpenAPIV3.SchemaObject;
|
|
@@ -15,7 +14,7 @@ export declare function OpenAPISchemaProperty(props: OpenAPISchemaPropertyEntry
|
|
|
15
14
|
circularRefs?: CircularRefsIds;
|
|
16
15
|
context: OpenAPIClientContext;
|
|
17
16
|
className?: string;
|
|
18
|
-
}):
|
|
17
|
+
}): import("react").JSX.Element;
|
|
19
18
|
/**
|
|
20
19
|
* Render a set of properties of an OpenAPI schema.
|
|
21
20
|
*/
|
|
@@ -24,22 +23,26 @@ export declare function OpenAPISchemaProperties(props: {
|
|
|
24
23
|
properties: OpenAPISchemaPropertyEntry[];
|
|
25
24
|
circularRefs?: CircularRefsIds;
|
|
26
25
|
context: OpenAPIClientContext;
|
|
27
|
-
}):
|
|
26
|
+
}): import("react").JSX.Element | null;
|
|
28
27
|
/**
|
|
29
28
|
* Render a root schema (such as the request body or response body).
|
|
30
29
|
*/
|
|
31
30
|
export declare function OpenAPIRootSchema(props: {
|
|
32
31
|
schema: OpenAPIV3.SchemaObject;
|
|
33
32
|
context: OpenAPIClientContext;
|
|
34
|
-
}):
|
|
33
|
+
}): import("react").JSX.Element;
|
|
35
34
|
/**
|
|
36
35
|
* Render the enum value for a schema.
|
|
37
36
|
*/
|
|
38
37
|
export declare function OpenAPISchemaEnum(props: {
|
|
39
38
|
enumValues: any[];
|
|
40
|
-
}):
|
|
39
|
+
}): import("react").JSX.Element;
|
|
40
|
+
export declare function OpenAPISchemaPresentation(props: OpenAPISchemaPropertyEntry): import("react").JSX.Element;
|
|
41
41
|
/**
|
|
42
42
|
* Get the alternatives to display for a schema.
|
|
43
43
|
*/
|
|
44
44
|
export declare function getSchemaAlternatives(schema: OpenAPIV3.SchemaObject, ancestors?: Set<OpenAPIV3.SchemaObject>): null | [OpenAPIV3.SchemaObject[], OpenAPIV3.DiscriminatorObject | undefined];
|
|
45
|
+
export declare function getSchemaTitle(schema: OpenAPIV3.SchemaObject,
|
|
46
|
+
/** If the title is inferred in a oneOf with discriminator, we can use it to optimize the title */
|
|
47
|
+
discriminator?: OpenAPIV3.DiscriminatorObject): string;
|
|
45
48
|
export {};
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
|
+
if (ar || !(i in from)) {
|
|
4
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
5
|
+
ar[i] = from[i];
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
|
+
};
|
|
10
|
+
import clsx from 'clsx';
|
|
11
|
+
import { useId } from 'react';
|
|
12
|
+
import { InteractiveSection } from './InteractiveSection';
|
|
13
|
+
import { Markdown } from './Markdown';
|
|
14
|
+
import { checkIsReference, resolveDescription } from './utils';
|
|
15
|
+
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
|
16
|
+
import { OpenAPISchemaName } from './OpenAPISchemaName';
|
|
17
|
+
import { OpenAPIDisclosure } from './OpenAPIDisclosure';
|
|
18
|
+
/**
|
|
19
|
+
* Render a property of an OpenAPI schema.
|
|
20
|
+
*/
|
|
21
|
+
export function OpenAPISchemaProperty(props) {
|
|
22
|
+
var _a;
|
|
23
|
+
var schema = props.schema, _b = props.circularRefs, parentCircularRefs = _b === void 0 ? new Map() : _b, context = props.context, className = props.className;
|
|
24
|
+
var id = useId();
|
|
25
|
+
var parentCircularRef = parentCircularRefs.get(schema);
|
|
26
|
+
var circularRefs = new Map(parentCircularRefs).set(schema, id);
|
|
27
|
+
// Avoid recursing infinitely, and instead render a link to the parent schema
|
|
28
|
+
var properties = parentCircularRef ? null : getSchemaProperties(schema);
|
|
29
|
+
var alternatives = parentCircularRef
|
|
30
|
+
? null
|
|
31
|
+
: getSchemaAlternatives(schema, new Set(circularRefs.keys()));
|
|
32
|
+
if ((properties && !!properties.length) || schema.type === 'object') {
|
|
33
|
+
return (<InteractiveSection id={id} className={clsx('openapi-schema', className)}>
|
|
34
|
+
<OpenAPISchemaPresentation {...props}/>
|
|
35
|
+
{properties && properties.length > 0 ? (<OpenAPIDisclosure context={context}>
|
|
36
|
+
<OpenAPISchemaProperties properties={properties} circularRefs={circularRefs} context={context}/>
|
|
37
|
+
</OpenAPIDisclosure>) : null}
|
|
38
|
+
</InteractiveSection>);
|
|
39
|
+
}
|
|
40
|
+
if ((_a = alternatives === null || alternatives === void 0 ? void 0 : alternatives[0]) === null || _a === void 0 ? void 0 : _a.length) {
|
|
41
|
+
return (<InteractiveSection id={id} className={clsx('openapi-schema', className)}>
|
|
42
|
+
<OpenAPISchemaPresentation {...props}/>
|
|
43
|
+
{alternatives[0].map(function (alternative, index) { return (<OpenAPISchemaAlternative key={"alternative-".concat(index)} schema={alternative} circularRefs={circularRefs} context={context}/>); })}
|
|
44
|
+
</InteractiveSection>);
|
|
45
|
+
}
|
|
46
|
+
return (<InteractiveSection id={id} className={clsx('openapi-schema', className)}>
|
|
47
|
+
<OpenAPISchemaPresentation {...props}/>
|
|
48
|
+
{(properties && properties.length > 0) ||
|
|
49
|
+
(schema.enum && schema.enum.length > 0) ||
|
|
50
|
+
parentCircularRef ? (<>
|
|
51
|
+
{(properties === null || properties === void 0 ? void 0 : properties.length) ? (<OpenAPISchemaProperties properties={properties} circularRefs={circularRefs} context={context}/>) : null}
|
|
52
|
+
{parentCircularRef ? (<OpenAPISchemaCircularRef id={parentCircularRef} schema={schema}/>) : null}
|
|
53
|
+
</>) : null}
|
|
54
|
+
</InteractiveSection>);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Render a set of properties of an OpenAPI schema.
|
|
58
|
+
*/
|
|
59
|
+
export function OpenAPISchemaProperties(props) {
|
|
60
|
+
var id = props.id, properties = props.properties, circularRefs = props.circularRefs, context = props.context;
|
|
61
|
+
if (!properties.length) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
return (<div id={id} className="openapi-schema-properties">
|
|
65
|
+
{properties.map(function (property) { return (<OpenAPISchemaProperty key={property.propertyName} circularRefs={circularRefs} {...property} context={context}/>); })}
|
|
66
|
+
</div>);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Render a root schema (such as the request body or response body).
|
|
70
|
+
*/
|
|
71
|
+
export function OpenAPIRootSchema(props) {
|
|
72
|
+
var schema = props.schema, context = props.context;
|
|
73
|
+
// Avoid recursing infinitely, and instead render a link to the parent schema
|
|
74
|
+
var properties = getSchemaProperties(schema);
|
|
75
|
+
if (properties && properties.length > 0) {
|
|
76
|
+
return <OpenAPISchemaProperties properties={properties} context={context}/>;
|
|
77
|
+
}
|
|
78
|
+
return (<OpenAPISchemaProperty schema={schema} context={context} className="openapi-schema-root"/>);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Render a tab for an alternative schema.
|
|
82
|
+
* It renders directly the properties if relevant;
|
|
83
|
+
* for primitives, it renders the schema itself.
|
|
84
|
+
*/
|
|
85
|
+
function OpenAPISchemaAlternative(props) {
|
|
86
|
+
var schema = props.schema, circularRefs = props.circularRefs, context = props.context;
|
|
87
|
+
var id = useId();
|
|
88
|
+
var subProperties = getSchemaProperties(schema);
|
|
89
|
+
return (<OpenAPIDisclosure context={context}>
|
|
90
|
+
<OpenAPISchemaProperties id={id} properties={subProperties !== null && subProperties !== void 0 ? subProperties : [{ schema: schema }]} circularRefs={subProperties ? new Map(circularRefs).set(schema, id) : circularRefs} context={context}/>
|
|
91
|
+
</OpenAPIDisclosure>);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Render a circular reference to a schema.
|
|
95
|
+
*/
|
|
96
|
+
function OpenAPISchemaCircularRef(props) {
|
|
97
|
+
var id = props.id, schema = props.schema;
|
|
98
|
+
return (<div className="openapi-schema-circular">
|
|
99
|
+
Circular reference to <a href={"#".concat(id)}>{getSchemaTitle(schema)}</a>{' '}
|
|
100
|
+
<span className="openapi-schema-circular-glyph">↩</span>
|
|
101
|
+
</div>);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Render the enum value for a schema.
|
|
105
|
+
*/
|
|
106
|
+
export function OpenAPISchemaEnum(props) {
|
|
107
|
+
var enumValues = props.enumValues;
|
|
108
|
+
return (<div className="openapi-schema-enum">
|
|
109
|
+
<span>
|
|
110
|
+
Options:{' '}
|
|
111
|
+
{enumValues.map(function (value, index) { return (<span key={index} className="openapi-schema-enum-value">
|
|
112
|
+
<code>{"".concat(value)}</code>
|
|
113
|
+
{index < enumValues.length - 1 ? ', ' : ''}
|
|
114
|
+
</span>); })}
|
|
115
|
+
</span>
|
|
116
|
+
</div>);
|
|
117
|
+
}
|
|
118
|
+
export function OpenAPISchemaPresentation(props) {
|
|
119
|
+
var schema = props.schema, propertyName = props.propertyName, required = props.required;
|
|
120
|
+
var shouldDisplayExample = function (schema) {
|
|
121
|
+
return (typeof schema.example === 'string' ||
|
|
122
|
+
typeof schema.example === 'number' ||
|
|
123
|
+
typeof schema.example === 'boolean' ||
|
|
124
|
+
(Array.isArray(schema.example) && schema.example.length > 0) ||
|
|
125
|
+
(typeof schema.example === 'object' &&
|
|
126
|
+
schema.example !== null &&
|
|
127
|
+
Object.keys(schema.example).length > 0));
|
|
128
|
+
};
|
|
129
|
+
var description = resolveDescription(schema);
|
|
130
|
+
return (<div className="openapi-schema-presentation">
|
|
131
|
+
<OpenAPISchemaName type={getSchemaTitle(schema)} propertyName={propertyName} required={required} deprecated={schema.deprecated}/>
|
|
132
|
+
{schema['x-deprecated-sunset'] ? (<div className="openapi-deprecated-sunset openapi-schema-description openapi-markdown">
|
|
133
|
+
Sunset date:{' '}
|
|
134
|
+
<span className="openapi-deprecated-sunset-date">
|
|
135
|
+
{schema['x-deprecated-sunset']}
|
|
136
|
+
</span>
|
|
137
|
+
</div>) : null}
|
|
138
|
+
{description ? (<Markdown source={description} className="openapi-schema-description"/>) : null}
|
|
139
|
+
{shouldDisplayExample(schema) ? (<div className="openapi-schema-example">
|
|
140
|
+
Example:{' '}
|
|
141
|
+
<code>
|
|
142
|
+
{typeof schema.example === 'string'
|
|
143
|
+
? schema.example
|
|
144
|
+
: stringifyOpenAPI(schema.example)}
|
|
145
|
+
</code>
|
|
146
|
+
</div>) : null}
|
|
147
|
+
{schema.pattern ? (<div className="openapi-schema-pattern">
|
|
148
|
+
Pattern: <code>{schema.pattern}</code>
|
|
149
|
+
</div>) : null}
|
|
150
|
+
{schema.enum && schema.enum.length > 0 ? (<OpenAPISchemaEnum enumValues={schema.enum}/>) : null}
|
|
151
|
+
</div>);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get the sub-properties of a schema.
|
|
155
|
+
*/
|
|
156
|
+
function getSchemaProperties(schema) {
|
|
157
|
+
if (schema.allOf) {
|
|
158
|
+
return schema.allOf.reduce(function (acc, subSchema) {
|
|
159
|
+
var _a;
|
|
160
|
+
var properties = (_a = getSchemaProperties(subSchema)) !== null && _a !== void 0 ? _a : [
|
|
161
|
+
{
|
|
162
|
+
schema: subSchema,
|
|
163
|
+
},
|
|
164
|
+
];
|
|
165
|
+
return __spreadArray(__spreadArray([], acc, true), properties, true);
|
|
166
|
+
}, []);
|
|
167
|
+
}
|
|
168
|
+
// check array AND schema.items as this is sometimes null despite what the type indicates
|
|
169
|
+
if (schema.type === 'array' && !!schema.items) {
|
|
170
|
+
var items = schema.items;
|
|
171
|
+
var itemProperties = getSchemaProperties(items);
|
|
172
|
+
if (itemProperties) {
|
|
173
|
+
return itemProperties;
|
|
174
|
+
}
|
|
175
|
+
return [
|
|
176
|
+
{
|
|
177
|
+
propertyName: 'items',
|
|
178
|
+
schema: items,
|
|
179
|
+
},
|
|
180
|
+
];
|
|
181
|
+
}
|
|
182
|
+
if (schema.type === 'object' || schema.properties) {
|
|
183
|
+
var result_1 = [];
|
|
184
|
+
if (schema.properties) {
|
|
185
|
+
Object.entries(schema.properties).forEach(function (_a) {
|
|
186
|
+
var propertyName = _a[0], propertySchema = _a[1];
|
|
187
|
+
result_1.push({
|
|
188
|
+
propertyName: propertyName,
|
|
189
|
+
required: Array.isArray(schema.required)
|
|
190
|
+
? schema.required.includes(propertyName)
|
|
191
|
+
: undefined,
|
|
192
|
+
schema: propertySchema,
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
if (schema.additionalProperties) {
|
|
197
|
+
var additionalProperties = schema.additionalProperties;
|
|
198
|
+
result_1.push({
|
|
199
|
+
propertyName: 'Other properties',
|
|
200
|
+
schema: additionalProperties === true ? {} : additionalProperties,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return result_1;
|
|
204
|
+
}
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Get the alternatives to display for a schema.
|
|
209
|
+
*/
|
|
210
|
+
export function getSchemaAlternatives(schema, ancestors) {
|
|
211
|
+
if (ancestors === void 0) { ancestors = new Set(); }
|
|
212
|
+
var downAncestors = new Set(ancestors).add(schema);
|
|
213
|
+
if (schema.anyOf) {
|
|
214
|
+
return [flattenAlternatives('anyOf', schema.anyOf, downAncestors), schema.discriminator];
|
|
215
|
+
}
|
|
216
|
+
if (schema.oneOf) {
|
|
217
|
+
return [flattenAlternatives('oneOf', schema.oneOf, downAncestors), schema.discriminator];
|
|
218
|
+
}
|
|
219
|
+
if (schema.allOf) {
|
|
220
|
+
// allOf is managed in `getSchemaProperties`
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
function flattenAlternatives(alternativeType, alternatives, ancestors) {
|
|
226
|
+
return alternatives.reduce(function (acc, alternative) {
|
|
227
|
+
var _a;
|
|
228
|
+
if (!!alternative[alternativeType] && !ancestors.has(alternative)) {
|
|
229
|
+
return __spreadArray(__spreadArray([], acc, true), (((_a = getSchemaAlternatives(alternative, ancestors)) === null || _a === void 0 ? void 0 : _a[0]) || []), true);
|
|
230
|
+
}
|
|
231
|
+
return __spreadArray(__spreadArray([], acc, true), [alternative], false);
|
|
232
|
+
}, []);
|
|
233
|
+
}
|
|
234
|
+
export function getSchemaTitle(schema,
|
|
235
|
+
/** If the title is inferred in a oneOf with discriminator, we can use it to optimize the title */
|
|
236
|
+
discriminator) {
|
|
237
|
+
var _a;
|
|
238
|
+
if (schema.title) {
|
|
239
|
+
// If the schema has a title, use it
|
|
240
|
+
return schema.title;
|
|
241
|
+
}
|
|
242
|
+
// Try using the discriminator
|
|
243
|
+
if ((discriminator === null || discriminator === void 0 ? void 0 : discriminator.propertyName) && schema.properties) {
|
|
244
|
+
var discriminatorProperty = schema.properties[discriminator.propertyName];
|
|
245
|
+
if (discriminatorProperty && !checkIsReference(discriminatorProperty)) {
|
|
246
|
+
if (discriminatorProperty.enum) {
|
|
247
|
+
return discriminatorProperty.enum.map(function (value) { return value.toString(); }).join(' | ');
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// Otherwise try to infer a nice title
|
|
252
|
+
var type = 'any';
|
|
253
|
+
if (schema.enum) {
|
|
254
|
+
type = 'enum';
|
|
255
|
+
// check array AND schema.items as this is sometimes null despite what the type indicates
|
|
256
|
+
}
|
|
257
|
+
else if (schema.type === 'array' && !!schema.items) {
|
|
258
|
+
type = "".concat(getSchemaTitle(schema.items), "[]");
|
|
259
|
+
}
|
|
260
|
+
else if (Array.isArray(schema.type)) {
|
|
261
|
+
type = schema.type.join(' | ');
|
|
262
|
+
}
|
|
263
|
+
else if (schema.type || schema.properties) {
|
|
264
|
+
type = (_a = schema.type) !== null && _a !== void 0 ? _a : 'object';
|
|
265
|
+
if (schema.format) {
|
|
266
|
+
type += " ".concat(schema.format);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
else if ('anyOf' in schema) {
|
|
270
|
+
type = 'any of';
|
|
271
|
+
}
|
|
272
|
+
else if ('oneOf' in schema) {
|
|
273
|
+
type = 'one of';
|
|
274
|
+
}
|
|
275
|
+
else if ('allOf' in schema) {
|
|
276
|
+
type = 'all of';
|
|
277
|
+
}
|
|
278
|
+
else if ('not' in schema) {
|
|
279
|
+
type = 'not';
|
|
280
|
+
}
|
|
281
|
+
if (schema.nullable) {
|
|
282
|
+
type = "nullable ".concat(type);
|
|
283
|
+
}
|
|
284
|
+
return type;
|
|
285
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface OpenAPISchemaNameProps {
|
|
2
|
+
propertyName?: string | JSX.Element;
|
|
3
|
+
required?: boolean;
|
|
4
|
+
type?: string;
|
|
5
|
+
deprecated?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Display the schema name row.
|
|
9
|
+
* It includes the property name, type, required and deprecated status.
|
|
10
|
+
*/
|
|
11
|
+
export declare function OpenAPISchemaName(props: OpenAPISchemaNameProps): JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Display the schema name row.
|
|
3
|
+
* It includes the property name, type, required and deprecated status.
|
|
4
|
+
*/
|
|
5
|
+
export function OpenAPISchemaName(props) {
|
|
6
|
+
var type = props.type, propertyName = props.propertyName, required = props.required, deprecated = props.deprecated;
|
|
7
|
+
return (<div className="openapi-schema-name">
|
|
8
|
+
{propertyName ? (<span data-deprecated={deprecated} className="openapi-schema-propertyname">
|
|
9
|
+
{propertyName}
|
|
10
|
+
</span>) : null}
|
|
11
|
+
{type ? <span className="openapi-schema-type">{type}</span> : null}
|
|
12
|
+
{required ? <span className="openapi-schema-required">required</span> : null}
|
|
13
|
+
{deprecated ? <span className="openapi-deprecated">Deprecated</span> : null}
|
|
14
|
+
</div>);
|
|
15
|
+
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { OpenAPIClientContext } from './types';
|
|
3
|
-
import { OpenAPIOperationData } from './fetchOpenAPIOperation';
|
|
1
|
+
import type { OpenAPIClientContext, OpenAPIOperationData } from './types';
|
|
4
2
|
/**
|
|
5
3
|
* Present securities authorization that can be used for this operation.
|
|
6
4
|
*/
|
|
7
5
|
export declare function OpenAPISecurities(props: {
|
|
8
6
|
securities: OpenAPIOperationData['securities'];
|
|
9
7
|
context: OpenAPIClientContext;
|
|
10
|
-
}):
|
|
8
|
+
}): import("react").JSX.Element | null;
|