-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 04cb471
Showing
13 changed files
with
220 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
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 @@ | ||
/target |
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,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>blueprint-converter</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
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,6 @@ | ||
eclipse.preferences.version=1 | ||
encoding//src/main/java=UTF-8 | ||
encoding//src/main/resources=UTF-8 | ||
encoding//src/test/java=UTF-8 | ||
encoding//src/test/resources=UTF-8 | ||
encoding/<project>=UTF-8 |
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,5 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | ||
org.eclipse.jdt.core.compiler.compliance=1.7 | ||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | ||
org.eclipse.jdt.core.compiler.source=1.7 |
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,4 @@ | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
resolveWorkspaceProjects=true | ||
version=1 |
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,44 @@ | ||
<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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>de.taimos</groupId> | ||
<artifactId>standalone-parent</artifactId> | ||
<version>1-SNAPSHOT</version> | ||
</parent> | ||
<groupId>org.restdoc.blueprint</groupId> | ||
<artifactId>blueprint-converter</artifactId> | ||
<version>0.1-SNAPSHOT</version> | ||
<name>RestDoc to Blueprint converter</name> | ||
<properties> | ||
<mainClass>org.restdoc.blueprint.converter.Starter</mainClass> | ||
</properties> | ||
<scm> | ||
<connection>scm:git:[email protected]:taimos/velocity-cli.git</connection> | ||
<developerConnection>scm:git:[email protected]:taimos/velocity-cli.git</developerConnection> | ||
<url>scm:git:[email protected]:taimos/velocity-cli.git</url> | ||
<tag>HEAD</tag> | ||
</scm> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.velocity</groupId> | ||
<artifactId>velocity</artifactId> | ||
<version>1.7</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.velocity</groupId> | ||
<artifactId>velocity-tools</artifactId> | ||
<version>2.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>de.taimos</groupId> | ||
<artifactId>httputils</artifactId> | ||
<version>1.7</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.restdoc</groupId> | ||
<artifactId>restdoc-api</artifactId> | ||
<version>1.4</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Empty file.
66 changes: 66 additions & 0 deletions
66
src/main/java/org/restdoc/blueprint/converter/Starter.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,66 @@ | ||
package org.restdoc.blueprint.converter; | ||
|
||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
|
||
import org.apache.commons.lang.CharEncoding; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.velocity.Template; | ||
import org.apache.velocity.VelocityContext; | ||
import org.apache.velocity.app.Velocity; | ||
import org.apache.velocity.runtime.RuntimeConstants; | ||
import org.apache.velocity.tools.generic.DateTool; | ||
import org.apache.velocity.tools.generic.MathTool; | ||
import org.restdoc.api.RestDoc; | ||
import org.restdoc.api.util.RestDocParser; | ||
|
||
import de.taimos.httputils.WS; | ||
|
||
/** | ||
* Copyright 2014 Hoegernet<br> | ||
* <br> | ||
* | ||
* @author Thorsten Hoeger | ||
* | ||
*/ | ||
public class Starter { | ||
|
||
public static void main(String[] args) throws IOException { | ||
if (args.length != 1) { | ||
System.err.println("usage: restdoc2blueprint <url>"); | ||
} | ||
String url = args[0]; | ||
|
||
RestDoc doc = Starter.fetchDoc(url); | ||
|
||
Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "class"); | ||
Velocity.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); | ||
Velocity.init(); | ||
VelocityContext context = new VelocityContext(); | ||
context.put("mathTool", new MathTool()); | ||
context.put("dateTool", new DateTool()); | ||
context.put("rd", doc); | ||
|
||
Template template = Velocity.getTemplate("velocity/blueprint.vm", CharEncoding.UTF_8); | ||
|
||
// try (OutputStreamWriter out = new OutputStreamWriter(System.out, CharEncoding.UTF_8);) { | ||
// template.merge(context, out); | ||
// } catch (IOException e) { | ||
// e.printStackTrace(); | ||
// } | ||
try (FileWriter out = new FileWriter("blueprint.md");) { | ||
template.merge(context, out); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private static RestDoc fetchDoc(String url) throws IOException { | ||
HttpResponse res = WS.url(url).options(); | ||
if (WS.isStatusOK(res)) { | ||
String string = WS.getResponseAsString(res); | ||
return RestDocParser.parseString(string); | ||
} | ||
throw new IOException("invalid HTTP code: " + WS.getStatus(res)); | ||
} | ||
} |
Empty file.
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,35 @@ | ||
#set( $H = '#' ) | ||
|
||
#foreach($resource in ${rd.resources}) | ||
$H #if (${resource.id}) ${resource.id} [${resource.path}]#else ${resource.path} #end | ||
|
||
$!{resource.description} | ||
|
||
Parameter: | ||
#foreach($param in ${resource.params.entrySet()}) | ||
${param.key} - ${param.value.description} #if(${param.value.validations.size()} > 0)(#foreach($validation in ${param.value.validations})$validation#end)#end | ||
|
||
#end | ||
|
||
#foreach($method in ${resource.methods.entrySet()}) | ||
$H$H #if (${method.value.description}) ${method.value.description} [$method.key]#else ${method.key} #end | ||
|
||
Header: | ||
#foreach($header in ${method.value.headers.entrySet()}) | ||
${header.key} #if(${header.required}) (required)#end: ${header.description} | ||
|
||
#end | ||
|
||
Body: | ||
#foreach($accept in ${method.value.accepts}) | ||
- ${accept.schema} (${accept.type}) | ||
|
||
#end | ||
|
||
#foreach($status in ${method.value.statusCodes.entrySet()}) | ||
+ Response ${status.key} | ||
#end | ||
|
||
#end ##method | ||
|
||
#end ##resource |
Empty file.
Empty file.