@gitbook/react-openapi 1.0.3 → 1.0.4
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 +8 -0
- package/dist/OpenAPICodeSample.jsx +6 -7
- package/dist/OpenAPIDisclosure.d.ts +2 -1
- package/dist/OpenAPIDisclosure.jsx +1 -1
- package/dist/OpenAPIDisclosureGroup.d.ts +1 -1
- package/dist/OpenAPIDisclosureGroup.jsx +2 -2
- package/dist/OpenAPIOperation.jsx +2 -2
- package/dist/OpenAPIPath.d.ts +3 -2
- package/dist/OpenAPIPath.jsx +4 -15
- package/dist/OpenAPIRequestBody.jsx +1 -1
- package/dist/OpenAPIResponse.jsx +1 -1
- package/dist/OpenAPIResponseExample.jsx +3 -3
- package/dist/OpenAPIResponses.d.ts +1 -1
- package/dist/OpenAPIResponses.jsx +2 -2
- package/dist/OpenAPISchema.d.ts +5 -1
- package/dist/OpenAPISchema.jsx +29 -20
- package/dist/OpenAPISchemaName.d.ts +4 -3
- package/dist/OpenAPISchemaName.jsx +1 -1
- package/dist/OpenAPISecurities.jsx +2 -2
- package/dist/OpenAPITabs.d.ts +3 -3
- package/dist/OpenAPITabs.jsx +11 -12
- package/dist/ScalarApiButton.jsx +1 -1
- package/dist/code-samples.js +11 -11
- package/dist/generateSchemaExample.js +2 -1
- package/dist/resolveOpenAPIOperation.d.ts +3 -3
- package/dist/resolveOpenAPIOperation.js +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/util/server.d.ts +1 -1
- package/dist/util/server.js +1 -3
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +4 -6
- package/package.json +2 -7
- package/src/InteractiveSection.tsx +4 -4
- package/src/OpenAPICodeSample.tsx +9 -10
- package/src/OpenAPIDisclosure.tsx +4 -3
- package/src/OpenAPIDisclosureGroup.tsx +5 -5
- package/src/OpenAPIOperation.tsx +3 -3
- package/src/OpenAPIOperationContext.tsx +1 -1
- package/src/OpenAPIPath.tsx +11 -10
- package/src/OpenAPIRequestBody.tsx +2 -2
- package/src/OpenAPIResponse.tsx +3 -3
- package/src/OpenAPIResponseExample.tsx +5 -5
- package/src/OpenAPIResponses.tsx +4 -4
- package/src/OpenAPISchema.test.ts +5 -5
- package/src/OpenAPISchema.tsx +75 -25
- package/src/OpenAPISchemaName.tsx +5 -4
- package/src/OpenAPISecurities.tsx +3 -3
- package/src/OpenAPITabs.tsx +15 -15
- package/src/ScalarApiButton.tsx +3 -3
- package/src/code-samples.test.ts +66 -66
- package/src/code-samples.ts +14 -14
- package/src/generateSchemaExample.ts +3 -3
- package/src/json2xml.test.ts +1 -1
- package/src/resolveOpenAPIOperation.test.ts +6 -6
- package/src/resolveOpenAPIOperation.ts +7 -7
- package/src/stringifyOpenAPI.ts +1 -1
- package/src/util/server.test.ts +3 -3
- package/src/util/server.ts +2 -3
- package/src/utils.ts +4 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
2
|
|
|
3
|
-
import { resolveOpenAPIOperation } from './resolveOpenAPIOperation';
|
|
4
3
|
import { parseOpenAPI, traverse } from '@gitbook/openapi-parser';
|
|
4
|
+
import { resolveOpenAPIOperation } from './resolveOpenAPIOperation';
|
|
5
5
|
|
|
6
6
|
async function fetchFilesystem(url: string) {
|
|
7
7
|
const response = await fetch(url);
|
|
@@ -19,7 +19,7 @@ async function fetchFilesystem(url: string) {
|
|
|
19
19
|
describe('#resolveOpenAPIOperation', () => {
|
|
20
20
|
it('should resolve refs', async () => {
|
|
21
21
|
const filesystem = await fetchFilesystem(
|
|
22
|
-
'https://petstore3.swagger.io/api/v3/openapi.json'
|
|
22
|
+
'https://petstore3.swagger.io/api/v3/openapi.json'
|
|
23
23
|
);
|
|
24
24
|
const resolved = await resolveOpenAPIOperation(filesystem, { method: 'put', path: '/pet' });
|
|
25
25
|
|
|
@@ -49,7 +49,7 @@ describe('#resolveOpenAPIOperation', () => {
|
|
|
49
49
|
|
|
50
50
|
it('should support yaml', async () => {
|
|
51
51
|
const filesystem = await fetchFilesystem(
|
|
52
|
-
'https://petstore3.swagger.io/api/v3/openapi.yaml'
|
|
52
|
+
'https://petstore3.swagger.io/api/v3/openapi.yaml'
|
|
53
53
|
);
|
|
54
54
|
const resolved = await resolveOpenAPIOperation(filesystem, { method: 'put', path: '/pet' });
|
|
55
55
|
|
|
@@ -98,7 +98,7 @@ describe('#resolveOpenAPIOperation', () => {
|
|
|
98
98
|
|
|
99
99
|
it('should resolve to null if the method is not supported', async () => {
|
|
100
100
|
const filesystem = await fetchFilesystem(
|
|
101
|
-
'https://petstore3.swagger.io/api/v3/openapi.json'
|
|
101
|
+
'https://petstore3.swagger.io/api/v3/openapi.json'
|
|
102
102
|
);
|
|
103
103
|
const resolved = await resolveOpenAPIOperation(filesystem, {
|
|
104
104
|
method: 'dontexist',
|
|
@@ -144,7 +144,7 @@ describe('#resolveOpenAPIOperation', () => {
|
|
|
144
144
|
|
|
145
145
|
it('should resolve a ref with whitespace', async () => {
|
|
146
146
|
const filesystem = await fetchFilesystem(
|
|
147
|
-
' https://petstore3.swagger.io/api/v3/openapi.json'
|
|
147
|
+
' https://petstore3.swagger.io/api/v3/openapi.json'
|
|
148
148
|
);
|
|
149
149
|
const resolved = await resolveOpenAPIOperation(filesystem, {
|
|
150
150
|
method: 'put',
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fromJSON, toJSON } from 'flatted';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
type OpenAPIV3xDocument,
|
|
5
4
|
type Filesystem,
|
|
6
5
|
type OpenAPIV3,
|
|
7
6
|
type OpenAPIV3_1,
|
|
7
|
+
type OpenAPIV3xDocument,
|
|
8
8
|
dereference,
|
|
9
9
|
} from '@gitbook/openapi-parser';
|
|
10
|
-
import { OpenAPIOperationData } from './types';
|
|
10
|
+
import type { OpenAPIOperationData } from './types';
|
|
11
11
|
import { checkIsReference } from './utils';
|
|
12
12
|
|
|
13
13
|
export { toJSON, fromJSON };
|
|
@@ -20,7 +20,7 @@ export async function resolveOpenAPIOperation(
|
|
|
20
20
|
operationDescriptor: {
|
|
21
21
|
path: string;
|
|
22
22
|
method: string;
|
|
23
|
-
}
|
|
23
|
+
}
|
|
24
24
|
): Promise<OpenAPIOperationData | null> {
|
|
25
25
|
const { path, method } = operationDescriptor;
|
|
26
26
|
const schema = await memoDereferenceFilesystem(filesystem);
|
|
@@ -102,7 +102,7 @@ async function dereferenceFilesystem(filesystem: Filesystem): Promise<OpenAPIV3x
|
|
|
102
102
|
*/
|
|
103
103
|
function getPathObject(
|
|
104
104
|
schema: OpenAPIV3.Document | OpenAPIV3_1.Document,
|
|
105
|
-
path: string
|
|
105
|
+
path: string
|
|
106
106
|
): OpenAPIV3.PathItemObject | OpenAPIV3_1.PathItemObject | null {
|
|
107
107
|
if (schema.paths?.[path]) {
|
|
108
108
|
return schema.paths[path];
|
|
@@ -115,7 +115,7 @@ function getPathObject(
|
|
|
115
115
|
*/
|
|
116
116
|
function getPathObjectParameter(
|
|
117
117
|
schema: OpenAPIV3.Document | OpenAPIV3_1.Document,
|
|
118
|
-
path: string
|
|
118
|
+
path: string
|
|
119
119
|
):
|
|
120
120
|
| (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[]
|
|
121
121
|
| (OpenAPIV3.ParameterObject | OpenAPIV3_1.ReferenceObject)[]
|
|
@@ -133,7 +133,7 @@ function getPathObjectParameter(
|
|
|
133
133
|
function getOperationByPathAndMethod(
|
|
134
134
|
schema: OpenAPIV3.Document | OpenAPIV3_1.Document,
|
|
135
135
|
path: string,
|
|
136
|
-
method: string
|
|
136
|
+
method: string
|
|
137
137
|
): OpenAPIV3.OperationObject | null {
|
|
138
138
|
// Types are buffy for OpenAPIV3_1.OperationObject, so we use v3
|
|
139
139
|
const pathObject = getPathObject(schema, path);
|
package/src/stringifyOpenAPI.ts
CHANGED
package/src/util/server.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { describe,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
3
|
+
import { getDefaultServerURL, interpolateServerURL } from './server';
|
|
4
4
|
|
|
5
5
|
describe('#interpolateServerURL', () => {
|
|
6
6
|
it('interpolates the server URL with the default values of the variables', () => {
|
package/src/util/server.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
1
|
+
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Get the default URL for the server.
|
|
@@ -23,9 +23,8 @@ export function interpolateServerURL(server: OpenAPIV3.ServerObject) {
|
|
|
23
23
|
.map((part) => {
|
|
24
24
|
if (part.kind === 'text') {
|
|
25
25
|
return part.text;
|
|
26
|
-
} else {
|
|
27
|
-
return server.variables?.[part.name]?.default ?? `{${part.name}}`;
|
|
28
26
|
}
|
|
27
|
+
return server.variables?.[part.name]?.default ?? `{${part.name}}`;
|
|
29
28
|
})
|
|
30
29
|
.join('');
|
|
31
30
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AnyObject, OpenAPIV3, OpenAPIV3_1 } from '@gitbook/openapi-parser';
|
|
2
2
|
|
|
3
3
|
export function checkIsReference(
|
|
4
|
-
input: unknown
|
|
4
|
+
input: unknown
|
|
5
5
|
): input is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject {
|
|
6
6
|
return typeof input === 'object' && !!input && '$ref' in input;
|
|
7
7
|
}
|
|
@@ -32,7 +32,7 @@ export function resolveDescription(object: OpenAPIV3.SchemaObject | AnyObject) {
|
|
|
32
32
|
export function extractDescriptions(object: AnyObject) {
|
|
33
33
|
return {
|
|
34
34
|
description: object.description,
|
|
35
|
-
|
|
35
|
+
'x-gitbook-description-html':
|
|
36
36
|
'x-gitbook-description-html' in object
|
|
37
37
|
? object['x-gitbook-description-html']
|
|
38
38
|
: undefined,
|
|
@@ -61,7 +61,7 @@ export function resolveFirstExample(object: AnyObject) {
|
|
|
61
61
|
* Extract the description, example and deprecated from parameter.
|
|
62
62
|
*/
|
|
63
63
|
export function resolveParameterSchema(
|
|
64
|
-
parameter: OpenAPIV3.ParameterBaseObject
|
|
64
|
+
parameter: OpenAPIV3.ParameterBaseObject
|
|
65
65
|
): OpenAPIV3.SchemaObject {
|
|
66
66
|
const schema = checkIsReference(parameter.schema) ? undefined : parameter.schema;
|
|
67
67
|
return {
|
|
@@ -79,7 +79,7 @@ export function resolveParameterSchema(
|
|
|
79
79
|
* Transform a parameter object to a property object.
|
|
80
80
|
*/
|
|
81
81
|
export function parameterToProperty(
|
|
82
|
-
parameter: OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject
|
|
82
|
+
parameter: OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject
|
|
83
83
|
): {
|
|
84
84
|
propertyName: string | undefined;
|
|
85
85
|
schema: OpenAPIV3.SchemaObject;
|