@scalar/oas-utils 0.10.8 → 0.10.10
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 +8 -0
- package/dist/entities/cookie/cookie.js +11 -15
- package/dist/entities/cookie/index.js +1 -5
- package/dist/entities/environment/environment.js +7 -11
- package/dist/entities/environment/index.js +1 -5
- package/dist/entities/hotkeys/hotkeys.js +116 -111
- package/dist/entities/hotkeys/index.js +1 -6
- package/dist/entities/shared/index.js +1 -7
- package/dist/entities/shared/utility.js +9 -9
- package/dist/entities/spec/collection.js +91 -89
- package/dist/entities/spec/index.js +10 -59
- package/dist/entities/spec/operation.js +6 -6
- package/dist/entities/spec/parameters.js +38 -38
- package/dist/entities/spec/request-examples.js +421 -331
- package/dist/entities/spec/requests.js +102 -84
- package/dist/entities/spec/server.js +61 -46
- package/dist/entities/spec/spec-objects.js +121 -76
- package/dist/entities/spec/x-scalar-environments.js +18 -20
- package/dist/entities/spec/x-scalar-secrets.js +6 -8
- package/dist/entities/workspace/index.js +1 -7
- package/dist/entities/workspace/workspace.js +47 -46
- package/dist/helpers/client-plugins.js +13 -13
- package/dist/helpers/fetch-document.js +30 -25
- package/dist/helpers/fetch-with-proxy-fallback.js +26 -21
- package/dist/helpers/index.d.ts +1 -2
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +80 -119
- package/dist/helpers/normalize-mime-type-object.js +19 -18
- package/dist/helpers/normalize-mime-type.js +11 -9
- package/dist/helpers/operation-stability.js +25 -20
- package/dist/helpers/parse.d.ts +0 -4
- package/dist/helpers/parse.d.ts.map +1 -1
- package/dist/helpers/parse.js +77 -77
- package/dist/helpers/schema-model.js +13 -16
- package/dist/helpers/security/get-schemes.js +7 -8
- package/dist/helpers/security/has-token.js +18 -19
- package/dist/helpers/security/index.js +2 -7
- package/dist/helpers/servers.js +128 -79
- package/dist/helpers/should-ignore-entity.js +4 -5
- package/dist/migrations/data-version.js +15 -7
- package/dist/migrations/generate-types.js +34 -37
- package/dist/migrations/index.js +4 -18
- package/dist/migrations/local-storage.js +31 -29
- package/dist/migrations/migrate-to-indexdb.js +706 -529
- package/dist/migrations/migrator.js +58 -54
- package/dist/migrations/semver.js +24 -24
- package/dist/migrations/v-0.0.0/types.generated.js +1 -1
- package/dist/migrations/v-2.1.0/migration.js +272 -258
- package/dist/migrations/v-2.1.0/types.generated.js +1 -1
- package/dist/migrations/v-2.2.0/migration.js +99 -96
- package/dist/migrations/v-2.2.0/types.generated.js +1 -1
- package/dist/migrations/v-2.3.0/migration.js +45 -48
- package/dist/migrations/v-2.3.0/types.generated.js +1 -1
- package/dist/migrations/v-2.4.0/migration.js +25 -25
- package/dist/migrations/v-2.4.0/types.generated.js +1 -1
- package/dist/migrations/v-2.5.0/migration.js +122 -139
- package/dist/migrations/v-2.5.0/types.generated.js +1 -1
- package/dist/spec-getters/get-example-from-schema.js +489 -385
- package/dist/spec-getters/get-parameters-from-operation.js +39 -23
- package/dist/spec-getters/get-request-body-from-operation.d.ts.map +1 -1
- package/dist/spec-getters/get-request-body-from-operation.js +168 -126
- package/dist/spec-getters/get-server-variable-examples.js +10 -13
- package/dist/spec-getters/index.js +4 -11
- package/dist/transforms/import-spec.js +381 -291
- package/dist/transforms/index.js +1 -11
- package/package.json +15 -19
- package/dist/entities/cookie/cookie.js.map +0 -7
- package/dist/entities/cookie/index.js.map +0 -7
- package/dist/entities/environment/environment.js.map +0 -7
- package/dist/entities/environment/index.js.map +0 -7
- package/dist/entities/hotkeys/hotkeys.js.map +0 -7
- package/dist/entities/hotkeys/index.js.map +0 -7
- package/dist/entities/shared/index.js.map +0 -7
- package/dist/entities/shared/utility.js.map +0 -7
- package/dist/entities/spec/collection.js.map +0 -7
- package/dist/entities/spec/index.js.map +0 -7
- package/dist/entities/spec/operation.js.map +0 -7
- package/dist/entities/spec/parameters.js.map +0 -7
- package/dist/entities/spec/request-examples.js.map +0 -7
- package/dist/entities/spec/requests.js.map +0 -7
- package/dist/entities/spec/server.js.map +0 -7
- package/dist/entities/spec/spec-objects.js.map +0 -7
- package/dist/entities/spec/x-scalar-environments.js.map +0 -7
- package/dist/entities/spec/x-scalar-secrets.js.map +0 -7
- package/dist/entities/workspace/index.js.map +0 -7
- package/dist/entities/workspace/workspace.js.map +0 -7
- package/dist/helpers/client-plugins.js.map +0 -7
- package/dist/helpers/fetch-document.js.map +0 -7
- package/dist/helpers/fetch-with-proxy-fallback.js.map +0 -7
- package/dist/helpers/index.js.map +0 -7
- package/dist/helpers/normalize-mime-type-object.js.map +0 -7
- package/dist/helpers/normalize-mime-type.js.map +0 -7
- package/dist/helpers/operation-stability.js.map +0 -7
- package/dist/helpers/parse.js.map +0 -7
- package/dist/helpers/pretty-print-json.d.ts +0 -9
- package/dist/helpers/pretty-print-json.d.ts.map +0 -1
- package/dist/helpers/pretty-print-json.js +0 -38
- package/dist/helpers/pretty-print-json.js.map +0 -7
- package/dist/helpers/schema-model.js.map +0 -7
- package/dist/helpers/security/get-schemes.js.map +0 -7
- package/dist/helpers/security/has-token.js.map +0 -7
- package/dist/helpers/security/index.js.map +0 -7
- package/dist/helpers/servers.js.map +0 -7
- package/dist/helpers/should-ignore-entity.js.map +0 -7
- package/dist/migrations/data-version.js.map +0 -7
- package/dist/migrations/generate-types.js.map +0 -7
- package/dist/migrations/index.js.map +0 -7
- package/dist/migrations/local-storage.js.map +0 -7
- package/dist/migrations/migrate-to-indexdb.js.map +0 -7
- package/dist/migrations/migrator.js.map +0 -7
- package/dist/migrations/semver.js.map +0 -7
- package/dist/migrations/v-0.0.0/types.generated.js.map +0 -7
- package/dist/migrations/v-2.1.0/migration.js.map +0 -7
- package/dist/migrations/v-2.1.0/types.generated.js.map +0 -7
- package/dist/migrations/v-2.2.0/migration.js.map +0 -7
- package/dist/migrations/v-2.2.0/types.generated.js.map +0 -7
- package/dist/migrations/v-2.3.0/migration.js.map +0 -7
- package/dist/migrations/v-2.3.0/types.generated.js.map +0 -7
- package/dist/migrations/v-2.4.0/migration.js.map +0 -7
- package/dist/migrations/v-2.4.0/types.generated.js.map +0 -7
- package/dist/migrations/v-2.5.0/migration.js.map +0 -7
- package/dist/migrations/v-2.5.0/types.generated.js.map +0 -7
- package/dist/spec-getters/get-example-from-schema.js.map +0 -7
- package/dist/spec-getters/get-parameters-from-operation.js.map +0 -7
- package/dist/spec-getters/get-request-body-from-operation.js.map +0 -7
- package/dist/spec-getters/get-server-variable-examples.js.map +0 -7
- package/dist/spec-getters/index.js.map +0 -7
- package/dist/transforms/import-spec.js.map +0 -7
- package/dist/transforms/index.js.map +0 -7
|
@@ -1,24 +1,40 @@
|
|
|
1
|
-
import { getExampleFromSchema } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import { getExampleFromSchema } from './get-example-from-schema.js';
|
|
2
|
+
/**
|
|
3
|
+
* Get the query parameters from an operation.
|
|
4
|
+
*
|
|
5
|
+
* Example: [ { name: 'foobar', value: '' } ]
|
|
6
|
+
*
|
|
7
|
+
* - OpenAPI 3.x: Possible values are "query", "header", "path" or "cookie".
|
|
8
|
+
*/
|
|
9
|
+
export function getParametersFromOperation(operationParameters = [], pathParameters = [], where, requiredOnly = true) {
|
|
10
|
+
const parameters = [...(pathParameters || []), ...(operationParameters || [])];
|
|
11
|
+
const params = parameters
|
|
12
|
+
// query, path, header, cookie?
|
|
13
|
+
.filter((parameter) => parameter.in === where)
|
|
14
|
+
// don't add optional parameters
|
|
15
|
+
.filter((parameter) => (requiredOnly && parameter.required) || !requiredOnly)
|
|
16
|
+
// transform them
|
|
17
|
+
.map((parameter) => ({
|
|
18
|
+
name: parameter.name ?? 'Unknown Parameter',
|
|
19
|
+
description: parameter.description ?? null,
|
|
20
|
+
value: parameter.example
|
|
21
|
+
? parameter.example
|
|
22
|
+
: parameter.schema
|
|
23
|
+
? getExampleFromSchema(parameter.schema, { mode: 'write' })
|
|
24
|
+
: '',
|
|
25
|
+
required: parameter.required ?? false,
|
|
26
|
+
enabled: parameter.required ?? false,
|
|
27
|
+
}));
|
|
28
|
+
return params.sort((a, b) => {
|
|
29
|
+
// Move a up if a is required and b is not
|
|
30
|
+
if (a.required && !b.required) {
|
|
31
|
+
return -1;
|
|
32
|
+
}
|
|
33
|
+
// Move b up if b is required and a is not
|
|
34
|
+
if (!a.required && b.required) {
|
|
35
|
+
return 1;
|
|
36
|
+
}
|
|
37
|
+
// Keep original order if both have the same required status
|
|
38
|
+
return 0;
|
|
39
|
+
});
|
|
20
40
|
}
|
|
21
|
-
export {
|
|
22
|
-
getParametersFromOperation
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=get-parameters-from-operation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-request-body-from-operation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/get-request-body-from-operation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-request-body-from-operation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/get-request-body-from-operation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAGvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AA6ChD;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,aAAa,GAAG,YAAY,CAAC,EACxD,kBAAkB,CAAC,EAAE,MAAM,GAAG,MAAM,EACpC,8BAA8B,CAAC,EAAE,OAAO,GACvC;IACD,QAAQ,EAAE,WAAW,CAAA;IACrB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KACtB,EAAE,CAAA;CACJ,GAAG,IAAI,CA2KP"}
|
|
@@ -1,134 +1,176 @@
|
|
|
1
|
-
import { json2xml } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { getExampleFromSchema } from
|
|
6
|
-
import { getParametersFromOperation } from
|
|
1
|
+
import { json2xml } from '@scalar/helpers/file/json2xml';
|
|
2
|
+
import { prettyPrintJson } from '@scalar/helpers/json/pretty-print-json';
|
|
3
|
+
import { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref';
|
|
4
|
+
import { normalizeMimeTypeObject } from '../helpers/normalize-mime-type-object.js';
|
|
5
|
+
import { getExampleFromSchema } from './get-example-from-schema.js';
|
|
6
|
+
import { getParametersFromOperation } from './get-parameters-from-operation.js';
|
|
7
|
+
/**
|
|
8
|
+
* Transform the object into a nested array of objects
|
|
9
|
+
* that represent the key-value pairs of the object.
|
|
10
|
+
*/
|
|
7
11
|
function getParamsFromObject(obj, nested = false, field) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
return Object.entries(obj).flatMap(([key, value]) => {
|
|
13
|
+
const name = field ?? key;
|
|
14
|
+
if (Array.isArray(value) && !nested) {
|
|
15
|
+
return getParamsFromObject(value, true, key);
|
|
16
|
+
}
|
|
17
|
+
if (typeof value === 'object' && !(value instanceof File) && value !== null) {
|
|
18
|
+
// Nested object inside formData field: no way to represent it, so just serialize to JSON string
|
|
19
|
+
value = JSON.stringify(value);
|
|
20
|
+
}
|
|
21
|
+
return [{ name, value }];
|
|
22
|
+
});
|
|
18
23
|
}
|
|
24
|
+
// Define preferred standard mime types (order indicates preference)
|
|
19
25
|
const standardMimeTypes = [
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
'application/json',
|
|
27
|
+
'application/octet-stream',
|
|
28
|
+
'application/x-www-form-urlencoded',
|
|
29
|
+
'application/xml',
|
|
30
|
+
'multipart/form-data',
|
|
31
|
+
'text/plain',
|
|
26
32
|
];
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Get the request body from the operation.
|
|
35
|
+
*/
|
|
36
|
+
export function getRequestBodyFromOperation(operation, selectedExampleKey, omitEmptyAndOptionalProperties) {
|
|
37
|
+
const originalContent = operation.requestBody?.content;
|
|
38
|
+
const content = normalizeMimeTypeObject(originalContent);
|
|
39
|
+
// First try to find a standard mime type
|
|
40
|
+
const mimeType = standardMimeTypes.find((currentMimeType) => !!content?.[currentMimeType]) ??
|
|
41
|
+
(Object.keys(content ?? {})[0] || 'application/json');
|
|
42
|
+
// Handle JSON-like content types (e.g., application/vnd.github+json)
|
|
43
|
+
const isJsonLike = mimeType.includes('json') || mimeType.endsWith('+json');
|
|
44
|
+
/** Examples */
|
|
45
|
+
const examples = content?.[mimeType]?.examples ?? content?.['application/json']?.examples;
|
|
46
|
+
// Let's use the first example
|
|
47
|
+
const selectedExample = examples?.[selectedExampleKey ?? Object.keys(examples ?? {})[0] ?? ''];
|
|
48
|
+
if (selectedExample) {
|
|
49
|
+
return {
|
|
50
|
+
mimeType,
|
|
51
|
+
text: prettyPrintJson('value' in selectedExample ? selectedExample.value : selectedExample),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Body Parameters (Swagger 2.0)
|
|
56
|
+
*
|
|
57
|
+
* ”The payload that's appended to the HTTP request. Since there can only be one payload, there can only
|
|
58
|
+
* be one body parameter. The name of the body parameter has no effect on the parameter itself and is used
|
|
59
|
+
* for documentation purposes only. Since Form parameters are also in the payload, body and form
|
|
60
|
+
* parameters cannot exist together for the same operation.”
|
|
61
|
+
*/
|
|
62
|
+
const bodyParameters = getParametersFromOperation(operation.parameters ?? [],
|
|
42
63
|
// TODO: Add path parameters
|
|
43
|
-
[],
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
64
|
+
[], // operation.path ?? [],
|
|
65
|
+
'body', false);
|
|
66
|
+
if (bodyParameters.length > 0) {
|
|
67
|
+
return {
|
|
68
|
+
mimeType: 'application/json',
|
|
69
|
+
text: prettyPrintJson(bodyParameters[0]?.value ?? ''),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* FormData Parameters (Swagger 2.0)
|
|
74
|
+
*
|
|
75
|
+
* ”Form - Used to describe the payload of an HTTP request when either application/x-www-form-urlencoded,
|
|
76
|
+
* multipart/form-data or both are used as the content type of the request (in Swagger's definition, the
|
|
77
|
+
* consumes property of an operation). This is the only parameter type that can be used to send files,
|
|
78
|
+
* thus supporting the file type. Since form parameters are sent in the payload, they cannot be declared
|
|
79
|
+
* together with a body parameter for the same operation. Form parameters have a different format based on
|
|
80
|
+
* the content-type used (for further details, consult http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4):
|
|
81
|
+
* - application/x-www-form-urlencoded - Similar to the format of Query parameters but as a payload.
|
|
82
|
+
* For example, foo=1&bar=swagger - both foo and bar are form parameters. This is normally used for simple
|
|
83
|
+
* parameters that are being transferred.
|
|
84
|
+
* - multipart/form-data - each parameter takes a section in the payload with an internal header.
|
|
85
|
+
* For example, for the header Content-Disposition: form-data; name="submit-name" the name of the parameter is
|
|
86
|
+
* submit-name. This type of form parameters is more commonly used for file transfers.”
|
|
87
|
+
*/
|
|
88
|
+
const formDataParameters = getParametersFromOperation(operation.parameters ?? [],
|
|
56
89
|
// TODO: Add path parameters
|
|
57
|
-
[],
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
90
|
+
[], // operation.path ?? [],
|
|
91
|
+
'formData', false);
|
|
92
|
+
if (formDataParameters.length > 0) {
|
|
93
|
+
return {
|
|
94
|
+
mimeType: 'application/x-www-form-urlencoded',
|
|
95
|
+
params: formDataParameters.map((parameter) => ({
|
|
96
|
+
name: parameter.name,
|
|
97
|
+
/**
|
|
98
|
+
* TODO: This value MUST be a string
|
|
99
|
+
* Figure out why this is not always a string
|
|
100
|
+
*
|
|
101
|
+
* JSON.stringify is a TEMPORARY fix
|
|
102
|
+
*/
|
|
103
|
+
value: typeof parameter.value === 'string' ? parameter.value : JSON.stringify(parameter.value),
|
|
104
|
+
})),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
// If no mime type is supported, exit early
|
|
108
|
+
if (!mimeType) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
// Get the request body object for the mime type
|
|
112
|
+
const requestBodyObject = content?.[mimeType];
|
|
113
|
+
// Get example from operation
|
|
114
|
+
const example = requestBodyObject?.example ? requestBodyObject?.example : undefined;
|
|
115
|
+
// Update the JSON handling section
|
|
116
|
+
if (isJsonLike) {
|
|
117
|
+
const exampleFromSchema = requestBodyObject?.schema
|
|
118
|
+
? getExampleFromSchema(getResolvedRef(requestBodyObject?.schema), {
|
|
119
|
+
mode: 'write',
|
|
120
|
+
omitEmptyAndOptionalProperties: omitEmptyAndOptionalProperties ?? false,
|
|
121
|
+
})
|
|
122
|
+
: null;
|
|
123
|
+
const body = example ?? exampleFromSchema;
|
|
124
|
+
return {
|
|
125
|
+
mimeType,
|
|
126
|
+
text: body ? (typeof body === 'string' ? body : JSON.stringify(body, null, 2)) : undefined,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
// XML
|
|
130
|
+
if (mimeType === 'application/xml') {
|
|
131
|
+
const exampleFromSchema = requestBodyObject?.schema
|
|
132
|
+
? getExampleFromSchema(getResolvedRef(requestBodyObject?.schema), {
|
|
133
|
+
xml: true,
|
|
134
|
+
mode: 'write',
|
|
135
|
+
})
|
|
136
|
+
: null;
|
|
137
|
+
return {
|
|
138
|
+
mimeType,
|
|
139
|
+
text: example ?? json2xml(exampleFromSchema),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
// Binary data
|
|
143
|
+
if (mimeType === 'application/octet-stream') {
|
|
144
|
+
return {
|
|
145
|
+
mimeType,
|
|
146
|
+
text: 'BINARY',
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
// Plain text
|
|
150
|
+
if (mimeType === 'text/plain') {
|
|
151
|
+
const exampleFromSchema = requestBodyObject?.schema
|
|
152
|
+
? getExampleFromSchema(getResolvedRef(requestBodyObject?.schema), {
|
|
153
|
+
xml: true,
|
|
154
|
+
mode: 'write',
|
|
155
|
+
})
|
|
156
|
+
: null;
|
|
157
|
+
return {
|
|
158
|
+
mimeType,
|
|
159
|
+
text: example ?? exampleFromSchema ?? '',
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
// URL encoded data
|
|
163
|
+
if (mimeType === 'multipart/form-data' || mimeType === 'application/x-www-form-urlencoded') {
|
|
164
|
+
const exampleFromSchema = requestBodyObject?.schema
|
|
165
|
+
? getExampleFromSchema(getResolvedRef(requestBodyObject?.schema), {
|
|
166
|
+
xml: true,
|
|
167
|
+
mode: 'write',
|
|
168
|
+
})
|
|
169
|
+
: null;
|
|
170
|
+
return {
|
|
171
|
+
mimeType,
|
|
172
|
+
params: getParamsFromObject(example ?? exampleFromSchema ?? {}),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
78
175
|
return null;
|
|
79
|
-
}
|
|
80
|
-
const requestBodyObject = content?.[mimeType];
|
|
81
|
-
const example = requestBodyObject?.example ? requestBodyObject?.example : void 0;
|
|
82
|
-
if (isJsonLike) {
|
|
83
|
-
const exampleFromSchema = requestBodyObject?.schema ? getExampleFromSchema(getResolvedRef(requestBodyObject?.schema), {
|
|
84
|
-
mode: "write",
|
|
85
|
-
omitEmptyAndOptionalProperties: omitEmptyAndOptionalProperties ?? false
|
|
86
|
-
}) : null;
|
|
87
|
-
const body = example ?? exampleFromSchema;
|
|
88
|
-
return {
|
|
89
|
-
mimeType,
|
|
90
|
-
text: body ? typeof body === "string" ? body : JSON.stringify(body, null, 2) : void 0
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
if (mimeType === "application/xml") {
|
|
94
|
-
const exampleFromSchema = requestBodyObject?.schema ? getExampleFromSchema(getResolvedRef(requestBodyObject?.schema), {
|
|
95
|
-
xml: true,
|
|
96
|
-
mode: "write"
|
|
97
|
-
}) : null;
|
|
98
|
-
return {
|
|
99
|
-
mimeType,
|
|
100
|
-
text: example ?? json2xml(exampleFromSchema)
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
if (mimeType === "application/octet-stream") {
|
|
104
|
-
return {
|
|
105
|
-
mimeType,
|
|
106
|
-
text: "BINARY"
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
if (mimeType === "text/plain") {
|
|
110
|
-
const exampleFromSchema = requestBodyObject?.schema ? getExampleFromSchema(getResolvedRef(requestBodyObject?.schema), {
|
|
111
|
-
xml: true,
|
|
112
|
-
mode: "write"
|
|
113
|
-
}) : null;
|
|
114
|
-
return {
|
|
115
|
-
mimeType,
|
|
116
|
-
text: example ?? exampleFromSchema ?? ""
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
if (mimeType === "multipart/form-data" || mimeType === "application/x-www-form-urlencoded") {
|
|
120
|
-
const exampleFromSchema = requestBodyObject?.schema ? getExampleFromSchema(getResolvedRef(requestBodyObject?.schema), {
|
|
121
|
-
xml: true,
|
|
122
|
-
mode: "write"
|
|
123
|
-
}) : null;
|
|
124
|
-
return {
|
|
125
|
-
mimeType,
|
|
126
|
-
params: getParamsFromObject(example ?? exampleFromSchema ?? {})
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
return null;
|
|
130
176
|
}
|
|
131
|
-
export {
|
|
132
|
-
getRequestBodyFromOperation
|
|
133
|
-
};
|
|
134
|
-
//# sourceMappingURL=get-request-body-from-operation.js.map
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
/** Retrieve example values for server variables */
|
|
2
|
+
export const getServerVariableExamples = (server) => {
|
|
3
|
+
const examples = {};
|
|
4
|
+
if (server.variables) {
|
|
5
|
+
for (const [key, variable] of Object.entries(server.variables)) {
|
|
6
|
+
examples[key] = variable.enum?.filter((v) => typeof v === 'string') ?? [
|
|
7
|
+
variable.default,
|
|
8
|
+
];
|
|
9
|
+
}
|
|
8
10
|
}
|
|
9
|
-
|
|
10
|
-
return examples;
|
|
11
|
+
return examples;
|
|
11
12
|
};
|
|
12
|
-
export {
|
|
13
|
-
getServerVariableExamples
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=get-server-variable-examples.js.map
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
getExampleFromSchema,
|
|
7
|
-
getParametersFromOperation,
|
|
8
|
-
getRequestBodyFromOperation,
|
|
9
|
-
getServerVariableExamples
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { getExampleFromSchema } from './get-example-from-schema.js';
|
|
2
|
+
export { getParametersFromOperation } from './get-parameters-from-operation.js';
|
|
3
|
+
export { getRequestBodyFromOperation } from './get-request-body-from-operation.js';
|
|
4
|
+
export { getServerVariableExamples } from './get-server-variable-examples.js';
|