@gitbook/react-openapi 1.3.6 → 1.4.0
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 +16 -0
- package/dist/InteractiveSection.jsx +1 -1
- package/dist/OpenAPICodeSample.jsx +8 -5
- package/dist/OpenAPIPrefillContextProvider.d.ts +22 -0
- package/dist/OpenAPIPrefillContextProvider.jsx +19 -0
- package/dist/OpenAPIResponseExample.jsx +4 -1
- package/dist/OpenAPIResponses.jsx +11 -0
- package/dist/OpenAPISpec.jsx +11 -8
- package/dist/ScalarApiButton.d.ts +3 -0
- package/dist/ScalarApiButton.jsx +31 -6
- package/dist/code-samples.js +18 -3
- package/dist/contentTypeChecks.d.ts +1 -0
- package/dist/contentTypeChecks.js +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types.d.ts +12 -3
- package/dist/util/tryit-prefill.d.ts +20 -0
- package/dist/util/tryit-prefill.js +128 -0
- package/package.json +6 -2
- package/src/InteractiveSection.tsx +1 -1
- package/src/OpenAPICodeSample.tsx +8 -2
- package/src/OpenAPIPrefillContextProvider.tsx +40 -0
- package/src/OpenAPIResponseExample.tsx +7 -1
- package/src/OpenAPIResponses.tsx +14 -0
- package/src/OpenAPISpec.tsx +11 -8
- package/src/ScalarApiButton.tsx +39 -11
- package/src/code-samples.test.ts +2 -2
- package/src/code-samples.ts +14 -2
- package/src/contentTypeChecks.ts +4 -0
- package/src/index.ts +1 -0
- package/src/types.ts +16 -2
- package/src/util/tryit-prefill.test.ts +311 -0
- package/src/util/tryit-prefill.ts +156 -0
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import type { PrefillInputContextData } from '../OpenAPIPrefillContextProvider';
|
|
3
|
+
import type { OpenAPIOperationData } from '../types';
|
|
4
|
+
import { resolveTryItPrefillForOperation } from './tryit-prefill';
|
|
5
|
+
|
|
6
|
+
describe('resolveTryItPrefillForOperation', () => {
|
|
7
|
+
describe('prefill authentication info', () => {
|
|
8
|
+
it('should resolve prefill for bearer token scheme', () => {
|
|
9
|
+
const operation: OpenAPIOperationData = {
|
|
10
|
+
path: '/orgs/<orgId>/spaces/<spaceId>',
|
|
11
|
+
method: 'GET',
|
|
12
|
+
operation: { summary: 'Get space by ID' },
|
|
13
|
+
servers: [{ url: 'https://api.gitbook.com/v1/' }],
|
|
14
|
+
securities: [
|
|
15
|
+
[
|
|
16
|
+
'apiTokenScheme',
|
|
17
|
+
{
|
|
18
|
+
type: 'http',
|
|
19
|
+
scheme: 'bearer',
|
|
20
|
+
'x-gitbook-prefill': '{{ visitor.claims.apiToken }}',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const prefillInputContext: PrefillInputContextData = {
|
|
27
|
+
visitor: { claims: { apiToken: 'gb_api_testToken' } },
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const result = resolveTryItPrefillForOperation({
|
|
31
|
+
operation,
|
|
32
|
+
prefillInputContext,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
expect(result).toEqual({
|
|
36
|
+
authentication: {
|
|
37
|
+
securitySchemes: {
|
|
38
|
+
apiTokenScheme: { token: 'gb_api_testToken' },
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should resolve prefill for basic auth scheme', () => {
|
|
45
|
+
const operation: OpenAPIOperationData = {
|
|
46
|
+
path: '/orgs/<orgId>/spaces',
|
|
47
|
+
method: 'PUT',
|
|
48
|
+
operation: { summary: 'Create space in an org' },
|
|
49
|
+
servers: [{ url: 'https://api.gitbook.com/v1/' }],
|
|
50
|
+
securities: [
|
|
51
|
+
[
|
|
52
|
+
'basicAuthScheme',
|
|
53
|
+
{
|
|
54
|
+
type: 'http',
|
|
55
|
+
scheme: 'basic',
|
|
56
|
+
'x-gitbook-prefill': '{{ visitor.claims.basicAuth }}',
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
],
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const prefillInputContext: PrefillInputContextData = {
|
|
63
|
+
visitor: { claims: { basicAuth: 'testuser:testpassword' } },
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const result = resolveTryItPrefillForOperation({
|
|
67
|
+
operation,
|
|
68
|
+
prefillInputContext,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
expect(result).toEqual({
|
|
72
|
+
authentication: {
|
|
73
|
+
securitySchemes: {
|
|
74
|
+
basicAuthScheme: { username: 'testuser', password: 'testpassword' },
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should resolve prefill for apiKey scheme', () => {
|
|
81
|
+
const operation: OpenAPIOperationData = {
|
|
82
|
+
path: '/orgs/<orgId>/spaces/<spaceId>',
|
|
83
|
+
method: 'POST',
|
|
84
|
+
operation: { summary: 'Update space by ID' },
|
|
85
|
+
servers: [{ url: 'https://api.gitbook.com/v1/' }],
|
|
86
|
+
securities: [
|
|
87
|
+
[
|
|
88
|
+
'apiKeyHeader',
|
|
89
|
+
{
|
|
90
|
+
type: 'apiKey',
|
|
91
|
+
in: 'header',
|
|
92
|
+
name: 'X-API-KEY',
|
|
93
|
+
'x-gitbook-prefill': '{{ visitor.claims.apiKey }}',
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
],
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const prefillInputContext: PrefillInputContextData = {
|
|
100
|
+
visitor: { claims: { apiKey: 'key-123' } },
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const result = resolveTryItPrefillForOperation({
|
|
104
|
+
operation,
|
|
105
|
+
prefillInputContext,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
expect(result).toEqual({
|
|
109
|
+
authentication: {
|
|
110
|
+
securitySchemes: {
|
|
111
|
+
apiKeyHeader: { name: 'X-API-KEY', in: 'header', value: 'key-123' },
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('should return empty object if no visitor data matches prefill expression', () => {
|
|
118
|
+
const operation: OpenAPIOperationData = {
|
|
119
|
+
path: '/orgs/<orgId>/spaces',
|
|
120
|
+
method: 'GET',
|
|
121
|
+
operation: { summary: 'List all spaces in an org' },
|
|
122
|
+
servers: [{ url: 'https://api.gitbook.com/v1/' }],
|
|
123
|
+
securities: [
|
|
124
|
+
[
|
|
125
|
+
'bearer',
|
|
126
|
+
{
|
|
127
|
+
type: 'http',
|
|
128
|
+
scheme: 'bearer',
|
|
129
|
+
'x-gitbook-prefill': '{{ visitor.claims.missing }}',
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
],
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const prefillInputContext: PrefillInputContextData = {
|
|
136
|
+
visitor: { claims: {} },
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const result = resolveTryItPrefillForOperation({
|
|
140
|
+
operation,
|
|
141
|
+
prefillInputContext,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
expect(result).toEqual({});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe('prefill server info', () => {
|
|
149
|
+
it('should prefill server at url level', () => {
|
|
150
|
+
const operation: OpenAPIOperationData = {
|
|
151
|
+
path: '/orgs/<orgId>/spaces',
|
|
152
|
+
method: 'GET',
|
|
153
|
+
operation: { summary: 'List spaces in an org' },
|
|
154
|
+
servers: [
|
|
155
|
+
{
|
|
156
|
+
url: 'https://api.gitbook.com/v1/',
|
|
157
|
+
description: 'GitBook API endpoint',
|
|
158
|
+
'x-gitbook-prefill': '{{ visitor.claims.api.endpointUrl }}',
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
securities: [],
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const prefillInputContext: PrefillInputContextData = {
|
|
165
|
+
visitor: {
|
|
166
|
+
claims: { api: { endpointUrl: 'https://api.gitbook-staging.com/v1/' } },
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const result = resolveTryItPrefillForOperation({
|
|
171
|
+
operation,
|
|
172
|
+
prefillInputContext,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
expect(result).toEqual({
|
|
176
|
+
servers: [
|
|
177
|
+
{
|
|
178
|
+
url: 'https://api.gitbook-staging.com/v1/',
|
|
179
|
+
description: 'GitBook API endpoint',
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('should prefill server at variables level', () => {
|
|
186
|
+
const operation: OpenAPIOperationData = {
|
|
187
|
+
path: '/orgs/<orgId>/spaces',
|
|
188
|
+
method: 'GET',
|
|
189
|
+
operation: { summary: 'List spaces in an org' },
|
|
190
|
+
servers: [
|
|
191
|
+
{
|
|
192
|
+
url: 'https://api.{domain}/{version}/',
|
|
193
|
+
description: 'Versioned API endpoint by environment',
|
|
194
|
+
variables: {
|
|
195
|
+
domain: {
|
|
196
|
+
default: 'gitbook.com',
|
|
197
|
+
'x-gitbook-prefill':
|
|
198
|
+
'{{ visitor.claims.api.env === "staging" ? "gitbook-staging.com" : "gitbook.com" }}',
|
|
199
|
+
},
|
|
200
|
+
version: {
|
|
201
|
+
default: 'v1',
|
|
202
|
+
'x-gitbook-prefill': '{{ visitor.claims.api.version }}',
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
securities: [],
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
// Override env
|
|
211
|
+
const overrideEnvResult = resolveTryItPrefillForOperation({
|
|
212
|
+
operation,
|
|
213
|
+
prefillInputContext: { visitor: { claims: { api: { env: 'staging' } } } },
|
|
214
|
+
});
|
|
215
|
+
expect(overrideEnvResult).toEqual({
|
|
216
|
+
servers: [
|
|
217
|
+
{
|
|
218
|
+
url: 'https://api.{domain}/{version}/',
|
|
219
|
+
description: 'Versioned API endpoint by environment',
|
|
220
|
+
variables: {
|
|
221
|
+
domain: { default: 'gitbook-staging.com' },
|
|
222
|
+
version: { default: 'v1' },
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
],
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// Override version
|
|
229
|
+
const overrideVersionResult = resolveTryItPrefillForOperation({
|
|
230
|
+
operation,
|
|
231
|
+
prefillInputContext: { visitor: { claims: { api: { version: 'v2' } } } },
|
|
232
|
+
});
|
|
233
|
+
expect(overrideVersionResult).toEqual({
|
|
234
|
+
servers: [
|
|
235
|
+
{
|
|
236
|
+
url: 'https://api.{domain}/{version}/',
|
|
237
|
+
description: 'Versioned API endpoint by environment',
|
|
238
|
+
variables: {
|
|
239
|
+
domain: { default: 'gitbook.com' },
|
|
240
|
+
version: { default: 'v2' },
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
],
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// Override both
|
|
247
|
+
const overrideBoth = resolveTryItPrefillForOperation({
|
|
248
|
+
operation,
|
|
249
|
+
prefillInputContext: {
|
|
250
|
+
visitor: { claims: { api: { env: 'staging', version: 'v2' } } },
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
expect(overrideBoth).toEqual({
|
|
254
|
+
servers: [
|
|
255
|
+
{
|
|
256
|
+
url: 'https://api.{domain}/{version}/',
|
|
257
|
+
description: 'Versioned API endpoint by environment',
|
|
258
|
+
variables: {
|
|
259
|
+
domain: { default: 'gitbook-staging.com' },
|
|
260
|
+
version: { default: 'v2' },
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
],
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it('should ignore server prefill when no matching visitor data', () => {
|
|
268
|
+
const operation: OpenAPIOperationData = {
|
|
269
|
+
path: '/orgs/<orgId>/spaces',
|
|
270
|
+
method: 'GET',
|
|
271
|
+
operation: { summary: 'List spaces in an org' },
|
|
272
|
+
servers: [
|
|
273
|
+
{
|
|
274
|
+
url: 'https://api.{domain}/{version}/',
|
|
275
|
+
description: 'Versioned API endpoint by environment',
|
|
276
|
+
variables: {
|
|
277
|
+
domain: {
|
|
278
|
+
default: 'gitbook.com',
|
|
279
|
+
'x-gitbook-prefill':
|
|
280
|
+
'{{ visitor.claims.api.env === "staging" ? "gitbook-staging.com" : "gitbook.com" }}',
|
|
281
|
+
},
|
|
282
|
+
version: {
|
|
283
|
+
default: 'v1',
|
|
284
|
+
'x-gitbook-prefill': '{{ visitor.claims.api.version }}',
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
],
|
|
289
|
+
securities: [],
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
const result = resolveTryItPrefillForOperation({
|
|
293
|
+
operation,
|
|
294
|
+
prefillInputContext: { visitor: { claims: { isBetaUser: true } } },
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
expect(result).toEqual({
|
|
298
|
+
servers: [
|
|
299
|
+
{
|
|
300
|
+
url: 'https://api.{domain}/{version}/',
|
|
301
|
+
description: 'Versioned API endpoint by environment',
|
|
302
|
+
variables: {
|
|
303
|
+
domain: { default: 'gitbook.com' },
|
|
304
|
+
version: { default: 'v1' },
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
],
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
});
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { ExpressionRuntime, parseTemplate } from '@gitbook/expr';
|
|
2
|
+
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
|
3
|
+
import type { ApiClientConfiguration } from '@scalar/types';
|
|
4
|
+
import type { PrefillInputContextData } from '../OpenAPIPrefillContextProvider';
|
|
5
|
+
import type { OpenAPIOperationData } from '../types';
|
|
6
|
+
|
|
7
|
+
export interface TryItPrefillConfiguration {
|
|
8
|
+
authentication?: ApiClientConfiguration['authentication'];
|
|
9
|
+
servers?: ApiClientConfiguration['servers'];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Resolve the Scalar API client prefill configuration for a given OpenAPI operation.
|
|
14
|
+
*/
|
|
15
|
+
export function resolveTryItPrefillForOperation(args: {
|
|
16
|
+
/**
|
|
17
|
+
* The parsed OpenAPI operation.
|
|
18
|
+
*/
|
|
19
|
+
operation: Pick<OpenAPIOperationData, 'securities' | 'servers'>;
|
|
20
|
+
/**
|
|
21
|
+
* Prefill input context data.
|
|
22
|
+
*/
|
|
23
|
+
prefillInputContext: PrefillInputContextData | null;
|
|
24
|
+
}): TryItPrefillConfiguration {
|
|
25
|
+
const {
|
|
26
|
+
operation: { securities, servers },
|
|
27
|
+
prefillInputContext,
|
|
28
|
+
} = args;
|
|
29
|
+
|
|
30
|
+
// Fixed ExpressionRuntime and resolveTryItPrefillExpression function
|
|
31
|
+
const runtime = new ExpressionRuntime();
|
|
32
|
+
const resolveTryItPrefillExpression = (expr: string) => {
|
|
33
|
+
if (!prefillInputContext) return undefined;
|
|
34
|
+
const parts = parseTemplate(expr);
|
|
35
|
+
if (!parts.length) return undefined;
|
|
36
|
+
return runtime.evaluateTemplate(expr, prefillInputContext);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const prefillAuth = securities
|
|
40
|
+
? resolveTryItPrefillAuthForOperationSecurities({
|
|
41
|
+
securities,
|
|
42
|
+
resolveTryItPrefillExpression,
|
|
43
|
+
})
|
|
44
|
+
: undefined;
|
|
45
|
+
|
|
46
|
+
const prefillServers = servers
|
|
47
|
+
? resolveTryItPrefillServersForOperationServers({ servers, resolveTryItPrefillExpression })
|
|
48
|
+
: [];
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
...(prefillAuth ? { authentication: prefillAuth } : {}),
|
|
52
|
+
...(prefillServers ? { servers: prefillServers } : {}),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Resolve prefill authentication configuration for the security schemes defined for an operation.
|
|
58
|
+
*/
|
|
59
|
+
function resolveTryItPrefillAuthForOperationSecurities(args: {
|
|
60
|
+
securities: OpenAPIOperationData['securities'];
|
|
61
|
+
resolveTryItPrefillExpression: (expr: string) => string | undefined;
|
|
62
|
+
}): ApiClientConfiguration['authentication'] | undefined {
|
|
63
|
+
const { securities, resolveTryItPrefillExpression } = args;
|
|
64
|
+
const prefillAuthConfig: ApiClientConfiguration['authentication']['securitySchemes'] = {};
|
|
65
|
+
|
|
66
|
+
for (const [schemeName, security] of Object.values(securities)) {
|
|
67
|
+
const tryitPrefillAuthValue = security['x-gitbook-prefill']
|
|
68
|
+
? resolveTryItPrefillExpression(security['x-gitbook-prefill'])
|
|
69
|
+
: undefined;
|
|
70
|
+
|
|
71
|
+
if (!tryitPrefillAuthValue) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
switch (security.type) {
|
|
76
|
+
case 'http': {
|
|
77
|
+
if (security.scheme?.includes('bearer')) {
|
|
78
|
+
prefillAuthConfig[schemeName] = { token: tryitPrefillAuthValue };
|
|
79
|
+
} else if (
|
|
80
|
+
security.scheme?.includes('basic') &&
|
|
81
|
+
tryitPrefillAuthValue.includes(':')
|
|
82
|
+
) {
|
|
83
|
+
const [username, password] = tryitPrefillAuthValue.split(':', 2);
|
|
84
|
+
prefillAuthConfig[schemeName] = { username, password };
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case 'apiKey': {
|
|
89
|
+
prefillAuthConfig[schemeName] = {
|
|
90
|
+
name: security.name,
|
|
91
|
+
in: security.in,
|
|
92
|
+
value: tryitPrefillAuthValue,
|
|
93
|
+
};
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
case 'oauth2':
|
|
97
|
+
case 'openIdConnect': {
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return Object.keys(prefillAuthConfig).length > 0
|
|
104
|
+
? { securitySchemes: prefillAuthConfig }
|
|
105
|
+
: undefined;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Resolve prefill server configuration for the servers defined for an operation.
|
|
110
|
+
*/
|
|
111
|
+
function resolveTryItPrefillServersForOperationServers(args: {
|
|
112
|
+
servers: OpenAPIOperationData['servers'];
|
|
113
|
+
resolveTryItPrefillExpression: (expr: string) => string | undefined;
|
|
114
|
+
}): ApiClientConfiguration['servers'] | undefined {
|
|
115
|
+
const { servers, resolveTryItPrefillExpression } = args;
|
|
116
|
+
const resolvedServers: ApiClientConfiguration['servers'] = [];
|
|
117
|
+
|
|
118
|
+
for (const server of servers) {
|
|
119
|
+
// Url-level prefill
|
|
120
|
+
const tryItPrefillServerUrlExpr = server['x-gitbook-prefill'];
|
|
121
|
+
const tryItPrefillServerUrlValue = tryItPrefillServerUrlExpr
|
|
122
|
+
? resolveTryItPrefillExpression(tryItPrefillServerUrlExpr)
|
|
123
|
+
: undefined;
|
|
124
|
+
|
|
125
|
+
const variables: { [variable: string]: OpenAPIV3.ServerVariableObject } = server.variables
|
|
126
|
+
? { ...server.variables }
|
|
127
|
+
: {};
|
|
128
|
+
|
|
129
|
+
// Variable-level prefill
|
|
130
|
+
if (server.variables) {
|
|
131
|
+
for (const [varName, variable] of Object.entries(server.variables)) {
|
|
132
|
+
const { 'x-gitbook-prefill': tryItPrefillVarExpr, ...variableProps } = variable;
|
|
133
|
+
|
|
134
|
+
const tryItPrefillVarValue = tryItPrefillVarExpr
|
|
135
|
+
? resolveTryItPrefillExpression(tryItPrefillVarExpr)
|
|
136
|
+
: undefined;
|
|
137
|
+
variables[varName] = {
|
|
138
|
+
...variableProps,
|
|
139
|
+
...(tryItPrefillVarValue ? { default: String(tryItPrefillVarValue) } : {}),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const hasServerVariables = Object.keys(variables).length > 0;
|
|
145
|
+
if (server.url && (tryItPrefillServerUrlValue || hasServerVariables)) {
|
|
146
|
+
const resolvedServer: OpenAPIV3.ServerObject = {
|
|
147
|
+
url: tryItPrefillServerUrlValue ?? server.url,
|
|
148
|
+
...(server.description ? { description: server.description } : {}),
|
|
149
|
+
...(hasServerVariables ? { variables } : {}),
|
|
150
|
+
};
|
|
151
|
+
resolvedServers.push(resolvedServer);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return resolvedServers.length > 0 ? resolvedServers : undefined;
|
|
156
|
+
}
|