@scalar/workspace-store 0.75.0 → 0.77.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 +40 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +76 -62
- package/dist/entities/auth/index.d.ts.map +1 -1
- package/dist/entities/auth/index.js +26 -14
- package/dist/entities/auth/schema.d.ts +65 -0
- package/dist/entities/auth/schema.d.ts.map +1 -1
- package/dist/entities/history/index.d.ts.map +1 -1
- package/dist/entities/history/index.js +25 -14
- package/dist/helpers/dynamic-ref.d.ts +4 -25
- package/dist/helpers/dynamic-ref.d.ts.map +1 -1
- package/dist/helpers/dynamic-ref.js +33 -76
- 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-form-schema.js +1 -1
- package/dist/helpers/resolve-schema-with-annotations.js +1 -1
- package/dist/helpers/resolve-security-requirements.js +2 -2
- package/dist/mutators/document.js +3 -3
- package/dist/navigation/get-navigation-options.d.ts.map +1 -1
- package/dist/navigation/get-navigation-options.js +10 -0
- package/dist/navigation/helpers/traverse-asyncapi-document.d.ts.map +1 -1
- package/dist/navigation/helpers/traverse-asyncapi-document.js +37 -3
- 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/helpers/get-example-from-schema.d.ts.map +1 -1
- package/dist/request-example/builder/helpers/get-example-from-schema.js +21 -16
- package/dist/request-example/builder/helpers/get-example.js +1 -1
- package/dist/request-example/builder/helpers/get-resolved-url.d.ts.map +1 -1
- package/dist/request-example/builder/helpers/get-resolved-url.js +2 -4
- package/dist/request-example/builder/helpers/get-server-variables.d.ts +1 -1
- package/dist/request-example/builder/helpers/get-server-variables.d.ts.map +1 -1
- package/dist/request-example/builder/helpers/get-server-variables.js +2 -12
- package/dist/request-example/builder/helpers/resolve-server-url.d.ts +4 -0
- package/dist/request-example/builder/helpers/resolve-server-url.d.ts.map +1 -0
- package/dist/request-example/builder/helpers/resolve-server-url.js +4 -0
- package/dist/request-example/builder/index.d.ts +1 -0
- package/dist/request-example/builder/index.d.ts.map +1 -1
- package/dist/request-example/builder/index.js +1 -0
- package/dist/request-example/builder/request-factory.d.ts +3 -1
- package/dist/request-example/builder/request-factory.d.ts.map +1 -1
- package/dist/request-example/builder/request-factory.js +6 -7
- package/dist/request-example/context/security/merge-security.d.ts.map +1 -1
- package/dist/request-example/context/security/merge-security.js +13 -1
- package/dist/request-example/index.d.ts +2 -1
- package/dist/request-example/index.d.ts.map +1 -1
- package/dist/request-example/index.js +2 -1
- package/dist/request-example/xml/get-xml-example.js +7 -5
- package/dist/request-example/xml/write-xml.d.ts +2 -0
- package/dist/request-example/xml/write-xml.d.ts.map +1 -1
- package/dist/request-example/xml/write-xml.js +14 -4
- package/dist/{resolve.d.ts → resolve/index.d.ts} +3 -3
- package/dist/resolve/index.d.ts.map +1 -0
- package/dist/{resolve.js → resolve/index.js} +7 -5
- package/dist/schemas/navigation.d.ts +47 -2
- package/dist/schemas/navigation.d.ts.map +1 -1
- package/dist/schemas/navigation.js +11 -0
- package/dist/schemas/reference-config/index.d.ts +13 -0
- package/dist/schemas/reference-config/index.d.ts.map +1 -1
- package/dist/schemas/reference-config/settings.d.ts +13 -0
- package/dist/schemas/reference-config/settings.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/openapi-document.d.ts +455 -0
- package/dist/schemas/v3.1/strict/openapi-document.d.ts.map +1 -1
- package/dist/schemas/v3.2/strict/openapi-document.d.ts +455 -0
- package/dist/schemas/v3.2/strict/openapi-document.d.ts.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +11 -10
- package/package.json +16 -15
- package/dist/resolve.d.ts.map +0 -1
|
@@ -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":"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;
|
|
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;AA6wBD,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;AA0gBD;;;;;;;;;;;;;;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,OAkUF,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"}
|
|
@@ -8,7 +8,7 @@ import { getResolvedRef } from '../../../helpers/get-resolved-ref.js';
|
|
|
8
8
|
import { isFileSchema } from '../../../helpers/is-file-schema.js';
|
|
9
9
|
import { resolveFormSchema } from '../../../helpers/resolve-form-schema.js';
|
|
10
10
|
import { unpackProxyObject } from '../../../helpers/unpack-proxy.js';
|
|
11
|
-
import { resolve } from '../../../resolve.js';
|
|
11
|
+
import { resolve } from '../../../resolve/index.js';
|
|
12
12
|
import { generateContainsArray, getArrayDialect } from './array-contains.js';
|
|
13
13
|
import { EXAMPLE_EVALUATION } from './example-evaluation.js';
|
|
14
14
|
/** Maximum recursion depth to prevent infinite loops in circular references */
|
|
@@ -826,11 +826,14 @@ const handleArraySchema = (schema, options, level, seen, cacheKey, schemaPath, d
|
|
|
826
826
|
// (e.g. a category whose children reference the same anchor) render their nested levels instead of
|
|
827
827
|
// tripping the shared guard. Depth stays bounded by `MAX_LEVELS_DEEP`.
|
|
828
828
|
let itemsSeen = seen;
|
|
829
|
+
let itemsScope = childScope;
|
|
829
830
|
if (items && isDynamicRef(items)) {
|
|
830
|
-
const
|
|
831
|
+
const referenceScope = pushDynamicScope(childScope, items);
|
|
832
|
+
const resolvedDynamic = resolveDynamicRef(items.$dynamicRef, referenceScope);
|
|
831
833
|
if (resolvedDynamic) {
|
|
832
834
|
items = resolvedDynamic;
|
|
833
835
|
itemsSeen = new WeakSet();
|
|
836
|
+
itemsScope = referenceScope;
|
|
834
837
|
}
|
|
835
838
|
}
|
|
836
839
|
const itemsSchemaPath = [...schemaPath, 'items'];
|
|
@@ -870,7 +873,7 @@ const handleArraySchema = (schema, options, level, seen, cacheKey, schemaPath, d
|
|
|
870
873
|
parentSchema: schema,
|
|
871
874
|
schemaPath: itemsSchemaPath,
|
|
872
875
|
seen: itemsSeen,
|
|
873
|
-
dynamicScope:
|
|
876
|
+
dynamicScope: itemsScope,
|
|
874
877
|
});
|
|
875
878
|
return completeArrayExample(isDefined(merged) ? [merged] : []);
|
|
876
879
|
}
|
|
@@ -880,7 +883,7 @@ const handleArraySchema = (schema, options, level, seen, cacheKey, schemaPath, d
|
|
|
880
883
|
parentSchema: schema,
|
|
881
884
|
schemaPath: itemsSchemaPath,
|
|
882
885
|
seen: itemsSeen,
|
|
883
|
-
dynamicScope:
|
|
886
|
+
dynamicScope: itemsScope,
|
|
884
887
|
}))
|
|
885
888
|
.filter(isDefined);
|
|
886
889
|
// Let generation resolve references, declarations and union selections before deciding whether
|
|
@@ -909,7 +912,7 @@ const handleArraySchema = (schema, options, level, seen, cacheKey, schemaPath, d
|
|
|
909
912
|
parentSchema: schema,
|
|
910
913
|
schemaPath: itemsSchemaPath,
|
|
911
914
|
seen: itemsSeen,
|
|
912
|
-
dynamicScope:
|
|
915
|
+
dynamicScope: itemsScope,
|
|
913
916
|
});
|
|
914
917
|
if (ex === undefined) {
|
|
915
918
|
return values.length > 0 ? cache(schema, values, cacheKey, skipCache) : undefined;
|
|
@@ -928,7 +931,7 @@ const handleArraySchema = (schema, options, level, seen, cacheKey, schemaPath, d
|
|
|
928
931
|
level: level + 1,
|
|
929
932
|
schemaPath: itemsSchemaPath,
|
|
930
933
|
seen: itemsSeen,
|
|
931
|
-
dynamicScope:
|
|
934
|
+
dynamicScope: itemsScope,
|
|
932
935
|
});
|
|
933
936
|
// Propagate an omitted recursive item so optional arrays do not serialize it as null.
|
|
934
937
|
if (ex === undefined) {
|
|
@@ -1155,10 +1158,11 @@ const getCompositionRequiredNames = (schema, options, schemaPath, level, seen, d
|
|
|
1155
1158
|
visited.set(target, contexts);
|
|
1156
1159
|
// Requirements behind a dynamic reference constrain the same instance as its composition siblings.
|
|
1157
1160
|
// Follow the same binding as the example walk, within this collector's existing depth and step bounds.
|
|
1161
|
+
const childScope = pushDynamicScope(current.dynamicScope, current.schema);
|
|
1158
1162
|
if (isDynamicRef(current.schema)) {
|
|
1159
|
-
const resolved = resolveDynamicRef(current.schema.$dynamicRef,
|
|
1163
|
+
const resolved = resolveDynamicRef(current.schema.$dynamicRef, childScope);
|
|
1160
1164
|
if (resolved) {
|
|
1161
|
-
pending.push({ ...current, schema: resolved, depth: current.depth + 1 });
|
|
1165
|
+
pending.push({ ...current, schema: resolved, dynamicScope: childScope, depth: current.depth + 1 });
|
|
1162
1166
|
continue;
|
|
1163
1167
|
}
|
|
1164
1168
|
}
|
|
@@ -1204,7 +1208,7 @@ const getCompositionRequiredNames = (schema, options, schemaPath, level, seen, d
|
|
|
1204
1208
|
schema: resolved,
|
|
1205
1209
|
options: consumeCompositionSelection(current.options, current.schemaPath, keyword),
|
|
1206
1210
|
schemaPath: current.schemaPath,
|
|
1207
|
-
dynamicScope:
|
|
1211
|
+
dynamicScope: childScope,
|
|
1208
1212
|
depth: current.depth + 1,
|
|
1209
1213
|
});
|
|
1210
1214
|
}
|
|
@@ -1219,7 +1223,7 @@ const getCompositionRequiredNames = (schema, options, schemaPath, level, seen, d
|
|
|
1219
1223
|
schema: resolved,
|
|
1220
1224
|
options: current.options,
|
|
1221
1225
|
schemaPath: isChoiceMember ? [...current.schemaPath, String(choiceIndex++)] : current.schemaPath,
|
|
1222
|
-
dynamicScope:
|
|
1226
|
+
dynamicScope: childScope,
|
|
1223
1227
|
depth: current.depth + 1,
|
|
1224
1228
|
});
|
|
1225
1229
|
}
|
|
@@ -1456,10 +1460,13 @@ const generateExampleFromSchema = (schema, options, { level = 0, parentSchema, n
|
|
|
1456
1460
|
if (typeof _schema.$schema === 'string') {
|
|
1457
1461
|
options = { ...options, jsonSchemaDialect: _schema.$schema };
|
|
1458
1462
|
}
|
|
1459
|
-
//
|
|
1460
|
-
|
|
1463
|
+
// Grow the scope with this schema so nested references can bind to its `$dynamicAnchor`s.
|
|
1464
|
+
const childScope = pushDynamicScope(dynamicScope, _schema);
|
|
1465
|
+
// Resolve a `$dynamicRef` against the scope including this schema, then continue with the bound schema.
|
|
1466
|
+
// A reference declared on a resource belongs to that resource, matching the magic proxy's
|
|
1467
|
+
// `$dynamicRef-value`. When nothing matches, fall through and render the reference as before.
|
|
1461
1468
|
if (isDynamicRef(_schema)) {
|
|
1462
|
-
const resolvedDynamic = resolveDynamicRef(_schema.$dynamicRef,
|
|
1469
|
+
const resolvedDynamic = resolveDynamicRef(_schema.$dynamicRef, childScope);
|
|
1463
1470
|
if (resolvedDynamic) {
|
|
1464
1471
|
// The `seen` set guards against cycles in the static schema graph, but a `$dynamicRef` is resolved
|
|
1465
1472
|
// per evaluation path and intentionally points outside that graph. Re-entering the bound type with a
|
|
@@ -1471,14 +1478,12 @@ const generateExampleFromSchema = (schema, options, { level = 0, parentSchema, n
|
|
|
1471
1478
|
name,
|
|
1472
1479
|
seen: new WeakSet(),
|
|
1473
1480
|
schemaPath,
|
|
1474
|
-
dynamicScope,
|
|
1481
|
+
dynamicScope: childScope,
|
|
1475
1482
|
requiredScope,
|
|
1476
1483
|
isRequiredProperty,
|
|
1477
1484
|
});
|
|
1478
1485
|
}
|
|
1479
1486
|
}
|
|
1480
|
-
// Grow the scope with this schema so nested references can bind to its `$dynamicAnchor`s.
|
|
1481
|
-
const childScope = pushDynamicScope(dynamicScope, _schema);
|
|
1482
1487
|
// The same shared node can resolve differently per scope, so skip the result cache under a scope.
|
|
1483
1488
|
const skipCache = dynamicScope.length > 0 || !!options?.[EXAMPLE_EVALUATION];
|
|
1484
1489
|
// Unpack from all proxies to get the raw schema object for cycle detection
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getResolvedRef } from '../../../helpers/get-resolved-ref.js';
|
|
2
|
-
import { resolve } from '../../../resolve.js';
|
|
2
|
+
import { resolve } from '../../../resolve/index.js';
|
|
3
3
|
// Keep suggestion provenance out of API descriptions and persisted user examples.
|
|
4
4
|
const generatedExamples = new WeakSet();
|
|
5
5
|
/** Whether an example contains only enum suggestions rather than authored values. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-resolved-url.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/helpers/get-resolved-url.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-resolved-url.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/helpers/get-resolved-url.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAIhE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,iCAIxB;IACD,MAAM,EAAE,YAAY,GAAG,IAAI,CAAA;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,eAAe,CAAA;IAC3B,4BAA4B,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CAC3C,KAAG,MAEH,CAAA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { replaceVariables } from '@scalar/helpers/regex/replace-variables';
|
|
2
1
|
import { mergeUrls } from '@scalar/helpers/url/merge-urls';
|
|
3
|
-
import {
|
|
2
|
+
import { resolveServerUrl } from './resolve-server-url.js';
|
|
4
3
|
/**
|
|
5
4
|
* Resolves the full request URL by:
|
|
6
5
|
* 1. Applying OpenAPI server variables to the server URL template.
|
|
@@ -14,6 +13,5 @@ import { getServerVariables } from './get-server-variables.js';
|
|
|
14
13
|
* @returns The resolved URL as a string
|
|
15
14
|
*/
|
|
16
15
|
export const getResolvedUrl = ({ server, path, urlParams, }) => {
|
|
17
|
-
|
|
18
|
-
return mergeUrls(replaceVariables(server?.url ?? '', serverVariables), path, urlParams);
|
|
16
|
+
return mergeUrls(resolveServerUrl(server), path, urlParams);
|
|
19
17
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ServerObject } from '../../../schemas/v3.2/strict/server.js';
|
|
2
2
|
/**
|
|
3
3
|
* Extracts the default values of variables defined in a ServerObject into a simple key-value map.
|
|
4
|
-
* Ignores variables with no default value.
|
|
4
|
+
* Keeps empty string defaults because an empty value is a valid substitution. Ignores variables with no default value.
|
|
5
5
|
*
|
|
6
6
|
* @param server The OpenAPI ServerObject (may be null).
|
|
7
7
|
* @returns Record of variableName -> defaultValue.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-server-variables.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/helpers/get-server-variables.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAEhE;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,WAAY,YAAY,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"get-server-variables.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/helpers/get-server-variables.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAEhE;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,WAAY,YAAY,GAAG,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAKnF,CAAA"}
|
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
import { objectEntries } from '@scalar/helpers/object/object-entries';
|
|
2
2
|
/**
|
|
3
3
|
* Extracts the default values of variables defined in a ServerObject into a simple key-value map.
|
|
4
|
-
* Ignores variables with no default value.
|
|
4
|
+
* Keeps empty string defaults because an empty value is a valid substitution. Ignores variables with no default value.
|
|
5
5
|
*
|
|
6
6
|
* @param server The OpenAPI ServerObject (may be null).
|
|
7
7
|
* @returns Record of variableName -> defaultValue.
|
|
8
8
|
*/
|
|
9
|
-
export const getServerVariables = (server) => {
|
|
10
|
-
if (!server) {
|
|
11
|
-
return {};
|
|
12
|
-
}
|
|
13
|
-
return objectEntries(server?.variables ?? {}).reduce((acc, [name, variable]) => {
|
|
14
|
-
if (variable.default) {
|
|
15
|
-
acc[name] = variable.default;
|
|
16
|
-
}
|
|
17
|
-
return acc;
|
|
18
|
-
}, {});
|
|
19
|
-
};
|
|
9
|
+
export const getServerVariables = (server) => Object.fromEntries(objectEntries(server?.variables ?? {}).flatMap(([name, variable]) => variable.default === undefined ? [] : [[name, variable.default]]));
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ServerObject } from '../../../schemas/v3.2/strict/server.js';
|
|
2
|
+
/** Substitutes OpenAPI server variable defaults in the selected server URL. */
|
|
3
|
+
export declare const resolveServerUrl: (server: ServerObject | null) => string;
|
|
4
|
+
//# sourceMappingURL=resolve-server-url.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-server-url.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/helpers/resolve-server-url.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAIhE,+EAA+E;AAC/E,eAAO,MAAM,gBAAgB,WAAY,YAAY,GAAG,IAAI,KAAG,MACM,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { replacePathVariables } from '@scalar/helpers/regex/replace-variables';
|
|
2
|
+
import { getServerVariables } from './get-server-variables.js';
|
|
3
|
+
/** Substitutes OpenAPI server variable defaults in the selected server URL. */
|
|
4
|
+
export const resolveServerUrl = (server) => replacePathVariables(server?.url ?? '', getServerVariables(server));
|
|
@@ -14,6 +14,7 @@ export { getExample } from './helpers/get-example.js';
|
|
|
14
14
|
export { getExampleFromSchema } from './helpers/get-example-from-schema.js';
|
|
15
15
|
export { getResolvedUrl } from './helpers/get-resolved-url.js';
|
|
16
16
|
export { getServerVariables } from './helpers/get-server-variables.js';
|
|
17
|
+
export { resolveServerUrl } from './helpers/resolve-server-url.js';
|
|
17
18
|
export type { RequestFactory } from './request-factory.js';
|
|
18
19
|
export { requestFactory } from './request-factory.js';
|
|
19
20
|
export { INVALID_REQUEST_FACTORY_URL, MISSING_REQUEST_SERVER_BASE, type ResolveRequestFactoryUrlError, type ResolveRequestFactoryUrlResult, resolveRequestFactoryUrl, } from './resolve-request-factory-url.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/request-example/builder/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAA;AAC9F,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAA;AAClF,OAAO,EACL,6BAA6B,EAC7B,2BAA2B,EAC3B,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,KAAK,sBAAsB,EAAE,iCAAiC,EAAE,MAAM,gCAAgC,CAAA;AAC/G,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAC1E,OAAO,EACL,oBAAoB,EACpB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,YAAY,EACZ,2BAA2B,GAC5B,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAA;AAC9F,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAA;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,wBAAwB,EACxB,kBAAkB,EAClB,4BAA4B,EAC5B,2BAA2B,EAC3B,oBAAoB,EACpB,4BAA4B,GAC7B,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAA;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAA;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AACnE,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EACL,2BAA2B,EAC3B,2BAA2B,EAC3B,KAAK,6BAA6B,EAClC,KAAK,8BAA8B,EACnC,wBAAwB,GACzB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAA;AACxE,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,gCAAgC,EAChC,gCAAgC,EAChC,kCAAkC,EAClC,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,yBAAyB,EACzB,gBAAgB,EAChB,0BAA0B,EAC1B,gBAAgB,GACjB,MAAM,yBAAyB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/request-example/builder/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAA;AAC9F,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAA;AAClF,OAAO,EACL,6BAA6B,EAC7B,2BAA2B,EAC3B,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,KAAK,sBAAsB,EAAE,iCAAiC,EAAE,MAAM,gCAAgC,CAAA;AAC/G,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAC1E,OAAO,EACL,oBAAoB,EACpB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,YAAY,EACZ,2BAA2B,GAC5B,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAA;AAC9F,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAA;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,wBAAwB,EACxB,kBAAkB,EAClB,4BAA4B,EAC5B,2BAA2B,EAC3B,oBAAoB,EACpB,4BAA4B,GAC7B,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAA;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAA;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EACL,2BAA2B,EAC3B,2BAA2B,EAC3B,KAAK,6BAA6B,EAClC,KAAK,8BAA8B,EACnC,wBAAwB,GACzB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAA;AACxE,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,gCAAgC,EAChC,gCAAgC,EAChC,kCAAkC,EAClC,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,yBAAyB,EACzB,gBAAgB,EAChB,0BAA0B,EAC1B,gBAAgB,GACjB,MAAM,yBAAyB,CAAA"}
|
|
@@ -14,6 +14,7 @@ export { getExample } from './helpers/get-example.js';
|
|
|
14
14
|
export { getExampleFromSchema } from './helpers/get-example-from-schema.js';
|
|
15
15
|
export { getResolvedUrl } from './helpers/get-resolved-url.js';
|
|
16
16
|
export { getServerVariables } from './helpers/get-server-variables.js';
|
|
17
|
+
export { resolveServerUrl } from './helpers/resolve-server-url.js';
|
|
17
18
|
export { requestFactory } from './request-factory.js';
|
|
18
19
|
export { INVALID_REQUEST_FACTORY_URL, MISSING_REQUEST_SERVER_BASE, resolveRequestFactoryUrl, } from './resolve-request-factory-url.js';
|
|
19
20
|
export { isEncryptionSchemeType, isSaslSchemeType } from './security/broker-scheme-types.js';
|