-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webserver): generate a proper swagger specs
- Loading branch information
1 parent
fc76401
commit 1bdc921
Showing
12 changed files
with
352 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
webserver/src/main/java/io/kestra/webserver/controllers/ApiController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
Oops, something went wrong.