@gitbook/react-openapi 1.0.3 → 1.0.5
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 +15 -0
- package/dist/InteractiveSection.jsx +10 -9
- package/dist/OpenAPICodeSample.jsx +8 -9
- package/dist/OpenAPIDisclosure.d.ts +2 -1
- package/dist/OpenAPIDisclosure.jsx +2 -1
- package/dist/OpenAPIDisclosureGroup.d.ts +1 -1
- package/dist/OpenAPIDisclosureGroup.jsx +3 -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 +10 -10
- package/dist/OpenAPIResponses.d.ts +1 -1
- package/dist/OpenAPIResponses.jsx +5 -5
- package/dist/OpenAPISchema.d.ts +5 -1
- package/dist/OpenAPISchema.jsx +30 -21
- package/dist/OpenAPISchemaName.d.ts +4 -3
- package/dist/OpenAPISchemaName.jsx +1 -1
- package/dist/OpenAPISecurities.jsx +2 -2
- package/dist/OpenAPISpec.jsx +3 -4
- package/dist/OpenAPITabs.d.ts +3 -3
- package/dist/OpenAPITabs.jsx +52 -49
- package/dist/ScalarApiButton.jsx +1 -1
- package/dist/StaticSection.d.ts +10 -0
- package/dist/StaticSection.jsx +23 -0
- 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/useSyncedTabsGlobalState.d.ts +10 -1
- package/dist/useSyncedTabsGlobalState.js +19 -15
- 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 +13 -21
- package/src/OpenAPICodeSample.tsx +11 -12
- package/src/OpenAPIDisclosure.tsx +5 -3
- package/src/OpenAPIDisclosureGroup.tsx +13 -11
- 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 +12 -19
- package/src/OpenAPIResponses.tsx +7 -7
- package/src/OpenAPISchema.test.ts +5 -5
- package/src/OpenAPISchema.tsx +77 -27
- package/src/OpenAPISchemaName.tsx +5 -4
- package/src/OpenAPISecurities.tsx +3 -3
- package/src/OpenAPISpec.tsx +3 -5
- package/src/OpenAPITabs.tsx +56 -67
- package/src/ScalarApiButton.tsx +3 -3
- package/src/StaticSection.tsx +59 -0
- 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/useSyncedTabsGlobalState.ts +33 -21
- package/src/util/server.test.ts +3 -3
- package/src/util/server.ts +2 -3
- package/src/utils.ts +4 -4
|
@@ -1,23 +1,35 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
3
|
+
import { createStore } from 'zustand';
|
|
4
|
+
|
|
5
|
+
type Key = string | number;
|
|
6
|
+
|
|
7
|
+
type TabState = {
|
|
8
|
+
tabKey: Key | null;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type TabActions = { setTabKey: (tab: Key | null) => void };
|
|
12
|
+
|
|
13
|
+
type TabStore = TabState & TabActions;
|
|
14
|
+
|
|
15
|
+
const createTabStore = (initialTab?: Key) => {
|
|
16
|
+
return createStore<TabStore>()((set) => ({
|
|
17
|
+
tabKey: initialTab ?? null,
|
|
18
|
+
setTabKey: (tabKey) => {
|
|
19
|
+
set(() => ({ tabKey }));
|
|
20
|
+
},
|
|
21
|
+
}));
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const defaultTabStores = new Map<string, ReturnType<typeof createTabStore>>();
|
|
25
|
+
|
|
26
|
+
const createTabStoreFactory = (stores: typeof defaultTabStores) => {
|
|
27
|
+
return (storeKey: string, initialKey?: Key) => {
|
|
28
|
+
if (!stores.has(storeKey)) {
|
|
29
|
+
stores.set(storeKey, createTabStore(initialKey));
|
|
30
|
+
}
|
|
31
|
+
return stores.get(storeKey)!;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const getOrCreateTabStoreByKey = createTabStoreFactory(defaultTabStores);
|
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;
|