@gitbook/react-openapi 1.1.5 → 1.1.6
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/OpenAPICodeSample.d.ts +9 -0
- package/dist/OpenAPICodeSample.jsx +117 -58
- package/dist/OpenAPICodeSampleInteractive.d.ts +10 -0
- package/dist/OpenAPICodeSampleInteractive.jsx +78 -0
- package/dist/OpenAPISchemaName.jsx +7 -6
- package/dist/code-samples.d.ts +1 -2
- package/dist/code-samples.js +2 -2
- package/dist/generateSchemaExample.d.ts +31 -2
- package/dist/generateSchemaExample.js +307 -24
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +11 -7
- package/package.json +3 -3
- package/src/OpenAPICodeSample.tsx +176 -78
- package/src/OpenAPICodeSampleInteractive.tsx +114 -0
- package/src/OpenAPISchemaName.tsx +11 -6
- package/src/code-samples.ts +3 -3
- package/src/generateSchemaExample.ts +412 -25
- package/src/resolveOpenAPIOperation.test.ts +6 -6
- package/src/utils.ts +13 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @gitbook/react-openapi
|
|
2
2
|
|
|
3
|
+
## 1.1.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6eae764: Support body examples
|
|
8
|
+
- 7212973: Update scalar
|
|
9
|
+
- d2facb2: Mark properties as optional if not required
|
|
10
|
+
- 73e2b47: Fix write only properties in request example
|
|
11
|
+
- 70be2c6: Stringify default value
|
|
12
|
+
- fc00b51: Remove default value in generateSchemaExample
|
|
13
|
+
- a84b06b: Update resolveDescription and add minItems/maxItems
|
|
14
|
+
- Updated dependencies [48c18c0]
|
|
15
|
+
- Updated dependencies [7212973]
|
|
16
|
+
- @gitbook/openapi-parser@2.1.1
|
|
17
|
+
|
|
3
18
|
## 1.1.5
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
1
2
|
import type { OpenAPIContextProps, OpenAPIOperationData } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* Display code samples to execute the operation.
|
|
@@ -7,3 +8,11 @@ export declare function OpenAPICodeSample(props: {
|
|
|
7
8
|
data: OpenAPIOperationData;
|
|
8
9
|
context: OpenAPIContextProps;
|
|
9
10
|
}): import("react").JSX.Element | null;
|
|
11
|
+
export interface MediaTypeRenderer {
|
|
12
|
+
mediaType: string;
|
|
13
|
+
element: React.ReactNode;
|
|
14
|
+
examples: Array<{
|
|
15
|
+
example: OpenAPIV3.ExampleObject;
|
|
16
|
+
element: React.ReactNode;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
@@ -9,20 +9,47 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
+
import { OpenAPIMediaTypeExamplesBody, OpenAPIMediaTypeExamplesSelector, } from './OpenAPICodeSampleInteractive';
|
|
12
13
|
import { OpenAPITabs, OpenAPITabsList, OpenAPITabsPanels } from './OpenAPITabs';
|
|
13
14
|
import { ScalarApiButton } from './ScalarApiButton';
|
|
14
15
|
import { StaticSection } from './StaticSection';
|
|
15
16
|
import { codeSampleGenerators } from './code-samples';
|
|
16
|
-
import {
|
|
17
|
+
import { generateMediaTypeExamples, generateSchemaExample } from './generateSchemaExample';
|
|
17
18
|
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
|
18
19
|
import { getDefaultServerURL } from './util/server';
|
|
19
20
|
import { checkIsReference, createStateKey } from './utils';
|
|
21
|
+
var CUSTOM_CODE_SAMPLES_KEYS = ['x-custom-examples', 'x-code-samples', 'x-codeSamples'];
|
|
20
22
|
/**
|
|
21
23
|
* Display code samples to execute the operation.
|
|
22
24
|
* It supports the Redocly custom syntax as well (https://redocly.com/docs/api-reference-docs/specification-extensions/x-code-samples/)
|
|
23
25
|
*/
|
|
24
26
|
export function OpenAPICodeSample(props) {
|
|
25
|
-
var
|
|
27
|
+
var data = props.data;
|
|
28
|
+
// If code samples are disabled at operation level, we don't display the code samples.
|
|
29
|
+
if (data.operation['x-codeSamples'] === false) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
var customCodeSamples = getCustomCodeSamples(props);
|
|
33
|
+
// If code samples are disabled at the top-level and not custom code samples are defined,
|
|
34
|
+
// we don't display the code samples.
|
|
35
|
+
if (data['x-codeSamples'] === false && !customCodeSamples) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
var samples = customCodeSamples !== null && customCodeSamples !== void 0 ? customCodeSamples : generateCodeSamples(props);
|
|
39
|
+
if (samples.length === 0) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return (<OpenAPITabs stateKey={createStateKey('codesample')} items={samples}>
|
|
43
|
+
<StaticSection header={<OpenAPITabsList />} className="openapi-codesample">
|
|
44
|
+
<OpenAPITabsPanels />
|
|
45
|
+
</StaticSection>
|
|
46
|
+
</OpenAPITabs>);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Generate code samples for the operation.
|
|
50
|
+
*/
|
|
51
|
+
function generateCodeSamples(props) {
|
|
52
|
+
var _a, _b;
|
|
26
53
|
var data = props.data, context = props.context;
|
|
27
54
|
var searchParams = new URLSearchParams();
|
|
28
55
|
var headersObject = {};
|
|
@@ -51,34 +78,92 @@ export function OpenAPICodeSample(props) {
|
|
|
51
78
|
var requestBody = !checkIsReference(data.operation.requestBody)
|
|
52
79
|
? data.operation.requestBody
|
|
53
80
|
: undefined;
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
:
|
|
57
|
-
var
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
var url = getDefaultServerURL(data.servers) +
|
|
82
|
+
data.path +
|
|
83
|
+
(searchParams.size ? "?".concat(searchParams.toString()) : '');
|
|
84
|
+
var genericHeaders = __assign(__assign({}, getSecurityHeaders(data.securities)), headersObject);
|
|
85
|
+
var mediaTypeRendererFactories = Object.entries((_b = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content) !== null && _b !== void 0 ? _b : {}).map(function (_a) {
|
|
86
|
+
var mediaType = _a[0], mediaTypeObject = _a[1];
|
|
87
|
+
return function (generator) {
|
|
88
|
+
var mediaTypeHeaders = __assign(__assign({}, genericHeaders), { 'Content-Type': mediaType });
|
|
89
|
+
return {
|
|
90
|
+
mediaType: mediaType,
|
|
91
|
+
element: context.renderCodeBlock({
|
|
92
|
+
code: generator.generate({
|
|
93
|
+
url: url,
|
|
94
|
+
method: data.method,
|
|
95
|
+
body: undefined,
|
|
96
|
+
headers: mediaTypeHeaders,
|
|
97
|
+
}),
|
|
98
|
+
syntax: generator.syntax,
|
|
99
|
+
}),
|
|
100
|
+
examples: generateMediaTypeExamples(mediaTypeObject, {
|
|
101
|
+
mode: 'write',
|
|
102
|
+
}).map(function (example) { return ({
|
|
103
|
+
example: example,
|
|
104
|
+
element: context.renderCodeBlock({
|
|
105
|
+
code: generator.generate({
|
|
106
|
+
url: url,
|
|
107
|
+
method: data.method,
|
|
108
|
+
body: example.value,
|
|
109
|
+
headers: mediaTypeHeaders,
|
|
110
|
+
}),
|
|
111
|
+
syntax: generator.syntax,
|
|
112
|
+
}),
|
|
113
|
+
}); }),
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
return codeSampleGenerators.map(function (generator) {
|
|
118
|
+
if (mediaTypeRendererFactories.length > 0) {
|
|
119
|
+
var renderers = mediaTypeRendererFactories.map(function (generate) { return generate(generator); });
|
|
120
|
+
return {
|
|
121
|
+
key: "default-".concat(generator.id),
|
|
122
|
+
label: generator.label,
|
|
123
|
+
body: <OpenAPIMediaTypeExamplesBody data={data} renderers={renderers}/>,
|
|
124
|
+
footer: (<OpenAPICodeSampleFooter renderers={renderers} data={data} context={context}/>),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
key: "default-".concat(generator.id),
|
|
129
|
+
label: generator.label,
|
|
130
|
+
body: context.renderCodeBlock({
|
|
131
|
+
code: generator.generate({
|
|
132
|
+
url: url,
|
|
133
|
+
method: data.method,
|
|
134
|
+
body: undefined,
|
|
135
|
+
headers: genericHeaders,
|
|
136
|
+
}),
|
|
137
|
+
syntax: generator.syntax,
|
|
138
|
+
}),
|
|
139
|
+
footer: <OpenAPICodeSampleFooter data={data} renderers={[]} context={context}/>,
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function OpenAPICodeSampleFooter(props) {
|
|
144
|
+
var data = props.data, context = props.context, renderers = props.renderers;
|
|
145
|
+
var method = data.method, path = data.path;
|
|
146
|
+
var specUrl = context.specUrl;
|
|
147
|
+
var hideTryItPanel = data['x-hideTryItPanel'] || data.operation['x-hideTryItPanel'];
|
|
148
|
+
var hasMediaTypes = renderers.length > 0;
|
|
149
|
+
if (hideTryItPanel && !hasMediaTypes) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
if (!validateHttpMethod(method)) {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
return (<div className="openapi-codesample-footer">
|
|
156
|
+
{hasMediaTypes ? (<OpenAPIMediaTypeExamplesSelector data={data} renderers={renderers}/>) : (<span />)}
|
|
157
|
+
{!hideTryItPanel && <ScalarApiButton method={method} path={path} specUrl={specUrl}/>}
|
|
158
|
+
</div>);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Get custom code samples for the operation.
|
|
162
|
+
*/
|
|
163
|
+
function getCustomCodeSamples(props) {
|
|
164
|
+
var data = props.data, context = props.context;
|
|
80
165
|
var customCodeSamples = null;
|
|
81
|
-
|
|
166
|
+
CUSTOM_CODE_SAMPLES_KEYS.forEach(function (key) {
|
|
82
167
|
var customSamples = data.operation[key];
|
|
83
168
|
if (customSamples && Array.isArray(customSamples)) {
|
|
84
169
|
customCodeSamples = customSamples
|
|
@@ -88,43 +173,17 @@ export function OpenAPICodeSample(props) {
|
|
|
88
173
|
typeof sample.lang === 'string');
|
|
89
174
|
})
|
|
90
175
|
.map(function (sample, index) { return ({
|
|
91
|
-
key: "
|
|
176
|
+
key: "custom-sample-".concat(sample.lang, "-").concat(index),
|
|
92
177
|
label: sample.label,
|
|
93
178
|
body: context.renderCodeBlock({
|
|
94
179
|
code: sample.source,
|
|
95
180
|
syntax: sample.lang,
|
|
96
181
|
}),
|
|
97
|
-
footer: <OpenAPICodeSampleFooter data={data} context={context}
|
|
182
|
+
footer: (<OpenAPICodeSampleFooter renderers={[]} data={data} context={context}/>),
|
|
98
183
|
}); });
|
|
99
184
|
}
|
|
100
185
|
});
|
|
101
|
-
|
|
102
|
-
// If code samples are defined at the operation level, it will override the top-level setting
|
|
103
|
-
var codeSamplesDisabled = data['x-codeSamples'] === false || data.operation['x-codeSamples'] === false;
|
|
104
|
-
var samples = customCodeSamples !== null && customCodeSamples !== void 0 ? customCodeSamples : (!codeSamplesDisabled ? autoCodeSamples : []);
|
|
105
|
-
if (samples.length === 0) {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
return (<OpenAPITabs stateKey={createStateKey('codesample')} items={samples}>
|
|
109
|
-
<StaticSection header={<OpenAPITabsList />} className="openapi-codesample">
|
|
110
|
-
<OpenAPITabsPanels />
|
|
111
|
-
</StaticSection>
|
|
112
|
-
</OpenAPITabs>);
|
|
113
|
-
}
|
|
114
|
-
function OpenAPICodeSampleFooter(props) {
|
|
115
|
-
var data = props.data, context = props.context;
|
|
116
|
-
var method = data.method, path = data.path;
|
|
117
|
-
var specUrl = context.specUrl;
|
|
118
|
-
var hideTryItPanel = data['x-hideTryItPanel'] || data.operation['x-hideTryItPanel'];
|
|
119
|
-
if (hideTryItPanel) {
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
if (!validateHttpMethod(method)) {
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
return (<div className="openapi-codesample-footer">
|
|
126
|
-
<ScalarApiButton method={method} path={path} specUrl={specUrl}/>
|
|
127
|
-
</div>);
|
|
186
|
+
return customCodeSamples;
|
|
128
187
|
}
|
|
129
188
|
function getSecurityHeaders(securities) {
|
|
130
189
|
var _a;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MediaTypeRenderer } from './OpenAPICodeSample';
|
|
2
|
+
import type { OpenAPIOperationData } from './types';
|
|
3
|
+
export declare function OpenAPIMediaTypeExamplesSelector(props: {
|
|
4
|
+
data: OpenAPIOperationData;
|
|
5
|
+
renderers: MediaTypeRenderer[];
|
|
6
|
+
}): import("react").JSX.Element;
|
|
7
|
+
export declare function OpenAPIMediaTypeExamplesBody(props: {
|
|
8
|
+
data: OpenAPIOperationData;
|
|
9
|
+
renderers: MediaTypeRenderer[];
|
|
10
|
+
}): string | number | boolean | Iterable<import("react").ReactNode> | import("react").JSX.Element | null | undefined;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { useCallback } from 'react';
|
|
4
|
+
import { useStore } from 'zustand';
|
|
5
|
+
import { getOrCreateTabStoreByKey } from './useSyncedTabsGlobalState';
|
|
6
|
+
function useMediaTypeState(data, defaultKey) {
|
|
7
|
+
var method = data.method, path = data.path;
|
|
8
|
+
var store = useStore(getOrCreateTabStoreByKey("media-type-".concat(method, "-").concat(path), defaultKey));
|
|
9
|
+
if (typeof store.tabKey !== 'string') {
|
|
10
|
+
throw new Error('Media type key is not a string');
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
mediaType: store.tabKey,
|
|
14
|
+
setMediaType: useCallback(function (index) { return store.setTabKey(index); }, [store.setTabKey]),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function useMediaTypeSampleIndexState(data, mediaType) {
|
|
18
|
+
var method = data.method, path = data.path;
|
|
19
|
+
var store = useStore(getOrCreateTabStoreByKey("media-type-sample-".concat(mediaType, "-").concat(method, "-").concat(path), 0));
|
|
20
|
+
if (typeof store.tabKey !== 'number') {
|
|
21
|
+
throw new Error('Example key is not a number');
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
index: store.tabKey,
|
|
25
|
+
setIndex: useCallback(function (index) { return store.setTabKey(index); }, [store.setTabKey]),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function OpenAPIMediaTypeExamplesSelector(props) {
|
|
29
|
+
var data = props.data, renderers = props.renderers;
|
|
30
|
+
if (!renderers[0]) {
|
|
31
|
+
throw new Error('No renderers provided');
|
|
32
|
+
}
|
|
33
|
+
var state = useMediaTypeState(data, renderers[0].mediaType);
|
|
34
|
+
var selected = renderers.find(function (r) { return r.mediaType === state.mediaType; }) || renderers[0];
|
|
35
|
+
return (<div className="openapi-codesample-selectors">
|
|
36
|
+
<select className={clsx('openapi-select')} value={state.mediaType} onChange={function (e) { return state.setMediaType(e.target.value); }}>
|
|
37
|
+
{renderers.map(function (renderer) { return (<option key={renderer.mediaType} value={renderer.mediaType}>
|
|
38
|
+
{renderer.mediaType}
|
|
39
|
+
</option>); })}
|
|
40
|
+
</select>
|
|
41
|
+
<ExamplesSelector data={data} renderer={selected}/>
|
|
42
|
+
</div>);
|
|
43
|
+
}
|
|
44
|
+
function ExamplesSelector(props) {
|
|
45
|
+
var data = props.data, renderer = props.renderer;
|
|
46
|
+
var state = useMediaTypeSampleIndexState(data, renderer.mediaType);
|
|
47
|
+
if (renderer.examples.length < 2) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return (<select className={clsx('openapi-select')} value={String(state.index)} onChange={function (e) { return state.setIndex(Number(e.target.value)); }}>
|
|
51
|
+
{renderer.examples.map(function (example, index) { return (<option key={index} value={index}>
|
|
52
|
+
{example.example.summary || "Example ".concat(index + 1)}
|
|
53
|
+
</option>); })}
|
|
54
|
+
</select>);
|
|
55
|
+
}
|
|
56
|
+
export function OpenAPIMediaTypeExamplesBody(props) {
|
|
57
|
+
var _a;
|
|
58
|
+
var renderers = props.renderers, data = props.data;
|
|
59
|
+
if (!renderers[0]) {
|
|
60
|
+
throw new Error('No renderers provided');
|
|
61
|
+
}
|
|
62
|
+
var mediaTypeState = useMediaTypeState(data, renderers[0].mediaType);
|
|
63
|
+
var selected = (_a = renderers.find(function (r) { return r.mediaType === mediaTypeState.mediaType; })) !== null && _a !== void 0 ? _a : renderers[0];
|
|
64
|
+
if (selected.examples.length === 0) {
|
|
65
|
+
return selected.element;
|
|
66
|
+
}
|
|
67
|
+
return <ExamplesBody data={data} renderer={selected}/>;
|
|
68
|
+
}
|
|
69
|
+
function ExamplesBody(props) {
|
|
70
|
+
var _a;
|
|
71
|
+
var data = props.data, renderer = props.renderer;
|
|
72
|
+
var exampleState = useMediaTypeSampleIndexState(data, renderer.mediaType);
|
|
73
|
+
var example = (_a = renderer.examples[exampleState.index]) !== null && _a !== void 0 ? _a : renderer.examples[0];
|
|
74
|
+
if (!example) {
|
|
75
|
+
throw new Error("No example found for index ".concat(exampleState.index));
|
|
76
|
+
}
|
|
77
|
+
return example.element;
|
|
78
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
|
1
2
|
/**
|
|
2
3
|
* Display the schema name row.
|
|
3
4
|
* It includes the property name, type, required and deprecated status.
|
|
@@ -14,21 +15,21 @@ export function OpenAPISchemaName(props) {
|
|
|
14
15
|
{additionalItems ? (<span className="openapi-schema-type">{additionalItems}</span>) : null}
|
|
15
16
|
</span>
|
|
16
17
|
{(schema === null || schema === void 0 ? void 0 : schema.readOnly) ? <span className="openapi-schema-readonly">read-only</span> : null}
|
|
17
|
-
{required ? <span className="openapi-schema-required">required</span> :
|
|
18
|
+
{required ? (<span className="openapi-schema-required">required</span>) : (<span className="openapi-schema-optional">optional</span>)}
|
|
18
19
|
{(schema === null || schema === void 0 ? void 0 : schema.deprecated) ? <span className="openapi-deprecated">Deprecated</span> : null}
|
|
19
20
|
</div>);
|
|
20
21
|
}
|
|
21
22
|
function getAdditionalItems(schema) {
|
|
22
23
|
var additionalItems = '';
|
|
23
|
-
if (schema.minimum || schema.minLength) {
|
|
24
|
-
additionalItems += " \u00B7 min: ".concat(schema.minimum || schema.minLength);
|
|
24
|
+
if (schema.minimum || schema.minLength || schema.minItems) {
|
|
25
|
+
additionalItems += " \u00B7 min: ".concat(schema.minimum || schema.minLength || schema.minItems);
|
|
25
26
|
}
|
|
26
|
-
if (schema.maximum || schema.maxLength) {
|
|
27
|
-
additionalItems += " \u00B7 max: ".concat(schema.maximum || schema.maxLength);
|
|
27
|
+
if (schema.maximum || schema.maxLength || schema.maxItems) {
|
|
28
|
+
additionalItems += " \u00B7 max: ".concat(schema.maximum || schema.maxLength || schema.maxItems);
|
|
28
29
|
}
|
|
29
30
|
// If the schema has a default value, we display it
|
|
30
31
|
if (typeof schema.default !== 'undefined') {
|
|
31
|
-
additionalItems += " \u00B7 default: ".concat(schema.default);
|
|
32
|
+
additionalItems += " \u00B7 default: ".concat(stringifyOpenAPI(schema.default));
|
|
32
33
|
}
|
|
33
34
|
if (schema.nullable) {
|
|
34
35
|
additionalItems = ' | nullable';
|
package/dist/code-samples.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export interface CodeSampleInput {
|
|
|
4
4
|
headers?: Record<string, string>;
|
|
5
5
|
body?: any;
|
|
6
6
|
}
|
|
7
|
-
interface CodeSampleGenerator {
|
|
7
|
+
export interface CodeSampleGenerator {
|
|
8
8
|
id: string;
|
|
9
9
|
label: string;
|
|
10
10
|
syntax: string;
|
|
@@ -15,4 +15,3 @@ export declare function parseHostAndPath(url: string): {
|
|
|
15
15
|
host: string | undefined;
|
|
16
16
|
path: string;
|
|
17
17
|
};
|
|
18
|
-
export {};
|
package/dist/code-samples.js
CHANGED
|
@@ -203,7 +203,7 @@ var BodyGenerators = {
|
|
|
203
203
|
}
|
|
204
204
|
else if (isXML(contentType) || isCSV(contentType)) {
|
|
205
205
|
// We use --data-binary to avoid cURL converting newlines to \r\n
|
|
206
|
-
body = "--data-binary $'".concat(stringifyOpenAPI(body).replace(/"/g, ''), "'");
|
|
206
|
+
body = "--data-binary $'".concat(stringifyOpenAPI(body).replace(/"/g, '').replace(/\\n/g, '\n'), "'");
|
|
207
207
|
}
|
|
208
208
|
else if (isGraphQL(contentType)) {
|
|
209
209
|
body = "--data '".concat(stringifyOpenAPI(body), "'");
|
|
@@ -215,7 +215,7 @@ var BodyGenerators = {
|
|
|
215
215
|
body = "--data-binary '@".concat(String(body), "'");
|
|
216
216
|
}
|
|
217
217
|
else {
|
|
218
|
-
body = "--data '".concat(stringifyOpenAPI(body, null, 2), "'");
|
|
218
|
+
body = "--data '".concat(stringifyOpenAPI(body, null, 2).replace(/\\n/g, '\n'), "'");
|
|
219
219
|
}
|
|
220
220
|
return {
|
|
221
221
|
body: body,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
2
|
-
import { getExampleFromSchema } from '@scalar/oas-utils/spec-getters';
|
|
3
2
|
type JSONValue = string | number | boolean | null | JSONValue[] | {
|
|
4
3
|
[key: string]: JSONValue;
|
|
5
4
|
};
|
|
@@ -12,5 +11,35 @@ export declare function generateSchemaExample(schema: OpenAPIV3.SchemaObject, op
|
|
|
12
11
|
/**
|
|
13
12
|
* Generate an example for a media type.
|
|
14
13
|
*/
|
|
15
|
-
export declare function
|
|
14
|
+
export declare function generateMediaTypeExamples(mediaType: OpenAPIV3.MediaTypeObject, options?: GenerateSchemaExampleOptions): OpenAPIV3.ExampleObject[];
|
|
15
|
+
/**
|
|
16
|
+
* This function takes an OpenAPI schema and generates an example from it
|
|
17
|
+
* Forked from : https://github.com/scalar/scalar/blob/main/packages/oas-utils/src/spec-getters/getExampleFromSchema.ts
|
|
18
|
+
*/
|
|
19
|
+
declare const getExampleFromSchema: (schema: Record<string, any>, options?: {
|
|
20
|
+
/**
|
|
21
|
+
* The fallback string for empty string values.
|
|
22
|
+
* @default ''
|
|
23
|
+
*/
|
|
24
|
+
emptyString?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Whether to use the XML tag names as keys
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
xml?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Whether to show read-only/write-only properties. Otherwise all properties are shown.
|
|
32
|
+
* @default undefined
|
|
33
|
+
*/
|
|
34
|
+
mode?: "read" | "write";
|
|
35
|
+
/**
|
|
36
|
+
* Dynamic values to add to the example.
|
|
37
|
+
*/
|
|
38
|
+
variables?: Record<string, any>;
|
|
39
|
+
/**
|
|
40
|
+
* Whether to omit empty and optional properties.
|
|
41
|
+
* @default false
|
|
42
|
+
*/
|
|
43
|
+
omitEmptyAndOptionalProperties?: boolean;
|
|
44
|
+
}, level?: number, parentSchema?: Record<string, any>, name?: string) => any;
|
|
16
45
|
export {};
|