Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ enum ConfigName {
GENERATE_MODEL_FOR_USAGE_AS_BEAN_PARAM("generate-model-for-usage-as-bean-param"),
EQUALS_HASHCODE("equals-hashcode"),
USE_DYNAMIC_URL("use-dynamic-url"),
METHOD_PER_MEDIA_TYPE("method-per-media-type");
METHOD_PER_MEDIA_TYPE("method-per-media-type"),
NAME_MAPPINGS("name-mappings");

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,9 @@ protected void generate(OpenApiGeneratorOptions options) {
getValues(smallRyeConfig, openApiFilePath, CodegenConfig.ConfigName.METHOD_PER_MEDIA_TYPE, Boolean.class)
.ifPresent(generator::withMethodPerMediaType);

getValues(smallRyeConfig, openApiFilePath, ConfigName.NAME_MAPPINGS, String.class, String.class)
.ifPresent(generator::withNameMappings);

generator.generate(basePackage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ public OpenApiClientGeneratorWrapper withMethodPerMediaType(final Boolean method
return this;
}

public OpenApiClientGeneratorWrapper withNameMappings(final Map<String, String> nameMappings) {
nameMappings.forEach(configurator::addNameMapping);
return this;
}

/**
* Main entrypoint, or where to generate the files based on the given base package.
*
Expand Down
99 changes: 99 additions & 0 deletions client/integration-tests/name-mapping/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?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-integration-tests</artifactId>
<groupId>io.quarkiverse.openapi.generator</groupId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-openapi-generator-it-name-mapping</artifactId>
<name>Quarkus - OpenAPI Generator - Integration Tests - Client - Name Mapping</name>

<dependencies>
<dependency>
<groupId>io.quarkiverse.openapi.generator</groupId>
<artifactId>quarkus-openapi-generator</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<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>
</plugins>
</build>
<profiles>
<profile>
<id>native-image</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${native.surefire.skip}</skipTests>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>
${project.build.directory}/${project.build.finalName}-runner
</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager
</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"openapi": "3.0.2",
"info": {
"title": "Animals - OpenAPI 3.0",
"version": "1.0.5"
},
"servers": [
{
"url": "/api/v3"
}
],
"tags": [
{
"name": "primate",
"description": "Everything about Primates"
}
],
"paths": {
"/primate/{id}": {
"get": {
"tags": [
"primate"
],
"summary": "Find primate by ID",
"description": "Returns a single primate",
"operationId": "getPrimateById",
"parameters": [
{
"name": "id",
"in": "path",
"description": "ID of primate to return",
"required": true,
"schema": {
"type": "integer",
"format": "int64"
}
}
],
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Primate"
}
}
}
},
"400": {
"description": "Invalid ID supplied"
},
"404": {
"description": "Primate not found"
}
}
}
}
},
"components": {
"schemas": {
"Animal":{
"type": "object",
"properties": {
"born": {
"type": "string",
"description": "Dated Base extension.",
"format": "date-time"
},
"deceased": {
"type": "string",
"description": "Dated Base extension.",
"format": "date-time"
}
},
"xml": {
"name": "animal"
}
},
"Mammal": {
"type": "object",
"allOf": [{
"$ref": "#/components/schemas/Animal"
}],
"properties": {
"gender": {
"type": "string",
"enum": [
"female",
"male"
]
}
},
"xml": {
"name": "mammal"
}
},
"Primate": {
"required": [
"name"
],
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/Mammal"
}
],
"properties": {
"id": {
"type": "integer",
"format": "int64",
"example": 10
},
"name": {
"type": "string",
"example": "jane doe"
}
},
"xml": {
"name": "primate"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
quarkus.openapi-generator.codegen.spec.name_mappings_testing_yml.base-package=org.acme.openapi.animals
quarkus.openapi-generator.codegen.spec.name_mappings_testing_yml.name-mappings.born=bornDate
quarkus.openapi-generator.codegen.spec.name_mappings_testing_yml.name-mappings.deceased=deathDate

quarkus.keycloak.devservices.enabled=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.quarkiverse.openapi.generator.it.name.mapping;

import static org.assertj.core.api.Assertions.assertThat;

import jakarta.inject.Inject;

import org.acme.openapi.animals.api.PrimateApi;
import org.acme.openapi.animals.model.Primate;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.junit.jupiter.api.Test;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
@QuarkusTestResource(WiremockTestResource.class)
class QuarkusNameMappingTest {

@RestClient
@Inject
PrimateApi api;

@Test
void primateHasAllFields() {
Primate primate = api.getPrimateById(1L);

assertThat(primate).isNotNull();
assertThat(primate.getId()).isEqualTo(1L);
assertThat(primate.getName()).isEqualTo("Mary Jane");
assertThat(primate.getBornDate()).isEqualTo("1970-01-01T01:01:01.001Z");
assertThat(primate.getDeathDate()).isEqualTo("2020-01-01T01:01:01.001Z");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.quarkiverse.openapi.generator.it.name.mapping;

import static com.github.tomakehurst.wiremock.client.WireMock.*;

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Map;

import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;

import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;

public class WiremockTestResource implements QuarkusTestResourceLifecycleManager {

private WireMockServer wireMockServer;

@Override
public Map<String, String> start() {
wireMockServer = new WireMockServer(WireMockConfiguration.wireMockConfig().dynamicPort());
wireMockServer.start();

wireMockServer.stubFor(get(urlMatching("/primate/\\d+"))
.willReturn(okJson(resourceToString("/primate.json", StandardCharsets.UTF_8))));
return Collections.singletonMap("org.acme.openapi.animals.api.PrimateApi/mp-rest/url",
wireMockServer.baseUrl());
}

private String resourceToString(String resource, Charset charset) {
try (InputStream in = WiremockTestResource.class.getResourceAsStream(resource)) {
if (in == null) {
throw new IOException("Could not open resource " + resource);
}
return new String(in.readAllBytes(), charset);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

@Override
public void stop() {
if (null != wireMockServer) {
wireMockServer.stop();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"id": 1,
"born": "1970-01-01T01:01:01.001Z",
"deceased": "2020-01-01T01:01:01.001Z",
"name": "Mary Jane",
"gender": "female"
}
1 change: 1 addition & 0 deletions client/integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<module>override-credential-provider</module>
<module>jsonproperty-getter-and-setter</module>
<module>suppress-warnings</module>
<module>name-mapping</module>
</modules>
<dependencyManagement>
<dependencies>
Expand Down
5 changes: 5 additions & 0 deletions docs/modules/ROOT/pages/client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ include::./includes/use-gav-for-spec.adoc[leveloffset=+1, opts=optional]

include::./includes/generate-model-for-usage-as-bean-param.adoc[leveloffset=+1, opts=optional]

[[name-mappings]]
== Change generated property name

include::./includes/name-mappings.adoc[leveloffset=+1, opts=optional]

== Known Limitations

=== Supported Arguments
Expand Down
Loading
Loading