@scalar/workspace-store 0.18.1 → 0.19.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.
Files changed (69) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/client.d.ts.map +1 -1
  3. package/dist/client.js +1 -1
  4. package/dist/client.js.map +2 -2
  5. package/dist/events/definitions/auth.d.ts +59 -14
  6. package/dist/events/definitions/auth.d.ts.map +1 -1
  7. package/dist/events/definitions/operation.d.ts +200 -0
  8. package/dist/events/definitions/operation.d.ts.map +1 -1
  9. package/dist/events/definitions/ui.d.ts +5 -0
  10. package/dist/events/definitions/ui.d.ts.map +1 -1
  11. package/dist/helpers/generate-unique-value.d.ts +40 -0
  12. package/dist/helpers/generate-unique-value.d.ts.map +1 -0
  13. package/dist/helpers/generate-unique-value.js +42 -0
  14. package/dist/helpers/generate-unique-value.js.map +7 -0
  15. package/dist/helpers/overrides-proxy.d.ts.map +1 -1
  16. package/dist/helpers/overrides-proxy.js +1 -1
  17. package/dist/helpers/overrides-proxy.js.map +2 -2
  18. package/dist/helpers/unpack-proxy.d.ts +1 -1
  19. package/dist/helpers/unpack-proxy.d.ts.map +1 -1
  20. package/dist/helpers/unpack-proxy.js.map +2 -2
  21. package/dist/mutators/auth.d.ts +210 -0
  22. package/dist/mutators/auth.d.ts.map +1 -0
  23. package/dist/mutators/auth.js +223 -0
  24. package/dist/mutators/auth.js.map +7 -0
  25. package/dist/mutators/index.d.ts +3 -1
  26. package/dist/mutators/index.d.ts.map +1 -1
  27. package/dist/mutators/index.js +38 -0
  28. package/dist/mutators/index.js.map +2 -2
  29. package/dist/mutators/operation.d.ts +313 -0
  30. package/dist/mutators/operation.d.ts.map +1 -0
  31. package/dist/mutators/operation.js +340 -0
  32. package/dist/mutators/operation.js.map +7 -0
  33. package/dist/schemas/extensions/operation/x-scalar-operation-identifiers.d.ts +13 -0
  34. package/dist/schemas/extensions/operation/x-scalar-operation-identifiers.d.ts.map +1 -0
  35. package/dist/schemas/extensions/operation/x-scalar-operation-identifiers.js +9 -0
  36. package/dist/schemas/extensions/operation/x-scalar-operation-identifiers.js.map +7 -0
  37. package/dist/schemas/extensions/operation/x-scalar-selected-content-type.d.ts +21 -0
  38. package/dist/schemas/extensions/operation/x-scalar-selected-content-type.d.ts.map +1 -0
  39. package/dist/schemas/extensions/operation/x-scalar-selected-content-type.js +8 -0
  40. package/dist/schemas/extensions/operation/x-scalar-selected-content-type.js.map +7 -0
  41. package/dist/schemas/extensions/security/x-scalar-selected-security.d.ts +17 -0
  42. package/dist/schemas/extensions/security/x-scalar-selected-security.d.ts.map +1 -0
  43. package/dist/schemas/extensions/security/x-scalar-selected-security.js +14 -0
  44. package/dist/schemas/extensions/security/x-scalar-selected-security.js.map +7 -0
  45. package/dist/schemas/inmemory-workspace.d.ts +32 -8
  46. package/dist/schemas/inmemory-workspace.d.ts.map +1 -1
  47. package/dist/schemas/reference-config/index.d.ts +16 -4
  48. package/dist/schemas/reference-config/index.d.ts.map +1 -1
  49. package/dist/schemas/reference-config/settings.d.ts +16 -4
  50. package/dist/schemas/reference-config/settings.d.ts.map +1 -1
  51. package/dist/schemas/v3.1/strict/openapi-document.d.ts +546 -138
  52. package/dist/schemas/v3.1/strict/openapi-document.d.ts.map +1 -1
  53. package/dist/schemas/v3.1/strict/openapi-document.js +4 -1
  54. package/dist/schemas/v3.1/strict/openapi-document.js.map +2 -2
  55. package/dist/schemas/v3.1/strict/operation.d.ts +10 -6
  56. package/dist/schemas/v3.1/strict/operation.d.ts.map +1 -1
  57. package/dist/schemas/v3.1/strict/operation.js +9 -7
  58. package/dist/schemas/v3.1/strict/operation.js.map +2 -2
  59. package/dist/schemas/v3.1/strict/request-body.d.ts +6 -3
  60. package/dist/schemas/v3.1/strict/request-body.d.ts.map +1 -1
  61. package/dist/schemas/v3.1/strict/request-body.js +15 -8
  62. package/dist/schemas/v3.1/strict/request-body.js.map +2 -2
  63. package/dist/schemas/workspace-specification/config.d.ts +16 -4
  64. package/dist/schemas/workspace-specification/config.d.ts.map +1 -1
  65. package/dist/schemas/workspace-specification/index.d.ts +16 -4
  66. package/dist/schemas/workspace-specification/index.d.ts.map +1 -1
  67. package/dist/schemas/workspace.d.ts +112 -28
  68. package/dist/schemas/workspace.d.ts.map +1 -1
  69. package/package.json +7 -7
