@scalar/workspace-store 0.71.1 → 0.73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/client.d.ts +8 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +90 -30
- package/dist/entities/auth/schema.d.ts +100 -20
- package/dist/entities/auth/schema.d.ts.map +1 -1
- package/dist/mutators/auth.d.ts.map +1 -1
- package/dist/navigation/helpers/traverse-plugin-document.d.ts +11 -0
- package/dist/navigation/helpers/traverse-plugin-document.d.ts.map +1 -0
- package/dist/navigation/helpers/traverse-plugin-document.js +24 -0
- package/dist/navigation/helpers/update-order-ids.d.ts.map +1 -1
- package/dist/navigation/helpers/update-order-ids.js +2 -1
- package/dist/navigation/index.d.ts +1 -0
- package/dist/navigation/index.d.ts.map +1 -1
- package/dist/navigation/index.js +1 -0
- package/dist/plugins/bundler/code-sample-sources.d.ts +10 -0
- package/dist/plugins/bundler/code-sample-sources.d.ts.map +1 -0
- package/dist/plugins/bundler/code-sample-sources.js +174 -0
- package/dist/plugins/bundler/openapi-document.d.ts.map +1 -1
- package/dist/plugins/bundler/openapi-document.js +2 -4
- package/dist/schemas/extensions/operation/x-code-samples.d.ts +31 -10
- package/dist/schemas/extensions/operation/x-code-samples.d.ts.map +1 -1
- package/dist/schemas/extensions/operation/x-code-samples.js +2 -2
- package/dist/schemas/navigation.d.ts +32 -1
- package/dist/schemas/navigation.d.ts.map +1 -1
- package/dist/schemas/navigation.js +7 -0
- package/dist/schemas/plugin-document.d.ts +67 -0
- package/dist/schemas/plugin-document.d.ts.map +1 -0
- package/dist/schemas/plugin-document.js +20 -0
- package/dist/schemas/reference-config/index.d.ts +20 -4
- package/dist/schemas/reference-config/index.d.ts.map +1 -1
- package/dist/schemas/reference-config/settings.d.ts +20 -4
- package/dist/schemas/reference-config/settings.d.ts.map +1 -1
- package/dist/schemas/type-guards.d.ts +4 -2
- package/dist/schemas/type-guards.d.ts.map +1 -1
- package/dist/schemas/type-guards.js +7 -4
- package/dist/schemas/v3.1/strict/openapi-document.d.ts +700 -140
- package/dist/schemas/v3.1/strict/openapi-document.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/operation.d.ts +12 -4
- package/dist/schemas/v3.1/strict/operation.d.ts.map +1 -1
- package/dist/schemas/v3.2/strict/openapi-document.d.ts +700 -140
- package/dist/schemas/v3.2/strict/openapi-document.d.ts.map +1 -1
- package/dist/schemas/v3.2/strict/operation.d.ts +12 -4
- package/dist/schemas/v3.2/strict/operation.d.ts.map +1 -1
- package/dist/schemas/workspace.d.ts +2 -1
- package/dist/schemas/workspace.d.ts.map +1 -1
- package/dist/schemas.d.ts +1 -0
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +1 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +13 -3
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @scalar/workspace-store
|
|
2
2
|
|
|
3
|
+
## 0.73.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#10816](https://github.com/scalar/scalar/pull/10816): Add `documentTypes` to `createWorkspaceStore`, so the store can ingest document formats it does not support natively. A registered type claims a document before the OpenAPI and AsyncAPI pipelines run, and the store keeps it as an opaque plugin document with `plugin` navigation entries built by the type.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#10816](https://github.com/scalar/scalar/pull/10816): Keep plugin document classification consistent through replacement, hydration, and rebasing. Exclude plugin documents from Ask AI and reject unsupported request, authentication, and mock-server processing even when plugin data contains OpenAPI or AsyncAPI fields.
|
|
12
|
+
- [#10983](https://github.com/scalar/scalar/pull/10983): Preserve literal $ref values in AsyncAPI examples, schema values, and extensions during initial loading and lazy resolution without fetching them. Index authored document keys without following virtual proxy links. Keep wrapper resolution independent of key order and ignore reference siblings in AsyncAPI parameter schemas and wrapped OpenAPI 3.0 and draft-04/06 schemas, including identifiers and anchors in those ignored siblings. Traverse only schema and identity keywords supported by the wrapped format so unknown keyword values stay literal, including draft-04 `id` and draft-06/07 `$id` handling.
|
|
13
|
+
- [#10983](https://github.com/scalar/scalar/pull/10983): Resolve references inside AsyncAPI Multi Format Schema Objects and OpenAPI 3.2 media type `itemSchema` fields while preserving literal schema values. Keep `schemaFormat` and `schema` annotations in ordinary JSON Schema objects as literal data. Resolve native AsyncAPI schema `externalDocs` and tuple `additionalItems` references without processing ordinary JSON Schema annotations. Preserve schema contexts inside AsyncAPI protocol bindings. Resolve named AsyncAPI servers, variables, and reusable components even when their names match literal-data keywords. Ignore reference siblings in native AsyncAPI and draft-07 schemas.
|
|
14
|
+
|
|
15
|
+
## 0.72.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- [#11037](https://github.com/scalar/scalar/pull/11037): Load object-valued `x-codeSamples.source` and `x-code-samples.source` file references as raw code text, with relative origins and lazy operation loading. Retain failed references and show an unavailable sample instead of silently replacing them with an empty string. Preserve literal `$ref` values in other extensions and example data.
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- [#10998](https://github.com/scalar/scalar/pull/10998): Reuse the discovery response when importing extensionless API description URLs, avoiding a duplicate download while preserving URL metadata and subsequent fetches.
|
|
24
|
+
|
|
3
25
|
## 0.71.1
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/dist/client.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { OperationMeta } from './events/definitions/operation.js';
|
|
|
7
7
|
import { type ExternalExampleResolver } from './helpers/external-examples.js';
|
|
8
8
|
import type { NavigationOptions } from './navigation/get-navigation-options.js';
|
|
9
9
|
import type { InMemoryWorkspace } from './schemas/inmemory-workspace.js';
|
|
10
|
+
import { type DocumentTypeDefinition } from './schemas/plugin-document.js';
|
|
10
11
|
import type { RequestBodyObject } from './schemas/v3.2/strict/openapi-document.js';
|
|
11
12
|
import { type OpenApiDocument } from './schemas/v3.2/strict/openapi-document.js';
|
|
12
13
|
import type { DocumentMetaExtensions, Workspace, WorkspaceDocument, WorkspaceDocumentMeta, WorkspaceExtensions, WorkspaceMeta } from './schemas/workspace.js';
|
|
@@ -33,6 +34,8 @@ type WorkspaceDocumentMetaInput = {
|
|
|
33
34
|
export type UrlDoc = {
|
|
34
35
|
/** URL to fetch the OpenAPI document from */
|
|
35
36
|
url: string;
|
|
37
|
+
/** Already fetched response for this URL. Its body is consumed instead of fetching the initial document. */
|
|
38
|
+
response?: Response;
|
|
36
39
|
} & WorkspaceDocumentMetaInput;
|
|
37
40
|
/**
|
|
38
41
|
* Represents a document that is loaded from a URL.
|
|
@@ -73,6 +76,11 @@ type WorkspaceProps = {
|
|
|
73
76
|
plugins?: WorkspacePlugin[];
|
|
74
77
|
/** A file loader plugin for resolving local file references (for non browser environments) */
|
|
75
78
|
fileLoader?: LoaderPlugin;
|
|
79
|
+
/**
|
|
80
|
+
* Document formats the store does not support natively. Each one is checked, in order, before the
|
|
81
|
+
* built-in OpenAPI and AsyncAPI pipelines.
|
|
82
|
+
*/
|
|
83
|
+
documentTypes?: readonly DocumentTypeDefinition[];
|
|
76
84
|
/**
|
|
77
85
|
* Whether writes to the workspace are observable. Defaults to `true`.
|
|
78
86
|
*
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,YAAY,EAAU,MAAM,2BAA2B,CAAA;AAErE,OAAO,EAAE,KAAK,UAAU,EAAe,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAQ7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAI5C,OAAO,EAAE,KAAK,SAAS,EAAmB,MAAM,iBAAiB,CAAA;AACjE,OAAO,EAAE,KAAK,YAAY,EAAsB,MAAM,oBA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 +32,11 @@ import { createOverridesProxy } from './helpers/overrides-proxy.js';
|
|
|
32
32
|
import { resolveSecurityRequirements, restoreSecurityRequirements } from './helpers/resolve-security-requirements.js';
|
|
33
33
|
import { snapshotRequestBodies } from './helpers/snapshot-request-bodies.js';
|
|
34
34
|
import { unpackProxyObject } from './helpers/unpack-proxy.js';
|
|
35
|
-
import { createNavigation, traverseAsyncApiDocument } from './navigation/index.js';
|
|
35
|
+
import { createNavigation, traverseAsyncApiDocument, traversePluginDocument } from './navigation/index.js';
|
|
36
36
|
import { externalValueResolver, loadingStatus, normalizeAuthSchemes, normalizeRefs, openApiDocument, refsEverywhere, removeExtraScalarKeys, resolveOpenApiDocument, restoreOriginalRefs, syncPathParameters, } from './plugins/bundler/index.js';
|
|
37
|
+
import { codeSampleSources } from './plugins/bundler/code-sample-sources.js';
|
|
37
38
|
import { extensions } from './schemas/extensions.js';
|
|
39
|
+
import { PLUGIN_DOCUMENT_TYPE_KEY, findDocumentType, } from './schemas/plugin-document.js';
|
|
38
40
|
import { isAsyncApiDocument, isOpenApiDocument } from './schemas/type-guards.js';
|
|
39
41
|
import { generateSchema } from './schemas/v3.2/openapi/index.js';
|
|
40
42
|
import { recursiveRef } from './schemas/v3.2/openapi/reference.js';
|
|
@@ -67,7 +69,10 @@ const EXTERNAL_FETCH_CONCURRENCY_LIMIT = 10;
|
|
|
67
69
|
*/
|
|
68
70
|
function loadDocument(workspaceDocument) {
|
|
69
71
|
if ('url' in workspaceDocument) {
|
|
70
|
-
|
|
72
|
+
const response = workspaceDocument.response;
|
|
73
|
+
return fetchUrls({
|
|
74
|
+
fetch: response ? () => Promise.resolve(response) : workspaceDocument.fetch,
|
|
75
|
+
}).exec(workspaceDocument.url);
|
|
71
76
|
}
|
|
72
77
|
if ('path' in workspaceDocument) {
|
|
73
78
|
const loader = workspaceDocument.fileLoader;
|
|
@@ -105,7 +110,11 @@ const getDocumentSource = (input) => {
|
|
|
105
110
|
if ('path' in input) {
|
|
106
111
|
return input.path;
|
|
107
112
|
}
|
|
108
|
-
|
|
113
|
+
if ('document' in input) {
|
|
114
|
+
const originalSource = input.document['x-scalar-original-source-url'];
|
|
115
|
+
return input.documentSource ?? (typeof originalSource === 'string' ? originalSource : undefined);
|
|
116
|
+
}
|
|
117
|
+
return undefined;
|
|
109
118
|
};
|
|
110
119
|
const openapiSchema = generateSchema(recursiveRef);
|
|
111
120
|
/**
|
|
@@ -149,6 +158,7 @@ const purgeInternalDocumentKeys = (input) => {
|
|
|
149
158
|
'x-scalar-original-document-hash',
|
|
150
159
|
'x-scalar-original-source-url',
|
|
151
160
|
'x-scalar-registry-meta',
|
|
161
|
+
PLUGIN_DOCUMENT_TYPE_KEY,
|
|
152
162
|
];
|
|
153
163
|
// Remove top-level properties that should only exist temporarily or for internal usage
|
|
154
164
|
// These properties are used for internal purposes and are not needed in the final bundled document
|
|
@@ -482,6 +492,16 @@ export const createWorkspaceStore = (workspaceProps) => {
|
|
|
482
492
|
activeDocument['x-scalar-is-dirty'] = false;
|
|
483
493
|
return true;
|
|
484
494
|
};
|
|
495
|
+
/** The placeholder shown for a document that could not be loaded. */
|
|
496
|
+
const createLoadFailedDocument = (name, meta) => ({
|
|
497
|
+
...meta,
|
|
498
|
+
openapi: '3.1.0',
|
|
499
|
+
info: {
|
|
500
|
+
title: `Document '${name}' could not be loaded`,
|
|
501
|
+
version: 'unknown',
|
|
502
|
+
},
|
|
503
|
+
'x-scalar-original-document-hash': 'not-a-hash',
|
|
504
|
+
});
|
|
485
505
|
// Add a document to the store synchronously from an in-memory OpenAPI or AsyncAPI document
|
|
486
506
|
async function addInMemoryDocument(input, navigationOptions) {
|
|
487
507
|
const { name } = input;
|
|
@@ -491,6 +511,9 @@ export const createWorkspaceStore = (workspaceProps) => {
|
|
|
491
511
|
// else reads it, so every step below — including the check for a server-generated navigation —
|
|
492
512
|
// sees the document a non-compact server store would have sent.
|
|
493
513
|
withMeasurementSync('expandChunkIndex', () => expandChunkIndex(clonedRawInputDocument));
|
|
514
|
+
// The marker belongs to the store, never the source. Remove it before capturing the saved
|
|
515
|
+
// baseline so an export before the first save cannot leak it or misclassify the document.
|
|
516
|
+
delete clonedRawInputDocument[PLUGIN_DOCUMENT_TYPE_KEY];
|
|
494
517
|
withMeasurementSync('initialize', () => {
|
|
495
518
|
if (input.initialize !== false) {
|
|
496
519
|
// Store the original document in the originalDocuments map
|
|
@@ -522,6 +545,46 @@ export const createWorkspaceStore = (workspaceProps) => {
|
|
|
522
545
|
if (workspaceProps?.fileLoader) {
|
|
523
546
|
loaders.push(workspaceProps.fileLoader);
|
|
524
547
|
}
|
|
548
|
+
// Registered document types come first, so a format they claim never reaches the OpenAPI
|
|
549
|
+
// upgrade and coercion below (which would turn it into a broken OpenAPI document).
|
|
550
|
+
const documentType = findDocumentType(workspaceProps?.documentTypes, clonedRawInputDocument);
|
|
551
|
+
if (documentType) {
|
|
552
|
+
// Third-party code runs here, so a failure ends up as the usual "could not be loaded" document
|
|
553
|
+
// instead of leaving the workspace without this document.
|
|
554
|
+
try {
|
|
555
|
+
const ingestedDocument = await withMeasurementAsync('ingest', async () => (await documentType.ingest?.(deepClone(clonedRawInputDocument), { documentName: name })) ??
|
|
556
|
+
clonedRawInputDocument);
|
|
557
|
+
const pluginDocument = createMagicProxy({
|
|
558
|
+
...ingestedDocument,
|
|
559
|
+
info: isObject(ingestedDocument.info) ? ingestedDocument.info : {},
|
|
560
|
+
...meta,
|
|
561
|
+
[PLUGIN_DOCUMENT_TYPE_KEY]: documentType.type,
|
|
562
|
+
'x-scalar-original-document-hash': input.documentHash,
|
|
563
|
+
'x-scalar-original-source-url': input.documentSource,
|
|
564
|
+
});
|
|
565
|
+
if (documentType.bundle && pluginDocument[extensions.document.navigation] === undefined) {
|
|
566
|
+
await withMeasurementAsync('bundle', async () => await bundle(getRaw(pluginDocument), {
|
|
567
|
+
treeShake: false,
|
|
568
|
+
plugins: loaders,
|
|
569
|
+
urlMap: true,
|
|
570
|
+
origin: input.documentSource,
|
|
571
|
+
}));
|
|
572
|
+
}
|
|
573
|
+
if (pluginDocument[extensions.document.navigation] === undefined) {
|
|
574
|
+
pluginDocument[extensions.document.navigation] = traversePluginDocument(name, pluginDocument, documentType, navigationOptions);
|
|
575
|
+
}
|
|
576
|
+
const pluginOverrides = unpackProxyObject(overrides[name]);
|
|
577
|
+
workspace.documents[name] = needsOverridesProxy(pluginOverrides)
|
|
578
|
+
? createOverridesProxy(pluginDocument, { overrides: pluginOverrides })
|
|
579
|
+
: pluginDocument;
|
|
580
|
+
return true;
|
|
581
|
+
}
|
|
582
|
+
catch (error) {
|
|
583
|
+
console.error(`Failed to load document '${name}' with document type '${documentType.type}':`, error);
|
|
584
|
+
workspace.documents[name] = createLoadFailedDocument(name, meta);
|
|
585
|
+
return false;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
525
588
|
// AsyncAPI ingestion: skip the OpenAPI-specific upgrade and validation pipeline.
|
|
526
589
|
// The OpenAPI `coerce` step would otherwise inject an empty `openapi: ''` field
|
|
527
590
|
// and break the type discriminator. We still run the AsyncAPI-specific upgrader so
|
|
@@ -542,6 +605,7 @@ export const createWorkspaceStore = (workspaceProps) => {
|
|
|
542
605
|
});
|
|
543
606
|
if (asyncApiDocument[extensions.document.navigation] === undefined) {
|
|
544
607
|
await withMeasurementAsync('bundle', async () => await bundle(getRaw(asyncApiDocument), {
|
|
608
|
+
traversal: 'document',
|
|
545
609
|
treeShake: false,
|
|
546
610
|
plugins: loaders,
|
|
547
611
|
urlMap: true,
|
|
@@ -558,11 +622,13 @@ export const createWorkspaceStore = (workspaceProps) => {
|
|
|
558
622
|
workspace.documents[name] = needsOverridesProxy(asyncApiOverrides)
|
|
559
623
|
? createOverridesProxy(asyncApiDocument, { overrides: asyncApiOverrides })
|
|
560
624
|
: asyncApiDocument;
|
|
561
|
-
return;
|
|
625
|
+
return true;
|
|
562
626
|
}
|
|
563
627
|
const inputDocument = withMeasurementSync('upgrade', () => upgrade(deepClone(clonedRawInputDocument), '3.1'));
|
|
564
628
|
const strictDocument = createMagicProxy({
|
|
565
629
|
...inputDocument,
|
|
630
|
+
// Partial API descriptions still need document traversal rather than standalone schema traversal.
|
|
631
|
+
openapi: inputDocument.openapi ?? '',
|
|
566
632
|
...meta,
|
|
567
633
|
'x-original-oas-version': clonedRawInputDocument.openapi ?? clonedRawInputDocument.swagger,
|
|
568
634
|
'x-scalar-original-document-hash': input.documentHash,
|
|
@@ -573,9 +639,12 @@ export const createWorkspaceStore = (workspaceProps) => {
|
|
|
573
639
|
// We need to bundle document first before we validate, so we can also validate the external references
|
|
574
640
|
if (strictDocument[extensions.document.navigation] === undefined) {
|
|
575
641
|
await withMeasurementAsync('bundle', async () => await bundle(getRaw(strictDocument), {
|
|
642
|
+
// Example values and other literal data may contain authored `$ref` keys.
|
|
643
|
+
traversal: 'document',
|
|
576
644
|
treeShake: false,
|
|
577
645
|
plugins: [
|
|
578
646
|
...loaders,
|
|
647
|
+
codeSampleSources(),
|
|
579
648
|
openApiDocument(),
|
|
580
649
|
normalizeRefs(),
|
|
581
650
|
externalValueResolver({ lazy: true }),
|
|
@@ -619,6 +688,7 @@ export const createWorkspaceStore = (workspaceProps) => {
|
|
|
619
688
|
: magicDocument;
|
|
620
689
|
const baselineDocument = workspace.documents[name];
|
|
621
690
|
requestBodyBaselines[name] = withMeasurementSync('snapshotRequestBodies', () => snapshotRequestBodies(baselineDocument));
|
|
691
|
+
return true;
|
|
622
692
|
}
|
|
623
693
|
// Asynchronously adds a new document to the workspace by loading and validating the input.
|
|
624
694
|
// If loading fails, a placeholder error document is added instead.
|
|
@@ -634,37 +704,20 @@ export const createWorkspaceStore = (workspaceProps) => {
|
|
|
634
704
|
return await withMeasurementAsync('addDocument', async () => {
|
|
635
705
|
if (!resolve.ok) {
|
|
636
706
|
console.error(`Failed to fetch document '${name}': request was not successful`);
|
|
637
|
-
workspace.documents[name] =
|
|
638
|
-
...meta,
|
|
639
|
-
openapi: '3.1.0',
|
|
640
|
-
info: {
|
|
641
|
-
title: `Document '${name}' could not be loaded`,
|
|
642
|
-
version: 'unknown',
|
|
643
|
-
},
|
|
644
|
-
'x-scalar-original-document-hash': 'not-a-hash',
|
|
645
|
-
};
|
|
707
|
+
workspace.documents[name] = createLoadFailedDocument(name, meta);
|
|
646
708
|
return false;
|
|
647
709
|
}
|
|
648
710
|
if (!isObject(resolve.data)) {
|
|
649
711
|
console.error(`Failed to load document '${name}': response data is not a valid object`);
|
|
650
|
-
workspace.documents[name] =
|
|
651
|
-
...meta,
|
|
652
|
-
openapi: '3.1.0',
|
|
653
|
-
info: {
|
|
654
|
-
title: `Document '${name}' could not be loaded`,
|
|
655
|
-
version: 'unknown',
|
|
656
|
-
},
|
|
657
|
-
'x-scalar-original-document-hash': 'not-a-hash',
|
|
658
|
-
};
|
|
712
|
+
workspace.documents[name] = createLoadFailedDocument(name, meta);
|
|
659
713
|
return false;
|
|
660
714
|
}
|
|
661
|
-
await addInMemoryDocument({
|
|
715
|
+
return await addInMemoryDocument({
|
|
662
716
|
...input,
|
|
663
717
|
document: resolve.data,
|
|
664
718
|
documentSource: getDocumentSource(input),
|
|
665
719
|
documentHash: generateHash(resolve.raw),
|
|
666
720
|
}, navigationOptions);
|
|
667
|
-
return true;
|
|
668
721
|
});
|
|
669
722
|
}
|
|
670
723
|
const getOriginalDocument = (documentName) => {
|
|
@@ -979,9 +1032,11 @@ export const createWorkspaceStore = (workspaceProps) => {
|
|
|
979
1032
|
}
|
|
980
1033
|
return bundle(target, {
|
|
981
1034
|
root: activeDocument,
|
|
1035
|
+
traversal: 'document',
|
|
982
1036
|
origin: activeDocument?.['x-scalar-original-source-url'],
|
|
983
1037
|
treeShake: false,
|
|
984
1038
|
plugins: [
|
|
1039
|
+
codeSampleSources(path),
|
|
985
1040
|
openApiDocument(),
|
|
986
1041
|
fetchUrls({
|
|
987
1042
|
fetch: extraDocumentConfigurations[getActiveDocumentName()]?.fetch ?? workspaceProps?.fetch,
|
|
@@ -1165,7 +1220,9 @@ export const createWorkspaceStore = (workspaceProps) => {
|
|
|
1165
1220
|
message: `No changes detected for document '${name}': document hash matches the active document`,
|
|
1166
1221
|
};
|
|
1167
1222
|
}
|
|
1168
|
-
|
|
1223
|
+
// Source markers are not classification evidence, including when rebasing a saved baseline.
|
|
1224
|
+
const newDocumentOrigin = deepClone(resolve.data);
|
|
1225
|
+
delete newDocumentOrigin[PLUGIN_DOCUMENT_TYPE_KEY];
|
|
1169
1226
|
// ---- Override the configurations and metadata
|
|
1170
1227
|
overrides[name] = input.overrides ?? {};
|
|
1171
1228
|
extraDocumentConfigurations[name] = { fetch: input.fetch };
|
|
@@ -1205,7 +1262,8 @@ export const createWorkspaceStore = (workspaceProps) => {
|
|
|
1205
1262
|
// If the caller provided a fully resolved document, use it as-is.
|
|
1206
1263
|
return applyChangesInput.resolvedDocument;
|
|
1207
1264
|
};
|
|
1208
|
-
const mergedDocument = getNewActiveDocument();
|
|
1265
|
+
const mergedDocument = deepClone(getNewActiveDocument());
|
|
1266
|
+
delete mergedDocument[PLUGIN_DOCUMENT_TYPE_KEY];
|
|
1209
1267
|
// Detect whether the rebase folded in any local edits. When the
|
|
1210
1268
|
// merged result matches the upstream snapshot the pull was
|
|
1211
1269
|
// effectively a fast-forward (no unsaved local work to carry
|
|
@@ -1243,9 +1301,6 @@ export const createWorkspaceStore = (workspaceProps) => {
|
|
|
1243
1301
|
const activeServers = activeDocumentRaw.servers;
|
|
1244
1302
|
const mergedHasServers = Array.isArray(mergedServers) && mergedServers.length > 0;
|
|
1245
1303
|
const activeHasServers = Array.isArray(activeServers) && activeServers.length > 0;
|
|
1246
|
-
const preservedServers = !isAsyncApiDocument(mergedDocument) && !mergedHasServers && activeHasServers
|
|
1247
|
-
? deepClone(activeServers)
|
|
1248
|
-
: undefined;
|
|
1249
1304
|
// add the new active document to the workspace but don't re-initialize
|
|
1250
1305
|
await addInMemoryDocument({
|
|
1251
1306
|
...input,
|
|
@@ -1268,11 +1323,16 @@ export const createWorkspaceStore = (workspaceProps) => {
|
|
|
1268
1323
|
'x-scalar-selected-server': activeDocumentRaw['x-scalar-selected-server'],
|
|
1269
1324
|
...(environments !== undefined ? { 'x-scalar-environments': environments } : {}),
|
|
1270
1325
|
...(order !== undefined ? { 'x-scalar-order': order } : {}),
|
|
1271
|
-
...(preservedServers !== undefined ? { servers: preservedServers } : {}),
|
|
1272
1326
|
// Flag local edits that need pushing - see note above.
|
|
1273
1327
|
'x-scalar-is-dirty': hasLocalChangesAgainstUpstream,
|
|
1274
1328
|
},
|
|
1275
1329
|
});
|
|
1330
|
+
// Re-ingestion determines the resulting format. Raw input can carry OpenAPI-looking fields
|
|
1331
|
+
// while being claimed by a plugin, so only preserve HTTP servers after classification.
|
|
1332
|
+
const rebasedDocument = workspace.documents[name];
|
|
1333
|
+
if (isOpenApi && isOpenApiDocument(rebasedDocument) && !mergedHasServers && activeHasServers) {
|
|
1334
|
+
rebasedDocument.servers = deepClone(activeServers);
|
|
1335
|
+
}
|
|
1276
1336
|
},
|
|
1277
1337
|
};
|
|
1278
1338
|
},
|