@gitbook/react-openapi 1.0.0 → 1.0.2
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 +20 -0
- package/dist/InteractiveSection.d.ts +0 -2
- package/dist/InteractiveSection.jsx +8 -44
- package/dist/OpenAPICodeSample.jsx +12 -12
- package/dist/OpenAPIOperation.jsx +8 -5
- package/dist/OpenAPIRequestBody.d.ts +2 -2
- package/dist/OpenAPIRequestBody.jsx +5 -2
- package/dist/OpenAPIResponse.jsx +17 -25
- package/dist/OpenAPIResponseExample.jsx +157 -48
- package/dist/OpenAPIResponses.jsx +2 -3
- package/dist/OpenAPISchema.d.ts +2 -2
- package/dist/OpenAPISchema.jsx +28 -29
- package/dist/OpenAPISpec.jsx +4 -28
- package/dist/OpenAPITabs.d.ts +1 -0
- package/dist/OpenAPITabs.jsx +52 -16
- package/dist/generateSchemaExample.d.ts +5 -6
- package/dist/generateSchemaExample.js +15 -11
- package/dist/json2xml.d.ts +4 -0
- package/dist/json2xml.js +7 -0
- package/dist/resolveOpenAPIOperation.js +4 -4
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/useSyncedTabsGlobalState.d.ts +1 -0
- package/dist/useSyncedTabsGlobalState.js +16 -0
- package/dist/utils.d.ts +26 -3
- package/dist/utils.js +72 -9
- package/package.json +4 -2
- package/src/InteractiveSection.tsx +4 -41
- package/src/OpenAPICodeSample.tsx +12 -12
- package/src/OpenAPIOperation.tsx +8 -5
- package/src/OpenAPIRequestBody.tsx +7 -3
- package/src/OpenAPIResponse.tsx +7 -27
- package/src/OpenAPIResponseExample.tsx +237 -70
- package/src/OpenAPIResponses.tsx +2 -7
- package/src/OpenAPISchema.tsx +34 -33
- package/src/OpenAPISpec.tsx +4 -22
- package/src/OpenAPITabs.tsx +63 -23
- package/src/__snapshots__/json2xml.test.ts.snap +18 -0
- package/src/generateSchemaExample.ts +11 -10
- package/src/json2xml.test.ts +46 -0
- package/src/json2xml.ts +8 -0
- package/src/resolveOpenAPIOperation.test.ts +1 -1
- package/src/resolveOpenAPIOperation.ts +8 -7
- package/src/types.ts +1 -0
- package/src/useSyncedTabsGlobalState.ts +23 -0
- package/src/utils.ts +81 -13
- package/dist/fetchOpenAPIOperation.d.ts +0 -27
- package/dist/fetchOpenAPIOperation.js +0 -195
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/OpenAPISchema.jsx
CHANGED
|
@@ -11,7 +11,7 @@ import clsx from 'clsx';
|
|
|
11
11
|
import { useId } from 'react';
|
|
12
12
|
import { InteractiveSection } from './InteractiveSection';
|
|
13
13
|
import { Markdown } from './Markdown';
|
|
14
|
-
import { checkIsReference,
|
|
14
|
+
import { checkIsReference, resolveDescription } from './utils';
|
|
15
15
|
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
|
16
16
|
import { OpenAPISchemaName } from './OpenAPISchemaName';
|
|
17
17
|
import { OpenAPIDisclosure } from './OpenAPIDisclosure';
|
|
@@ -29,18 +29,18 @@ export function OpenAPISchemaProperty(props) {
|
|
|
29
29
|
var alternatives = parentCircularRef
|
|
30
30
|
? null
|
|
31
31
|
: getSchemaAlternatives(schema, new Set(circularRefs.keys()));
|
|
32
|
-
if ((properties &&
|
|
32
|
+
if ((properties && properties.length > 0) || schema.type === 'object') {
|
|
33
33
|
return (<InteractiveSection id={id} className={clsx('openapi-schema', className)}>
|
|
34
34
|
<OpenAPISchemaPresentation {...props}/>
|
|
35
|
-
<OpenAPIDisclosure context={context}>
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
{properties && properties.length > 0 ? (<OpenAPIDisclosure context={context}>
|
|
36
|
+
<OpenAPISchemaProperties properties={properties} circularRefs={circularRefs} context={context}/>
|
|
37
|
+
</OpenAPIDisclosure>) : null}
|
|
38
38
|
</InteractiveSection>);
|
|
39
39
|
}
|
|
40
40
|
if ((_a = alternatives === null || alternatives === void 0 ? void 0 : alternatives[0]) === null || _a === void 0 ? void 0 : _a.length) {
|
|
41
41
|
return (<InteractiveSection id={id} className={clsx('openapi-schema', className)}>
|
|
42
42
|
<OpenAPISchemaPresentation {...props}/>
|
|
43
|
-
{alternatives[0].map(function (alternative, index) { return (<OpenAPISchemaAlternative key={index} schema={alternative} circularRefs={circularRefs} context={context}/>); })}
|
|
43
|
+
{alternatives[0].map(function (alternative, index) { return (<OpenAPISchemaAlternative key={"alternative-".concat(index)} schema={alternative} circularRefs={circularRefs} context={context}/>); })}
|
|
44
44
|
</InteractiveSection>);
|
|
45
45
|
}
|
|
46
46
|
return (<InteractiveSection id={id} className={clsx('openapi-schema', className)}>
|
|
@@ -157,9 +157,9 @@ function getSchemaProperties(schema) {
|
|
|
157
157
|
if (schema.allOf) {
|
|
158
158
|
return schema.allOf.reduce(function (acc, subSchema) {
|
|
159
159
|
var _a;
|
|
160
|
-
var properties = (_a = getSchemaProperties(
|
|
160
|
+
var properties = (_a = getSchemaProperties(subSchema)) !== null && _a !== void 0 ? _a : [
|
|
161
161
|
{
|
|
162
|
-
schema:
|
|
162
|
+
schema: subSchema,
|
|
163
163
|
},
|
|
164
164
|
];
|
|
165
165
|
return __spreadArray(__spreadArray([], acc, true), properties, true);
|
|
@@ -167,7 +167,7 @@ function getSchemaProperties(schema) {
|
|
|
167
167
|
}
|
|
168
168
|
// check array AND schema.items as this is sometimes null despite what the type indicates
|
|
169
169
|
if (schema.type === 'array' && !!schema.items) {
|
|
170
|
-
var items =
|
|
170
|
+
var items = schema.items;
|
|
171
171
|
var itemProperties = getSchemaProperties(items);
|
|
172
172
|
if (itemProperties) {
|
|
173
173
|
return itemProperties;
|
|
@@ -183,11 +183,7 @@ function getSchemaProperties(schema) {
|
|
|
183
183
|
var result_1 = [];
|
|
184
184
|
if (schema.properties) {
|
|
185
185
|
Object.entries(schema.properties).forEach(function (_a) {
|
|
186
|
-
var propertyName = _a[0],
|
|
187
|
-
var isReference = checkIsReference(rawPropertySchema);
|
|
188
|
-
var propertySchema = isReference
|
|
189
|
-
? { propertyName: propertyName }
|
|
190
|
-
: rawPropertySchema;
|
|
186
|
+
var propertyName = _a[0], propertySchema = _a[1];
|
|
191
187
|
result_1.push({
|
|
192
188
|
propertyName: propertyName,
|
|
193
189
|
required: Array.isArray(schema.required)
|
|
@@ -198,7 +194,7 @@ function getSchemaProperties(schema) {
|
|
|
198
194
|
});
|
|
199
195
|
}
|
|
200
196
|
if (schema.additionalProperties) {
|
|
201
|
-
var additionalProperties =
|
|
197
|
+
var additionalProperties = schema.additionalProperties;
|
|
202
198
|
result_1.push({
|
|
203
199
|
propertyName: 'Other properties',
|
|
204
200
|
schema: additionalProperties === true ? {} : additionalProperties,
|
|
@@ -215,16 +211,10 @@ export function getSchemaAlternatives(schema, ancestors) {
|
|
|
215
211
|
if (ancestors === void 0) { ancestors = new Set(); }
|
|
216
212
|
var downAncestors = new Set(ancestors).add(schema);
|
|
217
213
|
if (schema.anyOf) {
|
|
218
|
-
return [
|
|
219
|
-
flattenAlternatives('anyOf', schema.anyOf.map(noReference), downAncestors),
|
|
220
|
-
noReference(schema.discriminator),
|
|
221
|
-
];
|
|
214
|
+
return [flattenAlternatives('anyOf', schema.anyOf, downAncestors), schema.discriminator];
|
|
222
215
|
}
|
|
223
216
|
if (schema.oneOf) {
|
|
224
|
-
return [
|
|
225
|
-
flattenAlternatives('oneOf', schema.oneOf.map(noReference), downAncestors),
|
|
226
|
-
noReference(schema.discriminator),
|
|
227
|
-
];
|
|
217
|
+
return [flattenAlternatives('oneOf', schema.oneOf, downAncestors), schema.discriminator];
|
|
228
218
|
}
|
|
229
219
|
if (schema.allOf) {
|
|
230
220
|
// allOf is managed in `getSchemaProperties`
|
|
@@ -251,8 +241,8 @@ discriminator) {
|
|
|
251
241
|
}
|
|
252
242
|
// Try using the discriminator
|
|
253
243
|
if ((discriminator === null || discriminator === void 0 ? void 0 : discriminator.propertyName) && schema.properties) {
|
|
254
|
-
var discriminatorProperty =
|
|
255
|
-
if (discriminatorProperty) {
|
|
244
|
+
var discriminatorProperty = schema.properties[discriminator.propertyName];
|
|
245
|
+
if (discriminatorProperty && !checkIsReference(discriminatorProperty)) {
|
|
256
246
|
if (discriminatorProperty.enum) {
|
|
257
247
|
return discriminatorProperty.enum.map(function (value) { return value.toString(); }).join(' | ');
|
|
258
248
|
}
|
|
@@ -261,11 +251,11 @@ discriminator) {
|
|
|
261
251
|
// Otherwise try to infer a nice title
|
|
262
252
|
var type = 'any';
|
|
263
253
|
if (schema.enum) {
|
|
264
|
-
type =
|
|
254
|
+
type = "".concat(schema.type, " \u00B7 enum");
|
|
265
255
|
// check array AND schema.items as this is sometimes null despite what the type indicates
|
|
266
256
|
}
|
|
267
257
|
else if (schema.type === 'array' && !!schema.items) {
|
|
268
|
-
type = "".concat(getSchemaTitle(
|
|
258
|
+
type = "".concat(getSchemaTitle(schema.items), "[]");
|
|
269
259
|
}
|
|
270
260
|
else if (Array.isArray(schema.type)) {
|
|
271
261
|
type = schema.type.join(' | ');
|
|
@@ -273,7 +263,7 @@ discriminator) {
|
|
|
273
263
|
else if (schema.type || schema.properties) {
|
|
274
264
|
type = (_a = schema.type) !== null && _a !== void 0 ? _a : 'object';
|
|
275
265
|
if (schema.format) {
|
|
276
|
-
type += " ".concat(schema.format);
|
|
266
|
+
type += " \u00B7 ".concat(schema.format);
|
|
277
267
|
}
|
|
278
268
|
}
|
|
279
269
|
else if ('anyOf' in schema) {
|
|
@@ -288,8 +278,17 @@ discriminator) {
|
|
|
288
278
|
else if ('not' in schema) {
|
|
289
279
|
type = 'not';
|
|
290
280
|
}
|
|
281
|
+
if (schema.minimum || schema.minLength) {
|
|
282
|
+
type += " \u00B7 min: ".concat(schema.minimum || schema.minLength);
|
|
283
|
+
}
|
|
284
|
+
if (schema.maximum || schema.maxLength) {
|
|
285
|
+
type += " \u00B7 max: ".concat(schema.maximum || schema.maxLength);
|
|
286
|
+
}
|
|
287
|
+
if (schema.default) {
|
|
288
|
+
type += " \u00B7 default: ".concat(schema.default);
|
|
289
|
+
}
|
|
291
290
|
if (schema.nullable) {
|
|
292
|
-
type = "
|
|
291
|
+
type = "".concat(type, " | nullable");
|
|
293
292
|
}
|
|
294
293
|
return type;
|
|
295
294
|
}
|
package/dist/OpenAPISpec.jsx
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
import { InteractiveSection } from './InteractiveSection';
|
|
14
3
|
import { OpenAPIRequestBody } from './OpenAPIRequestBody';
|
|
15
4
|
import { OpenAPIResponses } from './OpenAPIResponses';
|
|
16
5
|
import { OpenAPISchemaProperties } from './OpenAPISchema';
|
|
17
6
|
import { OpenAPISecurities } from './OpenAPISecurities';
|
|
18
|
-
import {
|
|
7
|
+
import { parameterToProperty } from './utils';
|
|
19
8
|
/**
|
|
20
9
|
* Client component to render the spec for the request and response.
|
|
21
10
|
*
|
|
@@ -33,25 +22,12 @@ export function OpenAPISpec(props) {
|
|
|
33
22
|
|
|
34
23
|
{parameterGroups.map(function (group) {
|
|
35
24
|
return (<InteractiveSection key={group.key} className="openapi-parameters" header={group.label}>
|
|
36
|
-
<OpenAPISchemaProperties properties={group.parameters.map(
|
|
37
|
-
var _a;
|
|
38
|
-
var description = resolveDescription(parameter);
|
|
39
|
-
return {
|
|
40
|
-
propertyName: parameter.name,
|
|
41
|
-
schema: __assign({
|
|
42
|
-
// Description of the parameter is defined at the parameter level
|
|
43
|
-
// we use display it if the schema doesn't override it
|
|
44
|
-
description: description, example: parameter.example,
|
|
45
|
-
// Deprecated can be defined at the parameter level
|
|
46
|
-
deprecated: parameter.deprecated }, ((_a = noReference(parameter.schema)) !== null && _a !== void 0 ? _a : {})),
|
|
47
|
-
required: parameter.required,
|
|
48
|
-
};
|
|
49
|
-
})} context={context}/>
|
|
25
|
+
<OpenAPISchemaProperties properties={group.parameters.map(parameterToProperty)} context={context}/>
|
|
50
26
|
</InteractiveSection>);
|
|
51
27
|
})}
|
|
52
28
|
|
|
53
|
-
{operation.requestBody ? (<OpenAPIRequestBody requestBody={
|
|
54
|
-
{operation.responses ? (<OpenAPIResponses responses={
|
|
29
|
+
{operation.requestBody ? (<OpenAPIRequestBody requestBody={operation.requestBody} context={context}/>) : null}
|
|
30
|
+
{operation.responses ? (<OpenAPIResponses responses={operation.responses} context={context}/>) : null}
|
|
55
31
|
</>);
|
|
56
32
|
}
|
|
57
33
|
function groupParameters(parameters) {
|
package/dist/OpenAPITabs.d.ts
CHANGED
package/dist/OpenAPITabs.jsx
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { createContext, useContext, useMemo, useState } from 'react';
|
|
2
|
+
import { createContext, useContext, useEffect, useMemo, useState } from 'react';
|
|
3
3
|
import { Tab, TabList, TabPanel, Tabs } from 'react-aria-components';
|
|
4
4
|
import { Markdown } from './Markdown';
|
|
5
|
+
import { useSyncedTabsGlobalState } from './useSyncedTabsGlobalState';
|
|
6
|
+
import { useIntersectionObserver } from 'usehooks-ts';
|
|
5
7
|
var OpenAPITabsContext = createContext(null);
|
|
6
8
|
function useOpenAPITabsContext() {
|
|
7
9
|
var context = useContext(OpenAPITabsContext);
|
|
@@ -14,17 +16,52 @@ function useOpenAPITabsContext() {
|
|
|
14
16
|
* The OpenAPI Tabs wrapper component.
|
|
15
17
|
*/
|
|
16
18
|
export function OpenAPITabs(props) {
|
|
17
|
-
var children = props.children, items = props.items;
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
var children = props.children, items = props.items, stateKey = props.stateKey;
|
|
20
|
+
var isVisible = stateKey
|
|
21
|
+
? useIntersectionObserver({
|
|
22
|
+
threshold: 0.1,
|
|
23
|
+
rootMargin: '200px',
|
|
24
|
+
})
|
|
25
|
+
: true;
|
|
26
|
+
var defaultTab = items[0];
|
|
27
|
+
var _a = useSyncedTabsGlobalState(), syncedTabs = _a[0], setSyncedTabs = _a[1];
|
|
28
|
+
var _b = useState(function () {
|
|
29
|
+
var _a, _b, _c;
|
|
30
|
+
if (isVisible && stateKey && syncedTabs && syncedTabs.has(stateKey)) {
|
|
31
|
+
var tabFromState = syncedTabs.get(stateKey);
|
|
32
|
+
return (_a = tabFromState === null || tabFromState === void 0 ? void 0 : tabFromState.key) !== null && _a !== void 0 ? _a : (_b = items[0]) === null || _b === void 0 ? void 0 : _b.key;
|
|
22
33
|
}
|
|
23
|
-
return
|
|
24
|
-
}),
|
|
25
|
-
var
|
|
34
|
+
return (_c = items[0]) === null || _c === void 0 ? void 0 : _c.key;
|
|
35
|
+
}), selectedTabKey = _b[0], setSelectedTabKey = _b[1];
|
|
36
|
+
var _c = useState(defaultTab), selectedTab = _c[0], setSelectedTab = _c[1];
|
|
37
|
+
var handleSelectionChange = function (key) {
|
|
38
|
+
setSelectedTabKey(key);
|
|
39
|
+
if (stateKey) {
|
|
40
|
+
var tab_1 = items.find(function (item) { return item.key === key; });
|
|
41
|
+
if (!tab_1) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
setSyncedTabs(function (state) {
|
|
45
|
+
var newState = new Map(state);
|
|
46
|
+
newState.set(stateKey, tab_1);
|
|
47
|
+
return newState;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
useEffect(function () {
|
|
52
|
+
if (isVisible && stateKey && syncedTabs && syncedTabs.has(stateKey)) {
|
|
53
|
+
var tabFromState_1 = syncedTabs.get(stateKey);
|
|
54
|
+
if (!items.some(function (item) { return item.key === (tabFromState_1 === null || tabFromState_1 === void 0 ? void 0 : tabFromState_1.key); })) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (tabFromState_1 && (tabFromState_1 === null || tabFromState_1 === void 0 ? void 0 : tabFromState_1.key) !== (selectedTab === null || selectedTab === void 0 ? void 0 : selectedTab.key)) {
|
|
58
|
+
setSelectedTab(tabFromState_1);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}, [isVisible, stateKey, syncedTabs, selectedTabKey]);
|
|
62
|
+
var contextValue = useMemo(function () { return ({ items: items, selectedTab: selectedTab }); }, [items, selectedTab]);
|
|
26
63
|
return (<OpenAPITabsContext.Provider value={contextValue}>
|
|
27
|
-
<Tabs className="openapi-tabs" onSelectionChange={
|
|
64
|
+
<Tabs className="openapi-tabs" onSelectionChange={handleSelectionChange} selectedKey={selectedTab === null || selectedTab === void 0 ? void 0 : selectedTab.key}>
|
|
28
65
|
{children}
|
|
29
66
|
</Tabs>
|
|
30
67
|
</OpenAPITabsContext.Provider>);
|
|
@@ -55,13 +92,12 @@ export function OpenAPITabsList() {
|
|
|
55
92
|
* It renders the content of the selected tab.
|
|
56
93
|
*/
|
|
57
94
|
export function OpenAPITabsPanels() {
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
if (!tab) {
|
|
95
|
+
var selectedTab = useOpenAPITabsContext().selectedTab;
|
|
96
|
+
if (!selectedTab) {
|
|
61
97
|
return null;
|
|
62
98
|
}
|
|
63
|
-
return (<TabPanel key={"TabPanel-".concat(
|
|
64
|
-
{
|
|
65
|
-
{
|
|
99
|
+
return (<TabPanel key={"TabPanel-".concat(selectedTab.key)} id={selectedTab.key.toString()} className="openapi-tabs-panel">
|
|
100
|
+
{selectedTab.body}
|
|
101
|
+
{selectedTab.description ? (<Markdown source={selectedTab.description} className="openapi-tabs-footer"/>) : null}
|
|
66
102
|
</TabPanel>);
|
|
67
103
|
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
+
import { getExampleFromSchema } from '@scalar/oas-utils/spec-getters';
|
|
2
3
|
type JSONValue = string | number | boolean | null | JSONValue[] | {
|
|
3
4
|
[key: string]: JSONValue;
|
|
4
5
|
};
|
|
6
|
+
type ScalarGetExampleFromSchemaOptions = NonNullable<Parameters<typeof getExampleFromSchema>[1]>;
|
|
7
|
+
type GenerateSchemaExampleOptions = Pick<ScalarGetExampleFromSchemaOptions, 'xml' | 'omitEmptyAndOptionalProperties' | 'mode'>;
|
|
5
8
|
/**
|
|
6
9
|
* Generate a JSON example from a schema
|
|
7
10
|
*/
|
|
8
|
-
export declare function generateSchemaExample(schema: OpenAPIV3.SchemaObject, options?:
|
|
9
|
-
onlyRequired?: boolean;
|
|
10
|
-
}): JSONValue | undefined;
|
|
11
|
+
export declare function generateSchemaExample(schema: OpenAPIV3.SchemaObject, options?: GenerateSchemaExampleOptions): JSONValue | undefined;
|
|
11
12
|
/**
|
|
12
13
|
* Generate an example for a media type.
|
|
13
14
|
*/
|
|
14
|
-
export declare function generateMediaTypeExample(mediaType: OpenAPIV3.MediaTypeObject, options?:
|
|
15
|
-
onlyRequired?: boolean;
|
|
16
|
-
}): JSONValue | undefined;
|
|
15
|
+
export declare function generateMediaTypeExample(mediaType: OpenAPIV3.MediaTypeObject, options?: GenerateSchemaExampleOptions): JSONValue | undefined;
|
|
17
16
|
export {};
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
2
12
|
import { getExampleFromSchema } from '@scalar/oas-utils/spec-getters';
|
|
3
13
|
/**
|
|
4
14
|
* Generate a JSON example from a schema
|
|
5
15
|
*/
|
|
6
16
|
export function generateSchemaExample(schema, options) {
|
|
7
|
-
|
|
8
|
-
return getExampleFromSchema(schema, {
|
|
9
|
-
emptyString: 'text',
|
|
10
|
-
omitEmptyAndOptionalProperties: options.onlyRequired,
|
|
11
|
-
variables: {
|
|
17
|
+
return getExampleFromSchema(schema, __assign({ emptyString: 'text', variables: {
|
|
12
18
|
'date-time': new Date().toISOString(),
|
|
13
19
|
date: new Date().toISOString().split('T')[0],
|
|
14
20
|
email: 'name@gmail.com',
|
|
@@ -20,14 +26,12 @@ export function generateSchemaExample(schema, options) {
|
|
|
20
26
|
binary: 'binary',
|
|
21
27
|
byte: 'Ynl0ZXM=',
|
|
22
28
|
password: 'password',
|
|
23
|
-
},
|
|
24
|
-
});
|
|
29
|
+
} }, options));
|
|
25
30
|
}
|
|
26
31
|
/**
|
|
27
32
|
* Generate an example for a media type.
|
|
28
33
|
*/
|
|
29
34
|
export function generateMediaTypeExample(mediaType, options) {
|
|
30
|
-
if (options === void 0) { options = {}; }
|
|
31
35
|
if (mediaType.example) {
|
|
32
36
|
return mediaType.example;
|
|
33
37
|
}
|
|
@@ -36,12 +40,12 @@ export function generateMediaTypeExample(mediaType, options) {
|
|
|
36
40
|
if (key) {
|
|
37
41
|
var example = mediaType.examples[key];
|
|
38
42
|
if (example) {
|
|
39
|
-
return
|
|
43
|
+
return example.value;
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
47
|
if (mediaType.schema) {
|
|
44
|
-
return generateSchemaExample(
|
|
48
|
+
return generateSchemaExample(mediaType.schema, options);
|
|
45
49
|
}
|
|
46
50
|
return undefined;
|
|
47
51
|
}
|
package/dist/json2xml.js
ADDED
|
@@ -56,7 +56,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
56
56
|
};
|
|
57
57
|
import { toJSON, fromJSON } from 'flatted';
|
|
58
58
|
import { dereference, } from '@gitbook/openapi-parser';
|
|
59
|
-
import {
|
|
59
|
+
import { checkIsReference } from './utils';
|
|
60
60
|
export { toJSON, fromJSON };
|
|
61
61
|
/**
|
|
62
62
|
* Resolve an OpenAPI operation in a file and compile it to a more usable format.
|
|
@@ -88,8 +88,8 @@ export function resolveOpenAPIOperation(filesystem, operationDescriptor) {
|
|
|
88
88
|
securityKey = Object.keys(entry)[0];
|
|
89
89
|
if (securityKey) {
|
|
90
90
|
securityScheme = (_f = (_e = schema.components) === null || _e === void 0 ? void 0 : _e.securitySchemes) === null || _f === void 0 ? void 0 : _f[securityKey];
|
|
91
|
-
if (securityScheme) {
|
|
92
|
-
securities.push([securityKey,
|
|
91
|
+
if (securityScheme && !checkIsReference(securityScheme)) {
|
|
92
|
+
securities.push([securityKey, securityScheme]);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
}
|
|
@@ -155,7 +155,7 @@ function getPathObject(schema, path) {
|
|
|
155
155
|
function getPathObjectParameter(schema, path) {
|
|
156
156
|
var pathObject = getPathObject(schema, path);
|
|
157
157
|
if (pathObject === null || pathObject === void 0 ? void 0 : pathObject.parameters) {
|
|
158
|
-
return pathObject.parameters
|
|
158
|
+
return pathObject.parameters;
|
|
159
159
|
}
|
|
160
160
|
return null;
|
|
161
161
|
}
|