@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.
Files changed (129) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/entities/cookie/cookie.js +11 -15
  3. package/dist/entities/cookie/index.js +1 -5
  4. package/dist/entities/environment/environment.js +7 -11
  5. package/dist/entities/environment/index.js +1 -5
  6. package/dist/entities/hotkeys/hotkeys.js +116 -111
  7. package/dist/entities/hotkeys/index.js +1 -6
  8. package/dist/entities/shared/index.js +1 -7
  9. package/dist/entities/shared/utility.js +9 -9
  10. package/dist/entities/spec/collection.js +91 -89
  11. package/dist/entities/spec/index.js +10 -59
  12. package/dist/entities/spec/operation.js +6 -6
  13. package/dist/entities/spec/parameters.js +38 -38
  14. package/dist/entities/spec/request-examples.js +421 -331
  15. package/dist/entities/spec/requests.js +102 -84
  16. package/dist/entities/spec/server.js +61 -46
  17. package/dist/entities/spec/spec-objects.js +121 -76
  18. package/dist/entities/spec/x-scalar-environments.js +18 -20
  19. package/dist/entities/spec/x-scalar-secrets.js +6 -8
  20. package/dist/entities/workspace/index.js +1 -7
  21. package/dist/entities/workspace/workspace.js +47 -46
  22. package/dist/helpers/client-plugins.js +13 -13
  23. package/dist/helpers/fetch-document.js +30 -25
  24. package/dist/helpers/fetch-with-proxy-fallback.js +26 -21
  25. package/dist/helpers/index.d.ts +1 -2
  26. package/dist/helpers/index.d.ts.map +1 -1
  27. package/dist/helpers/index.js +80 -119
  28. package/dist/helpers/normalize-mime-type-object.js +19 -18
  29. package/dist/helpers/normalize-mime-type.js +11 -9
  30. package/dist/helpers/operation-stability.js +25 -20
  31. package/dist/helpers/parse.d.ts +0 -4
  32. package/dist/helpers/parse.d.ts.map +1 -1
  33. package/dist/helpers/parse.js +77 -77
  34. package/dist/helpers/schema-model.js +13 -16
  35. package/dist/helpers/security/get-schemes.js +7 -8
  36. package/dist/helpers/security/has-token.js +18 -19
  37. package/dist/helpers/security/index.js +2 -7
  38. package/dist/helpers/servers.js +128 -79
  39. package/dist/helpers/should-ignore-entity.js +4 -5
  40. package/dist/migrations/data-version.js +15 -7
  41. package/dist/migrations/generate-types.js +34 -37
  42. package/dist/migrations/index.js +4 -18
  43. package/dist/migrations/local-storage.js +31 -29
  44. package/dist/migrations/migrate-to-indexdb.js +706 -529
  45. package/dist/migrations/migrator.js +58 -54
  46. package/dist/migrations/semver.js +24 -24
  47. package/dist/migrations/v-0.0.0/types.generated.js +1 -1
  48. package/dist/migrations/v-2.1.0/migration.js +272 -258
  49. package/dist/migrations/v-2.1.0/types.generated.js +1 -1
  50. package/dist/migrations/v-2.2.0/migration.js +99 -96
  51. package/dist/migrations/v-2.2.0/types.generated.js +1 -1
  52. package/dist/migrations/v-2.3.0/migration.js +45 -48
  53. package/dist/migrations/v-2.3.0/types.generated.js +1 -1
  54. package/dist/migrations/v-2.4.0/migration.js +25 -25
  55. package/dist/migrations/v-2.4.0/types.generated.js +1 -1
  56. package/dist/migrations/v-2.5.0/migration.js +122 -139
  57. package/dist/migrations/v-2.5.0/types.generated.js +1 -1
  58. package/dist/spec-getters/get-example-from-schema.js +489 -385
  59. package/dist/spec-getters/get-parameters-from-operation.js +39 -23
  60. package/dist/spec-getters/get-request-body-from-operation.d.ts.map +1 -1
  61. package/dist/spec-getters/get-request-body-from-operation.js +168 -126
  62. package/dist/spec-getters/get-server-variable-examples.js +10 -13
  63. package/dist/spec-getters/index.js +4 -11
  64. package/dist/transforms/import-spec.js +381 -291
  65. package/dist/transforms/index.js +1 -11
  66. package/package.json +15 -19
  67. package/dist/entities/cookie/cookie.js.map +0 -7
  68. package/dist/entities/cookie/index.js.map +0 -7
  69. package/dist/entities/environment/environment.js.map +0 -7
  70. package/dist/entities/environment/index.js.map +0 -7
  71. package/dist/entities/hotkeys/hotkeys.js.map +0 -7
  72. package/dist/entities/hotkeys/index.js.map +0 -7
  73. package/dist/entities/shared/index.js.map +0 -7
  74. package/dist/entities/shared/utility.js.map +0 -7
  75. package/dist/entities/spec/collection.js.map +0 -7
  76. package/dist/entities/spec/index.js.map +0 -7
  77. package/dist/entities/spec/operation.js.map +0 -7
  78. package/dist/entities/spec/parameters.js.map +0 -7
  79. package/dist/entities/spec/request-examples.js.map +0 -7
  80. package/dist/entities/spec/requests.js.map +0 -7
  81. package/dist/entities/spec/server.js.map +0 -7
  82. package/dist/entities/spec/spec-objects.js.map +0 -7
  83. package/dist/entities/spec/x-scalar-environments.js.map +0 -7
  84. package/dist/entities/spec/x-scalar-secrets.js.map +0 -7
  85. package/dist/entities/workspace/index.js.map +0 -7
  86. package/dist/entities/workspace/workspace.js.map +0 -7
  87. package/dist/helpers/client-plugins.js.map +0 -7
  88. package/dist/helpers/fetch-document.js.map +0 -7
  89. package/dist/helpers/fetch-with-proxy-fallback.js.map +0 -7
  90. package/dist/helpers/index.js.map +0 -7
  91. package/dist/helpers/normalize-mime-type-object.js.map +0 -7
  92. package/dist/helpers/normalize-mime-type.js.map +0 -7
  93. package/dist/helpers/operation-stability.js.map +0 -7
  94. package/dist/helpers/parse.js.map +0 -7
  95. package/dist/helpers/pretty-print-json.d.ts +0 -9
  96. package/dist/helpers/pretty-print-json.d.ts.map +0 -1
  97. package/dist/helpers/pretty-print-json.js +0 -38
  98. package/dist/helpers/pretty-print-json.js.map +0 -7
  99. package/dist/helpers/schema-model.js.map +0 -7
  100. package/dist/helpers/security/get-schemes.js.map +0 -7
  101. package/dist/helpers/security/has-token.js.map +0 -7
  102. package/dist/helpers/security/index.js.map +0 -7
  103. package/dist/helpers/servers.js.map +0 -7
  104. package/dist/helpers/should-ignore-entity.js.map +0 -7
  105. package/dist/migrations/data-version.js.map +0 -7
  106. package/dist/migrations/generate-types.js.map +0 -7
  107. package/dist/migrations/index.js.map +0 -7
  108. package/dist/migrations/local-storage.js.map +0 -7
  109. package/dist/migrations/migrate-to-indexdb.js.map +0 -7
  110. package/dist/migrations/migrator.js.map +0 -7
  111. package/dist/migrations/semver.js.map +0 -7
  112. package/dist/migrations/v-0.0.0/types.generated.js.map +0 -7
  113. package/dist/migrations/v-2.1.0/migration.js.map +0 -7
  114. package/dist/migrations/v-2.1.0/types.generated.js.map +0 -7
  115. package/dist/migrations/v-2.2.0/migration.js.map +0 -7
  116. package/dist/migrations/v-2.2.0/types.generated.js.map +0 -7
  117. package/dist/migrations/v-2.3.0/migration.js.map +0 -7
  118. package/dist/migrations/v-2.3.0/types.generated.js.map +0 -7
  119. package/dist/migrations/v-2.4.0/migration.js.map +0 -7
  120. package/dist/migrations/v-2.4.0/types.generated.js.map +0 -7
  121. package/dist/migrations/v-2.5.0/migration.js.map +0 -7
  122. package/dist/migrations/v-2.5.0/types.generated.js.map +0 -7
  123. package/dist/spec-getters/get-example-from-schema.js.map +0 -7
  124. package/dist/spec-getters/get-parameters-from-operation.js.map +0 -7
  125. package/dist/spec-getters/get-request-body-from-operation.js.map +0 -7
  126. package/dist/spec-getters/get-server-variable-examples.js.map +0 -7
  127. package/dist/spec-getters/index.js.map +0 -7
  128. package/dist/transforms/import-spec.js.map +0 -7
  129. package/dist/transforms/index.js.map +0 -7
