@gitbook/react-openapi 1.4.3 → 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 +27 -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,177 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'bun:test';
|
|
2
|
-
|
|
3
|
-
import { parseOpenAPI, traverse } from '@gitbook/openapi-parser';
|
|
4
|
-
import { resolveOpenAPIOperation } from './resolveOpenAPIOperation';
|
|
5
|
-
|
|
6
|
-
async function fetchFilesystem(url: string) {
|
|
7
|
-
const response = await fetch(url);
|
|
8
|
-
const text = await response.text();
|
|
9
|
-
const { filesystem } = await parseOpenAPI({ value: text, rootURL: url });
|
|
10
|
-
const transformedFs = await traverse(filesystem, async (node) => {
|
|
11
|
-
if ('description' in node && typeof node.description === 'string' && node.description) {
|
|
12
|
-
node['x-gitbook-description-html'] = node.description;
|
|
13
|
-
}
|
|
14
|
-
return node;
|
|
15
|
-
});
|
|
16
|
-
return transformedFs;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
describe('#resolveOpenAPIOperation', () => {
|
|
20
|
-
it('should resolve refs', async () => {
|
|
21
|
-
const filesystem = await fetchFilesystem(
|
|
22
|
-
'https://petstore3.swagger.io/api/v3/openapi.json'
|
|
23
|
-
);
|
|
24
|
-
const resolved = await resolveOpenAPIOperation(filesystem, { method: 'put', path: '/pet' });
|
|
25
|
-
|
|
26
|
-
expect(resolved).toMatchObject({
|
|
27
|
-
servers: [
|
|
28
|
-
{
|
|
29
|
-
url: '/api/v3',
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
operation: {
|
|
33
|
-
tags: ['pet'],
|
|
34
|
-
summary: 'Update an existing pet.',
|
|
35
|
-
description: 'Update an existing pet by Id.',
|
|
36
|
-
requestBody: {
|
|
37
|
-
content: {
|
|
38
|
-
'application/json': {
|
|
39
|
-
schema: {
|
|
40
|
-
type: 'object',
|
|
41
|
-
required: ['name', 'photoUrls'],
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should support yaml', async () => {
|
|
51
|
-
const filesystem = await fetchFilesystem(
|
|
52
|
-
'https://petstore3.swagger.io/api/v3/openapi.yaml'
|
|
53
|
-
);
|
|
54
|
-
const resolved = await resolveOpenAPIOperation(filesystem, { method: 'put', path: '/pet' });
|
|
55
|
-
|
|
56
|
-
expect(resolved).toMatchObject({
|
|
57
|
-
servers: [
|
|
58
|
-
{
|
|
59
|
-
url: '/api/v3',
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
operation: {
|
|
63
|
-
tags: ['pet'],
|
|
64
|
-
summary: 'Update an existing pet.',
|
|
65
|
-
description: 'Update an existing pet by Id.',
|
|
66
|
-
requestBody: {
|
|
67
|
-
content: {
|
|
68
|
-
'application/json': {
|
|
69
|
-
schema: {
|
|
70
|
-
type: 'object',
|
|
71
|
-
required: ['name', 'photoUrls'],
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('should resolve circular refs', async () => {
|
|
81
|
-
const filesystem = await fetchFilesystem('https://api.gitbook.com/openapi.json');
|
|
82
|
-
const resolved = await resolveOpenAPIOperation(filesystem, {
|
|
83
|
-
method: 'get',
|
|
84
|
-
path: '/spaces/{spaceId}/content/page/{pageId}',
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
expect(resolved).toMatchObject({
|
|
88
|
-
servers: [
|
|
89
|
-
{
|
|
90
|
-
url: '{host}/v1',
|
|
91
|
-
},
|
|
92
|
-
],
|
|
93
|
-
operation: {
|
|
94
|
-
operationId: 'getPageById',
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('should resolve to null if the method is not supported', async () => {
|
|
100
|
-
const filesystem = await fetchFilesystem(
|
|
101
|
-
'https://petstore3.swagger.io/api/v3/openapi.json'
|
|
102
|
-
);
|
|
103
|
-
const resolved = await resolveOpenAPIOperation(filesystem, {
|
|
104
|
-
method: 'dontexist',
|
|
105
|
-
path: '/pet',
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
expect(resolved).toBe(null);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('should parse Swagger 2.0', async () => {
|
|
112
|
-
const filesystem = await fetchFilesystem('https://petstore.swagger.io/v2/swagger.json');
|
|
113
|
-
const resolved = await resolveOpenAPIOperation(filesystem, {
|
|
114
|
-
method: 'put',
|
|
115
|
-
path: '/pet',
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
expect(resolved).toMatchObject({
|
|
119
|
-
servers: [
|
|
120
|
-
{
|
|
121
|
-
url: 'https://petstore.swagger.io/v2',
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
url: 'http://petstore.swagger.io/v2',
|
|
125
|
-
},
|
|
126
|
-
],
|
|
127
|
-
operation: {
|
|
128
|
-
tags: ['pet'],
|
|
129
|
-
summary: 'Update an existing pet',
|
|
130
|
-
description: '',
|
|
131
|
-
requestBody: {
|
|
132
|
-
content: {
|
|
133
|
-
'application/json': {
|
|
134
|
-
schema: {
|
|
135
|
-
type: 'object',
|
|
136
|
-
required: ['name', 'photoUrls'],
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('should resolve a ref with whitespace', async () => {
|
|
146
|
-
const filesystem = await fetchFilesystem(
|
|
147
|
-
' https://petstore3.swagger.io/api/v3/openapi.json'
|
|
148
|
-
);
|
|
149
|
-
const resolved = await resolveOpenAPIOperation(filesystem, {
|
|
150
|
-
method: 'put',
|
|
151
|
-
path: '/pet',
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
expect(resolved).toMatchObject({
|
|
155
|
-
servers: [
|
|
156
|
-
{
|
|
157
|
-
url: '/api/v3',
|
|
158
|
-
},
|
|
159
|
-
],
|
|
160
|
-
operation: {
|
|
161
|
-
tags: ['pet'],
|
|
162
|
-
summary: 'Update an existing pet.',
|
|
163
|
-
description: 'Update an existing pet by Id.',
|
|
164
|
-
requestBody: {
|
|
165
|
-
content: {
|
|
166
|
-
'application/json': {
|
|
167
|
-
schema: {
|
|
168
|
-
type: 'object',
|
|
169
|
-
required: ['name', 'photoUrls'],
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
});
|
|
@@ -1,151 +0,0 @@
|
|
|
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 { OpenAPIOperationData } from './types';
|
|
11
|
-
import { checkIsReference } from './utils';
|
|
12
|
-
|
|
13
|
-
export { fromJSON, toJSON };
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Resolve an OpenAPI operation in a file and compile it to a more usable format.
|
|
17
|
-
*/
|
|
18
|
-
export async function resolveOpenAPIOperation(
|
|
19
|
-
filesystem: Filesystem<OpenAPIV3xDocument>,
|
|
20
|
-
operationDescriptor: {
|
|
21
|
-
path: string;
|
|
22
|
-
method: string;
|
|
23
|
-
}
|
|
24
|
-
): Promise<OpenAPIOperationData | null> {
|
|
25
|
-
const { path, method } = operationDescriptor;
|
|
26
|
-
const schema = await dereferenceFilesystem(filesystem);
|
|
27
|
-
let operation = getOperationByPathAndMethod(schema, path, method);
|
|
28
|
-
|
|
29
|
-
if (!operation) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Resolve common parameters
|
|
34
|
-
const commonParameters = getPathObjectParameter(schema, path);
|
|
35
|
-
if (commonParameters) {
|
|
36
|
-
operation = {
|
|
37
|
-
...operation,
|
|
38
|
-
parameters: [...commonParameters, ...(operation.parameters ?? [])],
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const servers = 'servers' in schema ? (schema.servers ?? []) : [];
|
|
43
|
-
const schemaSecurity = Array.isArray(schema.security)
|
|
44
|
-
? schema.security
|
|
45
|
-
: schema.security
|
|
46
|
-
? [schema.security]
|
|
47
|
-
: [];
|
|
48
|
-
const security: OpenAPIV3_1.SecurityRequirementObject[] = operation.security ?? schemaSecurity;
|
|
49
|
-
|
|
50
|
-
// If security includes an empty object, it means that the security is optional
|
|
51
|
-
const isOptionalSecurity = security.some((entry) => Object.keys(entry).length === 0);
|
|
52
|
-
const flatSecurities = flattenSecurities(security);
|
|
53
|
-
|
|
54
|
-
// Resolve securities
|
|
55
|
-
const securities: OpenAPIOperationData['securities'] = [];
|
|
56
|
-
for (const entry of flatSecurities) {
|
|
57
|
-
const securityKey = Object.keys(entry)[0];
|
|
58
|
-
if (securityKey) {
|
|
59
|
-
const securityScheme = schema.components?.securitySchemes?.[securityKey];
|
|
60
|
-
if (securityScheme && !checkIsReference(securityScheme)) {
|
|
61
|
-
securities.push([
|
|
62
|
-
securityKey,
|
|
63
|
-
{
|
|
64
|
-
...securityScheme,
|
|
65
|
-
required: !isOptionalSecurity,
|
|
66
|
-
},
|
|
67
|
-
]);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
servers,
|
|
74
|
-
operation,
|
|
75
|
-
method,
|
|
76
|
-
path,
|
|
77
|
-
securities,
|
|
78
|
-
'x-codeSamples':
|
|
79
|
-
typeof schema['x-codeSamples'] === 'boolean' ? schema['x-codeSamples'] : undefined,
|
|
80
|
-
'x-hideTryItPanel':
|
|
81
|
-
typeof schema['x-hideTryItPanel'] === 'boolean'
|
|
82
|
-
? schema['x-hideTryItPanel']
|
|
83
|
-
: undefined,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Get a path object from its path.
|
|
89
|
-
*/
|
|
90
|
-
function getPathObject(
|
|
91
|
-
schema: OpenAPIV3.Document | OpenAPIV3_1.Document,
|
|
92
|
-
path: string
|
|
93
|
-
): OpenAPIV3.PathItemObject | OpenAPIV3_1.PathItemObject | null {
|
|
94
|
-
if (schema.paths?.[path]) {
|
|
95
|
-
return schema.paths[path];
|
|
96
|
-
}
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Resolve parameters from a path in an OpenAPI schema.
|
|
102
|
-
*/
|
|
103
|
-
function getPathObjectParameter(
|
|
104
|
-
schema: OpenAPIV3.Document | OpenAPIV3_1.Document,
|
|
105
|
-
path: string
|
|
106
|
-
):
|
|
107
|
-
| (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[]
|
|
108
|
-
| (OpenAPIV3.ParameterObject | OpenAPIV3_1.ReferenceObject)[]
|
|
109
|
-
| null {
|
|
110
|
-
const pathObject = getPathObject(schema, path);
|
|
111
|
-
if (pathObject?.parameters) {
|
|
112
|
-
return pathObject.parameters;
|
|
113
|
-
}
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Get an operation by its path and method.
|
|
119
|
-
*/
|
|
120
|
-
function getOperationByPathAndMethod(
|
|
121
|
-
schema: OpenAPIV3.Document | OpenAPIV3_1.Document,
|
|
122
|
-
path: string,
|
|
123
|
-
method: string
|
|
124
|
-
): OpenAPIV3.OperationObject | null {
|
|
125
|
-
// Types are buffy for OpenAPIV3_1.OperationObject, so we use v3
|
|
126
|
-
const pathObject = getPathObject(schema, path);
|
|
127
|
-
if (!pathObject) {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
const normalizedMethod = method.toLowerCase();
|
|
131
|
-
if (!pathObject[normalizedMethod]) {
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
return pathObject[normalizedMethod];
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Flatten security objects in case they are nested.
|
|
139
|
-
* @example [{bearerAuth:[], basicAuth:[]}] => [{ bearerAuth: [] }, { basicAuth: [] }]
|
|
140
|
-
*/
|
|
141
|
-
function flattenSecurities(security: OpenAPIV3.SecurityRequirementObject[]) {
|
|
142
|
-
if (!Array.isArray(security) || security.length === 0) {
|
|
143
|
-
return [];
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return security.flatMap((securityObject) => {
|
|
147
|
-
return Object.entries(securityObject).map(([authType, config]) => ({
|
|
148
|
-
[authType]: config,
|
|
149
|
-
}));
|
|
150
|
-
});
|
|
151
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
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,34 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { SectionBody } from '../StaticSection';
|
|
4
|
-
|
|
5
|
-
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
6
|
-
import { OpenAPIDisclosure } from '../OpenAPIDisclosure';
|
|
7
|
-
import { OpenAPIRootSchema } from '../OpenAPISchemaServer';
|
|
8
|
-
import { Section } from '../StaticSection';
|
|
9
|
-
import type { OpenAPIClientContext } from '../context';
|
|
10
|
-
import { getDisclosureLabel } from '../getDisclosureLabel';
|
|
11
|
-
|
|
12
|
-
export function OpenAPISchemaItem(props: {
|
|
13
|
-
name: string;
|
|
14
|
-
schema: OpenAPIV3.SchemaObject;
|
|
15
|
-
context: OpenAPIClientContext;
|
|
16
|
-
}) {
|
|
17
|
-
const { schema, context, name } = props;
|
|
18
|
-
|
|
19
|
-
return (
|
|
20
|
-
<OpenAPIDisclosure
|
|
21
|
-
className="openapi-schemas-disclosure"
|
|
22
|
-
key={name}
|
|
23
|
-
icon={context.icons.plus}
|
|
24
|
-
header={name}
|
|
25
|
-
label={(isExpanded) => getDisclosureLabel({ schema, isExpanded, context })}
|
|
26
|
-
>
|
|
27
|
-
<Section className="openapi-section-schemas">
|
|
28
|
-
<SectionBody>
|
|
29
|
-
<OpenAPIRootSchema schema={schema} context={context} />
|
|
30
|
-
</SectionBody>
|
|
31
|
-
</Section>
|
|
32
|
-
</OpenAPIDisclosure>
|
|
33
|
-
);
|
|
34
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import type { OpenAPISchema } from '@gitbook/openapi-parser';
|
|
2
|
-
import clsx from 'clsx';
|
|
3
|
-
import { OpenAPIExample } from '../OpenAPIExample';
|
|
4
|
-
import { OpenAPIRootSchema } from '../OpenAPISchemaServer';
|
|
5
|
-
import { StaticSection } from '../StaticSection';
|
|
6
|
-
import {
|
|
7
|
-
type OpenAPIContextInput,
|
|
8
|
-
getOpenAPIClientContext,
|
|
9
|
-
resolveOpenAPIContext,
|
|
10
|
-
} from '../context';
|
|
11
|
-
import { t } from '../translate';
|
|
12
|
-
import { getExampleFromSchema } from '../util/example';
|
|
13
|
-
import { OpenAPISchemaItem } from './OpenAPISchemaItem';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* OpenAPI Schemas component.
|
|
17
|
-
*/
|
|
18
|
-
export function OpenAPISchemas(props: {
|
|
19
|
-
className?: string;
|
|
20
|
-
schemas: OpenAPISchema[];
|
|
21
|
-
context: OpenAPIContextInput;
|
|
22
|
-
/**
|
|
23
|
-
* Whether to show the schema directly if there is only one.
|
|
24
|
-
*/
|
|
25
|
-
grouped?: boolean;
|
|
26
|
-
}) {
|
|
27
|
-
const { schemas, context: contextInput, grouped, className } = props;
|
|
28
|
-
|
|
29
|
-
const firstSchema = schemas[0];
|
|
30
|
-
|
|
31
|
-
if (!firstSchema) {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const context = resolveOpenAPIContext(contextInput);
|
|
36
|
-
const clientContext = getOpenAPIClientContext(context);
|
|
37
|
-
|
|
38
|
-
// If there is only one model and we are not grouping, we show it directly.
|
|
39
|
-
if (schemas.length === 1 && !grouped) {
|
|
40
|
-
const title = `The ${firstSchema.name} object`;
|
|
41
|
-
return (
|
|
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>
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// If there are multiple schemas, we use a disclosure group to show them all.
|
|
84
|
-
return (
|
|
85
|
-
<div className={clsx('openapi-schemas', className)}>
|
|
86
|
-
{schemas.map(({ name, schema }) => {
|
|
87
|
-
return (
|
|
88
|
-
<OpenAPISchemaItem
|
|
89
|
-
key={name}
|
|
90
|
-
name={name}
|
|
91
|
-
context={clientContext}
|
|
92
|
-
schema={schema}
|
|
93
|
-
/>
|
|
94
|
-
);
|
|
95
|
-
})}
|
|
96
|
-
</div>
|
|
97
|
-
);
|
|
98
|
-
}
|
package/src/schemas/index.ts
DELETED