Skip to content

Commit

Permalink
Improved Swagger handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Jun 15, 2018
1 parent 0d70f8c commit 114f14a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.sinistral</groupId>
<artifactId>proteus-core</artifactId>
<version>0.2.2-SNAPSHOT</version>
<version>0.2.3-SNAPSHOT</version>
<name>proteus core</name>
<description>Proteus is an extremely light, fast, and flexible Java REST API framework built atop Undertow.</description>
<url>http://github.com/noboomu/proteus</url>
Expand Down
33 changes: 22 additions & 11 deletions src/main/java/io/sinistral/proteus/services/SwaggerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,7 @@ public HttpHandler wrap(final HttpHandler handler)



try
{

this.swaggerSpec = writer.writeValueAsString(this.swagger);

} catch (Exception e)
{
log.error(e.getMessage(),e);
}



}
Expand Down Expand Up @@ -371,7 +363,7 @@ public void generateSwaggerHTML()
templateString = templateString.replaceAll("\\{\\{ themePath \\}\\}", themePath);
templateString = templateString.replaceAll("\\{\\{ swaggerBasePath \\}\\}", swaggerBasePath);
templateString = templateString.replaceAll("\\{\\{ title \\}\\}",applicationName + " Swagger UI");
templateString = templateString.replaceAll("\\{\\{ swaggerFullPath \\}\\}","//" + host + ((port != 80 && port != 443) ? ":" + port : "") + swaggerBasePath + ".json");
templateString = templateString.replaceAll("\\{\\{ swaggerFilePath \\}\\}", swaggerBasePath + ".json");

this.swaggerIndexHTML = templateString;
}
Expand Down Expand Up @@ -467,14 +459,33 @@ public RoutingHandler get()

FileResourceManager resourceManager = new FileResourceManager(this.swaggerResourcePath.toFile(),1024);

final Swagger swaggerCopy = this.swagger;

router.add(HttpMethod.GET, pathTemplate, new HttpHandler(){

@Override
public void handleRequest(HttpServerExchange exchange) throws Exception
{


exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, MediaType.APPLICATION_JSON);
exchange.getResponseSender().send(swaggerSpec);

String spec = null;

try
{

swaggerCopy.setHost(exchange.getHostAndPort());


spec = writer.writeValueAsString(swaggerCopy);

} catch (Exception e)
{
log.error(e.getMessage(),e);
}

exchange.getResponseSender().send(spec);

}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/io/sinistral/proteus/swagger/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
window.onload = function() {
// Build a system
const ui = SwaggerUIBundle({
url: "{{ swaggerFullPath }}",
url: window.location.origin + window.location.pathname + '.json',
dom_id: '#swagger-ui',
presets: [
SwaggerUIBundle.presets.apis,
Expand Down

0 comments on commit 114f14a

Please sign in to comment.