@@ -1,24 +1,40 @@
1
- import { getExampleFromSchema } from "./get-example-from-schema.js";
2
- function getParametersFromOperation(operationParameters = [], pathParameters = [], where, requiredOnly = true) {
3
- const parameters = [...pathParameters || [], ...operationParameters || []];
4
- const params = parameters.filter((parameter) => parameter.in === where).filter((parameter) => requiredOnly && parameter.required || !requiredOnly).map((parameter) => ({
5
- name: parameter.name ?? "Unknown Parameter",
6
- description: parameter.description ?? null,
7
- value: parameter.example ? parameter.example : parameter.schema ? getExampleFromSchema(parameter.schema, { mode: "write" }) : "",
8
- required: parameter.required ?? false,
9
- enabled: parameter.required ?? false
10
- }));
11
- return params.sort((a, b) => {
12
- if (a.required && !b.required) {
13
- return -1;
14
- }
15
- if (!a.required && b.required) {
16
- return 1;
17
- }
18
- return 0;
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":"AACA,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
+ {"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 "@scalar/helpers/file/json2xml";
2
- import { getResolvedRef } from "@scalar/workspace-store/helpers/get-resolved-ref";
3
- import { normalizeMimeTypeObject } from "../helpers/normalize-mime-type-object.js";
4
- import { prettyPrintJson } from "../helpers/pretty-print-json.js";
5
- import { getExampleFromSchema } from "./get-example-from-schema.js";
6
- import { getParametersFromOperation } from "./get-parameters-from-operation.js";
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
- return Object.entries(obj).flatMap(([key, value]) => {
9
- const name = field ?? key;
10
- if (Array.isArray(value) && !nested) {
11
- return getParamsFromObject(value, true, key);
12
- }
13
- if (typeof value === "object" && !(value instanceof File) && value !== null) {
14
- value = JSON.stringify(value);
15
- }
16
- return [{ name, value }];
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
- "application/json",
21
- "application/octet-stream",
22
- "application/x-www-form-urlencoded",
23
- "application/xml",
24
- "multipart/form-data",
25
- "text/plain"
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
- function getRequestBodyFromOperation(operation, selectedExampleKey, omitEmptyAndOptionalProperties) {
28
- const originalContent = operation.requestBody?.content;
29
- const content = normalizeMimeTypeObject(originalContent);
30
- const mimeType = standardMimeTypes.find((currentMimeType) => !!content?.[currentMimeType]) ?? (Object.keys(content ?? {})[0] || "application/json");
31
- const isJsonLike = mimeType.includes("json") || mimeType.endsWith("+json");
32
- const examples = content?.[mimeType]?.examples ?? content?.["application/json"]?.examples;
33
- const selectedExample = examples?.[selectedExampleKey ?? Object.keys(examples ?? {})[0] ?? ""];
34
- if (selectedExample) {
35
- return {
36
- mimeType,
37
- text: prettyPrintJson("value" in selectedExample ? selectedExample.value : selectedExample)
38
- };
39
- }
40
- const bodyParameters = getParametersFromOperation(
41
- operation.parameters ?? [],
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
- // operation.path ?? [],
45
- "body",
46
- false
47
- );
48
- if (bodyParameters.length > 0) {
49
- return {
50
- mimeType: "application/json",
51
- text: prettyPrintJson(bodyParameters[0]?.value ?? "")
52
- };
53
- }
54
- const formDataParameters = getParametersFromOperation(
55
- operation.parameters ?? [],
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
- // operation.path ?? [],
59
- "formData",
60
- false
61
- );
62
- if (formDataParameters.length > 0) {
63
- return {
64
- mimeType: "application/x-www-form-urlencoded",
65
- params: formDataParameters.map((parameter) => ({
66
- name: parameter.name,
67
- /**
68
- * TODO: This value MUST be a string
69
- * Figure out why this is not always a string
70
- *
71
- * JSON.stringify is a TEMPORARY fix
72
- */
73
- value: typeof parameter.value === "string" ? parameter.value : JSON.stringify(parameter.value)
74
- }))
75
- };
76
- }
77
- if (!mimeType) {
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
- const getServerVariableExamples = (server) => {
2
- const examples = {};
3
- if (server.variables) {
4
- for (const [key, variable] of Object.entries(server.variables)) {
5
- examples[key] = variable.enum?.filter((v) => typeof v === "string") ?? [
6
- variable.default
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
- import { getExampleFromSchema } from "./get-example-from-schema.js";
2
- import { getParametersFromOperation } from "./get-parameters-from-operation.js";
3
- import { getRequestBodyFromOperation } from "./get-request-body-from-operation.js";
4
- import { getServerVariableExamples } from "./get-server-variable-examples.js";
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';