Skip to content

Commit

Permalink
Add a way to load config from external paths
Browse files Browse the repository at this point in the history
  • Loading branch information
SAMANU committed Aug 13, 2022
1 parent 589e507 commit 174dc2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion demo/src/main/resources/conf/spark-swagger.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spark-swagger {


# API related configs
host = "localhost:8081"
host = "localhost:8082"
basePath = "/thor"
info {
version = "1.0.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import spark.HaltException;
import spark.Service;

import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
Expand All @@ -43,7 +44,7 @@ private SparkSwagger(final Service spark, final Options options) {
this.spark = spark;
this.options = options == null ? Options.defaultOptions().build() : options;
this.swagger = new Swagger();
this.config = ConfigFactory.parseResources(Objects.requireNonNull(options).getConfPath());
this.config = getConfig(options);
this.apiPath = this.config.getString("spark-swagger.basePath");
this.swagger.setBasePath(this.apiPath);
this.swagger.setExternalDocs(ExternalDocs.newBuilder().build());
Expand All @@ -52,6 +53,14 @@ private SparkSwagger(final Service spark, final Options options) {
configDocRoute();
}

private Config getConfig(Options options) {
Config config = ConfigFactory.parseResources(Objects.requireNonNull(options).getConfPath());
if (!config.hasPath("spark-swagger")) {
config = ConfigFactory.parseFile(new File(Objects.requireNonNull(options).getConfPath()));
}
return config;
}

public String getApiPath() {
return apiPath;
}
Expand Down

0 comments on commit 174dc2d

Please sign in to comment.