Skip to content

Commit

Permalink
fix(core): Avoid double STRING schema type for types that resolves to…
Browse files Browse the repository at this point in the history
… a String

Fixes #6821
  • Loading branch information
loicmathieu committed Jan 20, 2025
1 parent b48c6c3 commit 1a130da
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions core/src/main/java/io/kestra/core/docs/JsonSchemaGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
import jakarta.inject.Singleton;

import java.lang.reflect.*;
import java.time.Duration;
import java.time.LocalTime;
import java.time.*;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

@Singleton
public class JsonSchemaGenerator {
private static final List<Class<?>> TYPES_RESOLVED_AS_STRING = List.of(Duration.class, LocalTime.class, LocalDate.class, LocalDateTime.class, ZonedDateTime.class, OffsetDateTime.class, OffsetTime.class);

private final PluginRegistry pluginRegistry;

Expand Down Expand Up @@ -251,6 +251,7 @@ public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, Sch
if (javaType.isInstanceOf(Property.class)) {
TypeContext context = target.getContext();
Class<?> erasedType = javaType.getTypeParameters().getFirst().getErasedType();

if(String.class.isAssignableFrom(erasedType)) {
return List.of(
context.resolve(String.class)
Expand All @@ -267,6 +268,10 @@ public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, Sch
return List.of(
javaType.getTypeParameters().getFirst()
);
} else if (isAssignableFromResolvedAsString(erasedType)) {
return List.of(
javaType.getTypeParameters().getFirst()
);
} else {
return List.of(
javaType.getTypeParameters().getFirst(),
Expand Down Expand Up @@ -471,6 +476,15 @@ public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, Sch
}
}

private boolean isAssignableFromResolvedAsString(Class<?> declaredType) {
for (Class<?> clazz : TYPES_RESOLVED_AS_STRING) {
if (clazz.isAssignableFrom(declaredType)) {
return true;
}
}
return false;
}

protected List<ResolvedType> subtypeResolver(ResolvedType declaredType, TypeContext typeContext) {
if (declaredType.getErasedType() == Task.class) {
return getRegisteredPlugins()
Expand Down

0 comments on commit 1a130da

Please sign in to comment.