|
1 | 1 | import type { ValidateFunction } from 'ajv'; |
2 | 2 | import type Ajv from 'ajv'; |
3 | 3 |
|
4 | | -import { ACTOR_ENUM_MAX_LENGTH, ACTOR_MAX_DESCRIPTION_LENGTH } from '../const.js'; |
| 4 | +import { ACTOR_ENUM_MAX_LENGTH, ACTOR_MAX_DESCRIPTION_LENGTH, ADVANCED_INPUT_KEY } from '../const.js'; |
5 | 5 | import type { ActorInputSchemaProperties, IActorInputSchema, ISchemaProperties } from '../types.js'; |
6 | 6 | import { |
7 | 7 | addGlobsProperties, |
@@ -312,46 +312,47 @@ export function transformActorInputSchemaProperties( |
312 | 312 | // Deep clone input to avoid mutating the original object |
313 | 313 | const inputClone: IActorInputSchema = structuredClone(input); |
314 | 314 |
|
| 315 | + const transform = (transformInput: IActorInputSchema) => { |
| 316 | + let transformedProperties = markInputPropertiesAsRequired(transformInput); |
| 317 | + transformedProperties = buildApifySpecificProperties(transformedProperties); |
| 318 | + transformedProperties = filterSchemaProperties(transformedProperties); |
| 319 | + transformedProperties = inferArrayItemsTypeIfMissing(transformedProperties); |
| 320 | + transformedProperties = shortenProperties(transformedProperties); |
| 321 | + transformedProperties = addEnumsToDescriptionsWithExamples(transformedProperties); |
| 322 | + transformedProperties = encodeDotPropertyNames(transformedProperties); |
| 323 | + return transformedProperties; |
| 324 | + }; |
| 325 | + |
315 | 326 | if (options?.separateAdvancedInputs) { |
316 | 327 | inputClone.properties = separateAdvancedInputsInSchema(inputClone.properties); |
317 | | - if (inputClone.properties.advancedInput) { |
318 | | - // Recursively transform the advanced input properties |
319 | | - inputClone.properties.advancedInput.properties = transformActorInputSchemaProperties( |
320 | | - inputClone.properties.advancedInput as IActorInputSchema, |
321 | | - { separateAdvancedInputs: false }, |
322 | | - ); |
| 328 | + if (inputClone.properties[ADVANCED_INPUT_KEY]) { |
| 329 | + inputClone.properties[ADVANCED_INPUT_KEY].properties = transform(inputClone.properties[ADVANCED_INPUT_KEY] as IActorInputSchema); |
323 | 330 | } |
324 | 331 | } |
325 | 332 |
|
326 | | - let transformedProperties = markInputPropertiesAsRequired(inputClone); |
327 | | - transformedProperties = buildApifySpecificProperties(transformedProperties); |
328 | | - transformedProperties = filterSchemaProperties(transformedProperties); |
329 | | - transformedProperties = inferArrayItemsTypeIfMissing(transformedProperties); |
330 | | - transformedProperties = shortenProperties(transformedProperties); |
331 | | - transformedProperties = addEnumsToDescriptionsWithExamples(transformedProperties); |
332 | | - transformedProperties = encodeDotPropertyNames(transformedProperties); |
333 | | - return transformedProperties; |
| 333 | + return transform(inputClone); |
334 | 334 | } |
335 | 335 |
|
336 | 336 | export function transformActorInputForGetDetails( |
337 | 337 | input: Readonly<IActorInputSchema>, |
338 | 338 | options?: { separateAdvancedInputs?: boolean }, |
339 | | -) { |
| 339 | +): IActorInputSchema { |
340 | 340 | // Deep clone input to avoid mutating the original object |
341 | 341 | const inputClone = structuredClone(input) as IActorInputSchema; |
342 | 342 |
|
| 343 | + const transform = (transformInput: IActorInputSchema) => { |
| 344 | + let transformedProperties = filterSchemaProperties(transformInput.properties); |
| 345 | + transformedProperties = shortenProperties(transformedProperties); |
| 346 | + return transformedProperties; |
| 347 | + }; |
| 348 | + |
343 | 349 | if (options?.separateAdvancedInputs) { |
344 | 350 | inputClone.properties = separateAdvancedInputsInSchema(inputClone.properties); |
345 | | - if (inputClone.properties.advancedInput) { |
346 | | - // Recursively transform the advanced input properties |
347 | | - inputClone.properties.advancedInput = transformActorInputForGetDetails( |
348 | | - inputClone.properties.advancedInput as IActorInputSchema, |
349 | | - { separateAdvancedInputs: false }, |
350 | | - ) as ISchemaProperties; |
| 351 | + if (inputClone.properties[ADVANCED_INPUT_KEY]) { |
| 352 | + inputClone.properties[ADVANCED_INPUT_KEY].properties = transform(inputClone.properties[ADVANCED_INPUT_KEY] as IActorInputSchema); |
351 | 353 | } |
352 | 354 | } |
353 | 355 |
|
354 | | - inputClone.properties = filterSchemaProperties(inputClone.properties); |
355 | | - inputClone.properties = shortenProperties(inputClone.properties); |
| 356 | + inputClone.properties = transform(inputClone); |
356 | 357 | return inputClone; |
357 | 358 | } |
0 commit comments