-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
684 additions
and
29 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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>light-rest-4j</artifactId> | ||
<groupId>com.networknt</groupId> | ||
<version>2.0.0-BETA2</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.networknt</groupId> | ||
<artifactId>specification</artifactId> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.networknt</groupId> | ||
<artifactId>config</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.networknt</groupId> | ||
<artifactId>utility</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.networknt</groupId> | ||
<artifactId>security</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.networknt</groupId> | ||
<artifactId>handler</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.networknt</groupId> | ||
<artifactId>status</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.undertow</groupId> | ||
<artifactId>undertow-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.networknt</groupId> | ||
<artifactId>client</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-text</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
28 changes: 28 additions & 0 deletions
28
specification/src/main/java/com/networknt/specification/SpecDisplayHandler.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,28 @@ | ||
|
||
package com.networknt.specification; | ||
|
||
import com.networknt.config.Config; | ||
import com.networknt.handler.LightHttpHandler; | ||
import io.undertow.server.HttpServerExchange; | ||
import io.undertow.util.HttpString; | ||
|
||
/** | ||
* Display API Specification | ||
* | ||
* @author Gavin Chen | ||
*/ | ||
public class SpecDisplayHandler implements LightHttpHandler { | ||
public static final String CONFIG_NAME = "specification"; | ||
|
||
public SpecDisplayHandler(){ | ||
} | ||
|
||
@Override | ||
public void handleRequest(HttpServerExchange exchange) throws Exception { | ||
SpecificationConfig config = (SpecificationConfig)Config.getInstance().getJsonObjectConfig(CONFIG_NAME, SpecificationConfig.class); | ||
final String payload = Config.getInstance().getStringFromFile(config.getFileName()); | ||
exchange.getResponseHeaders().add(new HttpString("Content-Type"), config.getContentType()); | ||
exchange.getResponseSender().send(payload); | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
specification/src/main/java/com/networknt/specification/SpecSwaggerUIHandler.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,60 @@ | ||
|
||
package com.networknt.specification; | ||
|
||
import com.networknt.handler.LightHttpHandler; | ||
import io.undertow.server.HttpServerExchange; | ||
import io.undertow.util.HttpString; | ||
|
||
/** | ||
* Display API Specification in Swagger editor UI | ||
* | ||
* @author Gavin Chen | ||
*/ | ||
public class SpecSwaggerUIHandler implements LightHttpHandler { | ||
|
||
public SpecSwaggerUIHandler(){} | ||
|
||
|
||
|
||
@Override | ||
public void handleRequest(HttpServerExchange exchange) throws Exception { | ||
|
||
exchange.getResponseHeaders().add(new HttpString("Content-Type"), "text/html"); | ||
exchange.getResponseSender().send(getDisplayHtml()); | ||
} | ||
|
||
private String getDisplayHtml() { | ||
return "<html>\n" + | ||
"<head>\n" + | ||
" <title>OpenAPI Spec</title>\n" + | ||
" <link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.19.3/swagger-ui.css\">\n" + | ||
"</head>\n" + | ||
"<body>\n" + | ||
"<div id=\"swagger-ui\"></div>\n" + | ||
"<script src=\"https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.19.3/swagger-ui-bundle.js\"></script>\n" + | ||
"<script src=\"https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.19.3/swagger-ui-standalone-preset.js\"></script>\n" + | ||
"<script>\n" + | ||
"window.onload = function() {\n" + | ||
"\n" + | ||
" const ui = SwaggerUIBundle({\n" + | ||
" url: \"spec.yaml\",\n" + | ||
" validatorUrl : false,\n" + | ||
" dom_id: '#swagger-ui',\n" + | ||
" deepLinking: true,\n" + | ||
" presets: [\n" + | ||
" SwaggerUIBundle.presets.apis,\n" + | ||
" SwaggerUIStandalonePreset\n" + | ||
" ],\n" + | ||
" plugins: [\n" + | ||
" SwaggerUIBundle.plugins.DownloadUrl\n" + | ||
" ],\n" + | ||
" layout: \"StandaloneLayout\"\n" + | ||
" })\n" + | ||
"\n" + | ||
" window.ui = ui\n" + | ||
"}\n" + | ||
"</script>\n" + | ||
"</body>\n" + | ||
"</html>"; | ||
} | ||
} |
Oops, something went wrong.