@gitbook/react-openapi 1.1.3 → 1.1.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 +105 -91
- package/dist/OpenAPICodeSample.jsx +27 -2
- package/dist/OpenAPICopyButton.d.ts +4 -0
- package/dist/OpenAPICopyButton.jsx +32 -0
- package/dist/OpenAPIOperation.jsx +1 -1
- package/dist/OpenAPIPath.d.ts +1 -2
- package/dist/OpenAPIPath.jsx +32 -30
- package/dist/OpenAPIResponseExample.jsx +5 -8
- package/dist/OpenAPISchemaName.jsx +1 -0
- package/dist/OpenAPITabs.d.ts +1 -1
- package/dist/OpenAPITabs.jsx +9 -2
- package/dist/ScalarApiButton.jsx +2 -2
- package/dist/schemas/OpenAPISchemas.d.ts +3 -1
- package/dist/schemas/resolveOpenAPISchemas.d.ts +9 -3
- package/dist/schemas/resolveOpenAPISchemas.js +24 -15
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/OpenAPICodeSample.tsx +38 -2
- package/src/OpenAPICopyButton.tsx +54 -0
- package/src/OpenAPIOperation.tsx +1 -1
- package/src/OpenAPIPath.tsx +40 -42
- package/src/OpenAPIResponseExample.tsx +30 -33
- package/src/OpenAPISchemaName.tsx +1 -0
- package/src/OpenAPITabs.tsx +13 -4
- package/src/ScalarApiButton.tsx +2 -2
- package/src/schemas/OpenAPISchemas.tsx +6 -1
- package/src/schemas/resolveOpenAPISchemas.test.ts +174 -0
- package/src/schemas/resolveOpenAPISchemas.ts +31 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,203 +1,217 @@
|
|
|
1
1
|
# @gitbook/react-openapi
|
|
2
2
|
|
|
3
|
+
## 1.1.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 886e204: Update OpenAPI operation path design
|
|
8
|
+
|
|
9
|
+
## 1.1.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- c60e9ba: Handle read-only in OpenAPISchemaName
|
|
14
|
+
- 31d800e: Render OpenAPISchemas block
|
|
15
|
+
- ff3b708: Remove read-only properties from codesample
|
|
16
|
+
|
|
3
17
|
## 1.1.3
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
6
20
|
|
|
7
|
-
-
|
|
21
|
+
- 844059f: Fix spacing in OpenAPISecurities
|
|
8
22
|
|
|
9
23
|
## 1.1.2
|
|
10
24
|
|
|
11
25
|
### Patch Changes
|
|
12
26
|
|
|
13
|
-
-
|
|
27
|
+
- f127d28: Rename OpenAPIModels to OpenAPISchemas
|
|
14
28
|
|
|
15
29
|
## 1.1.1
|
|
16
30
|
|
|
17
31
|
### Patch Changes
|
|
18
32
|
|
|
19
|
-
-
|
|
33
|
+
- f574858: Fix OpenAPI example display error
|
|
20
34
|
|
|
21
35
|
## 1.1.0
|
|
22
36
|
|
|
23
37
|
### Minor Changes
|
|
24
38
|
|
|
25
|
-
-
|
|
39
|
+
- bb3ca9c: Implement OpenAPI models blocks
|
|
26
40
|
|
|
27
41
|
### Patch Changes
|
|
28
42
|
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
|
|
43
|
+
- 0278a14: Upgrade Scalar dependencies
|
|
44
|
+
- 3173d8e: Remove top level circular refs in alternatives
|
|
45
|
+
- Updated dependencies [0278a14]
|
|
46
|
+
- Updated dependencies [bb3ca9c]
|
|
47
|
+
- Updated dependencies [052e07a]
|
|
48
|
+
- @gitbook/openapi-parser@2.1.0
|
|
35
49
|
|
|
36
50
|
## 1.0.5
|
|
37
51
|
|
|
38
52
|
### Patch Changes
|
|
39
53
|
|
|
40
|
-
-
|
|
41
|
-
|
|
54
|
+
- Updated dependencies [53f5dbe]
|
|
55
|
+
- @gitbook/openapi-parser@2.0.2
|
|
42
56
|
|
|
43
57
|
## 1.0.4
|
|
44
58
|
|
|
45
59
|
### Patch Changes
|
|
46
60
|
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
|
|
61
|
+
- 722f02e: Fix recursion in OpenAPISchemaAlternative
|
|
62
|
+
- Updated dependencies [0924259]
|
|
63
|
+
- @gitbook/openapi-parser@2.0.1
|
|
50
64
|
|
|
51
65
|
## 1.0.3
|
|
52
66
|
|
|
53
67
|
### Patch Changes
|
|
54
68
|
|
|
55
|
-
-
|
|
56
|
-
-
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
-
|
|
60
|
-
-
|
|
61
|
-
-
|
|
62
|
-
-
|
|
63
|
-
-
|
|
64
|
-
-
|
|
65
|
-
|
|
69
|
+
- dc2dbc5: Update OpenAPI code examples to support multiple content-type
|
|
70
|
+
- f1d1d2f: Return empty string if no server provided
|
|
71
|
+
- 05e1d8c: Hide x-gitbook-\* symbols in OpenAPI blocks
|
|
72
|
+
- b4a12d6: Fix circularRef in schema + examples OpenAPI
|
|
73
|
+
- 9f0de74: Fix ID not set when there is no operation summary
|
|
74
|
+
- da55fac: Render GitBook blocks in OpenAPI operation description
|
|
75
|
+
- Updated dependencies [c808bb1]
|
|
76
|
+
- Updated dependencies [e24206e]
|
|
77
|
+
- Updated dependencies [a054554]
|
|
78
|
+
- Updated dependencies [da55fac]
|
|
79
|
+
- @gitbook/openapi-parser@2.0.0
|
|
66
80
|
|
|
67
81
|
## 1.0.2
|
|
68
82
|
|
|
69
83
|
### Patch Changes
|
|
70
84
|
|
|
71
|
-
-
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
75
|
-
-
|
|
76
|
-
-
|
|
77
|
-
|
|
85
|
+
- bb5c6a4: Support multiple response media types and examples
|
|
86
|
+
- a3f1fea: Fix display of OpenAPI header description
|
|
87
|
+
- 6157583: Improve Markdown parsing
|
|
88
|
+
- 7419ee7: Show additional fields in OpenAPI block
|
|
89
|
+
- 82cd9f2: Add support for anchor links in OpenAPI blocks
|
|
90
|
+
- Updated dependencies [6157583]
|
|
91
|
+
- @gitbook/openapi-parser@1.0.1
|
|
78
92
|
|
|
79
93
|
## 1.0.1
|
|
80
94
|
|
|
81
95
|
### Patch Changes
|
|
82
96
|
|
|
83
|
-
-
|
|
84
|
-
-
|
|
85
|
-
-
|
|
97
|
+
- f8d4c76: Sync tabs across all OpenAPI blocks
|
|
98
|
+
- dddb4ec: Fix long tab group description
|
|
99
|
+
- f8d4c76: Support for OpenAPI references
|
|
86
100
|
|
|
87
101
|
## 1.0.0
|
|
88
102
|
|
|
89
103
|
### Major Changes
|
|
90
104
|
|
|
91
|
-
-
|
|
92
|
-
-
|
|
105
|
+
- 727bde2: Improve and split OpenAPI parser into its own package
|
|
106
|
+
- 12c7862: Use `@scalar/openapi-parser` to be more resilient and perf on OpenAPI spec parsing:
|
|
93
107
|
|
|
94
|
-
|
|
95
|
-
|
|
108
|
+
- `fetcher.fetch` must now returns a valid OpenAPI document
|
|
109
|
+
- `parseOpenAPIV3` has been replaced by `parseOpenAPI`
|
|
96
110
|
|
|
97
111
|
### Minor Changes
|
|
98
112
|
|
|
99
|
-
-
|
|
100
|
-
-
|
|
101
|
-
-
|
|
102
|
-
-
|
|
103
|
-
-
|
|
104
|
-
-
|
|
105
|
-
-
|
|
113
|
+
- 162b4b7: Add in HTTP example code blocks
|
|
114
|
+
- e4e2f52: Add an optional client context to get a callback called when the Scalar client is opened for a block.
|
|
115
|
+
- eb7c22f: Revert scalar to 1.0.87 to mitigate an issue with ApiClientModalProvider
|
|
116
|
+
- 160fca1: new OpenAPI blocks design
|
|
117
|
+
- e721f17: Use `@scalar/oas-utils` getExampleFromSchema to generate OpenAPI examples
|
|
118
|
+
- fe8acc9: Fix an issue where a missing OpenAPI example would crash the page.
|
|
119
|
+
- 1823101: Fix internal properties appearing in OpenAPI docs.
|
|
106
120
|
|
|
107
121
|
### Patch Changes
|
|
108
122
|
|
|
109
|
-
-
|
|
110
|
-
-
|
|
111
|
-
-
|
|
112
|
-
-
|
|
113
|
-
-
|
|
114
|
-
-
|
|
115
|
-
-
|
|
116
|
-
-
|
|
117
|
-
-
|
|
118
|
-
-
|
|
119
|
-
-
|
|
120
|
-
-
|
|
121
|
-
-
|
|
122
|
-
-
|
|
123
|
-
-
|
|
124
|
-
-
|
|
125
|
-
-
|
|
126
|
-
|
|
123
|
+
- d9029c7: Support apiKey in CodeSample security headers
|
|
124
|
+
- 6e54a06: Support response examples
|
|
125
|
+
- 0c03676: Better securities sample and headers
|
|
126
|
+
- 3e5e458: Handle isArray schema type
|
|
127
|
+
- 46edde9: Improve the OpenAPI package API
|
|
128
|
+
- d9c8d57: Do not dereference before caching OpenAPI spec.
|
|
129
|
+
- ccf2cff: Fix an issue where a response object using a special ref would crash the page.
|
|
130
|
+
- dda0cc6: Flatten OpenAPI security object
|
|
131
|
+
- f92e906: Prevent codemirror from loading multiple versions in scalar
|
|
132
|
+
- dff08ae: Improve performances by loading Scalar API Client only when the button is clicked
|
|
133
|
+
- fc7b16f: Updated scalar depdenency
|
|
134
|
+
- a652958: Fix error on unresolvable refs by replacing with property name and any type
|
|
135
|
+
- 2f73db7: Support non primitive examples in OpenAPI block
|
|
136
|
+
- 160fca1: Support deprecated and x-deprecated-sunset in OpenAPI spec
|
|
137
|
+
- b41d425: Improve OpenAPI rendering performances by caching markdown parsing
|
|
138
|
+
- Updated dependencies [46edde9]
|
|
139
|
+
- Updated dependencies [727bde2]
|
|
140
|
+
- @gitbook/openapi-parser@1.0.0
|
|
127
141
|
|
|
128
142
|
## 0.7.1
|
|
129
143
|
|
|
130
144
|
### Patch Changes
|
|
131
145
|
|
|
132
|
-
-
|
|
133
|
-
-
|
|
134
|
-
-
|
|
135
|
-
-
|
|
136
|
-
-
|
|
146
|
+
- 4771c78: Fixed scalar api client routing
|
|
147
|
+
- ff50ac2: Bump @scalar/api-client-react version
|
|
148
|
+
- 867481c: Support Integers in Response example
|
|
149
|
+
- 7ba67fd: bumped the scalar api client dependency
|
|
150
|
+
- a78c1ec: Bumped scalar api client pacakge
|
|
137
151
|
|
|
138
152
|
## 0.7.0
|
|
139
153
|
|
|
140
154
|
### Minor Changes
|
|
141
155
|
|
|
142
|
-
-
|
|
143
|
-
-
|
|
144
|
-
-
|
|
145
|
-
-
|
|
146
|
-
-
|
|
156
|
+
- cf3045a: Add Python support in Code Samples
|
|
157
|
+
- 4247361: Add required query parameters to the code sample
|
|
158
|
+
- aa8c49e: Display pattern if available in parmas in OpenAPI block
|
|
159
|
+
- e914903: Synchronize response and response example tabs
|
|
160
|
+
- 4cbcc5b: Rollback of scalar modal while fixing perf issue
|
|
147
161
|
|
|
148
162
|
### Patch Changes
|
|
149
163
|
|
|
150
|
-
-
|
|
151
|
-
-
|
|
152
|
-
-
|
|
153
|
-
-
|
|
154
|
-
-
|
|
155
|
-
-
|
|
156
|
-
-
|
|
164
|
+
- 51fa3ab: Adds content-visibility css property to OpenAPI Operation for better render performance
|
|
165
|
+
- f89b31c: Upgrade the scalar api client package
|
|
166
|
+
- 094e9cd: bump: scalar from 1.0.5 to 1.0.7
|
|
167
|
+
- 237b703: Fix crash when `example` is undefined for a response
|
|
168
|
+
- 51955da: Adds tabs to Response Example section e.g. for status code examples
|
|
169
|
+
- a679e72: Render mandatory headers in code sample
|
|
170
|
+
- c079c3c: Update Scalar client to latest version
|
|
157
171
|
|
|
158
172
|
## 0.6.0
|
|
159
173
|
|
|
160
174
|
### Minor Changes
|
|
161
175
|
|
|
162
|
-
-
|
|
176
|
+
- 709f1a1: Update Scalar to the latest version, with faster performances and an improved experience
|
|
163
177
|
|
|
164
178
|
### Patch Changes
|
|
165
179
|
|
|
166
|
-
-
|
|
167
|
-
-
|
|
180
|
+
- ede2335: Fix x-codeSamples: false not working at the single operation level
|
|
181
|
+
- 0426312: Fix tabs being empty for code samples when they are updated dynamically
|
|
168
182
|
|
|
169
183
|
## 0.5.0
|
|
170
184
|
|
|
171
185
|
### Minor Changes
|
|
172
186
|
|
|
173
|
-
-
|
|
187
|
+
- 3445db4: Fix files published in the NPM packages by defining "files" in "package.json"
|
|
174
188
|
|
|
175
189
|
## 0.4.0
|
|
176
190
|
|
|
177
191
|
### Minor Changes
|
|
178
192
|
|
|
179
|
-
-
|
|
193
|
+
- 24cd72e: Fix changeset CI workflow
|
|
180
194
|
|
|
181
195
|
## 0.3.0
|
|
182
196
|
|
|
183
197
|
### Minor Changes
|
|
184
198
|
|
|
185
|
-
-
|
|
199
|
+
- de747b7: Refactor the repository to be a proper monorepo and publish JS files on NPM instead of TypeScript files.
|
|
186
200
|
|
|
187
201
|
## 0.3.0
|
|
188
202
|
|
|
189
203
|
### Minor Changes
|
|
190
204
|
|
|
191
|
-
-
|
|
205
|
+
- bd0ca5b: Fix missing react imports
|
|
192
206
|
|
|
193
207
|
## 0.2.0
|
|
194
208
|
|
|
195
209
|
### Minor Changes
|
|
196
210
|
|
|
197
|
-
-
|
|
211
|
+
- 57adb3e: Second release to fix publishing with changeset
|
|
198
212
|
|
|
199
213
|
## 0.1.0
|
|
200
214
|
|
|
201
215
|
### Minor Changes
|
|
202
216
|
|
|
203
|
-
-
|
|
217
|
+
- 5f8a8fe: Initial release
|
|
@@ -10,6 +10,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
12
|
import { OpenAPITabs, OpenAPITabsList, OpenAPITabsPanels } from './OpenAPITabs';
|
|
13
|
+
import { ScalarApiButton } from './ScalarApiButton';
|
|
13
14
|
import { StaticSection } from './StaticSection';
|
|
14
15
|
import { codeSampleGenerators } from './code-samples';
|
|
15
16
|
import { generateMediaTypeExample, generateSchemaExample } from './generateSchemaExample';
|
|
@@ -30,14 +31,18 @@ export function OpenAPICodeSample(props) {
|
|
|
30
31
|
return;
|
|
31
32
|
}
|
|
32
33
|
if (param.in === 'header' && param.required) {
|
|
33
|
-
var example = param.schema
|
|
34
|
+
var example = param.schema
|
|
35
|
+
? generateSchemaExample(param.schema, { mode: 'write' })
|
|
36
|
+
: undefined;
|
|
34
37
|
if (example !== undefined && param.name) {
|
|
35
38
|
headersObject[param.name] =
|
|
36
39
|
typeof example !== 'string' ? stringifyOpenAPI(example) : example;
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
else if (param.in === 'query' && param.required) {
|
|
40
|
-
var example = param.schema
|
|
43
|
+
var example = param.schema
|
|
44
|
+
? generateSchemaExample(param.schema, { mode: 'write' })
|
|
45
|
+
: undefined;
|
|
41
46
|
if (example !== undefined && param.name) {
|
|
42
47
|
searchParams.append(param.name, String(Array.isArray(example) ? example[0] : example));
|
|
43
48
|
}
|
|
@@ -69,6 +74,7 @@ export function OpenAPICodeSample(props) {
|
|
|
69
74
|
code: generator.generate(input),
|
|
70
75
|
syntax: generator.syntax,
|
|
71
76
|
}),
|
|
77
|
+
footer: <OpenAPICodeSampleFooter data={data} context={context}/>,
|
|
72
78
|
}); });
|
|
73
79
|
// Use custom samples if defined
|
|
74
80
|
var customCodeSamples = null;
|
|
@@ -88,6 +94,7 @@ export function OpenAPICodeSample(props) {
|
|
|
88
94
|
code: sample.source,
|
|
89
95
|
syntax: sample.lang,
|
|
90
96
|
}),
|
|
97
|
+
footer: <OpenAPICodeSampleFooter data={data} context={context}/>,
|
|
91
98
|
}); });
|
|
92
99
|
}
|
|
93
100
|
});
|
|
@@ -104,6 +111,21 @@ export function OpenAPICodeSample(props) {
|
|
|
104
111
|
</StaticSection>
|
|
105
112
|
</OpenAPITabs>);
|
|
106
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>);
|
|
128
|
+
}
|
|
107
129
|
function getSecurityHeaders(securities) {
|
|
108
130
|
var _a;
|
|
109
131
|
var _b, _c;
|
|
@@ -142,3 +164,6 @@ function getSecurityHeaders(securities) {
|
|
|
142
164
|
}
|
|
143
165
|
}
|
|
144
166
|
}
|
|
167
|
+
function validateHttpMethod(method) {
|
|
168
|
+
return ['get', 'post', 'put', 'delete', 'patch', 'head', 'options', 'trace'].includes(method);
|
|
169
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Button, Tooltip, TooltipTrigger } from 'react-aria-components';
|
|
4
|
+
export function OpenAPICopyButton(props) {
|
|
5
|
+
var value = props.value;
|
|
6
|
+
var children = props.children, onPress = props.onPress, className = props.className;
|
|
7
|
+
var _a = useState(false), copied = _a[0], setCopied = _a[1];
|
|
8
|
+
var _b = useState(false), isOpen = _b[0], setIsOpen = _b[1];
|
|
9
|
+
var handleCopy = function () {
|
|
10
|
+
if (!value)
|
|
11
|
+
return;
|
|
12
|
+
navigator.clipboard.writeText(value).then(function () {
|
|
13
|
+
setIsOpen(true);
|
|
14
|
+
setCopied(true);
|
|
15
|
+
setTimeout(function () {
|
|
16
|
+
setCopied(false);
|
|
17
|
+
}, 2000);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
return (<TooltipTrigger isOpen={isOpen} onOpenChange={setIsOpen} closeDelay={200} delay={200}>
|
|
21
|
+
<Button type="button" preventFocusOnPress onPress={function (e) {
|
|
22
|
+
handleCopy();
|
|
23
|
+
onPress === null || onPress === void 0 ? void 0 : onPress(e);
|
|
24
|
+
}} className={"openapi-copy-button ".concat(className)} {...props}>
|
|
25
|
+
{children}
|
|
26
|
+
</Button>
|
|
27
|
+
|
|
28
|
+
<Tooltip isOpen={isOpen} onOpenChange={setIsOpen} placement="top" offset={4} className="openapi-tooltip">
|
|
29
|
+
{copied ? 'Copied' : 'Copy to clipboard'}{' '}
|
|
30
|
+
</Tooltip>
|
|
31
|
+
</TooltipTrigger>);
|
|
32
|
+
}
|
|
@@ -25,6 +25,7 @@ export function OpenAPIOperation(props) {
|
|
|
25
25
|
title: operation.summary,
|
|
26
26
|
})
|
|
27
27
|
: null}
|
|
28
|
+
<OpenAPIPath data={data} context={context}/>
|
|
28
29
|
{operation.deprecated && <div className="openapi-deprecated">Deprecated</div>}
|
|
29
30
|
</div>
|
|
30
31
|
<div className="openapi-columns">
|
|
@@ -37,7 +38,6 @@ export function OpenAPIOperation(props) {
|
|
|
37
38
|
{'.'}
|
|
38
39
|
</div>) : null}
|
|
39
40
|
<OpenAPIOperationDescription operation={operation} context={context}/>
|
|
40
|
-
<OpenAPIPath data={data} context={context}/>
|
|
41
41
|
<OpenAPISpec data={data} context={clientContext}/>
|
|
42
42
|
</div>
|
|
43
43
|
<div className="openapi-column-preview">
|
package/dist/OpenAPIPath.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type React from 'react';
|
|
2
1
|
import type { OpenAPIContextProps, OpenAPIOperationData } from './types';
|
|
3
2
|
/**
|
|
4
3
|
* Display the path of an operation.
|
|
@@ -6,4 +5,4 @@ import type { OpenAPIContextProps, OpenAPIOperationData } from './types';
|
|
|
6
5
|
export declare function OpenAPIPath(props: {
|
|
7
6
|
data: OpenAPIOperationData;
|
|
8
7
|
context: OpenAPIContextProps;
|
|
9
|
-
}):
|
|
8
|
+
}): import("react").JSX.Element;
|
package/dist/OpenAPIPath.jsx
CHANGED
|
@@ -1,47 +1,49 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OpenAPICopyButton } from './OpenAPICopyButton';
|
|
2
|
+
import { getDefaultServerURL } from './util/server';
|
|
2
3
|
/**
|
|
3
4
|
* Display the path of an operation.
|
|
4
5
|
*/
|
|
5
6
|
export function OpenAPIPath(props) {
|
|
6
|
-
var data = props.data
|
|
7
|
-
var method = data.method, path = data.path;
|
|
8
|
-
var
|
|
9
|
-
var
|
|
7
|
+
var data = props.data;
|
|
8
|
+
var method = data.method, path = data.path, operation = data.operation;
|
|
9
|
+
var server = getDefaultServerURL(data.servers);
|
|
10
|
+
var formattedPath = formatPath(path);
|
|
10
11
|
return (<div className="openapi-path">
|
|
11
12
|
<div className={"openapi-method openapi-method-".concat(method)}>{method}</div>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
|
|
14
|
+
<OpenAPICopyButton value={server + path} className="openapi-path-title" data-deprecated={operation.deprecated}>
|
|
15
|
+
<span className="openapi-path-server">{server}</span>
|
|
16
|
+
{formattedPath}
|
|
17
|
+
</OpenAPICopyButton>
|
|
16
18
|
</div>);
|
|
17
19
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// Format the path to highlight placeholders
|
|
20
|
+
/**
|
|
21
|
+
* Format the path by wrapping placeholders in <span> tags.
|
|
22
|
+
*/
|
|
22
23
|
function formatPath(path) {
|
|
23
24
|
// Matches placeholders like {id}, {userId}, etc.
|
|
24
|
-
var regex = /\{(\w+)\}
|
|
25
|
+
var regex = /\{\s*(\w+)\s*\}|:\w+/g;
|
|
25
26
|
var parts = [];
|
|
26
27
|
var lastIndex = 0;
|
|
27
|
-
//
|
|
28
|
-
path.replace(regex, function (match,
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
//Wrap the variables in <span> tags and maintain either {variable} or :variable
|
|
29
|
+
path.replace(regex, function (match, _, offset) {
|
|
30
|
+
if (offset > lastIndex) {
|
|
31
|
+
parts.push(path.slice(lastIndex, offset));
|
|
32
|
+
}
|
|
33
|
+
parts.push(<span key={offset} className="openapi-path-variable">
|
|
34
|
+
{match}
|
|
35
|
+
</span>);
|
|
31
36
|
lastIndex = offset + match.length;
|
|
32
37
|
return match;
|
|
33
38
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
var formattedPath = parts.
|
|
38
|
-
if (typeof part === 'string'
|
|
39
|
-
|
|
40
|
-
/
|
|
41
|
-
</span>);
|
|
39
|
+
if (lastIndex < path.length) {
|
|
40
|
+
parts.push(path.slice(lastIndex));
|
|
41
|
+
}
|
|
42
|
+
var formattedPath = parts.map(function (part, index) {
|
|
43
|
+
if (typeof part === 'string') {
|
|
44
|
+
return <span key={index}>{part}</span>;
|
|
42
45
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return <span>{formattedPath}</span>;
|
|
46
|
+
return part;
|
|
47
|
+
});
|
|
48
|
+
return formattedPath;
|
|
47
49
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Markdown } from './Markdown';
|
|
1
2
|
import { OpenAPITabs, OpenAPITabsList, OpenAPITabsPanels } from './OpenAPITabs';
|
|
2
3
|
import { StaticSection } from './StaticSection';
|
|
3
4
|
import { generateSchemaExample } from './generateSchemaExample';
|
|
@@ -32,35 +33,31 @@ export function OpenAPIResponseExample(props) {
|
|
|
32
33
|
}
|
|
33
34
|
return Number(a) - Number(b);
|
|
34
35
|
});
|
|
35
|
-
var tabs = responses
|
|
36
|
-
.map(function (_a) {
|
|
36
|
+
var tabs = responses.map(function (_a) {
|
|
37
37
|
var key = _a[0], responseObject = _a[1];
|
|
38
38
|
var description = resolveDescription(responseObject);
|
|
39
39
|
if (checkIsReference(responseObject)) {
|
|
40
40
|
return {
|
|
41
41
|
key: key,
|
|
42
42
|
label: key,
|
|
43
|
-
description: description,
|
|
44
43
|
body: (<OpenAPIExample example={getExampleFromReference(responseObject)} context={context} syntax="json"/>),
|
|
44
|
+
footer: description ? <Markdown source={description}/> : undefined,
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
if (!responseObject.content || Object.keys(responseObject.content).length === 0) {
|
|
48
48
|
return {
|
|
49
49
|
key: key,
|
|
50
50
|
label: key,
|
|
51
|
-
description: description,
|
|
52
51
|
body: <OpenAPIEmptyResponseExample />,
|
|
52
|
+
footer: description ? <Markdown source={description}/> : undefined,
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
return {
|
|
56
56
|
key: key,
|
|
57
57
|
label: key,
|
|
58
|
-
description: resolveDescription(responseObject),
|
|
59
58
|
body: <OpenAPIResponse context={context} content={responseObject.content}/>,
|
|
59
|
+
footer: description ? <Markdown source={description}/> : undefined,
|
|
60
60
|
};
|
|
61
|
-
})
|
|
62
|
-
.filter(function (val) {
|
|
63
|
-
return Boolean(val);
|
|
64
61
|
});
|
|
65
62
|
if (tabs.length === 0) {
|
|
66
63
|
return null;
|
|
@@ -13,6 +13,7 @@ export function OpenAPISchemaName(props) {
|
|
|
13
13
|
{type ? <span className="openapi-schema-type">{type}</span> : null}
|
|
14
14
|
{additionalItems ? (<span className="openapi-schema-type">{additionalItems}</span>) : null}
|
|
15
15
|
</span>
|
|
16
|
+
{(schema === null || schema === void 0 ? void 0 : schema.readOnly) ? <span className="openapi-schema-readonly">read-only</span> : null}
|
|
16
17
|
{required ? <span className="openapi-schema-required">required</span> : null}
|
|
17
18
|
{(schema === null || schema === void 0 ? void 0 : schema.deprecated) ? <span className="openapi-deprecated">Deprecated</span> : null}
|
|
18
19
|
</div>);
|
package/dist/OpenAPITabs.d.ts
CHANGED
package/dist/OpenAPITabs.jsx
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { createContext, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { Tab, TabList, TabPanel, Tabs } from 'react-aria-components';
|
|
4
4
|
import { useEventCallback } from 'usehooks-ts';
|
|
5
|
-
import { Markdown } from './Markdown';
|
|
6
5
|
import { getOrCreateTabStoreByKey } from './useSyncedTabsGlobalState';
|
|
7
6
|
var OpenAPITabsContext = createContext(null);
|
|
8
7
|
function useOpenAPITabsContext() {
|
|
@@ -105,6 +104,14 @@ export function OpenAPITabsPanels() {
|
|
|
105
104
|
var key = selectedTab.key.toString();
|
|
106
105
|
return (<TabPanel key={key} id={key} className="openapi-tabs-panel">
|
|
107
106
|
{selectedTab.body}
|
|
108
|
-
{selectedTab.
|
|
107
|
+
{selectedTab.footer ? (<OpenAPITabsPanelFooter>{selectedTab.footer}</OpenAPITabsPanelFooter>) : null}
|
|
109
108
|
</TabPanel>);
|
|
110
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* The OpenAPI Tabs panel footer component.
|
|
112
|
+
* This component should be used as a child of the OpenAPITabs component.
|
|
113
|
+
*/
|
|
114
|
+
function OpenAPITabsPanelFooter(props) {
|
|
115
|
+
var children = props.children;
|
|
116
|
+
return <div className="openapi-tabs-footer">{children}</div>;
|
|
117
|
+
}
|
package/dist/ScalarApiButton.jsx
CHANGED
|
@@ -16,10 +16,10 @@ export function ScalarApiButton(props) {
|
|
|
16
16
|
(_b = (_a = controllerRef.current) === null || _a === void 0 ? void 0 : _a.openClient) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
17
17
|
setIsOpen(true);
|
|
18
18
|
}}>
|
|
19
|
-
|
|
19
|
+
Test it
|
|
20
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 12" fill="currentColor">
|
|
20
21
|
<path stroke="currentColor" strokeWidth="1.5" d="M1 10.05V1.43c0-.2.2-.31.37-.22l7.26 4.08c.17.1.17.33.01.43l-7.26 4.54a.25.25 0 0 1-.38-.21Z"/>
|
|
21
22
|
</svg>
|
|
22
|
-
Test it
|
|
23
23
|
</button>
|
|
24
24
|
|
|
25
25
|
{isOpen &&
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { OpenAPIContextProps, OpenAPISchemasData } from '../types';
|
|
2
|
+
type OpenAPISchemasContextProps = Omit<OpenAPIContextProps, 'renderCodeBlock' | 'renderHeading' | 'renderDocument'>;
|
|
2
3
|
/**
|
|
3
4
|
* Display OpenAPI Schemas.
|
|
4
5
|
*/
|
|
5
6
|
export declare function OpenAPISchemas(props: {
|
|
6
7
|
className?: string;
|
|
7
8
|
data: OpenAPISchemasData;
|
|
8
|
-
context:
|
|
9
|
+
context: OpenAPISchemasContextProps;
|
|
9
10
|
}): import("react").JSX.Element | null;
|
|
11
|
+
export {};
|