Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): document deprecated tasks #1078

Merged
merged 1 commit into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@ToString
@NoArgsConstructor
public class ClassPluginDocumentation<T> {
private Boolean deprecated;
private String cls;
private String icon;
private String group;
Expand Down Expand Up @@ -72,6 +73,7 @@ private ClassPluginDocumentation(JsonSchemaGenerator jsonSchemaGenerator, Regist

this.docDescription = this.propertiesSchema.containsKey("title") ? (String) this.propertiesSchema.get("title") : null;
this.docBody = this.propertiesSchema.containsKey("description") ? (String) this.propertiesSchema.get("description") : null;
this.deprecated = this.propertiesSchema.containsKey("$deprecated");

if (this.propertiesSchema.containsKey("$examples")) {
List<Map<String, Object>> examples = (List<Map<String, Object>>) this.propertiesSchema.get("$examples");
Expand Down
11 changes: 10 additions & 1 deletion core/src/main/java/io/kestra/core/docs/JsonSchemaGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, Sch
memberAttributes.put("$dynamic", pluginPropertyAnnotation.dynamic());
}


Schema schema = member.getAnnotationConsideringFieldAndGetter(Schema.class);
if (schema != null && schema.deprecated()) {
memberAttributes.put("$deprecated", true);
Expand Down Expand Up @@ -279,6 +278,13 @@ public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, Sch
collectedTypeAttributes.set("$metrics", context.getGeneratorConfig().createArrayNode().addAll(metrics));
}
}

// handle deprecated tasks
Schema schema = scope.getType().getErasedType().getAnnotation(Schema.class);
Deprecated deprecated = scope.getType().getErasedType().getAnnotation(Deprecated.class);
if ((schema != null && schema.deprecated()) || deprecated != null ) {
collectedTypeAttributes.put("$deprecated", "true");
}
});

// PluginProperty additionalProperties
Expand Down Expand Up @@ -510,6 +516,9 @@ private void addMainRefProperties(JsonNode mainClassDef, ObjectNode objectNode)
if (mainClassDef.has("$metrics")) {
objectNode.set("$metrics", mainClassDef.get("$metrics"));
}
if (mainClassDef.has("$deprecated")) {
objectNode.set("$deprecated", mainClassDef.get("$deprecated"));
}
}

private Object buildDefaultInstance(Class<?> cls) {
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/io/kestra/core/tasks/debugs/Echo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
@Getter
@NoArgsConstructor
@Schema(
title = "Debugging task that logs a rendered value.",
description = "This task is mostly useful for debugging purpose.\n\n" +
"It allows you to log inputs or outputs variables or to debug some templated functions."
title = "Log a message in the task logs.",
description = "This task is deprecated, please use the io.kestra.core.tasks.log.Log task instead.",
deprecated = true
)
@Plugin(
examples = {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/docs/task.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ icon: {{ icon }}
{{~/inline~}}
{{!-- {{ Main doc }} --}}
<h1>
{{#if icon ~}}<img width="25" src="data:image/svg+xml;base64,{{icon}}" alt="{{shortName}}" />{{/if }} {{shortName}}
{{#if icon ~}}<img width="25" src="data:image/svg+xml;base64,{{icon}}" alt="{{shortName}}" />{{/if }} {{shortName}} {{~#if deprecated }}- 🔒 Deprecated{{~/if}}
</h1>

```yaml
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kestra.core.docs;

import io.kestra.core.tasks.debugs.Echo;
import io.kestra.core.tasks.debugs.Return;
import io.kestra.core.tasks.flows.Flow;
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
Expand Down Expand Up @@ -91,4 +92,18 @@ void defaultBool() throws IOException {

assertThat(render, containsString("* **Default:** `false`"));
}

@Test
void echo() throws IOException {
PluginScanner pluginScanner = new PluginScanner(ClassPluginDocumentationTest.class.getClassLoader());
RegisteredPlugin scan = pluginScanner.scan();
Class<Echo> bash = scan.findClass(Echo.class.getName()).orElseThrow();

ClassPluginDocumentation<? extends Task> doc = ClassPluginDocumentation.of(jsonSchemaGenerator, scan, bash, Task.class);

String render = DocumentationGenerator.render(doc);

assertThat(render, containsString("Echo"));
assertThat(render, containsString("- \uD83D\uDD12 Deprecated"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.kestra.core.models.tasks.VoidOutput;
import io.kestra.core.models.triggers.AbstractTrigger;
import io.kestra.core.runners.RunContext;
import io.kestra.core.tasks.debugs.Echo;
import io.kestra.core.tasks.debugs.Return;
import io.kestra.core.Helpers;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down Expand Up @@ -160,6 +161,21 @@ void returnTask() throws URISyntaxException {
});
}

@SuppressWarnings("unchecked")
@Test
void echoTask() throws URISyntaxException {
Helpers.runApplicationContext((applicationContext) -> {
JsonSchemaGenerator jsonSchemaGenerator = applicationContext.getBean(JsonSchemaGenerator.class);

Map<String, Object> returnSchema = jsonSchemaGenerator.schemas(Echo.class);
System.out.println(returnSchema);
var definitions = (Map<String, Map<String, Object>>) returnSchema.get("definitions");
var returnTask = definitions.get("io.kestra.core.tasks.debugs.Echo-1");
var deprecated = (String) returnTask.get("$deprecated");
assertThat(deprecated, is("true"));
});
}

@SuppressWarnings("unchecked")
@Test
void testEnum() {
Expand Down