diff --git a/core/src/main/java/io/kestra/core/docs/JsonSchemaGenerator.java b/core/src/main/java/io/kestra/core/docs/JsonSchemaGenerator.java index af10cf07c5..0742261d91 100644 --- a/core/src/main/java/io/kestra/core/docs/JsonSchemaGenerator.java +++ b/core/src/main/java/io/kestra/core/docs/JsonSchemaGenerator.java @@ -296,21 +296,21 @@ public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, Sch .stream() .flatMap(registeredPlugin -> registeredPlugin.getTasks().stream()) .filter(Predicate.not(io.kestra.core.models.Plugin::isInternal)) - .map(clz -> typeContext.resolveSubtype(declaredType, clz)) + .flatMap(clz -> safelyResolveSubtype(declaredType, clz, typeContext).stream()) .toList(); } else if (declaredType.getErasedType() == AbstractTrigger.class) { return getRegisteredPlugins() .stream() .flatMap(registeredPlugin -> registeredPlugin.getTriggers().stream()) .filter(Predicate.not(io.kestra.core.models.Plugin::isInternal)) - .map(clz -> typeContext.resolveSubtype(declaredType, clz)) + .flatMap(clz -> safelyResolveSubtype(declaredType, clz, typeContext).stream()) .toList(); } else if (declaredType.getErasedType() == Condition.class) { return getRegisteredPlugins() .stream() .flatMap(registeredPlugin -> registeredPlugin.getConditions().stream()) .filter(Predicate.not(io.kestra.core.models.Plugin::isInternal)) - .map(clz -> typeContext.resolveSubtype(declaredType, clz)) + .flatMap(clz -> safelyResolveSubtype(declaredType, clz, typeContext).stream()) .toList(); } else if (declaredType.getErasedType() == ScheduleCondition.class) { return getRegisteredPlugins() @@ -318,17 +318,16 @@ public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, Sch .flatMap(registeredPlugin -> registeredPlugin.getConditions().stream()) .filter(ScheduleCondition.class::isAssignableFrom) .filter(Predicate.not(io.kestra.core.models.Plugin::isInternal)) - .map(clz -> typeContext.resolveSubtype(declaredType, clz)) + .flatMap(clz -> safelyResolveSubtype(declaredType, clz, typeContext).stream()) .toList(); } else if (declaredType.getErasedType() == TaskRunner.class) { return getRegisteredPlugins() .stream() .flatMap(registeredPlugin -> registeredPlugin.getTaskRunners().stream()) .filter(Predicate.not(io.kestra.core.models.Plugin::isInternal)) - .map(clz -> typeContext.resolveSubtype(declaredType, clz)) + .flatMap(clz -> safelyResolveSubtype(declaredType, clz, typeContext).stream()) .toList(); } - return null; }); // description as Markdown @@ -413,6 +412,16 @@ public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, Sch } } + private static Optional safelyResolveSubtype(ResolvedType declaredType, Class clz, TypeContext typeContext) { + try { + return Optional.ofNullable(typeContext.resolveSubtype(declaredType, clz)); + } catch (Exception e) { + // exception can be thrown when resolving a plugin-type depending on + // a non-backward compatible kestra (e.g., java.lang.TypeNotPresentException). + return Optional.empty(); + } + } + protected List getRegisteredPlugins() { return pluginRegistry.plugins(); }