Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wiremock module #648

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
* xref:client.adoc[Client Generator]
* xref:server.adoc[Server Generator]
* xref:server.adoc[Server Generator]
* xref:wiremock.adoc[Wiremock Generator]
63 changes: 63 additions & 0 deletions docs/modules/ROOT/pages/includes/wiremock-features.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
The OpenAPI Generator Wiremock extensions maps OpenAPI specification and transform it into a https://wiremock.org/docs/stubbing/#bulk-importing-stubs[Bulk Importing Stubs] JSON file.

== Request Matching

To build the Wiremock https://wiremock.org/docs/request-matching/[Request Matching], this extension looks just to https://swagger.io/docs/specification/paths-and-operations/[Paths and Operations] OpenAPI fields.

The OpenAPI path is converted to https://swagger.io/docs/specification/paths-and-operations/[path template] following the https://www.rfc-editor.org/rfc/rfc6570[RFC 6570] standard:
[source,yaml]
----
paths:
/users/{userId}/cars/{carId}:
----

Will be converted to:

[source,json]
----
{
"mappings": [
{
"request": {
"urlPathTemplate": "/users/{userId}/cars/{cardId}"
}
}
]
}
----

== Responses

This extension will get the first Response status code Operation. For example, if you have the following OpenAPI Response:

[source,yaml]
----
responses:
"500":
description: "Internal Server Error"
"200":
description: "Ok"
----

The extension will generate the following Wiremock Response templating:

[source,json]
----
{
"response": {
"status": 200
}
}
----

NOTE: If your Response entry does not contain `content` the Wiremock Stub `$.response.body` will be ignored.

== Media type

IMPORTANT: This extension only supports `"application/json"` media type.

== Schema Type

For the first release, we chose to looks for the https://swagger.io/docs/specification/data-models/[Schema] `type` and supports only https://swagger.io/docs/specification/data-models/data-types/[Data Types] `object`, `string` and `integer` types.

IMPORTANT: The root schema must have the type `object`.
36 changes: 36 additions & 0 deletions docs/modules/ROOT/pages/includes/wiremock-getting-started.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
The OpenAPI Generator Wiremock extensions maps OpenAPI specification and transform it into a https://wiremock.org/docs/stubbing/#bulk-importing-stubs[Bulk Importing Stubs] JSON file.

Add the following dependency to your project's `pom.xml` file:

[source,xml]
----
<dependency>
<groupId>io.quarkiverse.openapi.generator</groupId>
<artifactId>quarkus-openapi-generator-wiremock</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
----

You will also need to add or update the `quarkus-maven-plugin` configuration with the following:

WARNING: You probably already have this configuration if you created your application with https://code.quarkus.io/[Code Quarkus]. That said, double-check your configuration not to add another `plugin` entry.

[source,xml]
----
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
</goals>
</execution>
</executions>
</plugin>
----

Now, create the directory `openapi` under your `src/main` path and add the OpenAPI spec files there. We support JSON, YAML and YML extensions.
20 changes: 20 additions & 0 deletions docs/modules/ROOT/pages/wiremock.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
= Quarkus - OpenAPI Generator - Wiremock
:extension-status: experimental


WARNING: This is the instructions for the latest SNAPSHOT version (main branch). Please, see the https://docs.quarkiverse.io/quarkus-openapi-generator/dev/index.html[latest **released** documentation] if you are looking for instructions.
Quarkus' extension for generation of server Stubs based on OpenAPI specification files.

This extension is for Wiremock Stubs generation for Dev Services only.

**Want to contribute? Great!** We try to make it easy, and all contributions, even the smaller ones, are more than welcome. This includes bug reports, fixes, documentation, examples... But first, read https://github.com/quarkiverse/quarkus-openapi-generator/blob/main/CONTRIBUTING.md[this page].

[[getting-started]]
== Getting Started

include::./includes/wiremock-getting-started.adoc[leveloffset=+1, opts=optional]

[[features]]
== Wiremock Extension Features

include::./includes/wiremock-features.adoc[leveloffset=+1, opts=optional]
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<modules>
<module>client</module>
<module>server</module>
<module>wiremock</module>
<module>docs</module>
</modules>
<scm>
Expand All @@ -33,6 +34,7 @@
<version.org.assertj>3.25.3</version.org.assertj>
<version.org.eclipse.microprofile.fault-tolerance>4.0.2</version.org.eclipse.microprofile.fault-tolerance>
<version.com.github.tomakehurst>2.35.2</version.com.github.tomakehurst>
<version.io.swagger.parser>2.1.20</version.io.swagger.parser>
</properties>
<dependencyManagement>
<dependencies>
Expand Down
58 changes: 58 additions & 0 deletions wiremock/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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>quarkus-openapi-generator-wiremock-parent</artifactId>
<groupId>io.quarkiverse.openapi.generator</groupId>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-openapi-generator-wiremock-deployment</artifactId>
<name>Quarkus - OpenAPI Generator - Wiremock - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-qute-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.openapi.generator</groupId>
<artifactId>quarkus-openapi-generator-wiremock</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser</artifactId>
<version>${version.io.swagger.parser}</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.quarkiverse.openapi.wiremock.generator.deployment;

import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;

@ConfigRoot(name = CodegenConfig.OPENAPI_WIREMOCK_PREFIX, phase = ConfigPhase.BUILD_TIME)
public class CodegenConfig {
static final String OPENAPI_WIREMOCK_PREFIX = "quarkus.openapi.generator.wiremock";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.quarkiverse.openapi.wiremock.generator.deployment.codegen;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.quarkiverse.openapi.wiremock.generator.deployment.wrapper.OpenApiWiremockGeneratorWrapper;
import io.quarkus.bootstrap.prebuild.CodeGenException;
import io.quarkus.deployment.CodeGenContext;
import io.quarkus.deployment.CodeGenProvider;

/**
* OpenAPI Wiremock Stubbing Generator
*/
public class OpenApiWiremockCodegen implements CodeGenProvider {

private static final Logger LOGGER = LoggerFactory.getLogger(OpenApiWiremockCodegen.class);
public static final String WIREMOCK = "wiremock";
public static final String INPUT_DIR = "openapi";

@Override
public String providerId() {
return WIREMOCK;
}

@Override
public String inputDirectory() {
return INPUT_DIR;
}

@Override
public boolean trigger(CodeGenContext context) throws CodeGenException {
LOGGER.info("Generating Wiremock Stubbing");
OpenApiWiremockGeneratorWrapper wrapper = new OpenApiWiremockGeneratorWrapper(context.inputDir(), context.outDir());
try {
wrapper.generate();
LOGGER.info("Wiremock Stubbing generated successfully!");
return true;
} catch (CodeGenException | IOException e) {
LOGGER.error("Wiremock Stubbing was not generated!", e);
throw new CodeGenException(e);
}
}

}
Loading