Skip to content

Commit

Permalink
feat: add enable of swagger-ui and suggest
Browse files Browse the repository at this point in the history
  • Loading branch information
chaozwn committed Sep 8, 2023
1 parent 2419e90 commit f833f9e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,9 @@ public String notificationMessageEnabled() {
public String getLogo() {
return getOptional("notebook.logo", "Byzer Notebook");
}

public Boolean getSuggestEnable() {
return Objects.equals(getOptional("notebook.suggest.enable", "true"), "true");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -353,24 +353,29 @@ public void checkResourceLimit(String user, Integer newResourceNum) {

public List<CodeSuggestDTO> getCodeSuggestion(CodeSuggestionReq params) {
String result;
try {
String user = WebUtils.getCurrentLoginUser();
result = engineService.runAutoSuggest(
new EngineService.RunScriptParams()
.withSql(params.getSql())
.withOwner(user)
.with("lineNum", params.getLineNum().toString())
.with("columnNum", params.getColumnNum().toString())
.with("isDebug", params.getIsDebug().toString())
.withAsync("false")
);
} catch (ByzerException e) {
throw new ByzerIgnoreException(e);
} catch (EngineAccessException e) {
throw new EngineAccessException(ErrorCodeEnum.ENGINE_ACCESS_EXCEPTION, e);
boolean suggestEnable = config.getSuggestEnable();
if (suggestEnable) {
try {
String user = WebUtils.getCurrentLoginUser();
result = engineService.runAutoSuggest(
new EngineService.RunScriptParams()
.withSql(params.getSql())
.withOwner(user)
.with("lineNum", params.getLineNum().toString())
.with("columnNum", params.getColumnNum().toString())
.with("isDebug", params.getIsDebug().toString())
.withAsync("false")
);
} catch (ByzerException e) {
throw new ByzerIgnoreException(e);
} catch (EngineAccessException e) {
throw new EngineAccessException(ErrorCodeEnum.ENGINE_ACCESS_EXCEPTION, e);
}
List<CodeSuggestDTO> codeSuggests = JacksonUtils.readJsonArray(result, CodeSuggestDTO.class);
return codeSuggests;
} else {
return null;
}
List<CodeSuggestDTO> codeSuggests = JacksonUtils.readJsonArray(result, CodeSuggestDTO.class);
return codeSuggests;
}

public String getNotebookScripts(String user, Integer notebookId, String commitId, Map<String, String> options) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kyligence.notebook.console.support;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -16,9 +17,13 @@
@ConditionalOnClass(Docket.class)
public class SwaggerConfig {

@Value("${swagger.enable:true}")
private Boolean swaggerEnable;

@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.enable(swaggerEnable)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("io.kyligence.notebook.console.controller"))
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ server:
error:
include-stacktrace: always

swagger:
enable: true

management:
endpoint:
shutdown:
Expand Down

0 comments on commit f833f9e

Please sign in to comment.