@@ -0,0 +1,313 @@
1
+ import type { HttpMethod } from '@scalar/helpers/http/http-methods';
2
+ import type { WorkspaceDocument } from '../schemas.js';
3
+ /**
4
+ * Describes the minimal identity for an operation in the workspace document.
5
+ * It is used by mutators to find the target operation under `paths`.
6
+ *
7
+ * Example:
8
+ * ```ts
9
+ * const meta: OperationMeta = { method: 'get', path: '/users/{id}' }
10
+ * ```
11
+ */
12
+ export type OperationMeta = {
13
+ method: HttpMethod;
14
+ path: string;
15
+ };
16
+ /**
17
+ * Extends {@link OperationMeta} with an `exampleKey` to address a specific
18
+ * example variant (e.g. per environment or scenario) for request/parameters.
19
+ *
20
+ * Example:
21
+ * ```ts
22
+ * const meta: OperationExampleMeta = {
23
+ * method: 'post',
24
+ * path: '/upload',
25
+ * exampleKey: 'default',
26
+ * }
27
+ * ```
28
+ */
29
+ export type OperationExampleMeta = OperationMeta & {
30
+ exampleKey: string;
31
+ };
32
+ /** ------------------------------------------------------------------------------------------------
33
+ * Operation Draft Mutators
34
+ * ------------------------------------------------------------------------------------------------ */
35
+ /**
36
+ * Updates the `summary` of an operation.
37
+ * Safely no-ops if the document or operation does not exist.
38
+ *
39
+ * Example:
40
+ * ```ts
41
+ * updateOperationSummary({
42
+ * document,
43
+ * meta: { method: 'get', path: '/users/{id}' },
44
+ * payload: { summary: 'Get a single user' },
45
+ * })
46
+ * ```
47
+ */
48
+ export declare const updateOperationSummary: ({ document, meta, payload: { summary }, }: {
49
+ document: WorkspaceDocument | null;
50
+ payload: {
51
+ summary: string;
52
+ };
53
+ meta: OperationMeta;
54
+ }) => void;
55
+ /**
56
+ * Stores the chosen HTTP method under `x-scalar-method` on the operation.
57
+ * This does not move the operation to a different method slot under `paths`;
58
+ * it records the desired method as an extension for downstream consumers.
59
+ * Safely no-ops if the document or operation does not exist.
60
+ *
61
+ * Example:
62
+ * ```ts
63
+ * updateOperationMethodDraft({
64
+ * document,
65
+ * meta: { method: 'get', path: '/users' },
66
+ * payload: { method: 'post' },
67
+ * })
68
+ * ```
69
+ */
70
+ export declare const updateOperationMethodDraft: ({ document, meta, payload: { method }, }: {
71
+ document: WorkspaceDocument | null;
72
+ payload: {
73
+ method: HttpMethod;
74
+ };
75
+ meta: OperationMeta;
76
+ }) => void;
77
+ /**
78
+ * Records a normalized path for the operation under `x-scalar-path`, and
79
+ * synchronizes path parameters in `operation.parameters` with the placeholders
80
+ * present in the provided `path` (e.g. `/users/{id}`). Existing non-path
81
+ * parameters are preserved.
82
+ * Safely no-ops if the document or operation does not exist.
83
+ *
84
+ * Example:
85
+ * ```ts
86
+ * updateOperationPathDraft({
87
+ * document,
88
+ * meta: { method: 'get', path: '/users/{id}' },
89
+ * payload: { path: '/users/{id}' },
90
+ * })
91
+ * ```
92
+ */
93
+ export declare const updateOperationPathDraft: ({ document, meta, payload: { path }, }: {
94
+ document: WorkspaceDocument | null;
95
+ payload: {
96
+ path: string;
97
+ };
98
+ meta: OperationMeta;
99
+ }) => void;
100
+ /** ------------------------------------------------------------------------------------------------
101
+ * Operation Parameters Mutators
102
+ * ------------------------------------------------------------------------------------------------ */
103
+ /**
104
+ * Adds a parameter to the operation with an example value tracked by `exampleKey`.
105
+ * For `path` parameters `required` is set to true automatically.
106
+ * Safely no-ops if the document or operation does not exist.
107
+ *
108
+ * Example:
109
+ * ```ts
110
+ * addOperationParameter({
111
+ * document,
112
+ * type: 'query',
113
+ * meta: { method: 'get', path: '/search', exampleKey: 'default' },
114
+ * payload: { key: 'q', value: 'john', isEnabled: true },
115
+ * })
116
+ * ```
117
+ */
118
+ export declare const addOperationParameter: ({ document, meta, payload, type, }: {
119
+ document: WorkspaceDocument | null;
120
+ type: "header" | "path" | "query" | "cookie";
121
+ payload: {
122
+ key: string;
123
+ value: string;
124
+ isEnabled: boolean;
125
+ };
126
+ meta: OperationExampleMeta;
127
+ }) => void;
128
+ /**
129
+ * Updates an existing parameter of a given `type` by its index within that
130
+ * type subset (e.g. the N-th query parameter). Supports updating name, value,
131
+ * and enabled state for the targeted example.
132
+ * Safely no-ops if the document, operation, or parameter does not exist.
133
+ *
134
+ * Example:
135
+ * ```ts
136
+ * updateOperationParameter({
137
+ * document,
138
+ * type: 'query',
139
+ * index: 0,
140
+ * meta: { method: 'get', path: '/search', exampleKey: 'default' },
141
+ * payload: { value: 'alice', isEnabled: true },
142
+ * })
143
+ * ```
144
+ */
145
+ export declare const updateOperationParameter: ({ document, meta, type, payload, index, }: {
146
+ document: WorkspaceDocument | null;
147
+ type: "header" | "path" | "query" | "cookie";
148
+ index: number;
149
+ payload: Partial<{
150
+ key: string;
151
+ value: string;
152
+ isEnabled: boolean;
153
+ }>;
154
+ meta: OperationExampleMeta;
155
+ }) => void;
156
+ /**
157
+ * Removes a parameter from the operation by resolving its position within
158
+ * the filtered list of parameters of the specified `type`.
159
+ * Safely no-ops if the document, operation, or parameter does not exist.
160
+ *
161
+ * Example:
162
+ * ```ts
163
+ * deleteOperationParameter({
164
+ * document,
165
+ * type: 'header',
166
+ * index: 1,
167
+ * meta: { method: 'get', path: '/users', exampleKey: 'default' },
168
+ * })
169
+ * ```
170
+ */
171
+ export declare const deleteOperationParameter: ({ document, meta, index, type, }: {
172
+ document: WorkspaceDocument | null;
173
+ type: "header" | "path" | "query" | "cookie";
174
+ index: number;
175
+ meta: OperationExampleMeta;
176
+ }) => void;
177
+ /**
178
+ * Deletes all parameters of a given `type` from the operation.
179
+ * Safely no-ops if the document or operation does not exist.
180
+ *
181
+ * Example:
182
+ * ```ts
183
+ * deleteAllOperationParameters({
184
+ * document,
185
+ * type: 'cookie',
186
+ * meta: { method: 'get', path: '/users' },
187
+ * })
188
+ * ```
189
+ */
190
+ export declare const deleteAllOperationParameters: ({ document, meta, type, }: {
191
+ document: WorkspaceDocument | null;
192
+ type: "header" | "path" | "query" | "cookie";
193
+ meta: OperationMeta;
194
+ }) => void;
195
+ /** ------------------------------------------------------------------------------------------------
196
+ * Operation Request Body Mutators
197
+ * ------------------------------------------------------------------------------------------------ */
198
+ /**
199
+ * Sets the selected request-body content type for the current `exampleKey`.
200
+ * This stores the selection under `x-scalar-selected-content-type` on the
201
+ * resolved requestBody. Safely no-ops if the document or operation does not exist.
202
+ *
203
+ * Example:
204
+ * ```ts
205
+ * updateOperationRequestBodyContentType({
206
+ * document,
207
+ * meta: { method: 'post', path: '/upload', exampleKey: 'default' },
208
+ * payload: { contentType: 'multipart/form-data' },
209
+ * })
210
+ * ```
211
+ */
212
+ export declare const updateOperationRequestBodyContentType: ({ document, meta, payload, }: {
213
+ document: WorkspaceDocument | null;
214
+ payload: {
215
+ contentType: string;
216
+ };
217
+ meta: OperationExampleMeta;
218
+ }) => void;
219
+ /**
220
+ * Creates or updates a concrete example value for a specific request-body
221
+ * `contentType` and `exampleKey`. Safely no-ops if the document or operation
222
+ * does not exist.
223
+ *
224
+ * Example:
225
+ * ```ts
226
+ * updateOperationRequestBodyExample({
227
+ * document,
228
+ * contentType: 'application/json',
229
+ * meta: { method: 'post', path: '/users', exampleKey: 'default' },
230
+ * payload: { value: JSON.stringify({ name: 'Ada' }) },
231
+ * })
232
+ * ```
233
+ */
234
+ export declare const updateOperationRequestBodyExample: ({ document, meta, payload, contentType, }: {
235
+ document: WorkspaceDocument | null;
236
+ contentType: string;
237
+ payload: {
238
+ value: string | File | undefined;
239
+ };
240
+ meta: OperationExampleMeta;
241
+ }) => void;
242
+ /**
243
+ * Appends a form-data row to the request-body example identified by
244
+ * `contentType` and `exampleKey`. Initializes the example as an array when
245
+ * needed. Safely no-ops if the document or operation does not exist.
246
+ *
247
+ * Example:
248
+ * ```ts
249
+ * addOperationRequestBodyFormRow({
250
+ * document,
251
+ * contentType: 'multipart/form-data',
252
+ * meta: { method: 'post', path: '/upload', exampleKey: 'default' },
253
+ * payload: { key: 'file', value: new File(['x'], 'a.txt') },
254
+ * })
255
+ * ```
256
+ */
257
+ export declare const addOperationRequestBodyFormRow: ({ document, meta, payload, contentType, }: {
258
+ document: WorkspaceDocument | null;
259
+ payload: Partial<{
260
+ key: string;
261
+ value?: string | File;
262
+ }>;
263
+ contentType: string;
264
+ meta: OperationExampleMeta;
265
+ }) => void;
266
+ /**
267
+ * Updates a form-data row at a given `index` for the specified example and
268
+ * `contentType`. Setting `payload.value` to `null` clears the value (sets to
269
+ * `undefined`). Safely no-ops if the document, operation, or example does not exist.
270
+ *
271
+ * Example:
272
+ * ```ts
273
+ * updateOperationRequestBodyFormRow({
274
+ * document,
275
+ * index: 0,
276
+ * contentType: 'multipart/form-data',
277
+ * meta: { method: 'post', path: '/upload', exampleKey: 'default' },
278
+ * payload: { key: 'description', value: 'Profile picture' },
279
+ * })
280
+ * ```
281
+ */
282
+ export declare const updateOperationRequestBodyFormRow: ({ document, meta, index, payload, contentType, }: {
283
+ document: WorkspaceDocument | null;
284
+ index: number;
285
+ payload: Partial<{
286
+ key: string;
287
+ value: string | File | null;
288
+ }>;
289
+ contentType: string;
290
+ meta: OperationExampleMeta;
291
+ }) => void;
292
+ /**
293
+ * Deletes a form-data row at a given `index` from the example for the given
294
+ * `contentType`. If the example becomes empty, the example entry is removed.
295
+ * Safely no-ops if the document, operation, example, or row does not exist.
296
+ *
297
+ * Example:
298
+ * ```ts
299
+ * deleteOperationRequestBodyFormRow({
300
+ * document,
301
+ * index: 0,
302
+ * contentType: 'multipart/form-data',
303
+ * meta: { method: 'post', path: '/upload', exampleKey: 'default' },
304
+ * })
305
+ * ```
306
+ */
307
+ export declare const deleteOperationRequestBodyFormRow: ({ document, meta, index, contentType, }: {
308
+ document: WorkspaceDocument | null;
309
+ index: number;
310
+ contentType: string;
311
+ meta: OperationExampleMeta;
312
+ }) => void;
313
+ //# sourceMappingURL=operation.d.ts.map
@@ -0,0 +1 @@
1
+ {"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A;IACnB,IAAI,EAAE,oBAAoB,CAAA;CAC3B,SAuCA,CAAA"}
@@ -0,0 +1,340 @@
1
+ import { getResolvedRef } from "../helpers/get-resolved-ref.js";
2
+ const updateOperationSummary = ({
3
+ document,
4
+ meta,
5
+ payload: { summary }
6
+ }) => {
7
+ if (!document) {
8
+ return;
9
+ }
10
+ const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
11
+ if (!operation) {
12
+ return;
13
+ }
14
+ operation.summary = summary;
15
+ };
16
+ const updateOperationMethodDraft = ({
17
+ document,
18
+ meta,
19
+ payload: { method }
20
+ }) => {
21
+ if (!document) {
22
+ return;
23
+ }
24
+ const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
25
+ if (!operation) {
26
+ return;
27
+ }
28
+ operation["x-scalar-method"] = method;
29
+ };
30
+ const updateOperationPathDraft = ({
31
+ document,
32
+ meta,
33
+ payload: { path }
34
+ }) => {
35
+ if (!document) {
36
+ return;
37
+ }
38
+ const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
39
+ if (!operation) {
40
+ return;
41
+ }
42
+ operation["x-scalar-path"] = path;
43
+ const pathVariables = Array.from(path.matchAll(/{([^\/}]+)}/g), (m) => m[1]);
44
+ const pathVariablesWithoutPathParameters = operation.parameters?.filter((it) => getResolvedRef(it).in !== "path");
45
+ operation.parameters = [
46
+ ...pathVariablesWithoutPathParameters ?? [],
47
+ ...pathVariables.map((it) => ({
48
+ name: it ?? "",
49
+ in: "path",
50
+ required: true
51
+ }))
52
+ ];
53
+ };
54
+ const addOperationParameter = ({
55
+ document,
56
+ meta,
57
+ payload,
58
+ type
59
+ }) => {
60
+ if (!document) {
61
+ return;
62
+ }
63
+ const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
64
+ if (!operation) {
65
+ return;
66
+ }
67
+ if (!operation.parameters) {
68
+ operation.parameters = [];
69
+ }
70
+ operation.parameters.push({
71
+ name: payload.key,
72
+ in: type,
73
+ required: type === "path" ? true : false,
74
+ examples: {
75
+ [meta.exampleKey]: {
76
+ value: payload.value,
77
+ "x-disabled": !payload.isEnabled
78
+ }
79
+ }
80
+ });
81
+ };
82
+ const updateOperationParameter = ({
83
+ document,
84
+ meta,
85
+ type,
86
+ payload,
87
+ index
88
+ }) => {
89
+ if (!document) {
90
+ return;
91
+ }
92
+ const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
93
+ if (!operation) {
94
+ return;
95
+ }
96
+ const resolvedParameters = operation.parameters?.map((it) => getResolvedRef(it)).filter((it) => it.in === type) ?? [];
97
+ const parameter = resolvedParameters[index];
98
+ if (!parameter) {
99
+ return;
100
+ }
101
+ parameter.name = payload.key ?? parameter.name ?? "";
102
+ if ("examples" in parameter) {
103
+ if (!parameter.examples) {
104
+ parameter.examples = {};
105
+ }
106
+ const example = getResolvedRef(parameter.examples[meta.exampleKey]);
107
+ if (!example) {
108
+ return;
109
+ }
110
+ example.value = payload.value ?? example?.value ?? "";
111
+ example["x-disabled"] = payload.isEnabled === void 0 ? example["x-disabled"] : !payload.isEnabled;
112
+ }
113
+ };
114
+ const deleteOperationParameter = ({
115
+ document,
116
+ meta,
117
+ index,
118
+ type
119
+ }) => {
120
+ if (!document) {
121
+ return;
122
+ }
123
+ const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
124
+ if (!operation) {
125
+ return;
126
+ }
127
+ const resolvedParameters = operation.parameters?.map((it) => getResolvedRef(it)).filter((it) => it.in === type) ?? [];
128
+ const parameter = resolvedParameters[index];
129
+ if (!parameter) {
130
+ return;
131
+ }
132
+ const actualIndex = operation.parameters?.findIndex((it) => getResolvedRef(it) === parameter);
133
+ operation.parameters?.splice(actualIndex, 1);
134
+ };
135
+ const deleteAllOperationParameters = ({
136
+ document,
137
+ meta,
138
+ type
139
+ }) => {
140
+ if (!document) {
141
+ return;
142
+ }
143
+ const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
144
+ if (!operation) {
145
+ return;
146
+ }
147
+ operation.parameters = operation.parameters?.filter((it) => getResolvedRef(it).in !== type) ?? [];
148
+ };
149
+ const updateOperationRequestBodyContentType = ({
150
+ document,
151
+ meta,
152
+ payload
153
+ }) => {
154
+ if (!document) {
155
+ return;
156
+ }
157
+ const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
158
+ if (!operation) {
159
+ return;
160
+ }
161
+ let requestBody = getResolvedRef(operation.requestBody);
162
+ if (!requestBody) {
163
+ operation.requestBody = {
164
+ content: {}
165
+ };
166
+ requestBody = getResolvedRef(operation.requestBody);
167
+ }
168
+ if (!requestBody["x-scalar-selected-content-type"]) {
169
+ requestBody["x-scalar-selected-content-type"] = {};
170
+ }
171
+ requestBody["x-scalar-selected-content-type"][meta.exampleKey] = payload.contentType;
172
+ };
173
+ const updateOperationRequestBodyExample = ({
174
+ document,
175
+ meta,
176
+ payload,
177
+ contentType
178
+ }) => {
179
+ if (!document) {
180
+ return;
181
+ }
182
+ const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
183
+ if (!operation) {
184
+ return;
185
+ }
186
+ let requestBody = getResolvedRef(operation.requestBody);
187
+ if (!requestBody) {
188
+ operation.requestBody = {
189
+ content: {}
190
+ };
191
+ requestBody = getResolvedRef(operation.requestBody);
192
+ }
193
+ if (!requestBody.content[contentType]) {
194
+ requestBody.content[contentType] = {
195
+ examples: {}
196
+ };
197
+ }
198
+ const mediaType = requestBody.content[contentType];
199
+ mediaType.examples ??= {};
200
+ const examples = getResolvedRef(mediaType.examples);
201
+ const example = getResolvedRef(examples[meta.exampleKey]);
202
+ if (!example) {
203
+ examples[meta.exampleKey] = {
204
+ value: payload.value
205
+ };
206
+ return;
207
+ }
208
+ example.value = payload.value;
209
+ };
210
+ const addOperationRequestBodyFormRow = ({
211
+ document,
212
+ meta,
213
+ payload,
214
+ contentType
215
+ }) => {
216
+ if (!document) {
217
+ return;
218
+ }
219
+ const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
220
+ if (!operation) {
221
+ return;
222
+ }
223
+ let requestBody = getResolvedRef(operation.requestBody);
224
+ if (!requestBody) {
225
+ operation.requestBody = {
226
+ content: {}
227
+ };
228
+ requestBody = getResolvedRef(operation.requestBody);
229
+ }
230
+ if (!requestBody.content[contentType]) {
231
+ requestBody.content[contentType] = {
232
+ examples: {}
233
+ };
234
+ }
235
+ if (!requestBody.content[contentType].examples) {
236
+ requestBody.content[contentType].examples = {};
237
+ }
238
+ const examples = getResolvedRef(requestBody.content[contentType].examples);
239
+ const example = getResolvedRef(examples[meta.exampleKey]);
240
+ if (!example || !Array.isArray(example.value)) {
241
+ examples[meta.exampleKey] = {
242
+ value: [
243
+ {
244
+ name: payload.key,
245
+ value: payload.value
246
+ }
247
+ ]
248
+ };
249
+ return;
250
+ }
251
+ example.value.push({
252
+ name: payload.key ?? "",
253
+ value: payload.value ?? ""
254
+ });
255
+ };
256
+ const updateOperationRequestBodyFormRow = ({
257
+ document,
258
+ meta,
259
+ index,
260
+ payload,
261
+ contentType
262
+ }) => {
263
+ if (!document) {
264
+ return;
265
+ }
266
+ const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
267
+ if (!operation) {
268
+ return;
269
+ }
270
+ let requestBody = getResolvedRef(operation.requestBody);
271
+ if (!requestBody) {
272
+ operation.requestBody = {
273
+ content: {}
274
+ };
275
+ requestBody = getResolvedRef(operation.requestBody);
276
+ }
277
+ if (!requestBody.content[contentType]) {
278
+ return;
279
+ }
280
+ const examples = getResolvedRef(requestBody.content[contentType].examples);
281
+ if (!examples) {
282
+ return;
283
+ }
284
+ const example = getResolvedRef(examples[meta.exampleKey]);
285
+ if (!example || !Array.isArray(example.value)) {
286
+ return;
287
+ }
288
+ example.value[index] = {
289
+ name: payload.key ?? example.value[index]?.name ?? "",
290
+ value: payload.value === null ? void 0 : payload.value ?? example.value[index]?.value ?? ""
291
+ };
292
+ };
293
+ const deleteOperationRequestBodyFormRow = ({
294
+ document,
295
+ meta,
296
+ index,
297
+ contentType
298
+ }) => {
299
+ if (!document) {
300
+ return;
301
+ }
302
+ const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
303
+ if (!operation) {
304
+ return;
305
+ }
306
+ const requestBody = getResolvedRef(operation.requestBody);
307
+ if (!requestBody) {
308
+ return;
309
+ }
310
+ if (!requestBody.content[contentType]) {
311
+ return;
312
+ }
313
+ const examples = getResolvedRef(requestBody.content[contentType].examples);
314
+ if (!examples) {
315
+ return;
316
+ }
317
+ const example = getResolvedRef(examples[meta.exampleKey]);
318
+ if (!example || !Array.isArray(example.value)) {
319
+ return;
320
+ }
321
+ example.value.splice(index, 1);
322
+ if (example.value.length === 0) {
323
+ delete requestBody.content[contentType].examples[meta.exampleKey];
324
+ }
325
+ };
326
+ export {
327
+ addOperationParameter,
328
+ addOperationRequestBodyFormRow,
329
+ deleteAllOperationParameters,
330
+ deleteOperationParameter,
331
+ deleteOperationRequestBodyFormRow,
332
+ updateOperationMethodDraft,
333
+ updateOperationParameter,
334
+ updateOperationPathDraft,
335
+ updateOperationRequestBodyContentType,
336
+ updateOperationRequestBodyExample,
337
+ updateOperationRequestBodyFormRow,
338
+ updateOperationSummary
339
+ };
340
+ //# sourceMappingURL=operation.js.map