@scalar/workspace-store 0.40.2 → 0.40.4
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 +13 -0
- package/dist/client.d.ts +7 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +820 -681
- package/dist/entities/auth/index.js +96 -101
- package/dist/entities/auth/schema.d.ts +10 -0
- package/dist/entities/auth/schema.d.ts.map +1 -1
- package/dist/entities/auth/schema.js +42 -116
- package/dist/entities/history/index.js +80 -60
- package/dist/entities/history/schema.js +94 -88
- package/dist/events/bus.js +146 -93
- package/dist/events/definitions/analytics.js +1 -1
- package/dist/events/definitions/auth.js +1 -1
- package/dist/events/definitions/common.js +1 -1
- package/dist/events/definitions/cookie.js +1 -1
- package/dist/events/definitions/document.js +1 -1
- package/dist/events/definitions/environment.js +1 -1
- package/dist/events/definitions/hooks.js +1 -1
- package/dist/events/definitions/index.js +1 -1
- package/dist/events/definitions/meta.js +1 -1
- package/dist/events/definitions/operation.js +1 -1
- package/dist/events/definitions/server.js +1 -1
- package/dist/events/definitions/tabs.js +1 -1
- package/dist/events/definitions/tag.js +1 -1
- package/dist/events/definitions/ui.js +1 -1
- package/dist/events/definitions/workspace.js +1 -1
- package/dist/events/index.js +3 -9
- package/dist/events/listeners.js +20 -22
- package/dist/events/old-definitions.js +15 -12
- package/dist/helpers/deep-clone.js +33 -17
- package/dist/helpers/detect-changes-proxy.js +95 -57
- package/dist/helpers/general.js +78 -23
- package/dist/helpers/generate-unique-value.js +77 -45
- package/dist/helpers/get-fetch.js +12 -10
- package/dist/helpers/get-resolved-ref.js +11 -10
- package/dist/helpers/is-non-optional-security-requirement.js +3 -6
- package/dist/helpers/merge-object.js +71 -30
- package/dist/helpers/overrides-proxy.js +98 -58
- package/dist/helpers/unpack-proxy.js +60 -58
- package/dist/mutators/auth.js +358 -230
- package/dist/mutators/cookie.js +59 -42
- package/dist/mutators/document.js +104 -66
- package/dist/mutators/environment.js +97 -72
- package/dist/mutators/helpers.js +9 -13
- package/dist/mutators/index.js +62 -49
- package/dist/mutators/operation/body.js +88 -57
- package/dist/mutators/operation/extensions.js +20 -12
- package/dist/mutators/operation/helpers/fetch-request-to-har.js +144 -107
- package/dist/mutators/operation/helpers/fetch-response-to-har.js +143 -95
- package/dist/mutators/operation/helpers/get-parameter-position.js +12 -12
- package/dist/mutators/operation/helpers/har-to-operation.js +169 -132
- package/dist/mutators/operation/helpers/sync-path-parameters.js +109 -60
- package/dist/mutators/operation/history.js +60 -64
- package/dist/mutators/operation/index.js +25 -49
- package/dist/mutators/operation/operation.js +349 -240
- package/dist/mutators/operation/parameters.js +157 -93
- package/dist/mutators/server.js +213 -152
- package/dist/mutators/tabs.js +173 -130
- package/dist/mutators/tag.js +131 -97
- package/dist/mutators/workspace.js +72 -42
- package/dist/navigation/get-navigation-options.js +97 -84
- package/dist/navigation/helpers/get-openapi-object.js +46 -29
- package/dist/navigation/helpers/get-operation-entries.js +72 -32
- package/dist/navigation/helpers/get-parent-entry.js +16 -12
- package/dist/navigation/helpers/get-tag-entries.js +56 -29
- package/dist/navigation/helpers/get-tag.js +22 -23
- package/dist/navigation/helpers/get-x-keys.js +13 -9
- package/dist/navigation/helpers/traverse-description.js +90 -72
- package/dist/navigation/helpers/traverse-document.js +111 -98
- package/dist/navigation/helpers/traverse-examples.js +35 -31
- package/dist/navigation/helpers/traverse-paths.js +118 -106
- package/dist/navigation/helpers/traverse-schemas.js +65 -64
- package/dist/navigation/helpers/traverse-tags.js +158 -129
- package/dist/navigation/helpers/traverse-webhooks.js +96 -90
- package/dist/navigation/helpers/update-order-ids.js +59 -51
- package/dist/navigation/helpers/utils.js +71 -21
- package/dist/navigation/index.js +5 -13
- package/dist/navigation/types.js +1 -1
- package/dist/persistence/index.js +283 -285
- package/dist/persistence/indexdb.js +263 -126
- package/dist/plugins/bundler/helpers.js +21 -12
- package/dist/plugins/bundler/index.d.ts +7 -0
- package/dist/plugins/bundler/index.d.ts.map +1 -1
- package/dist/plugins/bundler/index.js +305 -171
- package/dist/plugins/client/index.js +1 -5
- package/dist/plugins/client/persistence.js +95 -90
- package/dist/resolve.js +18 -25
- package/dist/schemas/compose.js +6 -7
- package/dist/schemas/extensions/document/x-internal.js +3 -7
- package/dist/schemas/extensions/document/x-scalar-environments.js +16 -22
- package/dist/schemas/extensions/document/x-scalar-icon.js +3 -7
- package/dist/schemas/extensions/document/x-scalar-ignore.js +3 -7
- package/dist/schemas/extensions/document/x-scalar-is-dirty.js +21 -8
- package/dist/schemas/extensions/document/x-scalar-original-document-hash.js +17 -8
- package/dist/schemas/extensions/document/x-scalar-registry-meta.js +15 -21
- package/dist/schemas/extensions/document/x-scalar-sdk-installation.js +5 -13
- package/dist/schemas/extensions/document/x-scalar-watch-mode.js +4 -8
- package/dist/schemas/extensions/document/x-tags.js +3 -7
- package/dist/schemas/extensions/example/x-disabled.js +17 -7
- package/dist/schemas/extensions/general/x-scalar-active-environment.js +4 -7
- package/dist/schemas/extensions/general/x-scalar-cookies.js +9 -14
- package/dist/schemas/extensions/general/x-scalar-order.js +8 -7
- package/dist/schemas/extensions/operation/index.js +4 -23
- package/dist/schemas/extensions/operation/x-badge.js +42 -50
- package/dist/schemas/extensions/operation/x-code-samples.js +8 -12
- package/dist/schemas/extensions/operation/x-draft-examples.js +3 -7
- package/dist/schemas/extensions/operation/x-post-response.js +18 -7
- package/dist/schemas/extensions/operation/x-scalar-disable-parameters.js +57 -13
- package/dist/schemas/extensions/operation/x-scalar-selected-content-type.js +9 -7
- package/dist/schemas/extensions/operation/x-scalar-stability.js +15 -14
- package/dist/schemas/extensions/parameter/x-global.js +12 -7
- package/dist/schemas/extensions/schema/x-additional-properties-name.js +10 -7
- package/dist/schemas/extensions/schema/x-enum-descriptions.js +17 -12
- package/dist/schemas/extensions/schema/x-enum-varnames.js +21 -8
- package/dist/schemas/extensions/schema/x-examples.js +3 -7
- package/dist/schemas/extensions/schema/x-variable.js +3 -7
- package/dist/schemas/extensions/security/index.js +1 -1
- package/dist/schemas/extensions/security/x-default-scopes.js +16 -7
- package/dist/schemas/extensions/security/x-scalar-credentials-location.js +16 -7
- package/dist/schemas/extensions/security/x-scalar-security-body.js +14 -7
- package/dist/schemas/extensions/security/x-scalar-security-query.js +14 -7
- package/dist/schemas/extensions/security/x-scalar-security-secrets.js +66 -37
- package/dist/schemas/extensions/security/x-tokenName.js +11 -7
- package/dist/schemas/extensions/security/x-use-pkce.js +6 -10
- package/dist/schemas/extensions/server/x-scalar-selected-server.js +3 -7
- package/dist/schemas/extensions/tag/index.js +1 -1
- package/dist/schemas/extensions/tag/x-display-name.js +11 -7
- package/dist/schemas/extensions/tag/x-tag-groups.js +13 -15
- package/dist/schemas/extensions/workspace/index.js +2 -11
- package/dist/schemas/extensions/workspace/x-scalar-active-proxy.js +13 -7
- package/dist/schemas/extensions/workspace/x-scalar-tabs.js +15 -13
- package/dist/schemas/extensions.js +11 -15
- package/dist/schemas/inmemory-workspace.d.ts +6 -0
- package/dist/schemas/inmemory-workspace.d.ts.map +1 -1
- package/dist/schemas/inmemory-workspace.js +13 -21
- package/dist/schemas/navigation.js +48 -85
- package/dist/schemas/reference-config/appearance.js +15 -22
- package/dist/schemas/reference-config/features.js +14 -21
- package/dist/schemas/reference-config/index.d.ts +2 -0
- package/dist/schemas/reference-config/index.d.ts.map +1 -1
- package/dist/schemas/reference-config/index.js +42 -44
- package/dist/schemas/reference-config/meta.js +11 -18
- package/dist/schemas/reference-config/routing.js +7 -14
- package/dist/schemas/reference-config/settings.d.ts +2 -0
- package/dist/schemas/reference-config/settings.d.ts.map +1 -1
- package/dist/schemas/reference-config/settings.js +10 -17
- package/dist/schemas/typebox-coerce.js +23 -6
- package/dist/schemas/v3.1/strict/callback.js +6 -12
- package/dist/schemas/v3.1/strict/components.js +26 -48
- package/dist/schemas/v3.1/strict/contact.js +9 -12
- package/dist/schemas/v3.1/strict/discriminator.js +11 -10
- package/dist/schemas/v3.1/strict/encoding.js +15 -12
- package/dist/schemas/v3.1/strict/example.js +11 -13
- package/dist/schemas/v3.1/strict/external-documentation.js +7 -10
- package/dist/schemas/v3.1/strict/header.js +27 -28
- package/dist/schemas/v3.1/strict/info.js +10 -16
- package/dist/schemas/v3.1/strict/license.js +9 -12
- package/dist/schemas/v3.1/strict/link.js +22 -19
- package/dist/schemas/v3.1/strict/media-type.js +17 -16
- package/dist/schemas/v3.1/strict/oauth-flow.js +28 -62
- package/dist/schemas/v3.1/strict/oauthflows.js +14 -20
- package/dist/schemas/v3.1/strict/openapi-document.d.ts +70 -0
- package/dist/schemas/v3.1/strict/openapi-document.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/openapi-document.js +126 -210
- package/dist/schemas/v3.1/strict/operation.js +16 -43
- package/dist/schemas/v3.1/strict/parameter.d.ts +6 -0
- package/dist/schemas/v3.1/strict/parameter.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/parameter.js +29 -35
- package/dist/schemas/v3.1/strict/path-item.js +36 -40
- package/dist/schemas/v3.1/strict/paths.js +8 -11
- package/dist/schemas/v3.1/strict/ref-definitions.js +76 -100
- package/dist/schemas/v3.1/strict/reference.js +18 -21
- package/dist/schemas/v3.1/strict/request-body.js +8 -16
- package/dist/schemas/v3.1/strict/response.js +12 -16
- package/dist/schemas/v3.1/strict/responses.js +13 -11
- package/dist/schemas/v3.1/strict/schema.js +149 -157
- package/dist/schemas/v3.1/strict/security-requirement.js +13 -12
- package/dist/schemas/v3.1/strict/security-scheme.js +29 -41
- package/dist/schemas/v3.1/strict/server-variable.js +9 -12
- package/dist/schemas/v3.1/strict/server.js +10 -13
- package/dist/schemas/v3.1/strict/tag.js +11 -20
- package/dist/schemas/v3.1/strict/type-guards.js +20 -20
- package/dist/schemas/v3.1/strict/xml.js +17 -16
- package/dist/schemas/workspace-specification/index.js +11 -23
- package/dist/schemas/workspace-specification/info.js +4 -8
- package/dist/schemas/workspace.d.ts +6 -0
- package/dist/schemas/workspace.d.ts.map +1 -1
- package/dist/schemas/workspace.js +25 -51
- package/dist/schemas.js +2 -6
- package/dist/server.js +286 -176
- package/dist/workspace-plugin.js +1 -1
- package/package.json +13 -19
- package/dist/client.js.map +0 -7
- package/dist/entities/auth/index.js.map +0 -7
- package/dist/entities/auth/schema.js.map +0 -7
- package/dist/entities/history/index.js.map +0 -7
- package/dist/entities/history/schema.js.map +0 -7
- package/dist/events/bus.js.map +0 -7
- package/dist/events/definitions/analytics.js.map +0 -7
- package/dist/events/definitions/auth.js.map +0 -7
- package/dist/events/definitions/common.js.map +0 -7
- package/dist/events/definitions/cookie.js.map +0 -7
- package/dist/events/definitions/document.js.map +0 -7
- package/dist/events/definitions/environment.js.map +0 -7
- package/dist/events/definitions/hooks.js.map +0 -7
- package/dist/events/definitions/index.js.map +0 -7
- package/dist/events/definitions/meta.js.map +0 -7
- package/dist/events/definitions/operation.js.map +0 -7
- package/dist/events/definitions/server.js.map +0 -7
- package/dist/events/definitions/tabs.js.map +0 -7
- package/dist/events/definitions/tag.js.map +0 -7
- package/dist/events/definitions/ui.js.map +0 -7
- package/dist/events/definitions/workspace.js.map +0 -7
- package/dist/events/index.js.map +0 -7
- package/dist/events/listeners.js.map +0 -7
- package/dist/events/old-definitions.js.map +0 -7
- package/dist/helpers/apply-selective-updates.d.ts +0 -19
- package/dist/helpers/apply-selective-updates.d.ts.map +0 -1
- package/dist/helpers/apply-selective-updates.js +0 -37
- package/dist/helpers/apply-selective-updates.js.map +0 -7
- package/dist/helpers/deep-clone.js.map +0 -7
- package/dist/helpers/detect-changes-proxy.js.map +0 -7
- package/dist/helpers/general.js.map +0 -7
- package/dist/helpers/generate-unique-value.js.map +0 -7
- package/dist/helpers/get-fetch.js.map +0 -7
- package/dist/helpers/get-resolved-ref.js.map +0 -7
- package/dist/helpers/is-non-optional-security-requirement.js.map +0 -7
- package/dist/helpers/merge-object.js.map +0 -7
- package/dist/helpers/overrides-proxy.js.map +0 -7
- package/dist/helpers/unpack-proxy.js.map +0 -7
- package/dist/mutators/auth.js.map +0 -7
- package/dist/mutators/cookie.js.map +0 -7
- package/dist/mutators/document.js.map +0 -7
- package/dist/mutators/environment.js.map +0 -7
- package/dist/mutators/helpers.js.map +0 -7
- package/dist/mutators/index.js.map +0 -7
- package/dist/mutators/operation/body.js.map +0 -7
- package/dist/mutators/operation/extensions.js.map +0 -7
- package/dist/mutators/operation/helpers/fetch-request-to-har.js.map +0 -7
- package/dist/mutators/operation/helpers/fetch-response-to-har.js.map +0 -7
- package/dist/mutators/operation/helpers/get-parameter-position.js.map +0 -7
- package/dist/mutators/operation/helpers/har-to-operation.js.map +0 -7
- package/dist/mutators/operation/helpers/sync-path-parameters.js.map +0 -7
- package/dist/mutators/operation/history.js.map +0 -7
- package/dist/mutators/operation/index.js.map +0 -7
- package/dist/mutators/operation/operation.js.map +0 -7
- package/dist/mutators/operation/parameters.js.map +0 -7
- package/dist/mutators/server.js.map +0 -7
- package/dist/mutators/tabs.js.map +0 -7
- package/dist/mutators/tag.js.map +0 -7
- package/dist/mutators/workspace.js.map +0 -7
- package/dist/navigation/get-navigation-options.js.map +0 -7
- package/dist/navigation/helpers/get-openapi-object.js.map +0 -7
- package/dist/navigation/helpers/get-operation-entries.js.map +0 -7
- package/dist/navigation/helpers/get-parent-entry.js.map +0 -7
- package/dist/navigation/helpers/get-tag-entries.js.map +0 -7
- package/dist/navigation/helpers/get-tag.js.map +0 -7
- package/dist/navigation/helpers/get-x-keys.js.map +0 -7
- package/dist/navigation/helpers/traverse-description.js.map +0 -7
- package/dist/navigation/helpers/traverse-document.js.map +0 -7
- package/dist/navigation/helpers/traverse-examples.js.map +0 -7
- package/dist/navigation/helpers/traverse-paths.js.map +0 -7
- package/dist/navigation/helpers/traverse-schemas.js.map +0 -7
- package/dist/navigation/helpers/traverse-tags.js.map +0 -7
- package/dist/navigation/helpers/traverse-webhooks.js.map +0 -7
- package/dist/navigation/helpers/update-order-ids.js.map +0 -7
- package/dist/navigation/helpers/utils.js.map +0 -7
- package/dist/navigation/index.js.map +0 -7
- package/dist/navigation/types.js.map +0 -7
- package/dist/persistence/index.js.map +0 -7
- package/dist/persistence/indexdb.js.map +0 -7
- package/dist/plugins/bundler/helpers.js.map +0 -7
- package/dist/plugins/bundler/index.js.map +0 -7
- package/dist/plugins/client/index.js.map +0 -7
- package/dist/plugins/client/persistence.js.map +0 -7
- package/dist/resolve.js.map +0 -7
- package/dist/schemas/compose.js.map +0 -7
- package/dist/schemas/extensions/document/x-internal.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-environments.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-icon.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-ignore.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-is-dirty.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-original-document-hash.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-registry-meta.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-sdk-installation.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-watch-mode.js.map +0 -7
- package/dist/schemas/extensions/document/x-tags.js.map +0 -7
- package/dist/schemas/extensions/example/x-disabled.js.map +0 -7
- package/dist/schemas/extensions/general/x-scalar-active-environment.js.map +0 -7
- package/dist/schemas/extensions/general/x-scalar-cookies.js.map +0 -7
- package/dist/schemas/extensions/general/x-scalar-order.js.map +0 -7
- package/dist/schemas/extensions/operation/index.js.map +0 -7
- package/dist/schemas/extensions/operation/x-badge.js.map +0 -7
- package/dist/schemas/extensions/operation/x-code-samples.js.map +0 -7
- package/dist/schemas/extensions/operation/x-draft-examples.js.map +0 -7
- package/dist/schemas/extensions/operation/x-post-response.js.map +0 -7
- package/dist/schemas/extensions/operation/x-scalar-disable-parameters.js.map +0 -7
- package/dist/schemas/extensions/operation/x-scalar-selected-content-type.js.map +0 -7
- package/dist/schemas/extensions/operation/x-scalar-stability.js.map +0 -7
- package/dist/schemas/extensions/parameter/x-global.js.map +0 -7
- package/dist/schemas/extensions/schema/x-additional-properties-name.js.map +0 -7
- package/dist/schemas/extensions/schema/x-enum-descriptions.js.map +0 -7
- package/dist/schemas/extensions/schema/x-enum-varnames.js.map +0 -7
- package/dist/schemas/extensions/schema/x-examples.js.map +0 -7
- package/dist/schemas/extensions/schema/x-variable.js.map +0 -7
- package/dist/schemas/extensions/security/index.js.map +0 -7
- package/dist/schemas/extensions/security/x-default-scopes.js.map +0 -7
- package/dist/schemas/extensions/security/x-scalar-credentials-location.js.map +0 -7
- package/dist/schemas/extensions/security/x-scalar-security-body.js.map +0 -7
- package/dist/schemas/extensions/security/x-scalar-security-query.js.map +0 -7
- package/dist/schemas/extensions/security/x-scalar-security-secrets.js.map +0 -7
- package/dist/schemas/extensions/security/x-tokenName.js.map +0 -7
- package/dist/schemas/extensions/security/x-use-pkce.js.map +0 -7
- package/dist/schemas/extensions/server/x-scalar-selected-server.js.map +0 -7
- package/dist/schemas/extensions/tag/index.js.map +0 -7
- package/dist/schemas/extensions/tag/x-display-name.js.map +0 -7
- package/dist/schemas/extensions/tag/x-tag-groups.js.map +0 -7
- package/dist/schemas/extensions/workspace/index.js.map +0 -7
- package/dist/schemas/extensions/workspace/x-scalar-active-proxy.js.map +0 -7
- package/dist/schemas/extensions/workspace/x-scalar-tabs.js.map +0 -7
- package/dist/schemas/extensions.js.map +0 -7
- package/dist/schemas/inmemory-workspace.js.map +0 -7
- package/dist/schemas/navigation.js.map +0 -7
- package/dist/schemas/reference-config/appearance.js.map +0 -7
- package/dist/schemas/reference-config/features.js.map +0 -7
- package/dist/schemas/reference-config/index.js.map +0 -7
- package/dist/schemas/reference-config/meta.js.map +0 -7
- package/dist/schemas/reference-config/routing.js.map +0 -7
- package/dist/schemas/reference-config/settings.js.map +0 -7
- package/dist/schemas/typebox-coerce.js.map +0 -7
- package/dist/schemas/v3.1/strict/callback.js.map +0 -7
- package/dist/schemas/v3.1/strict/components.js.map +0 -7
- package/dist/schemas/v3.1/strict/contact.js.map +0 -7
- package/dist/schemas/v3.1/strict/discriminator.js.map +0 -7
- package/dist/schemas/v3.1/strict/encoding.js.map +0 -7
- package/dist/schemas/v3.1/strict/example.js.map +0 -7
- package/dist/schemas/v3.1/strict/external-documentation.js.map +0 -7
- package/dist/schemas/v3.1/strict/header.js.map +0 -7
- package/dist/schemas/v3.1/strict/info.js.map +0 -7
- package/dist/schemas/v3.1/strict/license.js.map +0 -7
- package/dist/schemas/v3.1/strict/link.js.map +0 -7
- package/dist/schemas/v3.1/strict/media-type.js.map +0 -7
- package/dist/schemas/v3.1/strict/oauth-flow.js.map +0 -7
- package/dist/schemas/v3.1/strict/oauthflows.js.map +0 -7
- package/dist/schemas/v3.1/strict/openapi-document.js.map +0 -7
- package/dist/schemas/v3.1/strict/operation.js.map +0 -7
- package/dist/schemas/v3.1/strict/parameter.js.map +0 -7
- package/dist/schemas/v3.1/strict/path-item.js.map +0 -7
- package/dist/schemas/v3.1/strict/paths.js.map +0 -7
- package/dist/schemas/v3.1/strict/ref-definitions.js.map +0 -7
- package/dist/schemas/v3.1/strict/reference.js.map +0 -7
- package/dist/schemas/v3.1/strict/request-body.js.map +0 -7
- package/dist/schemas/v3.1/strict/response.js.map +0 -7
- package/dist/schemas/v3.1/strict/responses.js.map +0 -7
- package/dist/schemas/v3.1/strict/schema.js.map +0 -7
- package/dist/schemas/v3.1/strict/security-requirement.js.map +0 -7
- package/dist/schemas/v3.1/strict/security-scheme.js.map +0 -7
- package/dist/schemas/v3.1/strict/server-variable.js.map +0 -7
- package/dist/schemas/v3.1/strict/server.js.map +0 -7
- package/dist/schemas/v3.1/strict/tag.js.map +0 -7
- package/dist/schemas/v3.1/strict/type-guards.js.map +0 -7
- package/dist/schemas/v3.1/strict/xml.js.map +0 -7
- package/dist/schemas/workspace-specification/index.js.map +0 -7
- package/dist/schemas/workspace-specification/info.js.map +0 -7
- package/dist/schemas/workspace.js.map +0 -7
- package/dist/schemas.js.map +0 -7
- package/dist/server.js.map +0 -7
- package/dist/workspace-plugin.js.map +0 -7
|
@@ -1,251 +1,360 @@
|
|
|
1
|
-
import { isHttpMethod } from
|
|
2
|
-
import { preventPollution } from
|
|
3
|
-
import { findVariables } from
|
|
4
|
-
import { getResolvedRef } from
|
|
5
|
-
import { unpackProxyObject } from
|
|
6
|
-
import { syncParametersForPathChange } from
|
|
7
|
-
import { getOperationEntries } from
|
|
8
|
-
import { getNavigationOptions } from
|
|
9
|
-
import { updateOrderIds } from
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
1
|
+
import { isHttpMethod } from '@scalar/helpers/http/is-http-method';
|
|
2
|
+
import { preventPollution } from '@scalar/helpers/object/prevent-pollution';
|
|
3
|
+
import { findVariables } from '@scalar/helpers/regex/find-variables';
|
|
4
|
+
import { getResolvedRef } from '../../helpers/get-resolved-ref.js';
|
|
5
|
+
import { unpackProxyObject } from '../../helpers/unpack-proxy.js';
|
|
6
|
+
import { syncParametersForPathChange } from '../../mutators/operation/helpers/sync-path-parameters.js';
|
|
7
|
+
import { getOperationEntries } from '../../navigation/index.js';
|
|
8
|
+
import { getNavigationOptions } from '../../navigation/get-navigation-options.js';
|
|
9
|
+
import { updateOrderIds } from '../../navigation/helpers/update-order-ids.js';
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new operation at a specific path and method in the document.
|
|
12
|
+
* Automatically normalizes the path to ensure it starts with a slash.
|
|
13
|
+
*
|
|
14
|
+
* Returns the normalized path if successful, undefined otherwise.
|
|
15
|
+
*
|
|
16
|
+
* Example:
|
|
17
|
+
* ```ts
|
|
18
|
+
* createOperation(
|
|
19
|
+
* document,
|
|
20
|
+
* 'users',
|
|
21
|
+
* 'get',
|
|
22
|
+
* { tags: ['Users'] },
|
|
23
|
+
* )
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export const createOperation = (workspaceStore, payload) => {
|
|
27
|
+
const document = workspaceStore?.workspace.documents[payload.documentName];
|
|
28
|
+
if (!document) {
|
|
29
|
+
payload.callback?.(false);
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const { path, method, operation } = payload;
|
|
33
|
+
/** Ensure the path starts with a slash */
|
|
34
|
+
const normalizedPath = path.startsWith('/') ? path : `/${path}`;
|
|
35
|
+
/** Create the operation in the document */
|
|
36
|
+
if (!document.paths) {
|
|
37
|
+
document.paths = {};
|
|
38
|
+
}
|
|
39
|
+
if (!document.paths[normalizedPath]) {
|
|
40
|
+
document.paths[normalizedPath] = {};
|
|
41
|
+
}
|
|
42
|
+
/** Prevent pollution of the path and method */
|
|
43
|
+
preventPollution(normalizedPath);
|
|
44
|
+
preventPollution(method);
|
|
45
|
+
/** Create the operation in the document */
|
|
46
|
+
document.paths[normalizedPath][method] = operation;
|
|
47
|
+
// Make sure that we are selecting the new operation server
|
|
48
|
+
const { servers } = operation;
|
|
49
|
+
const firstServer = unpackProxyObject(servers?.[0]);
|
|
50
|
+
// For now we only support document servers but in the future we might support operation servers
|
|
51
|
+
for (const server of servers ?? []) {
|
|
52
|
+
// If the server does not exist in the document, add it
|
|
53
|
+
if (!document.servers?.some((s) => s.url === server.url)) {
|
|
54
|
+
if (!document.servers) {
|
|
55
|
+
document.servers = [];
|
|
56
|
+
}
|
|
57
|
+
document.servers.push(unpackProxyObject(server));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Update the selected server to the first server of the created operation
|
|
61
|
+
if (firstServer) {
|
|
62
|
+
document['x-scalar-selected-server'] = firstServer.url;
|
|
63
|
+
}
|
|
64
|
+
const existingParameters = operation.parameters;
|
|
65
|
+
// Sync path variables
|
|
66
|
+
const result = syncParametersForPathChange(normalizedPath, normalizedPath, existingParameters ?? [], getResolvedRef);
|
|
67
|
+
if (existingParameters !== undefined || result.length > 0) {
|
|
68
|
+
operation.parameters = result;
|
|
69
|
+
}
|
|
70
|
+
payload.callback?.(true);
|
|
71
|
+
return normalizedPath;
|
|
63
72
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
);
|
|
94
|
-
if (oldPathParams.length > 0 || newPathParams.length > 0) {
|
|
95
|
-
const existingParameters = operation.parameters ?? [];
|
|
96
|
-
const result = syncParametersForPathChange(finalPath, meta.path, existingParameters, getResolvedRef);
|
|
97
|
-
operation.parameters = result;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const { generateId } = getNavigationOptions(documentNavigation.name);
|
|
101
|
-
const operationEntriesMap = getOperationEntries(documentNavigation);
|
|
102
|
-
const entries = operationEntriesMap.get(`${meta.path}|${meta.method}`);
|
|
103
|
-
if (entries) {
|
|
104
|
-
updateOrderIds({ store, operation, generateId, method: finalMethod, path: finalPath, entries });
|
|
105
|
-
}
|
|
106
|
-
if (!document.paths) {
|
|
107
|
-
document.paths = {};
|
|
108
|
-
}
|
|
109
|
-
if (!document.paths[finalPath]) {
|
|
110
|
-
document.paths[finalPath] = {};
|
|
111
|
-
}
|
|
112
|
-
preventPollution(finalPath);
|
|
113
|
-
preventPollution(meta.path);
|
|
114
|
-
preventPollution(finalMethod);
|
|
115
|
-
document.paths[finalPath][finalMethod] = unpackProxyObject(operation);
|
|
116
|
-
const oldPathItems = document.paths[meta.path];
|
|
117
|
-
if (oldPathItems && isHttpMethod(meta.method)) {
|
|
118
|
-
delete oldPathItems[meta.method];
|
|
119
|
-
if (Object.keys(oldPathItems).length === 0) {
|
|
120
|
-
delete document.paths[meta.path];
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
store.history.clearOperationHistory(document["x-scalar-navigation"]?.name ?? "", meta.path, meta.method);
|
|
124
|
-
callback("success");
|
|
73
|
+
/**
|
|
74
|
+
* Updates the `description` of an operation.
|
|
75
|
+
* Safely no-ops if the document or operation does not exist.
|
|
76
|
+
*
|
|
77
|
+
* Example:
|
|
78
|
+
* ```ts
|
|
79
|
+
* updateOperationDescription(
|
|
80
|
+
* document,
|
|
81
|
+
* { meta: { method: 'get', path: '/users' }, payload: { description: 'Get a single user' },
|
|
82
|
+
* })
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export const updateOperationMeta = (store, document, { meta, payload }) => {
|
|
86
|
+
if (!document || !store) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const documentName = document['x-scalar-navigation']?.name;
|
|
90
|
+
if (documentName === undefined) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
|
|
94
|
+
if (!operation) {
|
|
95
|
+
console.error('Operation not found', { meta, document });
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
// Update the description of the operation
|
|
99
|
+
Object.assign(operation, payload);
|
|
100
|
+
// Rebuild the sidebar to reflect the cahnges
|
|
101
|
+
store.buildSidebar(documentName);
|
|
125
102
|
};
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Updates the HTTP method and/or path of an operation and moves it to the new location.
|
|
105
|
+
* This function:
|
|
106
|
+
* 1. Moves the operation from the old method/path to the new method/path under paths
|
|
107
|
+
* 2. Updates x-scalar-order to maintain the operation's position in the sidebar
|
|
108
|
+
* 3. Syncs path parameters when the path changes
|
|
109
|
+
*
|
|
110
|
+
* Safely no-ops if nothing has changed, or if the document or operation does not exist.
|
|
111
|
+
*
|
|
112
|
+
* Example:
|
|
113
|
+
* ```ts
|
|
114
|
+
* updateOperationPathMethod({
|
|
115
|
+
* document,
|
|
116
|
+
* store,
|
|
117
|
+
* meta: { method: 'get', path: '/users' },
|
|
118
|
+
* payload: { method: 'post', path: '/api/users' },
|
|
119
|
+
* })
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export const updateOperationPathMethod = (document, store, { meta, payload: { method, path }, callback }) => {
|
|
123
|
+
const methodChanged = meta.method !== method;
|
|
124
|
+
const pathChanged = meta.path !== path;
|
|
125
|
+
// If nothing has changed, no need to do anything
|
|
126
|
+
if (!methodChanged && !pathChanged) {
|
|
127
|
+
callback('no-change');
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
// Determine the final method and path
|
|
131
|
+
const finalMethod = methodChanged ? method : meta.method;
|
|
132
|
+
const finalPath = pathChanged ? path : meta.path;
|
|
133
|
+
// Check for conflicts at the target location
|
|
134
|
+
if (document?.paths?.[finalPath]?.[finalMethod]) {
|
|
135
|
+
callback('conflict');
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const documentNavigation = document?.['x-scalar-navigation'];
|
|
139
|
+
if (!documentNavigation || !store) {
|
|
140
|
+
console.error('Document or workspace not found', { document });
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
|
|
144
|
+
if (!operation) {
|
|
145
|
+
console.error('Operation not found', { meta, document });
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
// Sync path parameters if the path has changed
|
|
149
|
+
if (pathChanged) {
|
|
150
|
+
const oldPathParams = findVariables(meta.path, { includePath: true, includeEnv: false }).filter((v) => v !== undefined);
|
|
151
|
+
const newPathParams = findVariables(finalPath, { includePath: true, includeEnv: false }).filter((v) => v !== undefined);
|
|
152
|
+
if (oldPathParams.length > 0 || newPathParams.length > 0) {
|
|
153
|
+
const existingParameters = operation.parameters ?? [];
|
|
154
|
+
const result = syncParametersForPathChange(finalPath, meta.path, existingParameters, getResolvedRef);
|
|
155
|
+
operation.parameters = result;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* We don't pass navigation options as we don't have config on the client,
|
|
160
|
+
* and we don't change path or method on the references
|
|
161
|
+
*/
|
|
162
|
+
const { generateId } = getNavigationOptions(documentNavigation.name);
|
|
163
|
+
/** Grabs all of the current operation entries for the given path and method */
|
|
164
|
+
const operationEntriesMap = getOperationEntries(documentNavigation);
|
|
165
|
+
const entries = operationEntriesMap.get(`${meta.path}|${meta.method}`);
|
|
166
|
+
// Updates the order ID so we don't lose the sidebar ordering when it rebuilds
|
|
167
|
+
if (entries) {
|
|
168
|
+
updateOrderIds({ store, operation, generateId, method: finalMethod, path: finalPath, entries });
|
|
169
|
+
}
|
|
170
|
+
// Initialize the paths object if it does not exist
|
|
171
|
+
if (!document.paths) {
|
|
172
|
+
document.paths = {};
|
|
173
|
+
}
|
|
174
|
+
// Initialize the new path if it does not exist
|
|
175
|
+
if (!document.paths[finalPath]) {
|
|
176
|
+
document.paths[finalPath] = {};
|
|
177
|
+
}
|
|
178
|
+
// Prevent assigning dangerous keys to the path items object
|
|
179
|
+
preventPollution(finalPath);
|
|
180
|
+
preventPollution(meta.path);
|
|
181
|
+
preventPollution(finalMethod);
|
|
182
|
+
// Move the operation to the new location
|
|
183
|
+
document.paths[finalPath][finalMethod] = unpackProxyObject(operation);
|
|
184
|
+
// Remove the operation from the old location
|
|
185
|
+
const oldPathItems = document.paths[meta.path];
|
|
186
|
+
if (oldPathItems && isHttpMethod(meta.method)) {
|
|
187
|
+
delete oldPathItems[meta.method];
|
|
188
|
+
// If the old path has no more operations, remove the path entry
|
|
189
|
+
if (Object.keys(oldPathItems).length === 0) {
|
|
190
|
+
delete document.paths[meta.path];
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
// We need to reset the history for the operation when the path or method changes
|
|
194
|
+
store.history.clearOperationHistory(document['x-scalar-navigation']?.name ?? '', meta.path, meta.method);
|
|
195
|
+
callback('success');
|
|
137
196
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
197
|
+
/**
|
|
198
|
+
* Deletes an operation from the workspace
|
|
199
|
+
*
|
|
200
|
+
* Example:
|
|
201
|
+
* ```ts
|
|
202
|
+
* deleteOperation({
|
|
203
|
+
* document,
|
|
204
|
+
* meta: { method: 'get', path: '/users' },
|
|
205
|
+
* })
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
export const deleteOperation = (workspace, { meta, documentName }) => {
|
|
209
|
+
const document = workspace?.workspace.documents[documentName];
|
|
210
|
+
if (!document) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
preventPollution(meta.path);
|
|
214
|
+
preventPollution(meta.method);
|
|
215
|
+
delete document.paths?.[meta.path]?.[meta.method];
|
|
216
|
+
// If the path has no more operations, remove the path entry
|
|
217
|
+
if (Object.keys(document.paths?.[meta.path] ?? {}).length === 0) {
|
|
218
|
+
delete document.paths?.[meta.path];
|
|
219
|
+
}
|
|
153
220
|
};
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (!requestBody) {
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
Object.values(requestBody.content ?? {}).forEach((mediaType) => {
|
|
184
|
-
delete mediaType.examples?.[exampleKey];
|
|
185
|
-
});
|
|
221
|
+
/**
|
|
222
|
+
* Adds an example name to the 'x-draft-examples' array for a specific operation in a document.
|
|
223
|
+
*
|
|
224
|
+
* - Finds the target operation using the provided path and method within the specified document.
|
|
225
|
+
* - If the operation is found and has an 'x-draft-examples' array, pushes the new exampleName to it.
|
|
226
|
+
* - Safely no-ops if the document or operation does not exist.
|
|
227
|
+
*/
|
|
228
|
+
export const createOperationDraftExample = (workspace, { meta: { path, method }, documentName, exampleName }) => {
|
|
229
|
+
const document = workspace?.workspace.documents[documentName];
|
|
230
|
+
if (!document) {
|
|
231
|
+
console.error('Document not found', { documentName });
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const operation = getResolvedRef(document.paths?.[path]?.[method]);
|
|
235
|
+
if (!operation) {
|
|
236
|
+
console.error('Operation not found', { path, method });
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
// Ensure that the x-draft-examples array exists
|
|
240
|
+
operation['x-draft-examples'] ??= [];
|
|
241
|
+
// Remove duplicates
|
|
242
|
+
const dedupe = new Set(operation['x-draft-examples']);
|
|
243
|
+
// Add the new example name
|
|
244
|
+
dedupe.add(exampleName);
|
|
245
|
+
// Update the operation with the new x-draft-examples array
|
|
246
|
+
operation['x-draft-examples'] = Array.from(dedupe);
|
|
186
247
|
};
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
248
|
+
/**
|
|
249
|
+
* Deletes an example with the given exampleKey from operation parameters and request body.
|
|
250
|
+
*
|
|
251
|
+
* - Finds the target operation within the specified document and path/method.
|
|
252
|
+
* - Removes example values matching exampleKey from both parameter-level and content-level examples.
|
|
253
|
+
* - Safely no-ops if the document, operation, or request body does not exist.
|
|
254
|
+
*/
|
|
255
|
+
export const deleteOperationExample = (workspace, { meta: { path, method, exampleKey }, documentName }) => {
|
|
256
|
+
// Find the document in workspace based on documentName
|
|
257
|
+
const document = workspace?.workspace.documents[documentName];
|
|
258
|
+
if (!document) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
// Get the operation object for the given path and method
|
|
262
|
+
const operation = getResolvedRef(document.paths?.[path]?.[method]);
|
|
263
|
+
if (!operation) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
// Remove the example from the x-draft-examples array
|
|
267
|
+
const dedupe = new Set(operation['x-draft-examples'] ?? []);
|
|
268
|
+
dedupe.delete(exampleKey);
|
|
269
|
+
if (operation['x-draft-examples'] !== undefined) {
|
|
270
|
+
operation['x-draft-examples'] = Array.from(dedupe);
|
|
271
|
+
}
|
|
272
|
+
// Remove the example from all operation parameters
|
|
273
|
+
operation.parameters?.forEach((parameter) => {
|
|
274
|
+
const resolvedParameter = getResolvedRef(parameter);
|
|
275
|
+
// Remove from content-level examples (if parameter uses content)
|
|
276
|
+
if ('content' in resolvedParameter && resolvedParameter.content) {
|
|
277
|
+
Object.values(resolvedParameter.content).forEach((mediaType) => {
|
|
278
|
+
delete mediaType.examples?.[exampleKey];
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
// Remove from parameter-level examples
|
|
282
|
+
if ('examples' in resolvedParameter && resolvedParameter.examples) {
|
|
283
|
+
delete resolvedParameter.examples?.[exampleKey];
|
|
211
284
|
}
|
|
212
|
-
|
|
285
|
+
});
|
|
286
|
+
// Remove the example from request body content types (if requestBody exists)
|
|
287
|
+
const requestBody = getResolvedRef(operation.requestBody);
|
|
288
|
+
if (!requestBody) {
|
|
289
|
+
return;
|
|
213
290
|
}
|
|
214
|
-
|
|
215
|
-
const requestBody = getResolvedRef(operation.requestBody);
|
|
216
|
-
if (requestBody) {
|
|
291
|
+
// For each media type, remove the example matching exampleKey
|
|
217
292
|
Object.values(requestBody.content ?? {}).forEach((mediaType) => {
|
|
218
|
-
|
|
219
|
-
records.push(mediaType.examples);
|
|
220
|
-
}
|
|
293
|
+
delete mediaType.examples?.[exampleKey];
|
|
221
294
|
});
|
|
222
|
-
if (requestBody["x-scalar-selected-content-type"]) {
|
|
223
|
-
records.push(requestBody["x-scalar-selected-content-type"]);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
if (operation["x-draft-examples"]?.includes(nextExampleName) || records.some((record) => Object.hasOwn(record, nextExampleName))) {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
if (operation["x-draft-examples"]) {
|
|
230
|
-
operation["x-draft-examples"] = operation["x-draft-examples"].map(
|
|
231
|
-
(name) => name === exampleKey ? nextExampleName : name
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
records.forEach((record) => {
|
|
235
|
-
if (!Object.hasOwn(record, exampleKey)) {
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
record[nextExampleName] = unpackProxyObject(record[exampleKey]);
|
|
239
|
-
delete record[exampleKey];
|
|
240
|
-
});
|
|
241
295
|
};
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
296
|
+
/**
|
|
297
|
+
* Renames an example key for an operation across all operation-level example containers:
|
|
298
|
+
* - `x-draft-examples`
|
|
299
|
+
* - parameter-level examples
|
|
300
|
+
* - parameter content-level examples
|
|
301
|
+
* - request-body content examples
|
|
302
|
+
* - request-body selected-content-type map
|
|
303
|
+
*
|
|
304
|
+
* If the target example name already exists in any container, this is a no-op to avoid
|
|
305
|
+
* accidental data overwrites.
|
|
306
|
+
*/
|
|
307
|
+
export const renameOperationExample = (workspace, { meta: { path, method, exampleKey }, documentName, payload }) => {
|
|
308
|
+
const document = workspace?.workspace.documents[documentName];
|
|
309
|
+
if (!document) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
const operation = getResolvedRef(document.paths?.[path]?.[method]);
|
|
313
|
+
if (!operation) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const nextExampleName = payload.name.trim();
|
|
317
|
+
if (!nextExampleName || nextExampleName === exampleKey) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
preventPollution(nextExampleName);
|
|
321
|
+
const records = [];
|
|
322
|
+
operation.parameters?.forEach((parameter) => {
|
|
323
|
+
const resolvedParameter = getResolvedRef(parameter);
|
|
324
|
+
if ('examples' in resolvedParameter && resolvedParameter.examples) {
|
|
325
|
+
records.push(resolvedParameter.examples);
|
|
326
|
+
}
|
|
327
|
+
if ('content' in resolvedParameter && resolvedParameter.content) {
|
|
328
|
+
Object.values(resolvedParameter.content).forEach((mediaType) => {
|
|
329
|
+
if (mediaType.examples) {
|
|
330
|
+
records.push(mediaType.examples);
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
const requestBody = getResolvedRef(operation.requestBody);
|
|
336
|
+
if (requestBody) {
|
|
337
|
+
Object.values(requestBody.content ?? {}).forEach((mediaType) => {
|
|
338
|
+
if (mediaType.examples) {
|
|
339
|
+
records.push(mediaType.examples);
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
if (requestBody['x-scalar-selected-content-type']) {
|
|
343
|
+
records.push(requestBody['x-scalar-selected-content-type']);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (operation['x-draft-examples']?.includes(nextExampleName) ||
|
|
347
|
+
records.some((record) => Object.hasOwn(record, nextExampleName))) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
if (operation['x-draft-examples']) {
|
|
351
|
+
operation['x-draft-examples'] = operation['x-draft-examples'].map((name) => name === exampleKey ? nextExampleName : name);
|
|
352
|
+
}
|
|
353
|
+
records.forEach((record) => {
|
|
354
|
+
if (!Object.hasOwn(record, exampleKey)) {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
record[nextExampleName] = unpackProxyObject(record[exampleKey]);
|
|
358
|
+
delete record[exampleKey];
|
|
359
|
+
});
|
|
250
360
|
};
|
|
251
|
-
//# sourceMappingURL=operation.js.map
|