@openapi-flow/core 0.1.0 → 0.2.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/README.md +27 -5
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/arguments/list-api-request-media-types.d.ts +2 -0
- package/dist/arguments/list-api-request-media-types.js +8 -0
- package/dist/arguments/request-contract.d.ts +4 -0
- package/dist/arguments/request-contract.js +38 -0
- package/dist/arguments/request-media-type-priority.d.ts +2 -0
- package/dist/arguments/request-media-type-priority.js +8 -0
- package/dist/arguments/select-default-api-request-media-type.d.ts +3 -0
- package/dist/arguments/select-default-api-request-media-type.js +17 -0
- package/dist/arguments/validate-api-arguments.d.ts +2 -0
- package/dist/arguments/validate-api-arguments.js +140 -0
- package/dist/bindings/combine-binding-schemas.d.ts +4 -0
- package/dist/bindings/combine-binding-schemas.js +17 -0
- package/dist/bindings/create-native-array-item-schema.d.ts +4 -0
- package/dist/bindings/create-native-array-item-schema.js +16 -0
- package/dist/bindings/json-pointer.d.ts +3 -0
- package/dist/bindings/json-pointer.js +24 -0
- package/dist/bindings/materialize-api-arguments.d.ts +4 -0
- package/dist/bindings/materialize-api-arguments.js +54 -0
- package/dist/bindings/native-binding-schema.d.ts +3 -0
- package/dist/bindings/native-binding-schema.js +6 -0
- package/dist/bindings/project-array-item-schema.d.ts +5 -0
- package/dist/bindings/project-array-item-schema.js +67 -0
- package/dist/bindings/request-binding-schema.d.ts +2 -0
- package/dist/bindings/request-binding-schema.js +23 -0
- package/dist/bindings/request-container-kind.d.ts +3 -0
- package/dist/bindings/request-container-kind.js +17 -0
- package/dist/bindings/resources/clone-schema-resource.d.ts +3 -0
- package/dist/bindings/resources/clone-schema-resource.js +38 -0
- package/dist/bindings/resources/create-schema-resource-context.d.ts +4 -0
- package/dist/bindings/resources/create-schema-resource-context.js +130 -0
- package/dist/bindings/response-binding-schema.d.ts +3 -0
- package/dist/bindings/response-binding-schema.js +21 -0
- package/dist/bindings/schema-allows-container.d.ts +3 -0
- package/dist/bindings/schema-allows-container.js +20 -0
- package/dist/bindings/schema-at-pointer.d.ts +4 -0
- package/dist/bindings/schema-at-pointer.js +89 -0
- package/dist/bindings/validate-api-binding-assignments.d.ts +2 -0
- package/dist/bindings/validate-api-binding-assignments.js +81 -0
- package/dist/bindings/validate-api-binding-gaps.d.ts +2 -0
- package/dist/bindings/validate-api-binding-gaps.js +10 -0
- package/dist/bindings/validate-api-binding-plan.d.ts +3 -0
- package/dist/bindings/validate-api-binding-plan.js +11 -0
- package/dist/bindings/validate-native-output-contracts.d.ts +3 -0
- package/dist/bindings/validate-native-output-contracts.js +16 -0
- package/dist/internal-api.d.ts +30 -0
- package/dist/internal-api.js +25 -0
- package/dist/openapi/catalog/create-api-catalog.d.ts +2 -0
- package/dist/openapi/catalog/create-api-catalog.js +34 -0
- package/dist/openapi/catalog/list-api-operations.d.ts +2 -0
- package/dist/openapi/catalog/list-api-operations.js +3 -0
- package/dist/openapi/common/check-oas-value.d.ts +3 -0
- package/dist/openapi/common/check-oas-value.js +6 -0
- package/dist/openapi/common/check-schema-value.d.ts +2 -0
- package/dist/openapi/common/check-schema-value.js +12 -0
- package/dist/openapi/common/create-oas-value-validator.d.ts +3 -0
- package/dist/openapi/common/create-oas-value-validator.js +39 -0
- package/dist/openapi/common/normalize-oas-value-schema.d.ts +4 -0
- package/dist/openapi/common/normalize-oas-value-schema.js +50 -0
- package/dist/openapi/common/operation-metadata.d.ts +2 -0
- package/dist/openapi/common/operation-metadata.js +25 -0
- package/dist/openapi/common/operation-reference.d.ts +3 -0
- package/dist/openapi/{operation-reference.js → common/operation-reference.js} +1 -4
- package/dist/openapi/common/parse-spec-utils.d.ts +3 -0
- package/dist/openapi/common/parse-spec-utils.js +12 -0
- package/dist/openapi/common/resolve-openapi-security.d.ts +3 -0
- package/dist/openapi/common/resolve-openapi-security.js +28 -0
- package/dist/openapi/common/unsupported-operation-error.d.ts +4 -0
- package/dist/openapi/common/unsupported-operation-error.js +8 -0
- package/dist/openapi/common/validate-spec.d.ts +3 -0
- package/dist/openapi/{validate-spec.js → common/validate-spec.js} +2 -1
- package/dist/openapi/inbound/callback/parse-callback-operations.d.ts +3 -0
- package/dist/openapi/inbound/callback/parse-callback-operations.js +31 -0
- package/dist/openapi/inbound/inbound-path-item-operations.d.ts +4 -0
- package/dist/openapi/inbound/inbound-path-item-operations.js +31 -0
- package/dist/openapi/inbound/list-inbound-operations.d.ts +4 -0
- package/dist/openapi/inbound/list-inbound-operations.js +13 -0
- package/dist/openapi/inbound/webhook/parse-webhook-operations.d.ts +3 -0
- package/dist/openapi/inbound/webhook/parse-webhook-operations.js +13 -0
- package/dist/openapi/request/create-operation-catalog.d.ts +2 -0
- package/dist/openapi/request/create-operation-catalog.js +24 -0
- package/dist/openapi/request/encode-form-field.d.ts +2 -0
- package/dist/openapi/request/encode-form-field.js +6 -0
- package/dist/openapi/request/map-http-operation-contract.d.ts +4 -0
- package/dist/openapi/request/map-http-operation-contract.js +21 -0
- package/dist/openapi/request/operation-mapping.d.ts +3 -0
- package/dist/openapi/request/operation-mapping.js +10 -0
- package/dist/openapi/request/parse-operation-responses.d.ts +3 -0
- package/dist/openapi/request/parse-operation-responses.js +30 -0
- package/dist/openapi/request/parse-request-body.d.ts +3 -0
- package/dist/openapi/request/parse-request-body.js +29 -0
- package/dist/openapi/request/parse-request-operations.d.ts +7 -0
- package/dist/openapi/request/parse-request-operations.js +50 -0
- package/dist/openapi/request/parse-request-parameters.d.ts +3 -0
- package/dist/openapi/request/parse-request-parameters.js +93 -0
- package/dist/openapi/request/parse-security.d.ts +3 -0
- package/dist/openapi/request/parse-security.js +31 -0
- package/dist/openapi/request/request-operation-reference.d.ts +1 -0
- package/dist/openapi/request/request-operation-reference.js +4 -0
- package/dist/openapi/request/response-contract.d.ts +6 -0
- package/dist/openapi/request/response-contract.js +32 -0
- package/dist/openapi/request/scalar-response-schema.d.ts +2 -0
- package/dist/openapi/request/scalar-response-schema.js +20 -0
- package/dist/openapi/request/serialize-form-body.d.ts +3 -0
- package/dist/openapi/request/serialize-form-body.js +89 -0
- package/dist/openapi/request/serialize-parameter.d.ts +5 -0
- package/dist/openapi/request/serialize-parameter.js +145 -0
- package/dist/openapi/resolve-api-operations.d.ts +3 -0
- package/dist/openapi/resolve-api-operations.js +84 -0
- package/dist/openapi/response/api-response-validation-value.d.ts +3 -0
- package/dist/openapi/response/api-response-validation-value.js +21 -0
- package/dist/openapi/response/create-api-response-schema.d.ts +4 -0
- package/dist/openapi/response/create-api-response-schema.js +114 -0
- package/dist/openapi/response/create-response-array-item-schema.d.ts +4 -0
- package/dist/openapi/response/create-response-array-item-schema.js +12 -0
- package/dist/openapi/response/create-response-value-schema.d.ts +4 -0
- package/dist/openapi/response/create-response-value-schema.js +8 -0
- package/dist/openapi/response/list-api-response-pointers.d.ts +4 -0
- package/dist/openapi/response/list-api-response-pointers.js +30 -0
- package/dist/openapi/response/list-declared-schema-pointers.d.ts +4 -0
- package/dist/openapi/response/list-declared-schema-pointers.js +91 -0
- package/dist/public-api.d.ts +49 -7
- package/dist/public-api.js +35 -5
- package/dist/runtime-api.d.ts +6 -0
- package/dist/runtime-api.js +7 -0
- package/dist/schemas/create-api-argument-generation-contract.d.ts +4 -0
- package/dist/schemas/create-api-argument-generation-contract.js +72 -0
- package/dist/schemas/create-api-arguments-schema.d.ts +3 -0
- package/dist/schemas/create-api-arguments-schema.js +4 -0
- package/dist/schemas/create-api-request-schema.d.ts +4 -0
- package/dist/schemas/create-api-request-schema.js +50 -0
- package/dist/schemas/create-oas-value-schema.d.ts +6 -0
- package/dist/schemas/create-oas-value-schema.js +25 -0
- package/dist/schemas/operation-plan-schema.d.ts +8 -0
- package/dist/schemas/operation-plan-schema.js +99 -0
- package/dist/schemas/project-literal-array-schema.d.ts +4 -0
- package/dist/schemas/project-literal-array-schema.js +55 -0
- package/dist/schemas/project-literal-input-schema.d.ts +3 -0
- package/dist/schemas/project-literal-input-schema.js +129 -0
- package/dist/types/api-argument-generation.d.ts +13 -0
- package/dist/types/api-arguments.d.ts +42 -0
- package/dist/types/api-arguments.js +1 -0
- package/dist/types/api-bindings.d.ts +34 -0
- package/dist/types/api-bindings.js +1 -0
- package/dist/types/api-catalog.d.ts +34 -0
- package/dist/types/api-catalog.js +1 -0
- package/dist/types/api-operation.d.ts +26 -0
- package/dist/types/api-operation.js +1 -0
- package/dist/types/api-response-pointers.d.ts +20 -0
- package/dist/types/api-response-pointers.js +1 -0
- package/dist/types/api-response.d.ts +14 -0
- package/dist/types/api-response.js +1 -0
- package/dist/types/array-projection.d.ts +5 -0
- package/dist/types/array-projection.js +1 -0
- package/dist/types/catalog.d.ts +17 -0
- package/dist/types/catalog.js +1 -0
- package/dist/types/inbound.d.ts +18 -0
- package/dist/types/inbound.js +1 -0
- package/dist/types/legacy-plan.d.ts +47 -0
- package/dist/types/legacy-plan.js +1 -0
- package/dist/types/node-output.d.ts +11 -0
- package/dist/types/node-output.js +1 -0
- package/dist/types/oas-value-validation.d.ts +8 -0
- package/dist/types/oas-value-validation.js +1 -0
- package/dist/types/openapi.d.ts +7 -23
- package/dist/types/request.d.ts +41 -0
- package/dist/types/request.js +1 -0
- package/dist/types/reviewable-workflow.d.ts +53 -0
- package/dist/types/reviewable-workflow.js +1 -0
- package/dist/types/schema-dialect.d.ts +1 -0
- package/dist/types/schema-dialect.js +1 -0
- package/dist/types/schema-json.d.ts +4 -0
- package/dist/types/schema-json.js +1 -0
- package/dist/types/schema-resource.d.ts +12 -0
- package/dist/types/schema-resource.js +1 -0
- package/dist/types/security.d.ts +17 -0
- package/dist/types/security.js +1 -0
- package/dist/types/workflow-capability-planning.d.ts +10 -0
- package/dist/types/workflow-capability-planning.js +1 -0
- package/dist/types/workflow-plan.d.ts +104 -0
- package/dist/types/workflow-plan.js +1 -0
- package/dist/utils/is-object.d.ts +2 -0
- package/dist/utils/is-object.js +3 -0
- package/dist/utils/json-values-equal.d.ts +2 -0
- package/dist/utils/json-values-equal.js +16 -0
- package/dist/workflow/assert-api-call-identities.d.ts +1 -0
- package/dist/workflow/assert-api-call-identities.js +6 -0
- package/dist/workflow/create-native-output-contracts.d.ts +3 -0
- package/dist/workflow/create-native-output-contracts.js +23 -0
- package/dist/workflow/create-reviewable-node-contracts.d.ts +3 -0
- package/dist/workflow/create-reviewable-node-contracts.js +36 -0
- package/dist/workflow/create-reviewable-workflow-graph-plan.d.ts +2 -0
- package/dist/workflow/create-reviewable-workflow-graph-plan.js +29 -0
- package/dist/workflow/create-workflow-graph-plan.d.ts +2 -0
- package/dist/workflow/create-workflow-graph-plan.js +17 -0
- package/dist/workflow/create-workflow-node-contracts.d.ts +2 -0
- package/dist/workflow/create-workflow-node-contracts.js +50 -0
- package/dist/workflow/create-workflow-planning-capabilities.d.ts +3 -0
- package/dist/workflow/create-workflow-planning-capabilities.js +20 -0
- package/dist/workflow/parse-native-node-parameters.d.ts +3 -0
- package/dist/workflow/parse-native-node-parameters.js +7 -0
- package/dist/workflow/validate-exclusive-output-rejoin.d.ts +3 -0
- package/dist/workflow/validate-exclusive-output-rejoin.js +26 -0
- package/dist/workflow/validate-native-api-response-references.d.ts +2 -0
- package/dist/workflow/validate-native-api-response-references.js +26 -0
- package/dist/workflow/validate-reviewable-workflow-graph-plan.d.ts +2 -0
- package/dist/workflow/validate-reviewable-workflow-graph-plan.js +98 -0
- package/dist/workflow/validate-workflow-edges.d.ts +2 -0
- package/dist/workflow/validate-workflow-edges.js +19 -0
- package/dist/workflow/validate-workflow-graph-plan.d.ts +3 -0
- package/dist/workflow/validate-workflow-graph-plan.js +41 -0
- package/dist/workflow/validate-workflow-topology.d.ts +2 -0
- package/dist/workflow/validate-workflow-topology.js +105 -0
- package/package.json +19 -25
- package/dist/openapi/operation-reference.d.ts +0 -3
- package/dist/openapi/parse-spec-utils.d.ts +0 -5
- package/dist/openapi/parse-spec-utils.js +0 -52
- package/dist/openapi/parse-spec.d.ts +0 -5
- package/dist/openapi/parse-spec.js +0 -182
- package/dist/openapi/validate-spec.d.ts +0 -3
- package/dist/planning/generate-workflow.d.ts +0 -2
- package/dist/planning/generate-workflow.js +0 -126
- package/dist/schemas/planning-schemas.d.ts +0 -62
- package/dist/schemas/planning-schemas.js +0 -48
- package/dist/types/workflow.d.ts +0 -75
- package/dist/utils/validation.d.ts +0 -7
- package/dist/utils/validation.js +0 -44
- package/dist/utils/workflow-id.d.ts +0 -1
- package/dist/utils/workflow-id.js +0 -8
- package/dist/workflow/compile-sequence.d.ts +0 -2
- package/dist/workflow/compile-sequence.js +0 -167
- package/dist/workflow/compile-workflow.d.ts +0 -4
- package/dist/workflow/compile-workflow.js +0 -128
- package/dist/workflow/sequence-url.d.ts +0 -3
- package/dist/workflow/sequence-url.js +0 -81
- package/dist/workflow/workflow-helpers.d.ts +0 -6
- package/dist/workflow/workflow-helpers.js +0 -81
- /package/dist/types/{workflow.js → api-argument-generation.js} +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { isObject } from '../../utils/is-object.js';
|
|
2
|
+
import { normalizeOasValueSchema } from '../common/normalize-oas-value-schema.js';
|
|
3
|
+
import { listDeclaredSchemaPointers } from './list-declared-schema-pointers.js';
|
|
4
|
+
/** Describe finite schema declarations, not guaranteed runtime fields or a whitelist. */
|
|
5
|
+
export function listApiResponsePointers(operation) {
|
|
6
|
+
const catalogs = [];
|
|
7
|
+
for (const [responseKey, response] of Object.entries(operation.operation.responses ?? {})) {
|
|
8
|
+
if (!isObject(response) || !isObject(response.content))
|
|
9
|
+
continue;
|
|
10
|
+
for (const [mediaType, media] of Object.entries(response.content)) {
|
|
11
|
+
if (!isObject(media))
|
|
12
|
+
continue;
|
|
13
|
+
const schema = media.schema;
|
|
14
|
+
if (typeof schema !== 'boolean' && !isObject(schema))
|
|
15
|
+
continue;
|
|
16
|
+
const normalized = normalizeOasValueSchema(schema, operation.openapiVersion.startsWith('3.0.')
|
|
17
|
+
? 'openapi-3.0'
|
|
18
|
+
: 'draft-2020-12');
|
|
19
|
+
const catalog = {
|
|
20
|
+
responseKey,
|
|
21
|
+
mediaType,
|
|
22
|
+
declaredPointers: [],
|
|
23
|
+
dynamicLocations: [],
|
|
24
|
+
};
|
|
25
|
+
listDeclaredSchemaPointers(normalized, catalog);
|
|
26
|
+
catalogs.push(catalog);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return catalogs;
|
|
30
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { BindingSchema } from '../../types/api-bindings.js';
|
|
2
|
+
import type { ApiResponsePointerCatalog } from '../../types/api-response-pointers.js';
|
|
3
|
+
/** Visit schema-valued declarations only; never invent a dictionary key or item index. */
|
|
4
|
+
export declare function listDeclaredSchemaPointers(schema: BindingSchema, catalog: ApiResponsePointerCatalog): void;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { isObject } from '../../utils/is-object.js';
|
|
2
|
+
function pointerToken(value) {
|
|
3
|
+
return value.replaceAll('~', '~0').replaceAll('/', '~1');
|
|
4
|
+
}
|
|
5
|
+
/** Visit schema-valued declarations only; never invent a dictionary key or item index. */
|
|
6
|
+
export function listDeclaredSchemaPointers(schema, catalog) {
|
|
7
|
+
const active = new Set();
|
|
8
|
+
function visit(current, pointer, location) {
|
|
9
|
+
if (current === false)
|
|
10
|
+
return;
|
|
11
|
+
function boundary(kind, suffix = '', constraint) {
|
|
12
|
+
catalog.dynamicLocations.push({
|
|
13
|
+
pointer,
|
|
14
|
+
schemaLocation: location + suffix,
|
|
15
|
+
kind,
|
|
16
|
+
...(constraint === undefined ? {} : { constraint }),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
if (active.has(current)) {
|
|
20
|
+
boundary('recursive-schema');
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
catalog.declaredPointers.push({
|
|
24
|
+
pointer,
|
|
25
|
+
schemaLocation: location,
|
|
26
|
+
...(typeof current !== 'boolean' &&
|
|
27
|
+
(typeof current.type === 'string' ||
|
|
28
|
+
(Array.isArray(current.type) &&
|
|
29
|
+
current.type.every((value) => typeof value === 'string')))
|
|
30
|
+
? { type: structuredClone(current.type) }
|
|
31
|
+
: {}),
|
|
32
|
+
...(typeof current !== 'boolean' &&
|
|
33
|
+
typeof current.description === 'string'
|
|
34
|
+
? { description: current.description }
|
|
35
|
+
: {}),
|
|
36
|
+
});
|
|
37
|
+
if (current === true) {
|
|
38
|
+
boundary('unconstrained');
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
active.add(current);
|
|
42
|
+
try {
|
|
43
|
+
for (const keyword of ['$ref', '$dynamicRef'])
|
|
44
|
+
if (typeof current[keyword] === 'string')
|
|
45
|
+
boundary('reference', '/' + keyword, current[keyword]);
|
|
46
|
+
if (isObject(current.properties))
|
|
47
|
+
for (const [name, child] of Object.entries(current.properties))
|
|
48
|
+
if (typeof child === 'boolean' || isObject(child))
|
|
49
|
+
visit(child, pointer + '/' + pointerToken(name), location + '/properties/' + pointerToken(name));
|
|
50
|
+
const types = Array.isArray(current.type) ? current.type : [current.type];
|
|
51
|
+
if ((current.type === undefined || types.includes('object')) &&
|
|
52
|
+
current.additionalProperties !== false)
|
|
53
|
+
boundary('additional-properties', current.additionalProperties === undefined
|
|
54
|
+
? ''
|
|
55
|
+
: '/additionalProperties');
|
|
56
|
+
if (isObject(current.patternProperties))
|
|
57
|
+
for (const [pattern, child] of Object.entries(current.patternProperties))
|
|
58
|
+
if (child !== false)
|
|
59
|
+
boundary('pattern-properties', '/patternProperties/' + pointerToken(pattern), pattern);
|
|
60
|
+
if (Array.isArray(current.prefixItems))
|
|
61
|
+
current.prefixItems.forEach((child, index) => {
|
|
62
|
+
if (typeof child === 'boolean' || isObject(child))
|
|
63
|
+
visit(child, pointer + '/' + index, location + '/prefixItems/' + index);
|
|
64
|
+
});
|
|
65
|
+
if ((current.type === undefined || types.includes('array')) &&
|
|
66
|
+
current.items !== false)
|
|
67
|
+
boundary('array-items', current.items === undefined ? '' : '/items');
|
|
68
|
+
for (const keyword of ['allOf', 'anyOf', 'oneOf']) {
|
|
69
|
+
const branches = current[keyword];
|
|
70
|
+
if (Array.isArray(branches))
|
|
71
|
+
branches.forEach((child, index) => {
|
|
72
|
+
if (typeof child === 'boolean' || isObject(child))
|
|
73
|
+
visit(child, pointer, location + '/' + keyword + '/' + index);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
for (const keyword of ['then', 'else']) {
|
|
77
|
+
const child = current[keyword];
|
|
78
|
+
if (typeof child === 'boolean' || isObject(child))
|
|
79
|
+
visit(child, pointer, location + '/' + keyword);
|
|
80
|
+
}
|
|
81
|
+
if (isObject(current.dependentSchemas))
|
|
82
|
+
for (const [name, child] of Object.entries(current.dependentSchemas))
|
|
83
|
+
if (typeof child === 'boolean' || isObject(child))
|
|
84
|
+
visit(child, pointer, location + '/dependentSchemas/' + pointerToken(name));
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
active.delete(current);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
visit(schema, '', '');
|
|
91
|
+
}
|
package/dist/public-api.d.ts
CHANGED
|
@@ -1,7 +1,49 @@
|
|
|
1
|
-
export { operationsFromSpec } from './openapi/parse-
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export
|
|
7
|
-
export
|
|
1
|
+
export { operationsFromSpec } from './openapi/request/parse-request-operations.js';
|
|
2
|
+
export { inboundOperationsFromSpec } from './openapi/inbound/list-inbound-operations.js';
|
|
3
|
+
export { validateOpenApi } from './openapi/common/validate-spec.js';
|
|
4
|
+
export { UnsupportedOperationError } from './openapi/common/unsupported-operation-error.js';
|
|
5
|
+
export { createApiCatalog } from './openapi/catalog/create-api-catalog.js';
|
|
6
|
+
export { listApiOperations } from './openapi/catalog/list-api-operations.js';
|
|
7
|
+
export { resolveApiOperations } from './openapi/resolve-api-operations.js';
|
|
8
|
+
export type * from './types/api-catalog.js';
|
|
9
|
+
export type * from './types/api-operation.js';
|
|
10
|
+
export { createApiArgumentsSchema } from './schemas/create-api-arguments-schema.js';
|
|
11
|
+
export { createApiArgumentGenerationContract } from './schemas/create-api-argument-generation-contract.js';
|
|
12
|
+
export type * from './types/api-argument-generation.js';
|
|
13
|
+
export type * from './types/api-arguments.js';
|
|
14
|
+
export { validateApiArguments } from './arguments/validate-api-arguments.js';
|
|
15
|
+
export { listApiRequestMediaTypes } from './arguments/list-api-request-media-types.js';
|
|
16
|
+
export { selectDefaultApiRequestMediaType } from './arguments/select-default-api-request-media-type.js';
|
|
17
|
+
export type * from './types/openapi.js';
|
|
18
|
+
export type * from './types/inbound.js';
|
|
19
|
+
export type * from './types/workflow-plan.js';
|
|
20
|
+
export { validateWorkflowGraphPlan } from './workflow/validate-workflow-graph-plan.js';
|
|
21
|
+
export { createWorkflowGraphPlan } from './workflow/create-workflow-graph-plan.js';
|
|
22
|
+
export type * from './types/api-bindings.js';
|
|
23
|
+
export type * from './types/node-output.js';
|
|
24
|
+
export { createNativeOutputContracts } from './workflow/create-native-output-contracts.js';
|
|
25
|
+
export { createReviewableNodeContracts } from './workflow/create-reviewable-node-contracts.js';
|
|
26
|
+
export { validateWorkflowEdges } from './workflow/validate-workflow-edges.js';
|
|
27
|
+
export { validateNativeOutputContracts } from './bindings/validate-native-output-contracts.js';
|
|
28
|
+
export { parseNativeNodeParameters } from './workflow/parse-native-node-parameters.js';
|
|
29
|
+
export { createWorkflowPlanningCapabilities } from './workflow/create-workflow-planning-capabilities.js';
|
|
30
|
+
export { validateNativeApiResponseReferences } from './workflow/validate-native-api-response-references.js';
|
|
31
|
+
export type * from './types/workflow-capability-planning.js';
|
|
32
|
+
export { validateApiBindingPlan } from './bindings/validate-api-binding-plan.js';
|
|
33
|
+
export { materializeApiArguments } from './bindings/materialize-api-arguments.js';
|
|
34
|
+
export { createApiRequestSchema } from './schemas/create-api-request-schema.js';
|
|
35
|
+
export { validateApiBindingAssignments } from './bindings/validate-api-binding-assignments.js';
|
|
36
|
+
export { validateApiBindingGaps } from './bindings/validate-api-binding-gaps.js';
|
|
37
|
+
export type * from './types/reviewable-workflow.js';
|
|
38
|
+
export { createReviewableWorkflowGraphPlan } from './workflow/create-reviewable-workflow-graph-plan.js';
|
|
39
|
+
export { validateReviewableWorkflowGraphPlan } from './workflow/validate-reviewable-workflow-graph-plan.js';
|
|
40
|
+
export { resolveOpenApiSecurity } from './openapi/common/resolve-openapi-security.js';
|
|
41
|
+
export type * from './types/security.js';
|
|
42
|
+
export { createApiResponseSchema } from './openapi/response/create-api-response-schema.js';
|
|
43
|
+
export { apiResponseValidationValue } from './openapi/response/api-response-validation-value.js';
|
|
44
|
+
export type * from './types/api-response.js';
|
|
45
|
+
export { createResponseArrayItemSchema } from './openapi/response/create-response-array-item-schema.js';
|
|
46
|
+
export { createNativeArrayItemSchema } from './bindings/create-native-array-item-schema.js';
|
|
47
|
+
export { createResponseValueSchema } from './openapi/response/create-response-value-schema.js';
|
|
48
|
+
export { listApiResponsePointers } from './openapi/response/list-api-response-pointers.js';
|
|
49
|
+
export type * from './types/api-response-pointers.js';
|
package/dist/public-api.js
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
|
-
export { operationsFromSpec } from './openapi/parse-
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
1
|
+
export { operationsFromSpec } from './openapi/request/parse-request-operations.js';
|
|
2
|
+
export { inboundOperationsFromSpec } from './openapi/inbound/list-inbound-operations.js';
|
|
3
|
+
export { validateOpenApi } from './openapi/common/validate-spec.js';
|
|
4
|
+
export { UnsupportedOperationError } from './openapi/common/unsupported-operation-error.js';
|
|
5
|
+
export { createApiCatalog } from './openapi/catalog/create-api-catalog.js';
|
|
6
|
+
export { listApiOperations } from './openapi/catalog/list-api-operations.js';
|
|
7
|
+
export { resolveApiOperations } from './openapi/resolve-api-operations.js';
|
|
8
|
+
export { createApiArgumentsSchema } from './schemas/create-api-arguments-schema.js';
|
|
9
|
+
export { createApiArgumentGenerationContract } from './schemas/create-api-argument-generation-contract.js';
|
|
10
|
+
export { validateApiArguments } from './arguments/validate-api-arguments.js';
|
|
11
|
+
export { listApiRequestMediaTypes } from './arguments/list-api-request-media-types.js';
|
|
12
|
+
export { selectDefaultApiRequestMediaType } from './arguments/select-default-api-request-media-type.js';
|
|
13
|
+
export { validateWorkflowGraphPlan } from './workflow/validate-workflow-graph-plan.js';
|
|
14
|
+
export { createWorkflowGraphPlan } from './workflow/create-workflow-graph-plan.js';
|
|
15
|
+
export { createNativeOutputContracts } from './workflow/create-native-output-contracts.js';
|
|
16
|
+
export { createReviewableNodeContracts } from './workflow/create-reviewable-node-contracts.js';
|
|
17
|
+
export { validateWorkflowEdges } from './workflow/validate-workflow-edges.js';
|
|
18
|
+
export { validateNativeOutputContracts } from './bindings/validate-native-output-contracts.js';
|
|
19
|
+
export { parseNativeNodeParameters } from './workflow/parse-native-node-parameters.js';
|
|
20
|
+
export { createWorkflowPlanningCapabilities } from './workflow/create-workflow-planning-capabilities.js';
|
|
21
|
+
export { validateNativeApiResponseReferences } from './workflow/validate-native-api-response-references.js';
|
|
22
|
+
export { validateApiBindingPlan } from './bindings/validate-api-binding-plan.js';
|
|
23
|
+
export { materializeApiArguments } from './bindings/materialize-api-arguments.js';
|
|
24
|
+
export { createApiRequestSchema } from './schemas/create-api-request-schema.js';
|
|
25
|
+
export { validateApiBindingAssignments } from './bindings/validate-api-binding-assignments.js';
|
|
26
|
+
export { validateApiBindingGaps } from './bindings/validate-api-binding-gaps.js';
|
|
27
|
+
export { createReviewableWorkflowGraphPlan } from './workflow/create-reviewable-workflow-graph-plan.js';
|
|
28
|
+
export { validateReviewableWorkflowGraphPlan } from './workflow/validate-reviewable-workflow-graph-plan.js';
|
|
29
|
+
export { resolveOpenApiSecurity } from './openapi/common/resolve-openapi-security.js';
|
|
30
|
+
export { createApiResponseSchema } from './openapi/response/create-api-response-schema.js';
|
|
31
|
+
export { apiResponseValidationValue } from './openapi/response/api-response-validation-value.js';
|
|
32
|
+
export { createResponseArrayItemSchema } from './openapi/response/create-response-array-item-schema.js';
|
|
33
|
+
export { createNativeArrayItemSchema } from './bindings/create-native-array-item-schema.js';
|
|
34
|
+
export { createResponseValueSchema } from './openapi/response/create-response-value-schema.js';
|
|
35
|
+
export { listApiResponsePointers } from './openapi/response/list-api-response-pointers.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { materializeApiArguments } from './bindings/materialize-api-arguments.js';
|
|
2
|
+
export * from './openapi/request/serialize-parameter.js';
|
|
3
|
+
export { serializeFormBody } from './openapi/request/serialize-form-body.js';
|
|
4
|
+
export { UnsupportedOperationError } from './openapi/common/unsupported-operation-error.js';
|
|
5
|
+
export { apiResponseValidationValue } from './openapi/response/api-response-validation-value.js';
|
|
6
|
+
export { pointerValue } from './bindings/json-pointer.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Execution-only entrypoint: excludes catalog hashing and document intake.
|
|
2
|
+
export { materializeApiArguments } from './bindings/materialize-api-arguments.js';
|
|
3
|
+
export * from './openapi/request/serialize-parameter.js';
|
|
4
|
+
export { serializeFormBody } from './openapi/request/serialize-form-body.js';
|
|
5
|
+
export { UnsupportedOperationError } from './openapi/common/unsupported-operation-error.js';
|
|
6
|
+
export { apiResponseValidationValue } from './openapi/response/api-response-validation-value.js';
|
|
7
|
+
export { pointerValue } from './bindings/json-pointer.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ApiArgumentsSchemaInput } from '../types/api-arguments.js';
|
|
2
|
+
import type { ApiArgumentGenerationContract } from '../types/api-argument-generation.js';
|
|
3
|
+
/** The OAS-derived schema decides whether the model has any values to propose. */
|
|
4
|
+
export declare function createApiArgumentGenerationContract({ operation, bindings, requestMediaType, }: ApiArgumentsSchemaInput): ApiArgumentGenerationContract;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { object } from '../openapi/common/parse-spec-utils.js';
|
|
3
|
+
import { bodyMediaSchema, parameterSchema, } from '../arguments/request-contract.js';
|
|
4
|
+
import { validateApiArguments } from '../arguments/validate-api-arguments.js';
|
|
5
|
+
import { optionalRequestProperties } from './operation-plan-schema.js';
|
|
6
|
+
import { pointerTokens } from '../bindings/json-pointer.js';
|
|
7
|
+
import { requestBindingSchemas } from '../bindings/request-binding-schema.js';
|
|
8
|
+
import { projectLiteralInputSchema } from './project-literal-input-schema.js';
|
|
9
|
+
import { createOasValueSchema } from './create-oas-value-schema.js';
|
|
10
|
+
/** The OAS-derived schema decides whether the model has any values to propose. */
|
|
11
|
+
export function createApiArgumentGenerationContract({ operation, bindings, requestMediaType, }) {
|
|
12
|
+
if (!Array.isArray(bindings))
|
|
13
|
+
throw new Error('arguments.bindings must be an array');
|
|
14
|
+
validateApiArguments({ operation, bindings, requestMediaType, values: {} });
|
|
15
|
+
for (const binding of bindings)
|
|
16
|
+
if (!requestBindingSchemas({ operation, requestMediaType, callId: operation.key.operationRef }, binding.targetPointer).length)
|
|
17
|
+
throw new Error(`binding ${binding.targetPointer} is not declared by ${operation.key.operationRef}`);
|
|
18
|
+
const dialect = operation.openapiVersion.startsWith('3.0.')
|
|
19
|
+
? 'openapi-3.0'
|
|
20
|
+
: 'draft-2020-12';
|
|
21
|
+
const groups = {};
|
|
22
|
+
for (const raw of operation.effective.parameters) {
|
|
23
|
+
const parameter = object(raw, `${operation.key.operationRef}.parameters`);
|
|
24
|
+
const location = String(parameter.in);
|
|
25
|
+
const name = String(parameter.name);
|
|
26
|
+
if (location === 'header' &&
|
|
27
|
+
['accept', 'content-type', 'authorization'].includes(name.toLowerCase()))
|
|
28
|
+
continue;
|
|
29
|
+
const pointer = '/' + location + '/' + name.replaceAll('~', '~0').replaceAll('/', '~1');
|
|
30
|
+
if (bindings.some((binding) => binding.targetPointer === pointer))
|
|
31
|
+
continue;
|
|
32
|
+
const projection = projectLiteralInputSchema(optionalRequestProperties(parameterSchema(parameter, pointer)), bindings
|
|
33
|
+
.filter((entry) => entry.targetPointer.startsWith(pointer + '/'))
|
|
34
|
+
.map((entry) => pointerTokens(entry.targetPointer).slice(2)), pointer);
|
|
35
|
+
if (!projection.hasLiteralValues)
|
|
36
|
+
continue;
|
|
37
|
+
const value = createOasValueSchema(projection.schema, dialect, `${operation.key.operationRef}${pointer}`).describe(typeof parameter.description === 'string'
|
|
38
|
+
? parameter.description
|
|
39
|
+
: `Scenario value for ${location} parameter ${name}`);
|
|
40
|
+
if (!Object.hasOwn(groups, location))
|
|
41
|
+
groups[location] = {};
|
|
42
|
+
Object.defineProperty(groups[location], name, {
|
|
43
|
+
value: value.optional(),
|
|
44
|
+
enumerable: true,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const fields = Object.fromEntries(Object.entries(groups).map(([location, properties]) => [
|
|
48
|
+
location,
|
|
49
|
+
z.object(properties).strict().optional(),
|
|
50
|
+
]));
|
|
51
|
+
const body = bodyMediaSchema(operation, requestMediaType);
|
|
52
|
+
if (body !== undefined &&
|
|
53
|
+
!bindings.some((binding) => binding.targetPointer === '/body')) {
|
|
54
|
+
const projection = projectLiteralInputSchema(optionalRequestProperties(body), bindings
|
|
55
|
+
.filter((entry) => entry.targetPointer.startsWith('/body/'))
|
|
56
|
+
.map((entry) => pointerTokens(entry.targetPointer).slice(1)), '/body');
|
|
57
|
+
if (projection.hasLiteralValues)
|
|
58
|
+
fields.body = createOasValueSchema(projection.schema, dialect, `${operation.key.operationRef}/body`)
|
|
59
|
+
.describe('Request body literal values explicitly supplied by the scenario; forbidden properties are owned by preceding nodes.')
|
|
60
|
+
.optional();
|
|
61
|
+
}
|
|
62
|
+
const schema = z
|
|
63
|
+
.object({
|
|
64
|
+
values: z.object(fields).strict(),
|
|
65
|
+
})
|
|
66
|
+
.strict();
|
|
67
|
+
return {
|
|
68
|
+
schema,
|
|
69
|
+
literalInputSchema: z.toJSONSchema(schema),
|
|
70
|
+
hasLiteralInputs: Object.keys(fields).length > 0,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ApiRequestSchemaInput } from '../types/api-arguments.js';
|
|
2
|
+
import type { JsonObject } from '../types/openapi.js';
|
|
3
|
+
/** Full unchanged OAS constraints, unlike the model's partial-value schema. */
|
|
4
|
+
export declare function createApiRequestSchema({ operation, requestMediaType, }: ApiRequestSchemaInput): JsonObject;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { bodyMediaSchema, parameterSchema, } from '../arguments/request-contract.js';
|
|
2
|
+
import { createOasValueValidator } from '../openapi/common/create-oas-value-validator.js';
|
|
3
|
+
/** Full unchanged OAS constraints, unlike the model's partial-value schema. */
|
|
4
|
+
export function createApiRequestSchema({ operation, requestMediaType, }) {
|
|
5
|
+
const properties = {};
|
|
6
|
+
const dialect = operation.openapiVersion.startsWith('3.0.')
|
|
7
|
+
? 'openapi-3.0'
|
|
8
|
+
: 'draft-2020-12';
|
|
9
|
+
const required = [];
|
|
10
|
+
for (const location of ['path', 'query', 'header', 'cookie', 'querystring']) {
|
|
11
|
+
const parameters = operation.effective.parameters.filter((item) => item.in === location &&
|
|
12
|
+
!(location === 'header' &&
|
|
13
|
+
['accept', 'content-type', 'authorization'].includes(item.name.toLowerCase())));
|
|
14
|
+
if (!parameters.length)
|
|
15
|
+
continue;
|
|
16
|
+
const requiredNames = parameters
|
|
17
|
+
.filter((item) => item.required === true)
|
|
18
|
+
.map((item) => item.name);
|
|
19
|
+
Object.defineProperty(properties, location, {
|
|
20
|
+
value: {
|
|
21
|
+
type: 'object',
|
|
22
|
+
additionalProperties: false,
|
|
23
|
+
properties: Object.fromEntries(parameters.map((item) => [
|
|
24
|
+
item.name,
|
|
25
|
+
createOasValueValidator(parameterSchema(item, `${location}.${item.name}`), dialect, `${operation.key.operationRef}/${location}/${item.name}`).schema,
|
|
26
|
+
])),
|
|
27
|
+
required: requiredNames,
|
|
28
|
+
},
|
|
29
|
+
enumerable: true,
|
|
30
|
+
});
|
|
31
|
+
if (requiredNames.length)
|
|
32
|
+
required.push(location);
|
|
33
|
+
}
|
|
34
|
+
const body = bodyMediaSchema(operation, requestMediaType);
|
|
35
|
+
if (body !== undefined) {
|
|
36
|
+
properties.body = createOasValueValidator(body, dialect, `${operation.key.operationRef}/body`).schema;
|
|
37
|
+
const requestBody = operation.operation.requestBody;
|
|
38
|
+
if (requestBody &&
|
|
39
|
+
'required' in requestBody &&
|
|
40
|
+
requestBody.required === true)
|
|
41
|
+
required.push('body');
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
$schema: 'https://json-schema.org/draft/2020-12/schema',
|
|
45
|
+
type: 'object',
|
|
46
|
+
properties,
|
|
47
|
+
required,
|
|
48
|
+
additionalProperties: false,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { JsonValue } from '../types/api-arguments.js';
|
|
3
|
+
import type { OasValueSchema } from '../types/oas-value-validation.js';
|
|
4
|
+
import type { SchemaDialect } from '../types/schema-dialect.js';
|
|
5
|
+
/** Keep OAS assertions intact instead of round-tripping through Zod types. */
|
|
6
|
+
export declare function createOasValueSchema(input: OasValueSchema, dialect: SchemaDialect, source: string): z.ZodType<JsonValue>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createOasValueValidator } from '../openapi/common/create-oas-value-validator.js';
|
|
3
|
+
/** Keep OAS assertions intact instead of round-tripping through Zod types. */
|
|
4
|
+
export function createOasValueSchema(input, dialect, source) {
|
|
5
|
+
const contract = createOasValueValidator(input, dialect, source);
|
|
6
|
+
const jsonValue = z.json();
|
|
7
|
+
return z
|
|
8
|
+
.unknown()
|
|
9
|
+
.superRefine((value, context) => {
|
|
10
|
+
if (!jsonValue.safeParse(value).success) {
|
|
11
|
+
context.addIssue({
|
|
12
|
+
code: 'custom',
|
|
13
|
+
message: `${source} must be a JSON value`,
|
|
14
|
+
});
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const result = contract.validate(value);
|
|
18
|
+
for (const error of result.errors)
|
|
19
|
+
context.addIssue({
|
|
20
|
+
code: 'custom',
|
|
21
|
+
message: `${source} does not match the OAS schema: ${error.message}`,
|
|
22
|
+
});
|
|
23
|
+
})
|
|
24
|
+
.meta(contract.schema);
|
|
25
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { Operation } from '../types/request.js';
|
|
3
|
+
export declare function optionalRequestProperties(schema: unknown): unknown;
|
|
4
|
+
export declare function createOperationPlanSchema(operation: Operation, openapiVersion: string, requestMediaType?: string): z.ZodObject<{
|
|
5
|
+
inputs: z.ZodObject<{
|
|
6
|
+
body?: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>> | undefined;
|
|
7
|
+
}, z.core.$strict>;
|
|
8
|
+
}, z.core.$strict>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { isObject } from '../utils/is-object.js';
|
|
3
|
+
import { createOasValueSchema } from './create-oas-value-schema.js';
|
|
4
|
+
function parameterGroup(parameters, location, dialect) {
|
|
5
|
+
const fields = parameters
|
|
6
|
+
.filter((parameter) => parameter.in === location)
|
|
7
|
+
.map((parameter) => [
|
|
8
|
+
parameter.name,
|
|
9
|
+
createOasValueSchema(optionalRequestProperties(parameter.schema), dialect, `${location}.${parameter.name}`)
|
|
10
|
+
.describe(`Value explicitly stated for ${location} parameter ${parameter.name}`)
|
|
11
|
+
.optional(),
|
|
12
|
+
]);
|
|
13
|
+
if (fields.length === 0)
|
|
14
|
+
return undefined;
|
|
15
|
+
return z.object(Object.fromEntries(fields)).strict().optional();
|
|
16
|
+
}
|
|
17
|
+
// The model may omit values absent from the scenario. The compiler still checks
|
|
18
|
+
// the unchanged OAS schema and reports missing required request values.
|
|
19
|
+
export function optionalRequestProperties(schema) {
|
|
20
|
+
if (!isObject(schema))
|
|
21
|
+
return schema;
|
|
22
|
+
const result = { ...schema };
|
|
23
|
+
delete result.required;
|
|
24
|
+
delete result.default;
|
|
25
|
+
for (const key of [
|
|
26
|
+
'properties',
|
|
27
|
+
'patternProperties',
|
|
28
|
+
'$defs',
|
|
29
|
+
'definitions',
|
|
30
|
+
'dependentSchemas',
|
|
31
|
+
]) {
|
|
32
|
+
if (!isObject(result[key]))
|
|
33
|
+
continue;
|
|
34
|
+
result[key] = Object.fromEntries(Object.entries(result[key]).map(([name, value]) => [
|
|
35
|
+
name,
|
|
36
|
+
optionalRequestProperties(value),
|
|
37
|
+
]));
|
|
38
|
+
}
|
|
39
|
+
for (const key of [
|
|
40
|
+
'items',
|
|
41
|
+
'additionalProperties',
|
|
42
|
+
'not',
|
|
43
|
+
'if',
|
|
44
|
+
'then',
|
|
45
|
+
'else',
|
|
46
|
+
'contains',
|
|
47
|
+
'unevaluatedProperties',
|
|
48
|
+
'propertyNames',
|
|
49
|
+
]) {
|
|
50
|
+
if (result[key] !== undefined)
|
|
51
|
+
result[key] = optionalRequestProperties(result[key]);
|
|
52
|
+
}
|
|
53
|
+
for (const key of ['allOf', 'anyOf', 'oneOf', 'prefixItems']) {
|
|
54
|
+
if (Array.isArray(result[key]))
|
|
55
|
+
result[key] = result[key].map(optionalRequestProperties);
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
function requestBodySchema(operation, dialect, requestMediaType) {
|
|
60
|
+
if (!operation.body)
|
|
61
|
+
return undefined;
|
|
62
|
+
const mediaTypes = Object.entries(operation.body.mediaTypes).filter(([mediaType]) => requestMediaType === undefined || mediaType === requestMediaType);
|
|
63
|
+
if (requestMediaType !== undefined && mediaTypes.length === 0)
|
|
64
|
+
throw new Error(`operationRef ${operation.operationRef}.requestBody has no media type ${requestMediaType}`);
|
|
65
|
+
if (mediaTypes.length === 0)
|
|
66
|
+
throw new Error(`operationRef ${operation.operationRef}.requestBody.content has no media types`);
|
|
67
|
+
const schemas = mediaTypes.map(([mediaType, media]) => media.schema === undefined
|
|
68
|
+
? z.json()
|
|
69
|
+
: createOasValueSchema(optionalRequestProperties(media.schema), dialect, `operationRef ${operation.operationRef}.requestBody.${mediaType}.schema`));
|
|
70
|
+
const body = schemas
|
|
71
|
+
.slice(1)
|
|
72
|
+
.reduce((combined, schema) => z.union([combined, schema]), schemas[0]);
|
|
73
|
+
return body
|
|
74
|
+
.describe('Request body values explicitly stated in the scenario')
|
|
75
|
+
.optional();
|
|
76
|
+
}
|
|
77
|
+
export function createOperationPlanSchema(operation, openapiVersion, requestMediaType) {
|
|
78
|
+
let dialect;
|
|
79
|
+
if (openapiVersion.startsWith('3.0.'))
|
|
80
|
+
dialect = 'openapi-3.0';
|
|
81
|
+
else if (openapiVersion.startsWith('3.1.') ||
|
|
82
|
+
openapiVersion.startsWith('3.2.'))
|
|
83
|
+
dialect = 'draft-2020-12';
|
|
84
|
+
else
|
|
85
|
+
throw new Error(`spec.openapi is not a supported OAS version: ${openapiVersion}`);
|
|
86
|
+
const groups = Object.fromEntries(['path', 'query', 'header', 'cookie']
|
|
87
|
+
.map((location) => [
|
|
88
|
+
location,
|
|
89
|
+
parameterGroup(operation.parameters, location, dialect),
|
|
90
|
+
])
|
|
91
|
+
.filter(([, schema]) => schema !== undefined));
|
|
92
|
+
const body = requestBodySchema(operation, dialect, requestMediaType);
|
|
93
|
+
return z
|
|
94
|
+
.object({
|
|
95
|
+
inputs: z.object({ ...groups, ...(body ? { body } : {}) }).strict(),
|
|
96
|
+
})
|
|
97
|
+
.strict()
|
|
98
|
+
.describe('Only request values explicitly stated in the scenario');
|
|
99
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { LiteralInputProjection } from '../types/api-argument-generation.js';
|
|
2
|
+
import type { JsonObject } from '../types/openapi.js';
|
|
3
|
+
/** Project specific array positions, never every item because one index is bound. */
|
|
4
|
+
export declare function projectLiteralArraySchema(schema: JsonObject, targets: string[][], source: string): LiteralInputProjection;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { isObject } from '../utils/is-object.js';
|
|
2
|
+
import { projectLiteralInputSchema } from './project-literal-input-schema.js';
|
|
3
|
+
/** Project specific array positions, never every item because one index is bound. */
|
|
4
|
+
export function projectLiteralArraySchema(schema, targets, source) {
|
|
5
|
+
const prefix = [];
|
|
6
|
+
const original = Array.isArray(schema.prefixItems)
|
|
7
|
+
? schema.prefixItems
|
|
8
|
+
: Array.isArray(schema.items)
|
|
9
|
+
? schema.items
|
|
10
|
+
: [];
|
|
11
|
+
for (const child of original) {
|
|
12
|
+
if (typeof child !== 'boolean' && !isObject(child))
|
|
13
|
+
throw new Error(`${source}.prefixItems must contain schemas`);
|
|
14
|
+
prefix.push(child);
|
|
15
|
+
}
|
|
16
|
+
const rawRest = Array.isArray(schema.items)
|
|
17
|
+
? schema.additionalItems
|
|
18
|
+
: schema.items;
|
|
19
|
+
if (rawRest !== undefined &&
|
|
20
|
+
typeof rawRest !== 'boolean' &&
|
|
21
|
+
!isObject(rawRest))
|
|
22
|
+
throw new Error(`${source}.items must be a schema`);
|
|
23
|
+
const rest = rawRest === undefined ? true : rawRest;
|
|
24
|
+
const availability = prefix.map((child) => child !== false);
|
|
25
|
+
let limit = typeof schema.maxItems === 'number' ? schema.maxItems : Infinity;
|
|
26
|
+
for (const token of new Set(targets.map(([index]) => index))) {
|
|
27
|
+
if (!/^(0|[1-9][0-9]*)$/.test(token) ||
|
|
28
|
+
!Number.isSafeInteger(Number(token)))
|
|
29
|
+
throw new Error(`${source}/${token}: binding requires an array index`);
|
|
30
|
+
const index = Number(token);
|
|
31
|
+
while (prefix.length <= index) {
|
|
32
|
+
prefix.push(structuredClone(rest));
|
|
33
|
+
availability.push(rest !== false);
|
|
34
|
+
}
|
|
35
|
+
const projected = projectLiteralInputSchema(prefix[index], targets.filter(([key]) => key === token).map((tokens) => tokens.slice(1)), `${source}/${token}`);
|
|
36
|
+
prefix[index] = projected.schema;
|
|
37
|
+
availability[index] = projected.hasLiteralValues;
|
|
38
|
+
// JSON literals cannot leave a hole for a fully bound element.
|
|
39
|
+
if (projected.schema === false)
|
|
40
|
+
limit = Math.min(limit, index);
|
|
41
|
+
}
|
|
42
|
+
schema.prefixItems = prefix;
|
|
43
|
+
schema.items = rest;
|
|
44
|
+
delete schema.additionalItems;
|
|
45
|
+
if (Number.isFinite(limit))
|
|
46
|
+
schema.maxItems = limit;
|
|
47
|
+
if (typeof schema.minItems === 'number' &&
|
|
48
|
+
targets.some(([index]) => Number(index) + 1 >= Number(schema.minItems)))
|
|
49
|
+
schema.minItems = 0;
|
|
50
|
+
return {
|
|
51
|
+
schema,
|
|
52
|
+
hasLiteralValues: availability.slice(0, limit).some(Boolean) ||
|
|
53
|
+
(rest !== false && prefix.length < limit),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { LiteralInputProjection, LiteralInputSchema } from '../types/api-argument-generation.js';
|
|
2
|
+
/** Bound fields do not belong in the model's literal-value output schema. */
|
|
3
|
+
export declare function projectLiteralInputSchema(input: LiteralInputSchema, targets: string[][], source: string): LiteralInputProjection;
|