-
-
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.
Browse files
Browse the repository at this point in the history
- added and implemented openapi-extender-restassured module - added quarkus sample with openapi-extender-restassured module
- Loading branch information
Showing
11 changed files
with
715 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,33 @@ | ||
<?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>openapi-extender-parent</artifactId> | ||
<groupId>org.rodnansol</groupId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>openapi-extender-restassured</artifactId> | ||
<name>OpenAPI Extender - REST Assured</name> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.rodnansol</groupId> | ||
<artifactId>openapi-extender-resource-generator</artifactId> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
29 changes: 29 additions & 0 deletions
29
...ain/java/org/rodnalsol/openapi/extender/restassured/exception/OpenApiFilterException.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,29 @@ | ||
package org.rodnalsol.openapi.extender.restassured.exception; | ||
|
||
/** | ||
* Exception for OpenAPI filters. | ||
* | ||
* @author csaba.balogh | ||
* @since 0.3.0 | ||
*/ | ||
public class OpenApiFilterException extends RuntimeException { | ||
|
||
/** | ||
* Constructs a new {@link OpenApiFilterException} with the specified detail message. | ||
* | ||
* @param message the detail message. | ||
*/ | ||
public OpenApiFilterException(String message) { | ||
super(message); | ||
} | ||
|
||
/** | ||
* Constructs a new {@link OpenApiFilterException} with the specified detail message and cause. | ||
* | ||
* @param message the detail message. | ||
* @param cause the cause. | ||
*/ | ||
public OpenApiFilterException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
...src/main/java/org/rodnalsol/openapi/extender/restassured/filter/OpenApiRequestFilter.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,98 @@ | ||
package org.rodnalsol.openapi.extender.restassured.filter; | ||
|
||
import io.restassured.filter.Filter; | ||
import io.restassured.filter.FilterContext; | ||
import io.restassured.response.Response; | ||
import io.restassured.specification.FilterableRequestSpecification; | ||
import io.restassured.specification.FilterableResponseSpecification; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.rodnalsol.openapi.extender.restassured.exception.OpenApiFilterException; | ||
import org.rodnansol.generator.ReportParams; | ||
import org.rodnansol.generator.RequestBodyExampleFileOutputResourceGenerator; | ||
|
||
/** | ||
* Rest assured filter class for generating OpenAPI request example. | ||
* | ||
* @author csaba.balogh | ||
* @since 0.3.0 | ||
*/ | ||
public class OpenApiRequestFilter implements Filter { | ||
|
||
/** | ||
* The OpenAPI request example generator. | ||
*/ | ||
private final RequestBodyExampleFileOutputResourceGenerator requestBodyExampleFileOutputResourceGenerator; | ||
|
||
/** | ||
* The operation's name. | ||
*/ | ||
private final String operation; | ||
|
||
/** | ||
* The name of the OpenAPI request example. | ||
*/ | ||
private final String name; | ||
|
||
/** | ||
* The description of the OpenAPI request example. | ||
*/ | ||
private final String description; | ||
|
||
/** | ||
* Creates a new {@link OpenApiRequestFilter} with the specified operation and name. | ||
* The description will be null and the output directory will be {@link RequestBodyExampleFileOutputResourceGenerator#DEFAULT_OUTPUT_DIRECTORY}. | ||
* | ||
* @param operation the operation's name. | ||
* @param name the name of the OpenAPI request example. | ||
*/ | ||
public OpenApiRequestFilter(String operation, String name) { | ||
this(operation, name, null, RequestBodyExampleFileOutputResourceGenerator.DEFAULT_OUTPUT_DIRECTORY); | ||
} | ||
|
||
/** | ||
* Creates a new {@link OpenApiRequestFilter} with the specified operation, name and description. | ||
* The output directory will be {@link RequestBodyExampleFileOutputResourceGenerator#DEFAULT_OUTPUT_DIRECTORY}. | ||
* | ||
* @param operation the operation's name. | ||
* @param name the name of the OpenAPI request example. | ||
* @param description the description of the OpenAPI request example. | ||
*/ | ||
public OpenApiRequestFilter(String operation, String name, String description) { | ||
this(operation, name, description, RequestBodyExampleFileOutputResourceGenerator.DEFAULT_OUTPUT_DIRECTORY); | ||
} | ||
|
||
/** | ||
* Creates a new {@link OpenApiRequestFilter} with the specified operation, name, description and output directory. | ||
* | ||
* @param operation the operation's name. | ||
* @param name the name of the OpenAPI request example. | ||
* @param description the description of the OpenAPI request example. | ||
* @param outputDirectory the output directory of the OpenAPI request example. | ||
*/ | ||
public OpenApiRequestFilter(String operation, String name, String description, String outputDirectory) { | ||
this.operation = operation; | ||
this.name = name; | ||
this.description = description; | ||
this.requestBodyExampleFileOutputResourceGenerator = new RequestBodyExampleFileOutputResourceGenerator(outputDirectory); | ||
} | ||
|
||
@Override | ||
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) { | ||
try { | ||
Response response = ctx.next(requestSpec, responseSpec); | ||
generateResources(requestSpec, response); | ||
return response; | ||
} catch (Exception e) { | ||
throw new OpenApiFilterException("Error during documenting response", e); | ||
} | ||
} | ||
|
||
private void generateResources(FilterableRequestSpecification requestSpec, Response response) throws IOException { | ||
byte[] requestBodyAsByteArray = requestSpec.getBody().toString().getBytes(StandardCharsets.UTF_8); | ||
ReportParams params = new ReportParams(operation, name, response.getStatusCode(), requestSpec.getContentType(), requestBodyAsByteArray); | ||
params.setDescription(description); | ||
requestBodyExampleFileOutputResourceGenerator.generateResources(params); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
...rc/main/java/org/rodnalsol/openapi/extender/restassured/filter/OpenApiResponseFilter.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,96 @@ | ||
package org.rodnalsol.openapi.extender.restassured.filter; | ||
|
||
import io.restassured.filter.Filter; | ||
import io.restassured.filter.FilterContext; | ||
import io.restassured.response.Response; | ||
import io.restassured.specification.FilterableRequestSpecification; | ||
import io.restassured.specification.FilterableResponseSpecification; | ||
import java.io.IOException; | ||
|
||
import org.rodnalsol.openapi.extender.restassured.exception.OpenApiFilterException; | ||
import org.rodnansol.generator.ApiResponseExampleFileOutputResourceGenerator; | ||
import org.rodnansol.generator.ReportParams; | ||
|
||
/** | ||
* Rest assured filter class for generating OpenAPI response example. | ||
* | ||
* @author csaba.balogh | ||
* @since 0.3.0 | ||
*/ | ||
public class OpenApiResponseFilter implements Filter { | ||
|
||
/** | ||
* The OpenAPI response example generator. | ||
*/ | ||
private final ApiResponseExampleFileOutputResourceGenerator apiResponseExampleFileOutputResourceGenerator; | ||
|
||
/** | ||
* The operation's name. | ||
*/ | ||
private final String operation; | ||
|
||
/** | ||
* The name of the OpenAPI response example. | ||
*/ | ||
private final String name; | ||
|
||
/** | ||
* The description of the OpenAPI response example. | ||
*/ | ||
private final String description; | ||
|
||
/** | ||
* Creates a new {@link OpenApiResponseFilter} with the specified operation and name. | ||
* The description will be null and the output directory will be {@link ApiResponseExampleFileOutputResourceGenerator#DEFAULT_OUTPUT_DIRECTORY}. | ||
* | ||
* @param operation the operation's name. | ||
* @param name the name of the OpenAPI response example. | ||
*/ | ||
public OpenApiResponseFilter(String operation, String name) { | ||
this(operation, name, null, ApiResponseExampleFileOutputResourceGenerator.DEFAULT_OUTPUT_DIRECTORY); | ||
} | ||
|
||
/** | ||
* Creates a new {@link OpenApiResponseFilter} with the specified operation, name and description. | ||
* The output directory will be {@link ApiResponseExampleFileOutputResourceGenerator#DEFAULT_OUTPUT_DIRECTORY}. | ||
* | ||
* @param operation the operation's name. | ||
* @param name the name of the OpenAPI response example. | ||
* @param description the description of the OpenAPI response example. | ||
*/ | ||
public OpenApiResponseFilter(String operation, String name, String description) { | ||
this(operation, name, description, ApiResponseExampleFileOutputResourceGenerator.DEFAULT_OUTPUT_DIRECTORY); | ||
} | ||
|
||
/** | ||
* Creates a new {@link OpenApiResponseFilter} with the specified operation, name, description and output directory. | ||
* | ||
* @param operation the operation's name. | ||
* @param name the name of the OpenAPI response example. | ||
* @param description the description of the OpenAPI response example. | ||
* @param outputDirectory the output directory of the OpenAPI response example. | ||
*/ | ||
public OpenApiResponseFilter(String operation, String name, String description, String outputDirectory) { | ||
this.operation = operation; | ||
this.name = name; | ||
this.description = description; | ||
this.apiResponseExampleFileOutputResourceGenerator = new ApiResponseExampleFileOutputResourceGenerator(outputDirectory); | ||
} | ||
|
||
@Override | ||
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) { | ||
try { | ||
Response response = ctx.next(requestSpec, responseSpec); | ||
generateResources(response); | ||
return response; | ||
} catch (Exception e) { | ||
throw new OpenApiFilterException("Error during documenting response", e); | ||
} | ||
} | ||
|
||
private void generateResources(Response response) throws IOException { | ||
ReportParams params = new ReportParams(operation, name, response.getStatusCode(), response.getContentType(), response.asByteArray()); | ||
params.setDescription(description); | ||
apiResponseExampleFileOutputResourceGenerator.generateResources(params); | ||
} | ||
} |
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,84 @@ | ||
<?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>openapi-extender-parent</artifactId> | ||
<groupId>org.rodnansol</groupId> | ||
<version>999-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>quarkus-with-restassured</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
|
||
<quarkus.platform.version>2.13.0.Final</quarkus.platform.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus.platform</groupId> | ||
<artifactId>quarkus-bom</artifactId> | ||
<version>${quarkus.platform.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.rodnansol</groupId> | ||
<artifactId>openapi-extender-restassured</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-jackson</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-jaxb</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.dataformat</groupId> | ||
<artifactId>jackson-dataformat-xml</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-jaxb</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus.platform</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<version>${quarkus.platform.version}</version> | ||
<extensions>true</extensions> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
<goal>generate-code</goal> | ||
<goal>generate-code-tests</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Oops, something went wrong.