@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,80 +0,0 @@
|
|
|
1
|
-
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
-
import type React from 'react';
|
|
3
|
-
import type { OpenAPIClientContext } from './context';
|
|
4
|
-
import { t, tString } from './translate';
|
|
5
|
-
|
|
6
|
-
interface OpenAPISchemaNameProps {
|
|
7
|
-
schema?: OpenAPIV3.SchemaObject;
|
|
8
|
-
propertyName?: string | React.JSX.Element;
|
|
9
|
-
required?: boolean | null;
|
|
10
|
-
type?: string;
|
|
11
|
-
context: OpenAPIClientContext;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Display the schema name row.
|
|
16
|
-
* It includes the property name, type, required and deprecated status.
|
|
17
|
-
*/
|
|
18
|
-
export function OpenAPISchemaName(props: OpenAPISchemaNameProps) {
|
|
19
|
-
const { schema, type, propertyName, required, context } = props;
|
|
20
|
-
|
|
21
|
-
const additionalItems = schema && getAdditionalItems(schema, context);
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
<span className="openapi-schema-name">
|
|
25
|
-
{propertyName ? (
|
|
26
|
-
<span data-deprecated={schema?.deprecated} className="openapi-schema-propertyname">
|
|
27
|
-
{propertyName}
|
|
28
|
-
</span>
|
|
29
|
-
) : null}
|
|
30
|
-
{type || additionalItems ? (
|
|
31
|
-
<span>
|
|
32
|
-
{type ? <span className="openapi-schema-type">{type}</span> : null}
|
|
33
|
-
{additionalItems ? (
|
|
34
|
-
<span className="openapi-schema-type">{additionalItems}</span>
|
|
35
|
-
) : null}
|
|
36
|
-
</span>
|
|
37
|
-
) : null}
|
|
38
|
-
{schema?.readOnly ? (
|
|
39
|
-
<span className="openapi-schema-readonly">
|
|
40
|
-
{t(context.translation, 'read_only')}
|
|
41
|
-
</span>
|
|
42
|
-
) : null}
|
|
43
|
-
{schema?.writeOnly ? (
|
|
44
|
-
<span className="openapi-schema-writeonly">
|
|
45
|
-
{t(context.translation, 'write_only')}
|
|
46
|
-
</span>
|
|
47
|
-
) : null}
|
|
48
|
-
{required === null ? null : required ? (
|
|
49
|
-
<span className="openapi-schema-required">
|
|
50
|
-
{t(context.translation, 'required')}
|
|
51
|
-
</span>
|
|
52
|
-
) : (
|
|
53
|
-
<span className="openapi-schema-optional">
|
|
54
|
-
{t(context.translation, 'optional')}
|
|
55
|
-
</span>
|
|
56
|
-
)}
|
|
57
|
-
{schema?.deprecated ? (
|
|
58
|
-
<span className="openapi-deprecated">{t(context.translation, 'deprecated')}</span>
|
|
59
|
-
) : null}
|
|
60
|
-
</span>
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function getAdditionalItems(schema: OpenAPIV3.SchemaObject, context: OpenAPIClientContext): string {
|
|
65
|
-
let additionalItems = '';
|
|
66
|
-
|
|
67
|
-
if (schema.minimum || schema.minLength || schema.minItems) {
|
|
68
|
-
additionalItems += ` · ${tString(context.translation, 'min').toLowerCase()}: ${schema.minimum || schema.minLength || schema.minItems}`;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (schema.maximum || schema.maxLength || schema.maxItems) {
|
|
72
|
-
additionalItems += ` · ${tString(context.translation, 'max').toLowerCase()}: ${schema.maximum || schema.maxLength || schema.maxItems}`;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (schema.nullable) {
|
|
76
|
-
additionalItems = ` | ${tString(context.translation, 'nullable').toLowerCase()}`;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return additionalItems;
|
|
80
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
-
import {
|
|
3
|
-
OpenAPIRootSchemaFromServer,
|
|
4
|
-
OpenAPISchemaPropertiesFromServer,
|
|
5
|
-
type OpenAPISchemaPropertyEntry,
|
|
6
|
-
} from './OpenAPISchema';
|
|
7
|
-
import type { OpenAPIClientContext } from './context';
|
|
8
|
-
import { decycle } from './decycle';
|
|
9
|
-
|
|
10
|
-
export function OpenAPISchemaProperties(props: {
|
|
11
|
-
id?: string;
|
|
12
|
-
properties: OpenAPISchemaPropertyEntry[];
|
|
13
|
-
context: OpenAPIClientContext;
|
|
14
|
-
}) {
|
|
15
|
-
return (
|
|
16
|
-
<OpenAPISchemaPropertiesFromServer
|
|
17
|
-
id={props.id}
|
|
18
|
-
properties={JSON.stringify(props.properties, decycle())}
|
|
19
|
-
context={props.context}
|
|
20
|
-
/>
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function OpenAPIRootSchema(props: {
|
|
25
|
-
schema: OpenAPIV3.SchemaObject;
|
|
26
|
-
context: OpenAPIClientContext;
|
|
27
|
-
}) {
|
|
28
|
-
return (
|
|
29
|
-
<OpenAPIRootSchemaFromServer
|
|
30
|
-
schema={JSON.stringify(props.schema, decycle())}
|
|
31
|
-
context={props.context}
|
|
32
|
-
/>
|
|
33
|
-
);
|
|
34
|
-
}
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
-
import { InteractiveSection } from './InteractiveSection';
|
|
3
|
-
import { Markdown } from './Markdown';
|
|
4
|
-
import { OpenAPICopyButton } from './OpenAPICopyButton';
|
|
5
|
-
import { OpenAPISchemaName } from './OpenAPISchemaName';
|
|
6
|
-
import type { OpenAPIClientContext } from './context';
|
|
7
|
-
import { t } from './translate';
|
|
8
|
-
import type { OpenAPIOperationData, OpenAPISecurityWithRequired } from './types';
|
|
9
|
-
import { createStateKey, resolveDescription } from './utils';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Present securities authorization that can be used for this operation.
|
|
13
|
-
*/
|
|
14
|
-
export function OpenAPISecurities(props: {
|
|
15
|
-
securities: OpenAPIOperationData['securities'];
|
|
16
|
-
context: OpenAPIClientContext;
|
|
17
|
-
}) {
|
|
18
|
-
const { securities, context } = props;
|
|
19
|
-
|
|
20
|
-
if (securities.length === 0) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<InteractiveSection
|
|
26
|
-
header={t(context.translation, 'authorizations')}
|
|
27
|
-
stateKey={createStateKey('securities', context.blockKey)}
|
|
28
|
-
toggeable
|
|
29
|
-
defaultOpened={false}
|
|
30
|
-
toggleIcon={context.icons.chevronRight}
|
|
31
|
-
selectIcon={context.icons.chevronDown}
|
|
32
|
-
className="openapi-securities"
|
|
33
|
-
tabs={securities.map(([key, security]) => {
|
|
34
|
-
const description = resolveDescription(security);
|
|
35
|
-
return {
|
|
36
|
-
key: key,
|
|
37
|
-
label: key,
|
|
38
|
-
body: (
|
|
39
|
-
<div className="openapi-schema">
|
|
40
|
-
<div className="openapi-schema-presentation">
|
|
41
|
-
{getLabelForType(security, context)}
|
|
42
|
-
|
|
43
|
-
{description ? (
|
|
44
|
-
<Markdown
|
|
45
|
-
source={description}
|
|
46
|
-
className="openapi-securities-description"
|
|
47
|
-
/>
|
|
48
|
-
) : null}
|
|
49
|
-
</div>
|
|
50
|
-
</div>
|
|
51
|
-
),
|
|
52
|
-
};
|
|
53
|
-
})}
|
|
54
|
-
/>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function getLabelForType(security: OpenAPISecurityWithRequired, context: OpenAPIClientContext) {
|
|
59
|
-
switch (security.type) {
|
|
60
|
-
case 'apiKey':
|
|
61
|
-
return (
|
|
62
|
-
<OpenAPISchemaName
|
|
63
|
-
context={context}
|
|
64
|
-
propertyName={security.name ?? 'apiKey'}
|
|
65
|
-
type="string"
|
|
66
|
-
required={security.required}
|
|
67
|
-
/>
|
|
68
|
-
);
|
|
69
|
-
case 'http':
|
|
70
|
-
if (security.scheme === 'basic') {
|
|
71
|
-
return (
|
|
72
|
-
<OpenAPISchemaName
|
|
73
|
-
context={context}
|
|
74
|
-
propertyName="Authorization"
|
|
75
|
-
type="string"
|
|
76
|
-
required={security.required}
|
|
77
|
-
/>
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (security.scheme === 'bearer') {
|
|
82
|
-
const description = resolveDescription(security);
|
|
83
|
-
return (
|
|
84
|
-
<>
|
|
85
|
-
<OpenAPISchemaName
|
|
86
|
-
context={context}
|
|
87
|
-
propertyName="Authorization"
|
|
88
|
-
type="string"
|
|
89
|
-
required={security.required}
|
|
90
|
-
/>
|
|
91
|
-
{/** Show a default description if none is provided */}
|
|
92
|
-
{!description ? (
|
|
93
|
-
<Markdown
|
|
94
|
-
source={`Bearer authentication header of the form Bearer ${'<token>'}.`}
|
|
95
|
-
className="openapi-securities-description"
|
|
96
|
-
/>
|
|
97
|
-
) : null}
|
|
98
|
-
</>
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return (
|
|
103
|
-
<OpenAPISchemaName
|
|
104
|
-
context={context}
|
|
105
|
-
propertyName="HTTP"
|
|
106
|
-
required={security.required}
|
|
107
|
-
/>
|
|
108
|
-
);
|
|
109
|
-
case 'oauth2':
|
|
110
|
-
return <OpenAPISchemaOAuth2Flows context={context} security={security} />;
|
|
111
|
-
case 'openIdConnect':
|
|
112
|
-
return (
|
|
113
|
-
<OpenAPISchemaName
|
|
114
|
-
context={context}
|
|
115
|
-
propertyName="OpenID Connect"
|
|
116
|
-
required={security.required}
|
|
117
|
-
/>
|
|
118
|
-
);
|
|
119
|
-
default:
|
|
120
|
-
// @ts-ignore
|
|
121
|
-
return security.type;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function OpenAPISchemaOAuth2Flows(props: {
|
|
126
|
-
context: OpenAPIClientContext;
|
|
127
|
-
security: OpenAPIV3.OAuth2SecurityScheme & { required?: boolean };
|
|
128
|
-
}) {
|
|
129
|
-
const { context, security } = props;
|
|
130
|
-
|
|
131
|
-
const flows = Object.entries(security.flows ?? {});
|
|
132
|
-
|
|
133
|
-
return (
|
|
134
|
-
<div className="openapi-securities-oauth-flows">
|
|
135
|
-
{flows.map(([name, flow], index) => (
|
|
136
|
-
<OpenAPISchemaOAuth2Item
|
|
137
|
-
key={index}
|
|
138
|
-
flow={flow}
|
|
139
|
-
name={name}
|
|
140
|
-
context={context}
|
|
141
|
-
security={security}
|
|
142
|
-
/>
|
|
143
|
-
))}
|
|
144
|
-
</div>
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function OpenAPISchemaOAuth2Item(props: {
|
|
149
|
-
flow: NonNullable<OpenAPIV3.OAuth2SecurityScheme['flows']>[keyof NonNullable<
|
|
150
|
-
OpenAPIV3.OAuth2SecurityScheme['flows']
|
|
151
|
-
>];
|
|
152
|
-
name: string;
|
|
153
|
-
context: OpenAPIClientContext;
|
|
154
|
-
security: OpenAPIV3.OAuth2SecurityScheme & { required?: boolean };
|
|
155
|
-
}) {
|
|
156
|
-
const { flow, context, security, name } = props;
|
|
157
|
-
|
|
158
|
-
if (!flow) {
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const scopes = Object.entries(flow?.scopes ?? {});
|
|
163
|
-
|
|
164
|
-
return (
|
|
165
|
-
<div>
|
|
166
|
-
<OpenAPISchemaName
|
|
167
|
-
context={context}
|
|
168
|
-
propertyName="OAuth2"
|
|
169
|
-
type={name}
|
|
170
|
-
required={security.required}
|
|
171
|
-
/>
|
|
172
|
-
<div className="openapi-securities-oauth-content openapi-markdown">
|
|
173
|
-
{security.description ? <Markdown source={security.description} /> : null}
|
|
174
|
-
{'authorizationUrl' in flow && flow.authorizationUrl ? (
|
|
175
|
-
<span>
|
|
176
|
-
Authorization URL:{' '}
|
|
177
|
-
<OpenAPICopyButton
|
|
178
|
-
value={flow.authorizationUrl}
|
|
179
|
-
context={context}
|
|
180
|
-
className="openapi-securities-url"
|
|
181
|
-
withTooltip
|
|
182
|
-
>
|
|
183
|
-
{flow.authorizationUrl}
|
|
184
|
-
</OpenAPICopyButton>
|
|
185
|
-
</span>
|
|
186
|
-
) : null}
|
|
187
|
-
{'tokenUrl' in flow && flow.tokenUrl ? (
|
|
188
|
-
<span>
|
|
189
|
-
Token URL:{' '}
|
|
190
|
-
<OpenAPICopyButton
|
|
191
|
-
value={flow.tokenUrl}
|
|
192
|
-
context={context}
|
|
193
|
-
className="openapi-securities-url"
|
|
194
|
-
withTooltip
|
|
195
|
-
>
|
|
196
|
-
{flow.tokenUrl}
|
|
197
|
-
</OpenAPICopyButton>
|
|
198
|
-
</span>
|
|
199
|
-
) : null}
|
|
200
|
-
{'refreshUrl' in flow && flow.refreshUrl ? (
|
|
201
|
-
<span>
|
|
202
|
-
Refresh URL:{' '}
|
|
203
|
-
<OpenAPICopyButton
|
|
204
|
-
value={flow.refreshUrl}
|
|
205
|
-
context={context}
|
|
206
|
-
className="openapi-securities-url"
|
|
207
|
-
withTooltip
|
|
208
|
-
>
|
|
209
|
-
{flow.refreshUrl}
|
|
210
|
-
</OpenAPICopyButton>
|
|
211
|
-
</span>
|
|
212
|
-
) : null}
|
|
213
|
-
{scopes.length ? (
|
|
214
|
-
<div>
|
|
215
|
-
{t(context.translation, 'available_scopes')}:{' '}
|
|
216
|
-
<ul>
|
|
217
|
-
{scopes.map(([key, value]) => (
|
|
218
|
-
<li key={key}>
|
|
219
|
-
<OpenAPICopyButton value={key} context={context} withTooltip>
|
|
220
|
-
<code>{key}</code>
|
|
221
|
-
</OpenAPICopyButton>
|
|
222
|
-
: {value}
|
|
223
|
-
</li>
|
|
224
|
-
))}
|
|
225
|
-
</ul>
|
|
226
|
-
</div>
|
|
227
|
-
) : null}
|
|
228
|
-
</div>
|
|
229
|
-
</div>
|
|
230
|
-
);
|
|
231
|
-
}
|
package/src/OpenAPISelect.tsx
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import clsx from 'clsx';
|
|
4
|
-
import { useCallback } from 'react';
|
|
5
|
-
import {
|
|
6
|
-
Button,
|
|
7
|
-
type Key,
|
|
8
|
-
ListBox,
|
|
9
|
-
ListBoxItem,
|
|
10
|
-
type ListBoxItemProps,
|
|
11
|
-
Popover,
|
|
12
|
-
type PopoverProps,
|
|
13
|
-
Select,
|
|
14
|
-
type SelectProps,
|
|
15
|
-
SelectValue,
|
|
16
|
-
} from 'react-aria-components';
|
|
17
|
-
import { useStore } from 'zustand';
|
|
18
|
-
import { getOrCreateStoreByKey } from './getOrCreateStoreByKey';
|
|
19
|
-
|
|
20
|
-
export type OpenAPISelectItem = {
|
|
21
|
-
key: Key;
|
|
22
|
-
label: string | React.ReactNode;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
interface OpenAPISelectProps<T extends OpenAPISelectItem> extends Omit<SelectProps<T>, 'children'> {
|
|
26
|
-
items: T[];
|
|
27
|
-
children: React.ReactNode | ((item: T) => React.ReactNode);
|
|
28
|
-
placement?: PopoverProps['placement'];
|
|
29
|
-
stateKey?: string;
|
|
30
|
-
/**
|
|
31
|
-
* Icon to display in the select button.
|
|
32
|
-
*/
|
|
33
|
-
icon?: React.ReactNode;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function useSelectState(stateKey = 'select-state', initialKey: Key = 'default') {
|
|
37
|
-
const store = useStore(getOrCreateStoreByKey(stateKey, initialKey));
|
|
38
|
-
return {
|
|
39
|
-
key: store.key,
|
|
40
|
-
setKey: useCallback((key: Key | null) => store.setKey(key), [store.setKey]),
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function OpenAPISelect<T extends OpenAPISelectItem>(props: OpenAPISelectProps<T>) {
|
|
45
|
-
const {
|
|
46
|
-
icon = '▼',
|
|
47
|
-
items,
|
|
48
|
-
children,
|
|
49
|
-
className,
|
|
50
|
-
placement,
|
|
51
|
-
stateKey,
|
|
52
|
-
selectedKey,
|
|
53
|
-
onSelectionChange,
|
|
54
|
-
} = props;
|
|
55
|
-
|
|
56
|
-
const state = useSelectState(stateKey, items[0]?.key);
|
|
57
|
-
|
|
58
|
-
const selected = items.find((item) => item.key === state.key) || items[0];
|
|
59
|
-
|
|
60
|
-
return (
|
|
61
|
-
<Select
|
|
62
|
-
aria-label="OpenAPI Select"
|
|
63
|
-
{...props}
|
|
64
|
-
selectedKey={selectedKey || selected?.key}
|
|
65
|
-
onSelectionChange={(key) => {
|
|
66
|
-
onSelectionChange?.(key);
|
|
67
|
-
state.setKey(key);
|
|
68
|
-
}}
|
|
69
|
-
className={clsx('openapi-select', className)}
|
|
70
|
-
>
|
|
71
|
-
<Button>
|
|
72
|
-
<SelectValue />
|
|
73
|
-
{icon}
|
|
74
|
-
</Button>
|
|
75
|
-
<Popover placement={placement} className="openapi-select-popover">
|
|
76
|
-
<ListBox className="openapi-select-listbox" items={items}>
|
|
77
|
-
{children}
|
|
78
|
-
</ListBox>
|
|
79
|
-
</Popover>
|
|
80
|
-
</Select>
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function OpenAPISelectItem(props: ListBoxItemProps) {
|
|
85
|
-
return (
|
|
86
|
-
<ListBoxItem
|
|
87
|
-
{...props}
|
|
88
|
-
className={({ isFocused, isSelected }) =>
|
|
89
|
-
clsx('openapi-select-item', {
|
|
90
|
-
'openapi-select-item-focused': isFocused,
|
|
91
|
-
'openapi-select-item-selected': isSelected,
|
|
92
|
-
})
|
|
93
|
-
}
|
|
94
|
-
/>
|
|
95
|
-
);
|
|
96
|
-
}
|
package/src/OpenAPISpec.tsx
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import type { OpenAPI } from '@gitbook/openapi-parser';
|
|
2
|
-
|
|
3
|
-
import { OpenAPIRequestBody } from './OpenAPIRequestBody';
|
|
4
|
-
import { OpenAPIResponses } from './OpenAPIResponses';
|
|
5
|
-
import { OpenAPISchemaProperties } from './OpenAPISchemaServer';
|
|
6
|
-
import { OpenAPISecurities } from './OpenAPISecurities';
|
|
7
|
-
import { StaticSection } from './StaticSection';
|
|
8
|
-
import type { OpenAPIClientContext } from './context';
|
|
9
|
-
import { tString } from './translate';
|
|
10
|
-
import type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
|
|
11
|
-
import { parameterToProperty } from './utils';
|
|
12
|
-
|
|
13
|
-
export function OpenAPISpec(props: {
|
|
14
|
-
data: OpenAPIOperationData | OpenAPIWebhookData;
|
|
15
|
-
context: OpenAPIClientContext;
|
|
16
|
-
}) {
|
|
17
|
-
const { data, context } = props;
|
|
18
|
-
|
|
19
|
-
const { operation } = data;
|
|
20
|
-
|
|
21
|
-
const parameters = deduplicateParameters(operation.parameters ?? []);
|
|
22
|
-
const parameterGroups = groupParameters(parameters, context);
|
|
23
|
-
|
|
24
|
-
const securities = 'securities' in data ? data.securities : [];
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<>
|
|
28
|
-
{securities.length > 0 ? (
|
|
29
|
-
<OpenAPISecurities key="securities" securities={securities} context={context} />
|
|
30
|
-
) : null}
|
|
31
|
-
|
|
32
|
-
{parameterGroups.map((group) => {
|
|
33
|
-
return (
|
|
34
|
-
<StaticSection
|
|
35
|
-
key={`parameter-${group.key}`}
|
|
36
|
-
className="openapi-parameters"
|
|
37
|
-
header={group.label}
|
|
38
|
-
>
|
|
39
|
-
<OpenAPISchemaProperties
|
|
40
|
-
properties={group.parameters.map(parameterToProperty)}
|
|
41
|
-
context={context}
|
|
42
|
-
/>
|
|
43
|
-
</StaticSection>
|
|
44
|
-
);
|
|
45
|
-
})}
|
|
46
|
-
|
|
47
|
-
{operation.requestBody ? (
|
|
48
|
-
<OpenAPIRequestBody
|
|
49
|
-
key="body"
|
|
50
|
-
requestBody={operation.requestBody}
|
|
51
|
-
context={context}
|
|
52
|
-
data={data}
|
|
53
|
-
/>
|
|
54
|
-
) : null}
|
|
55
|
-
{operation.responses ? (
|
|
56
|
-
<OpenAPIResponses
|
|
57
|
-
key="responses"
|
|
58
|
-
responses={operation.responses}
|
|
59
|
-
context={context}
|
|
60
|
-
/>
|
|
61
|
-
) : null}
|
|
62
|
-
</>
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function groupParameters(
|
|
67
|
-
parameters: OpenAPI.Parameters,
|
|
68
|
-
context: OpenAPIClientContext
|
|
69
|
-
): Array<{
|
|
70
|
-
key: string;
|
|
71
|
-
label: string;
|
|
72
|
-
parameters: OpenAPI.Parameters;
|
|
73
|
-
}> {
|
|
74
|
-
const sorted = ['path', 'query', 'header'];
|
|
75
|
-
|
|
76
|
-
const groups: Array<{
|
|
77
|
-
key: string;
|
|
78
|
-
label: string;
|
|
79
|
-
parameters: OpenAPI.Parameters;
|
|
80
|
-
}> = [];
|
|
81
|
-
|
|
82
|
-
parameters
|
|
83
|
-
.filter((parameter) => parameter.in)
|
|
84
|
-
.forEach((parameter) => {
|
|
85
|
-
const key = parameter.in;
|
|
86
|
-
const label = getParameterGroupName(parameter.in, context);
|
|
87
|
-
const group = groups.find((group) => group.key === key);
|
|
88
|
-
if (group) {
|
|
89
|
-
group.parameters.push(parameter);
|
|
90
|
-
} else {
|
|
91
|
-
groups.push({
|
|
92
|
-
key,
|
|
93
|
-
label,
|
|
94
|
-
parameters: [parameter],
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
groups.sort((a, b) => sorted.indexOf(a.key) - sorted.indexOf(b.key));
|
|
100
|
-
|
|
101
|
-
return groups;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function getParameterGroupName(paramIn: string, context: OpenAPIClientContext): string {
|
|
105
|
-
switch (paramIn) {
|
|
106
|
-
case 'path':
|
|
107
|
-
return tString(context.translation, 'path_parameters');
|
|
108
|
-
case 'query':
|
|
109
|
-
return tString(context.translation, 'query_parameters');
|
|
110
|
-
case 'header':
|
|
111
|
-
return tString(context.translation, 'header_parameters');
|
|
112
|
-
default:
|
|
113
|
-
return paramIn;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/** Deduplicate parameters by name and in.
|
|
118
|
-
* Some specs have both parameters define at path and operation level.
|
|
119
|
-
* We only want to display one of them.
|
|
120
|
-
* Parameters can have the wrong type (object instead of array) sometimes, we just return an empty array in that case.
|
|
121
|
-
*/
|
|
122
|
-
function deduplicateParameters(parameters: OpenAPI.Parameters): OpenAPI.Parameters {
|
|
123
|
-
const seen = new Set();
|
|
124
|
-
|
|
125
|
-
return Array.isArray(parameters)
|
|
126
|
-
? parameters.filter((param) => {
|
|
127
|
-
const key = `${param.name}:${param.in}`;
|
|
128
|
-
|
|
129
|
-
if (seen.has(key)) {
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
seen.add(key);
|
|
134
|
-
|
|
135
|
-
return true;
|
|
136
|
-
})
|
|
137
|
-
: [];
|
|
138
|
-
}
|