@scalar/workspace-store 0.74.0 → 0.76.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 +34 -0
- package/dist/client.d.ts +3 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +55 -5
- package/dist/entities/auth/schema.d.ts +210 -0
- package/dist/entities/auth/schema.d.ts.map +1 -1
- package/dist/helpers/async-api-schema-resources/load-inline.d.ts +3 -1
- package/dist/helpers/async-api-schema-resources/load-inline.d.ts.map +1 -1
- package/dist/helpers/async-api-schema-resources/load-inline.js +20 -60
- package/dist/helpers/async-api-schema-resources/resolver.d.ts +12 -0
- package/dist/helpers/async-api-schema-resources/resolver.d.ts.map +1 -0
- package/dist/helpers/async-api-schema-resources/resolver.js +31 -0
- package/dist/helpers/async-api-schema-resources/resources.d.ts +3 -0
- package/dist/helpers/async-api-schema-resources/resources.d.ts.map +1 -1
- package/dist/helpers/async-api-schema-resources/resources.js +17 -8
- package/dist/helpers/async-api-schema-resources/schema-wrappers.d.ts +9 -0
- package/dist/helpers/async-api-schema-resources/schema-wrappers.d.ts.map +1 -0
- package/dist/helpers/async-api-schema-resources/schema-wrappers.js +69 -0
- package/dist/helpers/async-api-schema-resources/track-edits.d.ts +3 -0
- package/dist/helpers/async-api-schema-resources/track-edits.d.ts.map +1 -0
- package/dist/helpers/async-api-schema-resources/track-edits.js +46 -0
- package/dist/helpers/get-resolved-security-scheme.d.ts +12 -0
- package/dist/helpers/get-resolved-security-scheme.d.ts.map +1 -0
- package/dist/helpers/get-resolved-security-scheme.js +24 -0
- package/dist/helpers/resolve-async-api-schema.d.ts.map +1 -1
- package/dist/helpers/resolve-async-api-schema.js +3 -1
- package/dist/helpers/resolve-security-requirements.js +2 -2
- package/dist/helpers/use-async-api-schema-resources.d.ts +12 -0
- package/dist/helpers/use-async-api-schema-resources.d.ts.map +1 -0
- package/dist/helpers/use-async-api-schema-resources.js +24 -0
- package/dist/navigation/helpers/get-x-badges.d.ts +10 -0
- package/dist/navigation/helpers/get-x-badges.d.ts.map +1 -0
- package/dist/navigation/helpers/get-x-badges.js +26 -0
- package/dist/navigation/helpers/traverse-paths.d.ts.map +1 -1
- package/dist/navigation/helpers/traverse-paths.js +3 -0
- package/dist/navigation/helpers/traverse-schemas.d.ts.map +1 -1
- package/dist/navigation/helpers/traverse-schemas.js +3 -0
- package/dist/navigation/helpers/traverse-tags.d.ts.map +1 -1
- package/dist/navigation/helpers/traverse-tags.js +3 -0
- package/dist/navigation/helpers/traverse-webhooks.d.ts.map +1 -1
- package/dist/navigation/helpers/traverse-webhooks.js +3 -0
- package/dist/plugins/bundler/async-api-schema-resources.d.ts +1 -1
- package/dist/plugins/bundler/async-api-schema-resources.d.ts.map +1 -1
- package/dist/plugins/bundler/async-api-schema-resources.js +9 -9
- package/dist/request-example/builder/body/aspnet-form-fields.d.ts +26 -0
- package/dist/request-example/builder/body/aspnet-form-fields.d.ts.map +1 -0
- package/dist/request-example/builder/body/aspnet-form-fields.js +179 -0
- package/dist/request-example/builder/body/build-multipart.d.ts.map +1 -1
- package/dist/request-example/builder/body/build-multipart.js +9 -5
- package/dist/request-example/builder/body/build-request-body.d.ts +5 -1
- package/dist/request-example/builder/body/build-request-body.d.ts.map +1 -1
- package/dist/request-example/builder/body/build-request-body.js +38 -8
- package/dist/request-example/builder/build-request.d.ts.map +1 -1
- package/dist/request-example/builder/build-request.js +3 -2
- package/dist/request-example/builder/helpers/get-example-from-schema.d.ts +3 -0
- package/dist/request-example/builder/helpers/get-example-from-schema.d.ts.map +1 -1
- package/dist/request-example/builder/helpers/get-example-from-schema.js +132 -29
- package/dist/request-example/builder/request-factory.d.ts +5 -1
- package/dist/request-example/builder/request-factory.d.ts.map +1 -1
- package/dist/request-example/builder/request-factory.js +4 -2
- package/dist/request-example/builder/security/build-request-security.d.ts +6 -4
- package/dist/request-example/builder/security/build-request-security.d.ts.map +1 -1
- package/dist/request-example/builder/security/build-request-security.js +1 -0
- package/dist/request-example/index.d.ts +1 -0
- package/dist/request-example/index.d.ts.map +1 -1
- package/dist/request-example/index.js +1 -0
- package/dist/schemas/extensions/security/x-scalar-token-prefix.d.ts +11 -0
- package/dist/schemas/extensions/security/x-scalar-token-prefix.d.ts.map +1 -0
- package/dist/schemas/extensions/security/x-scalar-token-prefix.js +8 -0
- package/dist/schemas/navigation.d.ts +49 -0
- package/dist/schemas/navigation.d.ts.map +1 -1
- package/dist/schemas/navigation.js +5 -0
- package/dist/schemas/reference-config/index.d.ts +42 -0
- package/dist/schemas/reference-config/index.d.ts.map +1 -1
- package/dist/schemas/reference-config/settings.d.ts +42 -0
- package/dist/schemas/reference-config/settings.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/openapi-document.d.ts +1470 -0
- package/dist/schemas/v3.1/strict/openapi-document.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/security-scheme.d.ts +4 -1
- package/dist/schemas/v3.1/strict/security-scheme.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/security-scheme.js +2 -1
- package/dist/schemas/v3.2/openapi/index.d.ts.map +1 -1
- package/dist/schemas/v3.2/openapi/index.js +2 -0
- package/dist/schemas/v3.2/strict/openapi-document.d.ts +1470 -0
- package/dist/schemas/v3.2/strict/openapi-document.d.ts.map +1 -1
- package/dist/schemas/v3.2/strict/security-scheme.d.ts +4 -1
- package/dist/schemas/v3.2/strict/security-scheme.d.ts.map +1 -1
- package/dist/schemas/v3.2/strict/security-scheme.js +2 -1
- package/package.json +12 -11
|
@@ -3,6 +3,7 @@ import { forEachPathItemOperation, getPathItemOperationKey } from '../../helpers
|
|
|
3
3
|
import { getPathEntries } from '../../helpers/get-path-entries.js';
|
|
4
4
|
import { getResolvedRef, mergeSiblingReferences } from '../../helpers/get-resolved-ref.js';
|
|
5
5
|
import { isHidden } from '../../helpers/is-hidden.js';
|
|
6
|
+
import { getXBadges } from './get-x-badges.js';
|
|
6
7
|
import { traverseOperationExamples } from './traverse-examples.js';
|
|
7
8
|
import { XScalarStabilityValues } from '../../schemas/extensions/operation/index.js';
|
|
8
9
|
import { getNavigationTagNames } from './get-navigation-tag-names.js';
|
|
@@ -33,6 +34,7 @@ const createOperationEntry = ({ ref, operation, method, path, generateId, parent
|
|
|
33
34
|
});
|
|
34
35
|
const title = operationTitleSource !== 'path' && operation.summary?.trim() ? operation.summary : path;
|
|
35
36
|
const isDeprecated = isDeprecatedOperation(operation);
|
|
37
|
+
const badges = getXBadges(operation);
|
|
36
38
|
const examples = traverseOperationExamples(operation).map((example) => ({
|
|
37
39
|
type: 'example',
|
|
38
40
|
id: generateId({
|
|
@@ -51,6 +53,7 @@ const createOperationEntry = ({ ref, operation, method, path, generateId, parent
|
|
|
51
53
|
ref,
|
|
52
54
|
type: 'operation',
|
|
53
55
|
isDeprecated,
|
|
56
|
+
...(badges ? { badges } : {}),
|
|
54
57
|
children: examples.length ? examples : undefined,
|
|
55
58
|
};
|
|
56
59
|
return entry;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traverse-schemas.d.ts","sourceRoot":"","sources":["../../../src/navigation/helpers/traverse-schemas.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"traverse-schemas.d.ts","sourceRoot":"","sources":["../../../src/navigation/helpers/traverse-schemas.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACtE,OAAO,KAAK,EAAa,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtE,OAAO,KAAK,EAAE,eAAe,EAAgB,MAAM,wCAAwC,CAAA;AA6C3F;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,mDAKzB;IACD,QAAQ,EAAE,eAAe,CAAA;IACzB,wCAAwC;IACxC,OAAO,EAAE,OAAO,CAAA;IAChB,UAAU,EAAE,mBAAmB,CAAC,YAAY,CAAC,CAAA;IAC7C,UAAU,EAAE,MAAM,CAAA;CACnB,KAAG,eAAe,EAmDlB,CAAA"}
|
|
@@ -3,6 +3,7 @@ import { getResolvedRef, mergeSiblingReferences } from '../../helpers/get-resolv
|
|
|
3
3
|
import { isHidden } from '../../helpers/is-hidden.js';
|
|
4
4
|
import { getNavigationTagNames } from './get-navigation-tag-names.js';
|
|
5
5
|
import { getTag } from './get-tag.js';
|
|
6
|
+
import { getXBadges } from './get-x-badges.js';
|
|
6
7
|
/** Creates a traversed schema entry from an OpenAPI schema object.
|
|
7
8
|
*
|
|
8
9
|
* @param ref - JSON pointer reference to the schema in the OpenAPI document
|
|
@@ -17,12 +18,14 @@ const createSchemaEntry = ({ ref, name, generateId, parentTag, _schema, parentId
|
|
|
17
18
|
// Use schema.title if available, otherwise fall back to name
|
|
18
19
|
// @see https://json-schema.org/draft/2020-12/json-schema-core#section-4.3.5
|
|
19
20
|
const title = (isObject(schema) && 'title' in schema && schema.title) || name;
|
|
21
|
+
const badges = getXBadges(schema);
|
|
20
22
|
const entry = {
|
|
21
23
|
id,
|
|
22
24
|
title,
|
|
23
25
|
name,
|
|
24
26
|
ref,
|
|
25
27
|
type: 'model',
|
|
28
|
+
...(badges ? { badges } : {}),
|
|
26
29
|
};
|
|
27
30
|
return entry;
|
|
28
31
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traverse-tags.d.ts","sourceRoot":"","sources":["../../../src/navigation/helpers/traverse-tags.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"traverse-tags.d.ts","sourceRoot":"","sources":["../../../src/navigation/helpers/traverse-tags.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACtE,OAAO,KAAK,EAAE,cAAc,EAAgB,MAAM,sBAAsB,CAAA;AACxE,OAAO,KAAK,EAAE,eAAe,EAAa,MAAM,wCAAwC,CAAA;AAIxF,KAAK,OAAO,GAAG,IAAI,CAAC,mBAAmB,EAAE,YAAY,GAAG,kBAAkB,GAAG,YAAY,CAAC,CAAA;AAuS1F;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,8FAKtB;IACD,QAAQ,EAAE,eAAe,CAAA;IACzB,oCAAoC;IACpC,OAAO,EAAE,OAAO,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,OAAO,CAAA;CACjB,KAAG,cAAc,EAuEjB,CAAA"}
|
|
@@ -3,6 +3,7 @@ import { getTagKind } from '../../helpers/get-tag-kind.js';
|
|
|
3
3
|
import { isHidden } from '../../helpers/is-hidden.js';
|
|
4
4
|
import { unpackProxyObject } from '../../helpers/unpack-proxy.js';
|
|
5
5
|
import { getTagExternalDocs } from './get-tag-external-docs.js';
|
|
6
|
+
import { getXBadges } from './get-x-badges.js';
|
|
6
7
|
import { getXKeysFromObject } from './get-x-keys.js';
|
|
7
8
|
import { getTag } from './get-tag.js';
|
|
8
9
|
/** Creates a traversed tag entry from an OpenAPI tag object.
|
|
@@ -24,6 +25,7 @@ const createTagEntry = ({ tag, generateId, children, isGroup = false, isTagGroup
|
|
|
24
25
|
});
|
|
25
26
|
// `summary` is the OpenAPI 3.2 display label; `x-displayName` keeps precedence for backwards compatibility.
|
|
26
27
|
const externalDocs = getTagExternalDocs(tag);
|
|
28
|
+
const badges = getXBadges(tag);
|
|
27
29
|
const title = tag['x-displayName'] ?? tag.summary ?? tag.name ?? 'Untitled Tag';
|
|
28
30
|
// Update the order of the children based on the items
|
|
29
31
|
// This will ensure that the sort order is always in sync with the items
|
|
@@ -40,6 +42,7 @@ const createTagEntry = ({ tag, generateId, children, isGroup = false, isTagGroup
|
|
|
40
42
|
// Real OpenAPI 3.2 nested-tag sections keep this unset and render their summary heading.
|
|
41
43
|
...(isTagGroup ? { isTagGroup: true } : {}),
|
|
42
44
|
isWebhooks: false,
|
|
45
|
+
...(badges ? { badges } : {}),
|
|
43
46
|
type: 'tag',
|
|
44
47
|
xKeys: getXKeysFromObject(unpackProxyObject(tag)),
|
|
45
48
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traverse-webhooks.d.ts","sourceRoot":"","sources":["../../../src/navigation/helpers/traverse-webhooks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"traverse-webhooks.d.ts","sourceRoot":"","sources":["../../../src/navigation/helpers/traverse-webhooks.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACtE,OAAO,KAAK,EAAa,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvE,OAAO,KAAK,EAAE,eAAe,EAA8B,MAAM,wCAAwC,CAAA;AA8DzG;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,6EAM1B;IACD,uBAAuB;IACvB,QAAQ,EAAE,eAAe,CAAA;IACzB,6CAA6C;IAC7C,OAAO,EAAE,OAAO,CAAA;IAChB,UAAU,EAAE,mBAAmB,CAAC,YAAY,CAAC,CAAA;IAC7C,wBAAwB,EAAE,MAAM,CAAA;IAChC,UAAU,EAAE,MAAM,CAAA;CACnB,KAAG,gBAAgB,EAwDnB,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { forEachPathItemOperation, getPathItemOperationKey } from '../../helpers/for-each-path-item-operation.js';
|
|
2
2
|
import { getResolvedRef, mergeSiblingReferences } from '../../helpers/get-resolved-ref.js';
|
|
3
3
|
import { isHidden } from '../../helpers/is-hidden.js';
|
|
4
|
+
import { getXBadges } from './get-x-badges.js';
|
|
4
5
|
import { isDeprecatedOperation } from './traverse-paths.js';
|
|
5
6
|
import { getNavigationTagNames } from './get-navigation-tag-names.js';
|
|
6
7
|
import { getTag } from './get-tag.js';
|
|
@@ -24,6 +25,7 @@ const createWebhookEntry = ({ ref, method, name, title, generateId, parentTag, w
|
|
|
24
25
|
parentTag,
|
|
25
26
|
parentId: parentId,
|
|
26
27
|
});
|
|
28
|
+
const badges = getXBadges(webhook);
|
|
27
29
|
const entry = {
|
|
28
30
|
id,
|
|
29
31
|
title,
|
|
@@ -32,6 +34,7 @@ const createWebhookEntry = ({ ref, method, name, title, generateId, parentTag, w
|
|
|
32
34
|
method: method,
|
|
33
35
|
type: 'webhook',
|
|
34
36
|
isDeprecated,
|
|
37
|
+
...(badges ? { badges } : {}),
|
|
35
38
|
};
|
|
36
39
|
return entry;
|
|
37
40
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { LifecyclePlugin } from '@scalar/json-magic/bundle';
|
|
2
|
-
/**
|
|
2
|
+
/** Defer native dependencies only at real AsyncAPI schema wrappers, never inside examples or extensions. */
|
|
3
3
|
export declare const asyncApiSchemaResources: () => LifecyclePlugin;
|
|
4
4
|
//# sourceMappingURL=async-api-schema-resources.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-api-schema-resources.d.ts","sourceRoot":"","sources":["../../../src/plugins/bundler/async-api-schema-resources.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"async-api-schema-resources.d.ts","sourceRoot":"","sources":["../../../src/plugins/bundler/async-api-schema-resources.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAIhE,4GAA4G;AAC5G,eAAO,MAAM,uBAAuB,QAAO,eAc1C,CAAA"}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { isObject } from '@scalar/helpers/object/is-object';
|
|
2
|
+
import { deferSchemaResources } from '../../helpers/async-api-schema-resources/resources.js';
|
|
3
|
+
/** Defer native dependencies only at real AsyncAPI schema wrappers, never inside examples or extensions. */
|
|
3
4
|
export const asyncApiSchemaResources = () => {
|
|
4
|
-
const load = createSchemaResourceLoader();
|
|
5
5
|
return {
|
|
6
6
|
type: 'lifecycle',
|
|
7
|
-
onBeforeNodeProcess:
|
|
7
|
+
onBeforeNodeProcess: (node, context) => {
|
|
8
8
|
if (context.referenceContext !== 'asyncapi-schema' || typeof node.schemaFormat !== 'string' || '$ref' in node)
|
|
9
9
|
return;
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
if (
|
|
10
|
+
// Completed server graphs stay portable. Deferred metadata must use the actual containing file,
|
|
11
|
+
// since its origin controls future downloads and may have been supplied by the document author.
|
|
12
|
+
const existing = node['x-scalar-schema-resources'];
|
|
13
|
+
if (existing !== undefined && !(isObject(existing) && existing.deferred === true))
|
|
14
14
|
return;
|
|
15
|
-
const resources =
|
|
15
|
+
const resources = deferSchemaResources(node.schemaFormat, context.origin);
|
|
16
16
|
if (resources)
|
|
17
17
|
node['x-scalar-schema-resources'] = resources;
|
|
18
18
|
},
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { MultipartNaming } from '@scalar/types/api-reference';
|
|
2
|
+
import type { MediaTypeObject, SchemaObject } from '../../../schemas/v3.2/strict/openapi-document.js';
|
|
3
|
+
/** ASP.NET Core binds named form fields. Ordered and nested MIME bodies use their own encodings. */
|
|
4
|
+
export declare const usesAspNetFormNaming: (contentType: string, media: MediaTypeObject | undefined, multipartNaming?: MultipartNaming) => boolean;
|
|
5
|
+
type FormField = {
|
|
6
|
+
name: string;
|
|
7
|
+
/** Encoding entries use the original property name, before indexed-dot flattening. */
|
|
8
|
+
rootName: string;
|
|
9
|
+
value: unknown;
|
|
10
|
+
schema: SchemaObject | undefined;
|
|
11
|
+
isRequired: boolean;
|
|
12
|
+
isDisabled: boolean;
|
|
13
|
+
isDisabledByDefault?: boolean;
|
|
14
|
+
isArray?: boolean;
|
|
15
|
+
};
|
|
16
|
+
/** Map a structured example or saved editor rows to the field names understood by ASP.NET Core. */
|
|
17
|
+
export declare const getAspNetFormFields: (value: unknown, schema: SchemaObject | undefined, compositionSelection?: Record<string, number>, includeMissing?: boolean) => FormField[];
|
|
18
|
+
/** Add explicit indices for sparse collections so MVC binds items beyond the first gap. */
|
|
19
|
+
export declare const getAspNetFormIndexFields: (names: string[]) => {
|
|
20
|
+
key: string;
|
|
21
|
+
value: string;
|
|
22
|
+
}[];
|
|
23
|
+
/** Include file upload examples when generating snippets for schema-backed multipart fields. */
|
|
24
|
+
export declare const withAspNetMultipartFilePlaceholder: (field: FormField, includeMissing: boolean, contentType?: string) => FormField;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=aspnet-form-fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aspnet-form-fields.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/body/aspnet-form-fields.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAKlE,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAO3F,oGAAoG;AACpG,eAAO,MAAM,oBAAoB,gBAClB,MAAM,SACZ,eAAe,GAAG,SAAS,oBAChB,eAAe,KAChC,OAI0C,CAAA;AAE7C,KAAK,SAAS,GAAG;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,sFAAsF;IACtF,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,EAAE,YAAY,GAAG,SAAS,CAAA;IAChC,UAAU,EAAE,OAAO,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAwCD,mGAAmG;AACnG,eAAO,MAAM,mBAAmB,UACvB,OAAO,UACN,YAAY,GAAG,SAAS,yBACT,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,+BAE5C,SAAS,EAgHX,CAAA;AAED,2FAA2F;AAC3F,eAAO,MAAM,wBAAwB,UAAW,MAAM,EAAE,KAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAuBxF,CAAA;AAED,gGAAgG;AAChG,eAAO,MAAM,kCAAkC,UACtC,SAAS,kBACA,OAAO,gBACT,MAAM,KACnB,SAcF,CAAA"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { isObject } from '@scalar/helpers/object/is-object';
|
|
2
|
+
import { isFileSchema } from '../../../helpers/is-file-schema.js';
|
|
3
|
+
import { resolveFormSchema } from '../../../helpers/resolve-form-schema.js';
|
|
4
|
+
import { unpackProxyShallow } from '../../../helpers/unpack-proxy.js';
|
|
5
|
+
import { isArraySchema, isObjectSchema } from '../../../schemas/v3.2/strict/type-guards.js';
|
|
6
|
+
import { needsMultipartEncoding } from './build-multipart.js';
|
|
7
|
+
import { coerceLeafValueToSchemaType } from './schema-value-coercion.js';
|
|
8
|
+
/** ASP.NET Core binds named form fields. Ordered and nested MIME bodies use their own encodings. */
|
|
9
|
+
export const usesAspNetFormNaming = (contentType, media, multipartNaming) => multipartNaming === 'indexed-dot' &&
|
|
10
|
+
(contentType === 'multipart/form-data' || contentType === 'application/x-www-form-urlencoded') &&
|
|
11
|
+
media !== undefined &&
|
|
12
|
+
!needsMultipartEncoding(contentType, media);
|
|
13
|
+
const getProperty = (schema, name) => schema && 'properties' in schema && schema.properties && Object.hasOwn(schema.properties, name)
|
|
14
|
+
? schema.properties[name]
|
|
15
|
+
: undefined;
|
|
16
|
+
const getItem = (schema, index) => {
|
|
17
|
+
if (!schema || !isArraySchema(schema)) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const item = schema.prefixItems?.[index] ?? schema.items;
|
|
21
|
+
return typeof item === 'object' ? item : undefined;
|
|
22
|
+
};
|
|
23
|
+
const isRequiredProperty = (schema, key) => Boolean(schema && 'required' in schema && schema.required?.includes(key));
|
|
24
|
+
const resolveField = (schema, name, compositionSelection) => {
|
|
25
|
+
const segments = getProperty(schema, name) === undefined ? name.split(/\.|\[(\d+)\]/).filter(Boolean) : [name];
|
|
26
|
+
let current = schema;
|
|
27
|
+
let isRequired = segments.length > 0;
|
|
28
|
+
const path = ['requestBody'];
|
|
29
|
+
for (const segment of segments) {
|
|
30
|
+
if (current && isArraySchema(current) && /^\d+$/.test(segment)) {
|
|
31
|
+
path.push('items');
|
|
32
|
+
current = resolveFormSchema(getItem(current, Number(segment)), compositionSelection, path);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
path.push(segment);
|
|
36
|
+
isRequired = isRequired && isRequiredProperty(current, segment);
|
|
37
|
+
current = resolveFormSchema(getProperty(current, segment), compositionSelection, path);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return { schema: current, isRequired, rootName: segments[0] ?? name };
|
|
41
|
+
};
|
|
42
|
+
/** Map a structured example or saved editor rows to the field names understood by ASP.NET Core. */
|
|
43
|
+
export const getAspNetFormFields = (value, schema, compositionSelection, includeMissing = false) => {
|
|
44
|
+
const fields = [];
|
|
45
|
+
const ancestors = new Set();
|
|
46
|
+
const visit = (field, inputSchema, schemaPath) => {
|
|
47
|
+
const { name, value, schema } = field;
|
|
48
|
+
// Schema placeholders can reach recursive references even when the example is finite.
|
|
49
|
+
const missingValueSchema = value === undefined ? inputSchema : undefined;
|
|
50
|
+
const source = isObject(value) || Array.isArray(value) ? value : missingValueSchema;
|
|
51
|
+
const identity = source && unpackProxyShallow(source);
|
|
52
|
+
if (identity && ancestors.has(identity)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (identity) {
|
|
56
|
+
ancestors.add(identity);
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
if (Array.isArray(value) || (includeMissing && value === undefined)) {
|
|
60
|
+
const entries = Array.isArray(value) ? value : [];
|
|
61
|
+
const itemPath = [...schemaPath, 'items'];
|
|
62
|
+
const item = resolveFormSchema(getItem(schema, 0), compositionSelection, itemPath);
|
|
63
|
+
if (entries.some((entry) => isObject(entry) || Array.isArray(entry)) ||
|
|
64
|
+
(item && (isObjectSchema(item) || isArraySchema(item)))) {
|
|
65
|
+
const canAddItem = schema && isArraySchema(schema) && schema.maxItems !== 0;
|
|
66
|
+
const items = entries.length || !includeMissing || !canAddItem ? entries : [undefined];
|
|
67
|
+
items.forEach((entry, index) => {
|
|
68
|
+
const itemInput = getItem(schema, index);
|
|
69
|
+
visit({
|
|
70
|
+
...field,
|
|
71
|
+
name: `${name}[${index}]`,
|
|
72
|
+
value: entry,
|
|
73
|
+
schema: resolveFormSchema(itemInput, compositionSelection, itemPath),
|
|
74
|
+
isArray: undefined,
|
|
75
|
+
}, itemInput, itemPath);
|
|
76
|
+
});
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const data = isObject(value) ? value : undefined;
|
|
81
|
+
const properties = schema && 'properties' in schema ? schema.properties : undefined;
|
|
82
|
+
if (data || (includeMissing && value === undefined && properties)) {
|
|
83
|
+
const names = new Set([...Object.keys(properties ?? {}), ...Object.keys(data ?? {})]);
|
|
84
|
+
for (const key of names) {
|
|
85
|
+
const childInput = getProperty(schema, key);
|
|
86
|
+
const path = [...schemaPath, key];
|
|
87
|
+
const childSchema = resolveFormSchema(childInput, compositionSelection, path);
|
|
88
|
+
const childValue = data && Object.hasOwn(data, key) ? data[key] : undefined;
|
|
89
|
+
if (childValue === undefined && (!includeMissing || childSchema?.readOnly)) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const isRequired = isRequiredProperty(schema, key);
|
|
93
|
+
const optionalRoot = !name && childInput !== undefined && !isRequired && !schema?.allOf && !schema?.oneOf && !schema?.anyOf;
|
|
94
|
+
visit({
|
|
95
|
+
name: name ? `${name}.${key}` : key,
|
|
96
|
+
rootName: name ? field.rootName : key,
|
|
97
|
+
value: childValue,
|
|
98
|
+
schema: childSchema,
|
|
99
|
+
isRequired: field.isRequired && isRequired,
|
|
100
|
+
isDisabled: field.isDisabled || optionalRoot,
|
|
101
|
+
isDisabledByDefault: field.isDisabledByDefault || optionalRoot || undefined,
|
|
102
|
+
}, childInput, path);
|
|
103
|
+
}
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (name) {
|
|
107
|
+
fields.push(field);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
if (identity) {
|
|
112
|
+
ancestors.delete(identity);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
if (Array.isArray(value)) {
|
|
117
|
+
for (const row of value) {
|
|
118
|
+
if (!isObject(row) || typeof row.name !== 'string') {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const field = resolveField(schema, row.name, compositionSelection);
|
|
122
|
+
// Older form rows store structured values as JSON text. Keep scalar input verbatim.
|
|
123
|
+
const restored = coerceLeafValueToSchemaType(row.value, row.isArray === true ? { type: 'array' } : field.schema);
|
|
124
|
+
visit({
|
|
125
|
+
name: row.name,
|
|
126
|
+
value: Array.isArray(restored) || isObject(restored) ? restored : row.value,
|
|
127
|
+
...field,
|
|
128
|
+
isDisabled: row.isDisabled === true,
|
|
129
|
+
isDisabledByDefault: row.isDisabledByDefault === true || undefined,
|
|
130
|
+
isArray: row.isArray === true || undefined,
|
|
131
|
+
}, field.schema, ['requestBody', row.name]);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
visit({ name: '', rootName: '', value, schema, isRequired: true, isDisabled: false }, schema, ['requestBody']);
|
|
136
|
+
}
|
|
137
|
+
return fields;
|
|
138
|
+
};
|
|
139
|
+
/** Add explicit indices for sparse collections so MVC binds items beyond the first gap. */
|
|
140
|
+
export const getAspNetFormIndexFields = (names) => {
|
|
141
|
+
const explicitNames = new Set(names.map((name) => name.toLowerCase()));
|
|
142
|
+
const collections = new Map();
|
|
143
|
+
for (const name of names) {
|
|
144
|
+
for (const match of name.matchAll(/\[(\d+)\](?=\.|\[|$)/g)) {
|
|
145
|
+
const index = match[1];
|
|
146
|
+
if (index === undefined || match.index === 0) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const key = `${name.slice(0, match.index)}.index`;
|
|
150
|
+
const normalized = key.toLowerCase();
|
|
151
|
+
if (explicitNames.has(normalized)) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const collection = collections.get(normalized) ?? { key, indices: new Set() };
|
|
155
|
+
collection.indices.add(index);
|
|
156
|
+
collections.set(normalized, collection);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return [...collections.values()].flatMap(({ key, indices }) => {
|
|
160
|
+
const values = [...indices];
|
|
161
|
+
return values.every((_, index) => indices.has(String(index))) ? [] : values.map((value) => ({ key, value }));
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
/** Include file upload examples when generating snippets for schema-backed multipart fields. */
|
|
165
|
+
export const withAspNetMultipartFilePlaceholder = (field, includeMissing, contentType) => {
|
|
166
|
+
if (!field.schema || !isFileSchema(field.schema, false, contentType)) {
|
|
167
|
+
return field;
|
|
168
|
+
}
|
|
169
|
+
const toFile = (value) => {
|
|
170
|
+
if (typeof value === 'string' && value.startsWith('@') && value.length > 1) {
|
|
171
|
+
return new File([], value.slice(1), { lastModified: 0 });
|
|
172
|
+
}
|
|
173
|
+
if (includeMissing && (value === undefined || value === null || value === '')) {
|
|
174
|
+
return new File([], 'filename', { lastModified: 0 });
|
|
175
|
+
}
|
|
176
|
+
return value;
|
|
177
|
+
};
|
|
178
|
+
return { ...field, value: Array.isArray(field.value) ? field.value.map(toFile) : toFile(field.value) };
|
|
179
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-multipart.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/body/build-multipart.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build-multipart.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/body/build-multipart.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEV,eAAe,EACf,YAAY,EACb,MAAM,8DAA8D,CAAA;AAWrE,sGAAsG;AACtG,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACjC,GAAG,CACA;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,IAAI,CAAA;CAAE,GAC7B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,IAAI,CAAA;CAAE,GAC7B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,aAAa,EAAE,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CACrE,CAAA;AAED,mFAAmF;AACnF,eAAO,MAAM,qBAAqB,gBAAiB,MAAM,SAAS,eAAe,KAAG,OASnF,CAAA;AAED,4EAA4E;AAC5E,eAAO,MAAM,sBAAsB,gBAAiB,MAAM,SAAS,eAAe,KAAG,OASpF,CAAA;AA4CD,sFAAsF;AACtF,eAAO,MAAM,sBAAsB,WACzB,YAAY,GAAG,SAAS,SACzB,MAAM,eACA,eAAe,CAAC,YAAY,CAAC,KACzC,YAAY,GAAG,SAMa,CAAA;AAc/B,6FAA6F;AAC7F,eAAO,MAAM,cAAc,UAClB,OAAO,eACD,MAAM,aACT,IAAI,CAAC,eAAe,EAAE,UAAU,GAAG,gBAAgB,GAAG,cAAc,GAAG,YAAY,CAAC,WACrF,YAAY,uBAEpB,aAAa,EAqIf,CAAA"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { isDefined } from '@scalar/helpers/array/is-defined';
|
|
1
2
|
import { parseMimeType } from '@scalar/helpers/http/mime-type';
|
|
2
3
|
import { isObject } from '@scalar/helpers/object/is-object';
|
|
3
4
|
import { getResolvedRef, mergeSiblingReferences } from '@scalar/workspace-store/helpers/get-resolved-ref';
|
|
4
5
|
import { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy';
|
|
5
6
|
import { isArraySchema } from '@scalar/workspace-store/schemas/v3.2/strict/type-guards';
|
|
7
|
+
import { getExampleValue } from '../../../helpers/get-example-value.js';
|
|
6
8
|
import { serializeXmlPart } from '../../xml/serialize-xml-part.js';
|
|
9
|
+
import { serializeSimpleStyle } from '../header/serialize-parameter.js';
|
|
7
10
|
import { MAX_MULTIPART_NESTING } from './multipart-limits.js';
|
|
8
11
|
import { resolveLeafSchema } from './schema-value-coercion.js';
|
|
9
12
|
import { hasEncodingStyle, serializeFormPropertyWithEncoding } from './serialize-form-property.js';
|
|
@@ -125,12 +128,13 @@ export const buildMultipart = (value, contentType, encoding = {}, schema, nestin
|
|
|
125
128
|
if (!header || !('schema' in header)) {
|
|
126
129
|
return [];
|
|
127
130
|
}
|
|
131
|
+
const example = getExampleValue(isDefined(header.example) ? { value: header.example } : Object.values(header.examples ?? {})[0]);
|
|
132
|
+
if (example?.source === 'serialized') {
|
|
133
|
+
return [[name, example.value]];
|
|
134
|
+
}
|
|
128
135
|
const headerSchema = getResolvedRef(header.schema);
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
headerSchema?.const ??
|
|
132
|
-
headerSchema?.default;
|
|
133
|
-
return example === undefined ? [] : [[name, String(example)]];
|
|
136
|
+
const value = example?.value ?? headerSchema?.const ?? headerSchema?.default;
|
|
137
|
+
return isDefined(value) ? [[name, String(serializeSimpleStyle(value, header.explode ?? false))]] : [];
|
|
134
138
|
}));
|
|
135
139
|
if (partSchema?.contentEncoding &&
|
|
136
140
|
!Object.keys(headers).some((name) => name.toLowerCase() === 'content-transfer-encoding')) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { MultipartNaming } from '@scalar/types/api-reference';
|
|
1
2
|
import type { RequestBodyObject } from '@scalar/workspace-store/schemas/v3.2/strict/request-body';
|
|
2
3
|
import { type MultipartPart } from './build-multipart.js';
|
|
3
4
|
type FormData = {
|
|
@@ -43,6 +44,9 @@ export declare const buildRequestBody: (requestBody: RequestBodyObject | undefin
|
|
|
43
44
|
/** The key of the current example */
|
|
44
45
|
exampleName?: string,
|
|
45
46
|
/** Selected anyOf/oneOf request-body variants keyed by schema path */
|
|
46
|
-
requestBodyCompositionSelection?: Record<string, number>, openapiVersion?: string, jsonSchemaDialect?: string
|
|
47
|
+
requestBodyCompositionSelection?: Record<string, number>, openapiVersion?: string, jsonSchemaDialect?: string, options?: {
|
|
48
|
+
multipartNaming?: MultipartNaming;
|
|
49
|
+
aspNetFilePlaceholders?: boolean;
|
|
50
|
+
}) => RequestBody | null;
|
|
47
51
|
export {};
|
|
48
52
|
//# sourceMappingURL=build-request-body.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-request-body.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/body/build-request-body.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build-request-body.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/body/build-request-body.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAGlE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0DAA0D,CAAA;AAajG,OAAO,EACL,KAAK,aAAa,EAKnB,MAAM,mBAAmB,CAAA;AAO1B,KAAK,QAAQ,GAAG;IACd,IAAI,EAAE,UAAU,CAAA;IAChB,KAAK,EAAE,CACH;QACE,IAAI,EAAE,MAAM,CAAA;QACZ,GAAG,EAAE,MAAM,CAAA;QACX,KAAK,EAAE,MAAM,CAAA;QACb,WAAW,CAAC,EAAE,MAAM,CAAA;KACrB,GACD;QACE,IAAI,EAAE,MAAM,CAAA;QACZ,GAAG,EAAE,MAAM,CAAA;QACX,KAAK,EAAE,IAAI,CAAA;QACX,WAAW,CAAC,EAAE,MAAM,CAAA;KACrB,GACD;QACE,IAAI,EAAE,MAAM,CAAA;QACZ,GAAG,EAAE,MAAM,CAAA;QACX,KAAK,EAAE,IAAI,CAAA;QACX,WAAW,CAAC,EAAE,MAAM,CAAA;KACrB,CACJ,EAAE,CAAA;CACJ,CAAA;AAwBD,KAAK,UAAU,GAAG;IAChB,IAAI,EAAE,YAAY,CAAA;IAClB,KAAK,EAAE;QACL,GAAG,EAAE,MAAM,CAAA;QACX,KAAK,EAAE,MAAM,CAAA;KACd,EAAE,CAAA;CACJ,CAAA;AAED,KAAK,GAAG,GAAG;IACT,IAAI,EAAE,KAAK,CAAA;IACX,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAA;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,WAAW,GACnB,QAAQ,GACR,UAAU,GACV,GAAG,GACH;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,aAAa,EAAE,CAAA;CAAE,CAAA;AA2CtE;;GAEG;AACH,eAAO,MAAM,gBAAgB,gBACd,iBAAiB,GAAG,SAAS;AAC1C,qCAAqC;;AAErC,sEAAsE;kCACpC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,mBACvC,MAAM,sBACH,MAAM,YAChB;IAAE,eAAe,CAAC,EAAE,eAAe,CAAC;IAAC,sBAAsB,CAAC,EAAE,OAAO,CAAA;CAAE,KAChF,WAAW,GAAG,IA+ZhB,CAAA"}
|
|
@@ -6,6 +6,8 @@ import { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'
|
|
|
6
6
|
import { isObjectSchema } from '@scalar/workspace-store/schemas/v3.2/strict/type-guards';
|
|
7
7
|
import { getExampleValue, getExplicitExampleText } from '../../../helpers/get-example-value.js';
|
|
8
8
|
import { resolveFormSchema } from '../../../helpers/resolve-form-schema.js';
|
|
9
|
+
import { getExample } from '../helpers/get-example.js';
|
|
10
|
+
import { getAspNetFormFields, getAspNetFormIndexFields, usesAspNetFormNaming, withAspNetMultipartFilePlaceholder, } from './aspnet-form-fields.js';
|
|
9
11
|
import { buildMultipart, getMultipartItemSchema, isPositionalMultipart, needsMultipartEncoding, } from './build-multipart.js';
|
|
10
12
|
import { getExampleFromBody } from './get-request-body-example.js';
|
|
11
13
|
import { getSelectedBodyContentType } from './get-selected-body-content-type.js';
|
|
@@ -67,7 +69,7 @@ export const buildRequestBody = (requestBody,
|
|
|
67
69
|
/** The key of the current example */
|
|
68
70
|
exampleName = 'default',
|
|
69
71
|
/** Selected anyOf/oneOf request-body variants keyed by schema path */
|
|
70
|
-
requestBodyCompositionSelection, openapiVersion, jsonSchemaDialect) => {
|
|
72
|
+
requestBodyCompositionSelection, openapiVersion, jsonSchemaDialect, options) => {
|
|
71
73
|
if (!requestBody) {
|
|
72
74
|
return null;
|
|
73
75
|
}
|
|
@@ -102,6 +104,7 @@ requestBodyCompositionSelection, openapiVersion, jsonSchemaDialect) => {
|
|
|
102
104
|
// (`toString`, `constructor`, …) is not misread as declared-and-optional and dropped.
|
|
103
105
|
const isOptionalBodyProperty = (key) => Boolean(bodyProperties && Object.hasOwn(bodyProperties, key) && !requiredBodyProperties.has(key));
|
|
104
106
|
const media = requestBody.content[bodyContentType];
|
|
107
|
+
const aspNetNaming = usesAspNetFormNaming(bodyContentType, media, options?.multipartNaming);
|
|
105
108
|
if (media && needsMultipartEncoding(bodyContentType, media)) {
|
|
106
109
|
// Raw editors store JSON text, while form editors store named rows.
|
|
107
110
|
const value = (() => {
|
|
@@ -146,11 +149,34 @@ requestBodyCompositionSelection, openapiVersion, jsonSchemaDialect) => {
|
|
|
146
149
|
value: multipartParts,
|
|
147
150
|
};
|
|
148
151
|
}
|
|
149
|
-
|
|
152
|
+
const formRows = (() => {
|
|
153
|
+
if (!aspNetNaming || (!isObject(example.value) && !Array.isArray(example.value))) {
|
|
154
|
+
return example.value;
|
|
155
|
+
}
|
|
156
|
+
const includeMissing = options?.aspNetFilePlaceholders === true &&
|
|
157
|
+
!getExampleValue(getExample(requestBody, exampleName, bodyContentType));
|
|
158
|
+
const fields = getAspNetFormFields(example.value, resolvedBodySchema, requestBodyCompositionSelection, includeMissing);
|
|
159
|
+
return options?.aspNetFilePlaceholders
|
|
160
|
+
? fields.map((field) => withAspNetMultipartFilePlaceholder(field, includeMissing, media?.encoding?.[field.rootName]?.contentType))
|
|
161
|
+
: fields;
|
|
162
|
+
})();
|
|
163
|
+
if (aspNetNaming && bodyContentType === 'application/x-www-form-urlencoded' && Array.isArray(formRows)) {
|
|
164
|
+
const value = formRows
|
|
165
|
+
.filter((field) => !field.isDisabled && field.name)
|
|
166
|
+
.flatMap((field) => {
|
|
167
|
+
const encoded = serializeFormPropertyWithEncoding(field.name, field.value, media?.encoding?.[field.rootName]);
|
|
168
|
+
const values = Array.isArray(field.value) ? field.value : [field.value];
|
|
169
|
+
return (encoded ??
|
|
170
|
+
values
|
|
171
|
+
.filter((value) => value !== undefined && value !== null)
|
|
172
|
+
.map((value) => ({ key: field.name, value: String(value) })));
|
|
173
|
+
});
|
|
174
|
+
return { mode: 'urlencoded', value: [...value, ...getAspNetFormIndexFields(value.map(({ key }) => key))] };
|
|
175
|
+
}
|
|
176
|
+
// Form data - array format (from UI editor or flattened for ASP.NET Core)
|
|
150
177
|
if ((bodyContentType === 'multipart/form-data' || bodyContentType === 'application/x-www-form-urlencoded') &&
|
|
151
|
-
Array.isArray(
|
|
152
|
-
const
|
|
153
|
-
const exampleValue = value.filter((item) => !item.isDisabled);
|
|
178
|
+
Array.isArray(formRows)) {
|
|
179
|
+
const exampleValue = formRows.filter((item) => !item.isDisabled);
|
|
154
180
|
const result = bodyContentType === 'multipart/form-data'
|
|
155
181
|
? {
|
|
156
182
|
mode: 'formdata',
|
|
@@ -172,13 +198,13 @@ requestBodyCompositionSelection, openapiVersion, jsonSchemaDialect) => {
|
|
|
172
198
|
// `entries` at the position of the *first* matching row, then keep folding leaves
|
|
173
199
|
// into the same live object reference so interleaved flat rows keep their order.
|
|
174
200
|
const multipartSchema = result.mode === 'formdata' ? resolvedBodySchema : undefined;
|
|
175
|
-
const entries = result.mode === 'formdata' ? regroupMultipartRows(exampleValue, multipartSchema) : exampleValue;
|
|
201
|
+
const entries = result.mode === 'formdata' && !aspNetNaming ? regroupMultipartRows(exampleValue, multipartSchema) : exampleValue;
|
|
176
202
|
// Loop over all entries and add them to the form
|
|
177
|
-
entries.forEach(({ name, value }) => {
|
|
203
|
+
entries.forEach(({ name, value, rootName }) => {
|
|
178
204
|
if (!name) {
|
|
179
205
|
return;
|
|
180
206
|
}
|
|
181
|
-
const partEncoding =
|
|
207
|
+
const partEncoding = media?.encoding?.[aspNetNaming ? (rootName ?? name) : name];
|
|
182
208
|
if (result.mode === 'formdata') {
|
|
183
209
|
// Older saved form rows store JSON text. Only restore arrays declared by the schema.
|
|
184
210
|
const schema = resolveLeafSchema(multipartSchema, [name]);
|
|
@@ -239,6 +265,10 @@ requestBodyCompositionSelection, openapiVersion, jsonSchemaDialect) => {
|
|
|
239
265
|
}
|
|
240
266
|
return;
|
|
241
267
|
});
|
|
268
|
+
if (aspNetNaming && result.mode === 'formdata') {
|
|
269
|
+
const indices = getAspNetFormIndexFields(result.value.map(({ key }) => key));
|
|
270
|
+
result.value.push(...indices.map(({ key, value }) => ({ type: 'text', key, value })));
|
|
271
|
+
}
|
|
242
272
|
return result;
|
|
243
273
|
}
|
|
244
274
|
// Form data - object format (from schema examples)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-request.d.ts","sourceRoot":"","sources":["../../../src/request-example/builder/build-request.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build-request.d.ts","sourceRoot":"","sources":["../../../src/request-example/builder/build-request.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAW,MAAM,8BAA8B,CAAA;AAQnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAA;AAC/E,OAAO,EACL,KAAK,6BAA6B,EAEnC,MAAM,uDAAuD,CAAA;AAK9D;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;AAwClD;;;;;;;GAOG;AACH,eAAO,MAAM,2BAA2B,YAC7B,cAAc,gBACT,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,mBACnB;IAAE,6BAA6B,CAAC,EAAE,OAAO,CAAA;CAAE,KAC3D,MAyBF,CAAA;AAED;;;;;KAKK;AACL,MAAM,MAAM,gBAAgB,GAAG;IAC7B,kGAAkG;IAClG,cAAc,EAAE,cAAc,CAAA;IAC9B,2BAA2B;IAC3B,UAAU,EAAE,eAAe,CAAA;IAC3B,0DAA0D;IAC1D,YAAY,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,wGAAwG;AACxG,eAAO,MAAM,oBAAoB,EAAG,sBAA+B,CAAA;AAEnE,MAAM,MAAM,uBAAuB,GAAG,6BAA6B,GAAG,OAAO,oBAAoB,CAAA;AAEjG,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,gBAAgB,EAAE,uBAAuB,CAAC,CAAA;AAElF,eAAO,MAAM,YAAY,YACd,cAAc,WACd;IACP,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACpC;;;OAGG;IACH,6BAA6B,CAAC,EAAE,OAAO,CAAA;CACxC,KACA,kBASF,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { formatTokenPrefix } from '@scalar/helpers/http/format-token-prefix';
|
|
1
2
|
import { isHttpMethod } from '@scalar/helpers/http/is-http-method';
|
|
2
3
|
import { X_SCALAR_DATE, X_SCALAR_DNT, X_SCALAR_REFERER, X_SCALAR_USER_AGENT } from '@scalar/helpers/http/scalar-headers';
|
|
3
4
|
import { replaceEnvVariables } from '@scalar/helpers/regex/replace-variables';
|
|
@@ -25,7 +26,7 @@ const formatSecurityValue = (security, replace) => {
|
|
|
25
26
|
// Normalize pasted tokens after resolving variables, which may also contain surrounding whitespace.
|
|
26
27
|
return `Bearer ${substitutedValue.trim()}`;
|
|
27
28
|
}
|
|
28
|
-
return substitutedValue;
|
|
29
|
+
return formatTokenPrefix(substitutedValue, security.tokenPrefix);
|
|
29
30
|
};
|
|
30
31
|
const createEnvReplaceFn = (envVariables) => {
|
|
31
32
|
return (value) => {
|
|
@@ -135,7 +136,7 @@ const buildRequestInner = (request, options) => {
|
|
|
135
136
|
// Format the security value based on its authentication scheme.
|
|
136
137
|
// - For 'basic': prefix with 'Basic' and base64-encode the value (username:password).
|
|
137
138
|
// - For 'bearer': prefix with 'Bearer'.
|
|
138
|
-
// - Otherwise:
|
|
139
|
+
// - Otherwise: apply any configured API-key prefix to the substituted credential.
|
|
139
140
|
const securityValue = formatSecurityValue(security, replace);
|
|
140
141
|
if (security.in === 'header') {
|
|
141
142
|
// Set the header (use replaced header name so {{ env }} placeholders work)
|
|
@@ -60,6 +60,9 @@ declare const generateExampleFromSchema: (schema: SchemaObject, options?: GetExa
|
|
|
60
60
|
/**
|
|
61
61
|
* Generate data, optionally retaining the exact schema decisions for another output format.
|
|
62
62
|
* Treat returned values as read-only: cached results and padded items can share object references.
|
|
63
|
+
*
|
|
64
|
+
* An example too large to render at full depth is rendered at the deepest depth that fits instead, so
|
|
65
|
+
* every branch is cut at the same level rather than the first ones using up the budget.
|
|
63
66
|
*/
|
|
64
67
|
export declare const getExampleFromSchema: (schema: SchemaObject, options?: GetExampleFromSchemaOptions, context?: Parameters<typeof generateExampleFromSchema>[2]) => unknown;
|
|
65
68
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-example-from-schema.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/helpers/get-example-from-schema.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,YAAY,EAAqD,MAAM,uBAAuB,CAAA;AAM5G,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAG1E,OAAO,EAAE,kBAAkB,EAA0B,KAAK,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"get-example-from-schema.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/helpers/get-example-from-schema.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,YAAY,EAAqD,MAAM,uBAAuB,CAAA;AAM5G,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAG1E,OAAO,EAAE,kBAAkB,EAA0B,KAAK,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAod9G,gGAAgG;AAChG,eAAO,MAAM,wBAAwB,WAC3B,YAAY,cACR,MAAM,EAAE,YACV,2BAA2B,+BAE7B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC9B,YAAY,GAAG,SAoBjB,CAAA;AA0wBD,sEAAsE;AACtE,MAAM,MAAM,2BAA2B,GAAG;IACxC,0EAA0E;IAC1E,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,4DAA4D;IAC5D,sBAAsB,CAAC,EAAE,MAAM,CAAA;IAC/B,kEAAkE;IAClE,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,2EAA2E;IAC3E,CAAC,kBAAkB,CAAC,CAAC,EAAE,sBAAsB,CAAA;IAC7C,mFAAmF;IACnF,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,kFAAkF;IAClF,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,uDAAuD;IACvD,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACvB,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnC,qDAAqD;IACrD,8BAA8B,CAAC,EAAE,OAAO,CAAA;IACxC,0DAA0D;IAC1D,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC9C,CAAA;AAygBD;;;;;;;;;;;;;;GAcG;AACH,QAAA,MAAM,yBAAyB,WACrB,YAAY,YACV,2BAA2B,sGAUlC,OAAO,CAAC;IACT,KAAK,EAAE,MAAM,CAAA;IACb,YAAY,EAAE,YAAY,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;IACrB,6EAA6E;IAC7E,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,qGAAqG;IACrG,YAAY,EAAE,YAAY,CAAA;IAC1B,4FAA4F;IAC5F,aAAa,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IAClC,+GAA+G;IAC/G,kBAAkB,EAAE,OAAO,CAAA;CAC5B,CAAC,KACD,OAgUF,CAAA;AA+ED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,WACvB,YAAY,YACV,2BAA2B,YAC5B,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC,CAAC,CAAC,KACvD,OA+BF,CAAA"}
|