Skip to content

Commit

Permalink
Merge pull request #19 from lanwen/readme
Browse files Browse the repository at this point in the history
readme with example
  • Loading branch information
lanwen authored Oct 11, 2016
2 parents 1922ac6 + 28ee87b commit 4e66188
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 5 deletions.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# RARC - Rest-Assured RAML Codegen

This project simplifies generation of test clients
(with [Rest-Assured lib](https://github.com/rest-assured/rest-assured/) under the hood) by your RAML spec.
Currently this project pointed to [0.8](http://raml.org/raml-08-spec), but
will be upgraded to [1.0](http://raml.org/raml-10-spec) soon.

## Quick Start

- Place your spec to `src/main/resources/api.raml`
- Add to your `<build>` section in `pom.xml`:

```xml
<plugin>
<groupId>ru.lanwen.raml</groupId>
<artifactId>rarc-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate-client</goal>
</goals>
<configuration>
<basePackage>ru.lanwen.raml.test</basePackage>
</configuration>
</execution>
</executions>
</plugin>
```

- Add dependency to rest-assured (currently tested on `2.8.0`):

```xml
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.8.0</version>
</dependency>
```

- Run `mvn clean compile`
- Use it! (Don't forget to add static imports and factory to base endpoint)

```java
ApiExample.example(
ApiExample.Config.exampleConfig()
.withReqSpecSupplier(
() -> new RequestSpecBuilder().setBaseUri("http://your_host/")
)
)
.rpcApi()
.uid().withUid("1")
.info()
.get(identity()).prettyPeek();
```

See working example in `rarc-example` module.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@
<version>2.8.0</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>

<!--https://github.com/square/javapoet-->
<dependency>
<groupId>com.squareup</groupId>
Expand Down
15 changes: 12 additions & 3 deletions rarc-core/src/main/java/ru/lanwen/raml/rarc/util/JsonCodegen.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

import com.jayway.restassured.path.json.JsonPath;
import com.sun.codemodel.JCodeModel;
import org.jsonschema2pojo.*;
import org.jsonschema2pojo.DefaultGenerationConfig;
import org.jsonschema2pojo.GenerationConfig;
import org.jsonschema2pojo.GsonAnnotator;
import org.jsonschema2pojo.SchemaGenerator;
import org.jsonschema2pojo.SchemaMapper;
import org.jsonschema2pojo.SchemaStore;
import org.jsonschema2pojo.SourceType;
import org.jsonschema2pojo.rules.RuleFactory;

import java.io.File;
Expand Down Expand Up @@ -35,7 +41,7 @@ public boolean isGenerateBuilders() { // set config option by overriding metho

@Override
public SourceType getSourceType() {
if(JsonPath.from(source).get("$schema") != null) {
if (JsonPath.from(source).get("$schema") != null) {
return SourceType.JSONSCHEMA;
}
return SourceType.JSON;
Expand All @@ -46,7 +52,10 @@ public boolean isUseLongIntegers() {
return true;
}


@Override
public boolean isUseCommonsLang3() {
return true;
}
};

SchemaMapper mapper = new SchemaMapper(
Expand Down
14 changes: 12 additions & 2 deletions rarc-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,18 @@

<dependencies>
<dependency>
<groupId>ru.lanwen.raml</groupId>
<artifactId>rarc-core</artifactId>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ru.lanwen.raml.test;

import com.jayway.restassured.builder.RequestSpecBuilder;
import org.junit.Ignore;
import org.junit.Test;

import static java.util.function.Function.identity;

/**
* @author lanwen (Merkushev Kirill)
*/
@Ignore
public class ApiExampleUsageTest {

@Test
public void shouldBeAbleToCompile() throws Exception {
ApiExample.example(
ApiExample.Config.exampleConfig()
.withReqSpecSupplier(
() -> new RequestSpecBuilder().setBaseUri("http://your_host/")
)
)
.rpcApi()
.uid().withUid("1")
.info()
.get(identity()).prettyPeek();

}
}

0 comments on commit 4e66188

Please sign in to comment.