@scalar/workspace-store 0.66.0 → 0.67.1
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 +31 -0
- package/dist/entities/auth/schema.d.ts +22 -22
- package/dist/entities/auth/schema.d.ts.map +1 -1
- package/dist/entities/auth/schema.js +6 -4
- package/dist/events/definitions/operation.d.ts +2 -0
- package/dist/events/definitions/operation.d.ts.map +1 -1
- package/dist/helpers/encode-chunk-name.d.ts.map +1 -1
- package/dist/helpers/encode-chunk-name.js +6 -1
- package/dist/helpers/merge-object.d.ts.map +1 -1
- package/dist/helpers/merge-object.js +9 -3
- package/dist/request-example/builder/body/build-request-body.d.ts +1 -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 +2 -2
- package/dist/request-example/builder/body/get-request-body-example.d.ts +4 -4
- package/dist/request-example/builder/body/get-request-body-example.d.ts.map +1 -1
- package/dist/request-example/builder/body/get-request-body-example.js +29 -5
- package/dist/request-example/builder/helpers/example-evaluation.d.ts +19 -0
- package/dist/request-example/builder/helpers/example-evaluation.d.ts.map +1 -0
- package/dist/request-example/builder/helpers/example-evaluation.js +2 -0
- package/dist/request-example/builder/helpers/get-example-from-schema.d.ts +11 -3
- 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 +66 -17
- package/dist/request-example/builder/helpers/get-example.d.ts.map +1 -1
- package/dist/request-example/builder/helpers/get-example.js +35 -21
- 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 +2 -2
- package/dist/request-example/index.d.ts +4 -0
- package/dist/request-example/index.d.ts.map +1 -1
- package/dist/request-example/index.js +3 -0
- package/dist/request-example/xml/get-xml-body-example.d.ts +8 -0
- package/dist/request-example/xml/get-xml-body-example.d.ts.map +1 -0
- package/dist/request-example/xml/get-xml-body-example.js +21 -0
- package/dist/request-example/xml/get-xml-example.d.ts +21 -0
- package/dist/request-example/xml/get-xml-example.d.ts.map +1 -0
- package/dist/request-example/xml/get-xml-example.js +352 -0
- package/dist/request-example/xml/match-xml-property-pattern.d.ts +10 -0
- package/dist/request-example/xml/match-xml-property-pattern.d.ts.map +1 -0
- package/dist/request-example/xml/match-xml-property-pattern.js +48 -0
- package/dist/request-example/xml/serialize-xml-part.d.ts +4 -5
- package/dist/request-example/xml/serialize-xml-part.d.ts.map +1 -1
- package/dist/request-example/xml/serialize-xml-part.js +14 -8
- package/dist/request-example/xml/write-xml.d.ts +9 -0
- package/dist/request-example/xml/write-xml.d.ts.map +1 -0
- package/dist/request-example/xml/write-xml.js +119 -0
- package/dist/request-example/xml/xml-node.d.ts +32 -0
- package/dist/request-example/xml/xml-node.d.ts.map +1 -0
- package/dist/request-example/xml/xml-node.js +1 -0
- package/package.json +8 -8
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { type DynamicScope } from '../../../helpers/dynamic-ref.js';
|
|
2
2
|
import type { SchemaObject } from '../../../schemas/v3.2/strict/openapi-document.js';
|
|
3
|
-
type
|
|
3
|
+
import { EXAMPLE_EVALUATION, type ExampleEvaluationState } from './example-evaluation.js';
|
|
4
|
+
/** Select a composition branch once for both generated values and supplied example metadata. */
|
|
5
|
+
export declare const selectExampleComposition: (schema: SchemaObject, schemaPath: string[], options?: GetExampleFromSchemaOptions, arrayItem?: boolean, value?: Record<string, unknown>) => SchemaObject | undefined;
|
|
6
|
+
/** Options shared by data generation and schema-aware serializers. */
|
|
7
|
+
export type GetExampleFromSchemaOptions = {
|
|
8
|
+
/** Internal provenance capture, excluded from persistent result caches. */
|
|
9
|
+
[EXAMPLE_EVALUATION]?: ExampleEvaluationState;
|
|
4
10
|
/** Fallback string for empty string values. */
|
|
5
11
|
emptyString?: string;
|
|
6
|
-
/**
|
|
12
|
+
/** @deprecated Use getXmlExampleFromSchema for schema-aware XML serialization. */
|
|
7
13
|
xml?: boolean;
|
|
8
14
|
/** Whether to show read-only/write-only properties. */
|
|
9
15
|
mode?: 'read' | 'write';
|
|
@@ -37,7 +43,7 @@ type GetExampleFromSchemaOptions = {
|
|
|
37
43
|
* @param name - The name of the property being processed.
|
|
38
44
|
* @returns An example value for the given schema.
|
|
39
45
|
*/
|
|
40
|
-
|
|
46
|
+
declare const generateExampleFromSchema: (schema: SchemaObject, options?: GetExampleFromSchemaOptions, { level, parentSchema, name, seen, schemaPath, dynamicScope, }?: Partial<{
|
|
41
47
|
level: number;
|
|
42
48
|
parentSchema: SchemaObject;
|
|
43
49
|
name: string;
|
|
@@ -47,5 +53,7 @@ export declare const getExampleFromSchema: (schema: SchemaObject, options?: GetE
|
|
|
47
53
|
/** Chain of schema resources entered so far, used to resolve `$dynamicRef` (JSON Schema 2020-12). */
|
|
48
54
|
dynamicScope: DynamicScope;
|
|
49
55
|
}>) => unknown;
|
|
56
|
+
/** Generate data, optionally retaining the exact schema decisions for another output format. */
|
|
57
|
+
export declare const getExampleFromSchema: (schema: SchemaObject, options?: GetExampleFromSchemaOptions, context?: Parameters<typeof generateExampleFromSchema>[2]) => unknown;
|
|
50
58
|
export {};
|
|
51
59
|
//# sourceMappingURL=get-example-from-schema.d.ts.map
|
|
@@ -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":"AAGA,OAAO,EAAE,KAAK,YAAY,EAAqD,MAAM,uBAAuB,CAAA;AAG5G,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,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":"AAGA,OAAO,EAAE,KAAK,YAAY,EAAqD,MAAM,uBAAuB,CAAA;AAG5G,OAAO,KAAK,EAAE,YAAY,EAAE,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CAAM,KACN,OA8OF,CAAA;AAED,gGAAgG;AAChG,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,YAAY,EACpB,UAAU,2BAA2B,EACrC,UAAS,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC,CAAC,CAAM,KAC5D,OA0BF,CAAA"}
|
|
@@ -3,6 +3,7 @@ import { escapeJsonPointer } from '@scalar/helpers/json/escape-json-pointer';
|
|
|
3
3
|
import { isDynamicRef, pushDynamicScope, resolveDynamicRef } from '../../../helpers/dynamic-ref.js';
|
|
4
4
|
import { unpackProxyObject } from '../../../helpers/unpack-proxy.js';
|
|
5
5
|
import { resolve } from '../../../resolve.js';
|
|
6
|
+
import { EXAMPLE_EVALUATION } from './example-evaluation.js';
|
|
6
7
|
/** Maximum recursion depth to prevent infinite loops in circular references */
|
|
7
8
|
const MAX_LEVELS_DEEP = 10;
|
|
8
9
|
/** Default name used for additional properties when no custom name is provided */
|
|
@@ -317,6 +318,25 @@ const consumeCompositionSelection = (options, schemaPath, composition) => {
|
|
|
317
318
|
const { [key]: _selection, ...compositionSelection } = options.compositionSelection;
|
|
318
319
|
return { ...options, compositionSelection };
|
|
319
320
|
};
|
|
321
|
+
/** Select a composition branch once for both generated values and supplied example metadata. */
|
|
322
|
+
export const selectExampleComposition = (schema, schemaPath, options, arrayItem = false, value) => {
|
|
323
|
+
const keyword = schema.oneOf ? 'oneOf' : schema.anyOf ? 'anyOf' : undefined;
|
|
324
|
+
const members = keyword ? schema[keyword] : undefined;
|
|
325
|
+
if (!keyword || !members?.length) {
|
|
326
|
+
return undefined;
|
|
327
|
+
}
|
|
328
|
+
const index = getCompositionSelectionIndex(schemaPath, keyword, options, members.length) ??
|
|
329
|
+
getDiscriminatorSelectionIndex(schema, members, options, value);
|
|
330
|
+
const isObject = 'properties' in schema || ('type' in schema && schema.type === 'object');
|
|
331
|
+
const candidate = index !== undefined || isObject || arrayItem
|
|
332
|
+
? members[index ?? 0]
|
|
333
|
+
: members.find((item) => {
|
|
334
|
+
const resolved = resolve.schema(item);
|
|
335
|
+
return resolved && (!('type' in resolved) || resolved.type !== 'null');
|
|
336
|
+
});
|
|
337
|
+
// The generator resolves the value at its entry point; serializers also need the reference site.
|
|
338
|
+
return candidate;
|
|
339
|
+
};
|
|
320
340
|
/**
|
|
321
341
|
* Use the discriminator as a generation hint. Only referenced variants have
|
|
322
342
|
* implicit names; inline titles are display labels, not discriminator mappings.
|
|
@@ -393,7 +413,7 @@ const handleObjectSchema = (schema, options, level, seen, cacheKey, schemaPath,
|
|
|
393
413
|
const response = {};
|
|
394
414
|
// Children are evaluated with this schema added to the dynamic scope so nested `$dynamicRef`s bind here.
|
|
395
415
|
const childScope = pushDynamicScope(dynamicScope, schema);
|
|
396
|
-
const skipCache = dynamicScope.length > 0;
|
|
416
|
+
const skipCache = dynamicScope.length > 0 || !!options?.[EXAMPLE_EVALUATION];
|
|
397
417
|
if ('properties' in schema && schema.properties) {
|
|
398
418
|
const properties = schema.properties;
|
|
399
419
|
const propertyNames = sortPropertyNamesByXOrder(properties);
|
|
@@ -469,10 +489,7 @@ const handleObjectSchema = (schema, options, level, seen, cacheKey, schemaPath,
|
|
|
469
489
|
const compositionKeyword = schema.oneOf ? 'oneOf' : schema.anyOf ? 'anyOf' : undefined;
|
|
470
490
|
const oneOfAnyOf = compositionKeyword ? schema[compositionKeyword] : undefined;
|
|
471
491
|
if (compositionKeyword && oneOfAnyOf?.length) {
|
|
472
|
-
const
|
|
473
|
-
getDiscriminatorSelectionIndex(schema, oneOfAnyOf, options, response) ??
|
|
474
|
-
0;
|
|
475
|
-
const chosen = resolve.schema(oneOfAnyOf[index]);
|
|
492
|
+
const chosen = selectExampleComposition(schema, schemaPath, options, false, response);
|
|
476
493
|
if (chosen) {
|
|
477
494
|
Object.assign(response, getExampleFromSchema(chosen, consumeCompositionSelection(options, schemaPath, compositionKeyword), {
|
|
478
495
|
level: level + 1,
|
|
@@ -516,7 +533,16 @@ const handleObjectSchema = (schema, options, level, seen, cacheKey, schemaPath,
|
|
|
516
533
|
/** Build an example for an array schema, including items, allOf, oneOf/anyOf, and XML wrapping */
|
|
517
534
|
const handleArraySchema = (schema, options, level, seen, cacheKey, schemaPath, dynamicScope) => {
|
|
518
535
|
const childScope = pushDynamicScope(dynamicScope, schema);
|
|
519
|
-
const skipCache = dynamicScope.length > 0;
|
|
536
|
+
const skipCache = dynamicScope.length > 0 || !!options?.[EXAMPLE_EVALUATION];
|
|
537
|
+
if ('prefixItems' in schema && Array.isArray(schema.prefixItems)) {
|
|
538
|
+
const values = schema.prefixItems.map((item, index) => getExampleFromSchema(item, options, {
|
|
539
|
+
level: level + 1,
|
|
540
|
+
schemaPath: [...schemaPath, 'prefixItems', String(index)],
|
|
541
|
+
seen,
|
|
542
|
+
dynamicScope: childScope,
|
|
543
|
+
}));
|
|
544
|
+
return cache(schema, values, cacheKey, skipCache);
|
|
545
|
+
}
|
|
520
546
|
let items = 'items' in schema ? resolve.schema(schema.items) : undefined;
|
|
521
547
|
// Bind a dynamic item type (e.g. the generic `PaginatedResponse<T>` pattern) before inspecting it.
|
|
522
548
|
// Crossing a `$dynamicRef` leaves the static schema graph, so the cycle guard built up by the outer
|
|
@@ -856,7 +882,7 @@ const getMaxDepthValue = (schema, options, schemaPath, seen = new Set()) => {
|
|
|
856
882
|
* @param name - The name of the property being processed.
|
|
857
883
|
* @returns An example value for the given schema.
|
|
858
884
|
*/
|
|
859
|
-
|
|
885
|
+
const generateExampleFromSchema = (schema, options, { level = 0, parentSchema, name, seen = new WeakSet(), schemaPath = [], dynamicScope = [], } = {}) => {
|
|
860
886
|
// A truncation only taints the call it happened in, so every top-level call starts clean.
|
|
861
887
|
if (level === 0) {
|
|
862
888
|
truncated = false;
|
|
@@ -888,7 +914,7 @@ export const getExampleFromSchema = (schema, options, { level = 0, parentSchema,
|
|
|
888
914
|
// Grow the scope with this schema so nested references can bind to its `$dynamicAnchor`s.
|
|
889
915
|
const childScope = pushDynamicScope(dynamicScope, _schema);
|
|
890
916
|
// The same shared node can resolve differently per scope, so skip the result cache under a scope.
|
|
891
|
-
const skipCache = dynamicScope.length > 0;
|
|
917
|
+
const skipCache = dynamicScope.length > 0 || !!options?.[EXAMPLE_EVALUATION];
|
|
892
918
|
// Unpack from all proxies to get the raw schema object for cycle detection
|
|
893
919
|
const targetValue = getSchemaCacheTarget(_schema);
|
|
894
920
|
if (seen.has(targetValue)) {
|
|
@@ -994,7 +1020,7 @@ export const getExampleFromSchema = (schema, options, { level = 0, parentSchema,
|
|
|
994
1020
|
return result;
|
|
995
1021
|
}
|
|
996
1022
|
// Handle array types
|
|
997
|
-
if (('type' in _schema && _schema.type === 'array') || 'items' in _schema) {
|
|
1023
|
+
if (('type' in _schema && _schema.type === 'array') || 'items' in _schema || 'prefixItems' in _schema) {
|
|
998
1024
|
const result = handleArraySchema(_schema, options, level, seen, cacheKey, schemaPath, dynamicScope);
|
|
999
1025
|
seen.delete(targetValue);
|
|
1000
1026
|
return result;
|
|
@@ -1009,14 +1035,7 @@ export const getExampleFromSchema = (schema, options, { level = 0, parentSchema,
|
|
|
1009
1035
|
const compositionKeyword = _schema.oneOf ? 'oneOf' : _schema.anyOf ? 'anyOf' : undefined;
|
|
1010
1036
|
const discriminate = compositionKeyword ? _schema[compositionKeyword] : undefined;
|
|
1011
1037
|
if (compositionKeyword && Array.isArray(discriminate) && discriminate.length > 0) {
|
|
1012
|
-
const
|
|
1013
|
-
getDiscriminatorSelectionIndex(_schema, discriminate, options);
|
|
1014
|
-
const candidate = index !== undefined
|
|
1015
|
-
? discriminate[index]
|
|
1016
|
-
: discriminate.find((item) => {
|
|
1017
|
-
const resolved = resolve.schema(item);
|
|
1018
|
-
return resolved && (!('type' in resolved) || resolved.type !== 'null');
|
|
1019
|
-
});
|
|
1038
|
+
const candidate = selectExampleComposition(_schema, schemaPath, options);
|
|
1020
1039
|
if (candidate) {
|
|
1021
1040
|
const resolved = resolve.schema(candidate);
|
|
1022
1041
|
if (resolved) {
|
|
@@ -1073,3 +1092,33 @@ export const getExampleFromSchema = (schema, options, { level = 0, parentSchema,
|
|
|
1073
1092
|
seen.delete(targetValue);
|
|
1074
1093
|
return cache(_schema, null, cacheKey, skipCache);
|
|
1075
1094
|
};
|
|
1095
|
+
/** Generate data, optionally retaining the exact schema decisions for another output format. */
|
|
1096
|
+
export const getExampleFromSchema = (schema, options, context = {}) => {
|
|
1097
|
+
const capture = options?.[EXAMPLE_EVALUATION];
|
|
1098
|
+
if (!capture) {
|
|
1099
|
+
return generateExampleFromSchema(schema, options, context);
|
|
1100
|
+
}
|
|
1101
|
+
const node = {
|
|
1102
|
+
schema,
|
|
1103
|
+
value: undefined,
|
|
1104
|
+
path: context.schemaPath ?? [],
|
|
1105
|
+
name: context.name,
|
|
1106
|
+
dynamicScope: context.dynamicScope ?? [],
|
|
1107
|
+
children: [],
|
|
1108
|
+
};
|
|
1109
|
+
const parent = capture.stack.at(-1);
|
|
1110
|
+
if (parent) {
|
|
1111
|
+
parent.children.push(node);
|
|
1112
|
+
}
|
|
1113
|
+
else {
|
|
1114
|
+
capture.root = node;
|
|
1115
|
+
}
|
|
1116
|
+
capture.stack.push(node);
|
|
1117
|
+
try {
|
|
1118
|
+
node.value = generateExampleFromSchema(schema, options, context);
|
|
1119
|
+
return node.value;
|
|
1120
|
+
}
|
|
1121
|
+
finally {
|
|
1122
|
+
capture.stack.pop();
|
|
1123
|
+
}
|
|
1124
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-example.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/helpers/get-example.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,eAAe,EACf,iBAAiB,
|
|
1
|
+
{"version":3,"file":"get-example.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/helpers/get-example.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,eAAe,EACf,iBAAiB,EAGlB,MAAM,8DAA8D,CAAA;AAyErE;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,GACrB,OAAO,eAAe,GAAG,iBAAiB,GAAG,eAAe,EAC5D,aAAa,MAAM,GAAG,SAAS,EAC/B,aAAa,MAAM,GAAG,SAAS,KAC9B,aAAa,GAAG,SAyBlB,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { getResolvedRef
|
|
1
|
+
import { getResolvedRef } from '../../../helpers/get-resolved-ref.js';
|
|
2
|
+
import { resolve } from '../../../resolve.js';
|
|
2
3
|
/** Helper to get example from examples object with fallback to example field */
|
|
3
4
|
const getExampleFromExamples = (examples, exampleField, exampleName) => {
|
|
4
5
|
if (!examples && exampleField === undefined) {
|
|
@@ -18,6 +19,38 @@ const getExampleFromExamples = (examples, exampleField, exampleName) => {
|
|
|
18
19
|
}
|
|
19
20
|
return undefined;
|
|
20
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* Keep parameter fallback precedence while collecting only values declared by the schema.
|
|
24
|
+
* The general schema generator also invents values for properties without examples, which would
|
|
25
|
+
* unexpectedly populate and enable optional request parameters.
|
|
26
|
+
*/
|
|
27
|
+
const getSchemaExample = (input, ancestors = new Set()) => {
|
|
28
|
+
const schema = resolve.schema(input);
|
|
29
|
+
if ('default' in schema && schema.default !== undefined) {
|
|
30
|
+
return { value: schema.default };
|
|
31
|
+
}
|
|
32
|
+
if ('enum' in schema && schema.enum?.[0] !== undefined) {
|
|
33
|
+
return { value: schema.enum[0] };
|
|
34
|
+
}
|
|
35
|
+
if ('examples' in schema && schema.examples?.[0] !== undefined) {
|
|
36
|
+
return { value: schema.examples[0] };
|
|
37
|
+
}
|
|
38
|
+
if ('example' in schema && schema.example !== undefined) {
|
|
39
|
+
return { value: schema.example };
|
|
40
|
+
}
|
|
41
|
+
// Reference siblings create a fresh merged object, so track the underlying schema for cycles.
|
|
42
|
+
const target = getResolvedRef(input) ?? input;
|
|
43
|
+
if (!('properties' in schema) || !schema.properties || ancestors.has(target)) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
ancestors.add(target);
|
|
47
|
+
const properties = Object.entries(schema.properties).flatMap(([name, property]) => {
|
|
48
|
+
const example = getSchemaExample(property, ancestors);
|
|
49
|
+
return example === undefined ? [] : [[name, example.value]];
|
|
50
|
+
});
|
|
51
|
+
ancestors.delete(target);
|
|
52
|
+
return properties.length > 0 ? { value: Object.fromEntries(properties) } : undefined;
|
|
53
|
+
};
|
|
21
54
|
/**
|
|
22
55
|
* Resolve an example value for a parameter or requestBody from either `examples` or `content.*.examples`.
|
|
23
56
|
* Or the [deprecated] `example` field.
|
|
@@ -46,26 +79,7 @@ export const getExample = (param, exampleName, contentType) => {
|
|
|
46
79
|
// Derive value from the schema
|
|
47
80
|
const resolvedParam = getResolvedRef(param);
|
|
48
81
|
if (resolvedParam && 'schema' in resolvedParam && resolvedParam.schema) {
|
|
49
|
-
|
|
50
|
-
if (!schema) {
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
// Default value
|
|
54
|
-
if ('default' in schema && schema.default !== undefined) {
|
|
55
|
-
return { value: schema.default };
|
|
56
|
-
}
|
|
57
|
-
// Enum value
|
|
58
|
-
if ('enum' in schema && schema.enum?.[0] !== undefined) {
|
|
59
|
-
return { value: schema.enum[0] };
|
|
60
|
-
}
|
|
61
|
-
// Examples value
|
|
62
|
-
if ('examples' in schema && schema.examples?.[0] !== undefined) {
|
|
63
|
-
return { value: schema.examples[0] };
|
|
64
|
-
}
|
|
65
|
-
// Example value
|
|
66
|
-
if ('example' in schema && schema.example !== undefined) {
|
|
67
|
-
return { value: schema.example };
|
|
68
|
-
}
|
|
82
|
+
return getSchemaExample(resolvedParam.schema);
|
|
69
83
|
}
|
|
70
84
|
return undefined;
|
|
71
85
|
};
|
|
@@ -180,7 +180,7 @@ export type RequestFactory = {
|
|
|
180
180
|
* Builds a request object fastory which can be used to build a request object.
|
|
181
181
|
* @returns A request object factory
|
|
182
182
|
*/
|
|
183
|
-
export declare const requestFactory: ({ exampleName, globalCookies, method, operation, path, proxyUrl, server, defaultHeaders, isElectron, selectedSecuritySchemes, requestBodyCompositionSelection, }: RequestExampleMeta & {
|
|
183
|
+
export declare const requestFactory: ({ exampleName, globalCookies, method, operation, path, proxyUrl, server, defaultHeaders, isElectron, selectedSecuritySchemes, openapiVersion, requestBodyCompositionSelection, }: RequestExampleMeta & {
|
|
184
184
|
/** The operation object */
|
|
185
185
|
operation: OperationObject;
|
|
186
186
|
/** For environment variables in the inputs */
|
|
@@ -198,6 +198,8 @@ export declare const requestFactory: ({ exampleName, globalCookies, method, oper
|
|
|
198
198
|
/** The selected security schemes for the current operation */
|
|
199
199
|
selectedSecuritySchemes: SecuritySchemeObjectSecret[];
|
|
200
200
|
/** Selected anyOf/oneOf request-body variants keyed by schema path */
|
|
201
|
+
/** Originating OpenAPI version, used for XML mapping rules. */
|
|
202
|
+
openapiVersion?: string;
|
|
201
203
|
requestBodyCompositionSelection?: Record<string, number>;
|
|
202
204
|
}) => {
|
|
203
205
|
request: RequestFactory;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-factory.d.ts","sourceRoot":"","sources":["../../../src/request-example/builder/request-factory.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2EAA2E,CAAA;AACnH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qEAAqE,CAAA;AACxG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8DAA8D,CAAA;AAChG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uDAAuD,CAAA;AAE5F,OAAO,EAAE,KAAK,oBAAoB,EAA2B,MAAM,iCAAiC,CAAA;AAEpG,OAAO,EACL,KAAK,0BAA0B,EAEhC,MAAM,2DAA2D,CAAA;AAClE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,iDAAiD,CAAA;AACjG,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;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GAAI,
|
|
1
|
+
{"version":3,"file":"request-factory.d.ts","sourceRoot":"","sources":["../../../src/request-example/builder/request-factory.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2EAA2E,CAAA;AACnH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qEAAqE,CAAA;AACxG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8DAA8D,CAAA;AAChG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uDAAuD,CAAA;AAE5F,OAAO,EAAE,KAAK,oBAAoB,EAA2B,MAAM,iCAAiC,CAAA;AAEpG,OAAO,EACL,KAAK,0BAA0B,EAEhC,MAAM,2DAA2D,CAAA;AAClE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,iDAAiD,CAAA;AACjG,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAGjE,OAAO,EAAE,KAAK,WAAW,EAAoB,MAAM,2BAA2B,CAAA;AAG9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B;;;;;OAKG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,IAAI,EAAE;QACJ;;;;;WAKG;QACH,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACjC,kDAAkD;QAClD,oBAAoB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;QAClC;;;;;WAKG;QACH,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IAED;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;;OAGG;IACH,KAAK,EAAE,eAAe,CAAA;IAEtB,wEAAwE;IACxE,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;IAE1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7 @@ import { buildRequestParameters } from './header/build-request-parameters.js';
|
|
|
12
12
|
* Builds a request object fastory which can be used to build a request object.
|
|
13
13
|
* @returns A request object factory
|
|
14
14
|
*/
|
|
15
|
-
export const requestFactory = ({ exampleName, globalCookies, method, operation, path, proxyUrl, server, defaultHeaders, isElectron, selectedSecuritySchemes, requestBodyCompositionSelection, }) => {
|
|
15
|
+
export const requestFactory = ({ exampleName, globalCookies, method, operation, path, proxyUrl, server, defaultHeaders, isElectron, selectedSecuritySchemes, openapiVersion, requestBodyCompositionSelection, }) => {
|
|
16
16
|
const requestBody = getResolvedRef(operation.requestBody);
|
|
17
17
|
/** Build out the request parameters */
|
|
18
18
|
const params = buildRequestParameters(operation.parameters ?? [], exampleName);
|
|
@@ -27,7 +27,7 @@ export const requestFactory = ({ exampleName, globalCookies, method, operation,
|
|
|
27
27
|
});
|
|
28
28
|
// If the method can have a body, build the request body, otherwise set it to null
|
|
29
29
|
const body = canMethodHaveBody(method)
|
|
30
|
-
? buildRequestBody(requestBody, exampleName, requestBodyCompositionSelection)
|
|
30
|
+
? buildRequestBody(requestBody, exampleName, requestBodyCompositionSelection, openapiVersion)
|
|
31
31
|
: null;
|
|
32
32
|
// Delete the Content-Type header so the browser will set it automatically based on the request body
|
|
33
33
|
if (body?.mode === 'formdata' || body?.mode === 'urlencoded') {
|
|
@@ -8,4 +8,8 @@ export { type BuildRequestExampleContext, combineParams, filterDisabledDefaultHe
|
|
|
8
8
|
export { CONTEXT_FUNCTION_NAMES, type ContextFunctionEntry, type ContextFunctionName, POPULAR_CONTEXT_FUNCTION_KEYS, contextFunctions, getContextFunctionComment, isContextFunctionName, } from './functions.js';
|
|
9
9
|
export { createVariablesStoreForRequest } from './variable-store/index.js';
|
|
10
10
|
export type { VariableEntry, VariablesStore } from './variable-store/types.js';
|
|
11
|
+
export { getXmlBodyExample } from './xml/get-xml-body-example.js';
|
|
12
|
+
export { type XmlExampleOptions, getXmlExampleFromSchema, serializeXmlExample } from './xml/get-xml-example.js';
|
|
13
|
+
export { serializeXmlPart } from './xml/serialize-xml-part.js';
|
|
14
|
+
export type { XmlDiagnostic, XmlExampleResult } from './xml/xml-node.js';
|
|
11
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/request-example/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,gBAAgB,EAChB,uBAAuB,EACvB,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,gCAAgC,EAChC,gCAAgC,EAChC,kCAAkC,EAClC,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,yBAAyB,EACzB,cAAc,EACd,6BAA6B,EAC7B,8BAA8B,EAC9B,gBAAgB,EAChB,0BAA0B,EAC1B,gBAAgB,GACjB,MAAM,WAAW,CAAA;AAClB,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,2BAA2B,EAC3B,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,6BAA6B,EAC7B,YAAY,EACZ,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,uBAAuB,EACvB,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,cAAc,EACd,wBAAwB,EACxB,0BAA0B,EAC1B,kBAAkB,EAClB,sBAAsB,EACtB,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,2BAA2B,EAC3B,iBAAiB,EACjB,wBAAwB,EACxB,qBAAqB,EACrB,oBAAoB,EACpB,wBAAwB,EACxB,iCAAiC,EACjC,kBAAkB,EAClB,4BAA4B,EAC5B,uBAAuB,EACvB,2BAA2B,EAC3B,oBAAoB,EACpB,4BAA4B,GAC7B,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAA;AAC7E,YAAY,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAA;AACtD,OAAO,EACL,KAAK,0BAA0B,EAC/B,aAAa,EACb,4BAA4B,EAC5B,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,EACxB,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,aAAa,EACb,qCAAqC,EACrC,6BAA6B,GAC9B,MAAM,WAAW,CAAA;AAClB,OAAO,EACL,sBAAsB,EACtB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,6BAA6B,EAC7B,gBAAgB,EAChB,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAA;AACjE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/request-example/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,gBAAgB,EAChB,uBAAuB,EACvB,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,gCAAgC,EAChC,gCAAgC,EAChC,kCAAkC,EAClC,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,yBAAyB,EACzB,cAAc,EACd,6BAA6B,EAC7B,8BAA8B,EAC9B,gBAAgB,EAChB,0BAA0B,EAC1B,gBAAgB,GACjB,MAAM,WAAW,CAAA;AAClB,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,2BAA2B,EAC3B,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,6BAA6B,EAC7B,YAAY,EACZ,oBAAoB,EAC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CAAA;AAC9D,OAAO,EAAE,KAAK,iBAAiB,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC5G,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAC3D,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -5,3 +5,6 @@ export { serializeMultipartBody } from './builder/body/encode-multipart-body.js'
|
|
|
5
5
|
export { combineParams, filterDisabledDefaultHeaders, getActiveEnvironment, getActiveProxyUrl, getDefaultHeaders, getRequestExampleContext, getSecurityRequirements, getSecuritySchemes, getSelectedSecurity, getSelectedServer, getServers, isAuthOptional, mergeSecurity, restoreConventionalDefaultHeaderNames, restoreConventionalHeaderName, } from './context/index.js';
|
|
6
6
|
export { CONTEXT_FUNCTION_NAMES, POPULAR_CONTEXT_FUNCTION_KEYS, contextFunctions, getContextFunctionComment, isContextFunctionName, } from './functions.js';
|
|
7
7
|
export { createVariablesStoreForRequest } from './variable-store/index.js';
|
|
8
|
+
export { getXmlBodyExample } from './xml/get-xml-body-example.js';
|
|
9
|
+
export { getXmlExampleFromSchema, serializeXmlExample } from './xml/get-xml-example.js';
|
|
10
|
+
export { serializeXmlPart } from './xml/serialize-xml-part.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type RefNode } from '../../helpers/get-resolved-ref.js';
|
|
2
|
+
import type { ExampleObject } from '../../schemas/v3.2/strict/example.js';
|
|
3
|
+
import { type SchemaObject } from '../../schemas/v3.2/strict/openapi-document.js';
|
|
4
|
+
import { type XmlExampleOptions } from './get-xml-example.js';
|
|
5
|
+
import type { XmlExampleResult } from './xml-node.js';
|
|
6
|
+
/** Resolve media-level XML examples without treating schema string values as serialized payloads. */
|
|
7
|
+
export declare const getXmlBodyExample: (schema: SchemaObject | undefined, inputExample: ExampleObject | RefNode<ExampleObject> | undefined, options?: XmlExampleOptions) => XmlExampleResult;
|
|
8
|
+
//# sourceMappingURL=get-xml-body-example.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-xml-body-example.d.ts","sourceRoot":"","sources":["../../../src/request-example/xml/get-xml-body-example.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAkB,MAAM,4BAA4B,CAAA;AAEzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAClE,OAAO,EAAE,KAAK,YAAY,EAAsB,MAAM,wCAAwC,CAAA;AAE9F,OAAO,EAAE,KAAK,iBAAiB,EAAgD,MAAM,mBAAmB,CAAA;AACxG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,qGAAqG;AACrG,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,YAAY,GAAG,SAAS,EAChC,cAAc,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,GAAG,SAAS,EAChE,UAAS,iBAAsB,KAC9B,gBAeF,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getResolvedRef } from '../../helpers/get-resolved-ref.js';
|
|
2
|
+
import { coerceValue } from '../../schemas/typebox-coerce.js';
|
|
3
|
+
import { SchemaObjectSchema } from '../../schemas/v3.2/strict/openapi-document.js';
|
|
4
|
+
import { getXmlExampleFromSchema, serializeXmlExample } from './get-xml-example.js';
|
|
5
|
+
/** Resolve media-level XML examples without treating schema string values as serialized payloads. */
|
|
6
|
+
export const getXmlBodyExample = (schema, inputExample, options = {}) => {
|
|
7
|
+
const example = getResolvedRef(inputExample);
|
|
8
|
+
if (example?.serializedValue !== undefined) {
|
|
9
|
+
return { xml: example.serializedValue, diagnostics: [] };
|
|
10
|
+
}
|
|
11
|
+
if (example?.dataValue !== undefined) {
|
|
12
|
+
return serializeXmlExample(example.dataValue, schema ?? coerceValue(SchemaObjectSchema, {}), options);
|
|
13
|
+
}
|
|
14
|
+
if (typeof example?.value === 'string') {
|
|
15
|
+
return { xml: example.value, diagnostics: [] };
|
|
16
|
+
}
|
|
17
|
+
if (example?.value !== undefined) {
|
|
18
|
+
return serializeXmlExample(example.value, schema ?? coerceValue(SchemaObjectSchema, {}), options);
|
|
19
|
+
}
|
|
20
|
+
return schema ? getXmlExampleFromSchema(schema, options) : { xml: undefined, diagnostics: [] };
|
|
21
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SchemaObject } from '../../schemas/v3.2/strict/openapi-document.js';
|
|
2
|
+
import { EXAMPLE_EVALUATION } from '../builder/helpers/example-evaluation.js';
|
|
3
|
+
import { type GetExampleFromSchemaOptions } from '../builder/helpers/get-example-from-schema.js';
|
|
4
|
+
import { type WriteXmlOptions } from './write-xml.js';
|
|
5
|
+
import type { XmlDiagnostic, XmlExampleResult } from './xml-node.js';
|
|
6
|
+
/** XML options share the data generator's value and branch-selection policies. */
|
|
7
|
+
export type XmlExampleOptions = Omit<GetExampleFromSchemaOptions, 'xml' | typeof EXAMPLE_EVALUATION> & WriteXmlOptions & {
|
|
8
|
+
/** Version-specific XML defaults. Existing descriptions default to OpenAPI 3.1 behavior. */
|
|
9
|
+
openapiVersion?: string;
|
|
10
|
+
/** Context retained by callers before resolving a component reference. */
|
|
11
|
+
rootName?: string;
|
|
12
|
+
/** Keep composition-selection keys aligned with the request editor. */
|
|
13
|
+
schemaPath?: string[];
|
|
14
|
+
/** Receives diagnostics; errors otherwise appear in the developer console instead of failing silently. */
|
|
15
|
+
onDiagnostic?: (diagnostic: XmlDiagnostic) => void;
|
|
16
|
+
};
|
|
17
|
+
/** Generate XML using the same value evaluator and selected branches as JSON examples. */
|
|
18
|
+
export declare const getXmlExampleFromSchema: (schema: SchemaObject, options?: XmlExampleOptions) => XmlExampleResult;
|
|
19
|
+
/** Serialize schema-ready example data. Serialized XML strings bypass this function at the media boundary. */
|
|
20
|
+
export declare const serializeXmlExample: (value: unknown, schema: SchemaObject, options?: XmlExampleOptions) => XmlExampleResult;
|
|
21
|
+
//# sourceMappingURL=get-xml-example.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-xml-example.d.ts","sourceRoot":"","sources":["../../../src/request-example/xml/get-xml-example.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAG1E,OAAO,EACL,kBAAkB,EAGnB,MAAM,uCAAuC,CAAA;AAC9C,OAAO,EACL,KAAK,2BAA2B,EAGjC,MAAM,4CAA4C,CAAA;AAEnD,OAAO,EAAE,KAAK,eAAe,EAAY,MAAM,aAAa,CAAA;AAC5D,OAAO,KAAK,EAAgB,aAAa,EAAE,gBAAgB,EAAoB,MAAM,YAAY,CAAA;AAEjG,kFAAkF;AAClF,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,2BAA2B,EAAE,KAAK,GAAG,OAAO,kBAAkB,CAAC,GAClG,eAAe,GAAG;IAChB,4FAA4F;IAC5F,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,0GAA0G;IAC1G,YAAY,CAAC,EAAE,CAAC,UAAU,EAAE,aAAa,KAAK,IAAI,CAAA;CACnD,CAAA;AAmBH,0FAA0F;AAC1F,eAAO,MAAM,uBAAuB,GAAI,QAAQ,YAAY,EAAE,UAAS,iBAAsB,KAAG,gBAQ/F,CAAA;AAED,8GAA8G;AAC9G,eAAO,MAAM,mBAAmB,GAC9B,OAAO,OAAO,EACd,QAAQ,YAAY,EACpB,UAAS,iBAAsB,KAC9B,gBAAqF,CAAA"}
|