Skip to content

Commit

Permalink
feat(webserver): generate a proper swagger specs
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed May 3, 2022
1 parent fc76401 commit 1bdc921
Show file tree
Hide file tree
Showing 12 changed files with 352 additions and 313 deletions.
3 changes: 3 additions & 0 deletions cli/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ micronaut:
ui:
paths: classpath:ui
mapping: /ui/**
static:
paths: classpath:static
mapping: /static/**
server:
max-request-size: 10GB
multipart:
Expand Down
12 changes: 11 additions & 1 deletion webserver/src/main/java/io/kestra/webserver/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.info.License;
import io.swagger.v3.oas.annotations.tags.Tag;

@OpenAPIDefinition(
info = @Info(
title = "Kestra",
license = @License(name = "Apache 2.0", url = "https://raw.githubusercontent.com/kestra-io/kestra/master/LICENSE")
)
),
tags = {
@Tag(name = "Flows", description = "Flows api"),
@Tag(name = "Templates", description = "Templates api"),
@Tag(name = "Executions", description = "Executions api"),
@Tag(name = "Logs", description = "Logs api"),
@Tag(name = "Plugins", description = "Plugins api"),
@Tag(name = "Stats", description = "Stats api"),
@Tag(name = "Misc", description = "Misc api"),
}
)
public class Application {
public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package io.kestra.webserver.controllers;

import io.kestra.core.exceptions.IllegalVariableEvaluationException;
import io.kestra.core.exceptions.InternalException;
import io.kestra.core.models.SearchResult;
import io.kestra.core.models.flows.Flow;
import io.kestra.core.models.hierarchies.FlowGraph;
import io.kestra.core.models.tasks.Task;
import io.kestra.core.models.validations.ManualConstraintViolation;
import io.kestra.core.repositories.FlowRepositoryInterface;
import io.kestra.webserver.responses.PagedResults;
import io.kestra.webserver.utils.PageableUtils;
import io.micronaut.context.annotation.Value;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.*;
import io.micronaut.http.exceptions.HttpStatusException;
import io.micronaut.scheduling.TaskExecutors;
import io.micronaut.scheduling.annotation.ExecuteOn;
import io.micronaut.validation.Validated;
import io.swagger.v3.oas.annotations.Hidden;
import jakarta.inject.Inject;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import javax.validation.ConstraintViolationException;
import javax.validation.Valid;

import static io.kestra.core.utils.Rethrow.throwFunction;

@Validated
@Controller("/api")
public class ApiController {
@Value("${micronaut.server.context-path:}")
protected String basePath;

protected String getBasePath() {
return basePath.replaceAll("/$","");
}

protected String getSwaggerFilename() {
return "kestra.yml";
}

@Get()
@Hidden
public HttpResponse<?> rapidoc() {
String doc = "<!doctype html>\n" +
"<html>\n" +
"<head>\n" +
" <title>Api | Kestra</title>\n" +
" <meta charset='utf-8'/>\n" +
" <link rel=\"shortcut icon\" type=\"image/png\" href=\"/static/icon_black.png\" />\n" +
" <meta name='viewport' content='width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes'/>\n" +
" <link href=\"https://fonts.googleapis.com/css2?family=Ubuntu:wght@300;400;700;900&display=swap\" rel=\"stylesheet\">\n" +
" <script src='https://unpkg.com/rapidoc/dist/rapidoc-min.js'></script>\n" +
"</head>\n" +
"<body>\n" +
" <rapi-doc " +
" id='rapidoc'\n" +
" layout=\"row\"\n" +
" sort-endpoints-by=\"path\"\n" +
" show-header=\"false\"\n" +
" theme=\"dark\"\n" +
" bg-color=\"#1b1e2a\"\n" +
" text-color=\"#c1c1d8\"\n" +
" primary-color=\"#4F83A5\"\n" +
" render-style=\"read\"\n" +
" schema-style=\"table\"\n" +
" regular-font='Ubuntu'\n" +
" >\n" +
" <img src=\"" + getBasePath() + "/static/logo.svg\" slot=\"nav-logo\" alt=\"logo\" />\n" +
"\n" +
" </rapi-doc>\n" +
" <script>\n" +
" const rapidoc = document.getElementById('rapidoc');\n" +
" rapidoc.setAttribute('spec-url', '" + getBasePath() + "/swagger/" + getSwaggerFilename() + "');\n" +
" </script>\n" +
"</body>\n" +
"</html>\n";

return HttpResponse
.ok()
.contentType(MediaType.TEXT_HTML_TYPE)
.body(doc);
}

}
Loading

0 comments on commit 1bdc921

Please sign in to comment.