Skip to content
Merged
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
11 changes: 10 additions & 1 deletion customer-service-client/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# existing patterns
**/.github/**
**/gradle/**
**/.gradle/**
Expand All @@ -15,4 +16,12 @@
**/git_push.sh
**/README.md
**/.openapi-generator/**
!src/gen/java/main/**
!src/gen/java/**

# --- Custom additions for generated DTO cleanup ---
# ignore these generated models regardless of location
**/src/gen/java/**/generated/dto/Page*.java
**/src/gen/java/**/generated/dto/ServiceResponse.java
**/src/gen/java/**/generated/dto/ServiceResponseVoid.java
**/src/gen/java/**/generated/dto/Meta.java
**/src/gen/java/**/generated/dto/Sort.java
22 changes: 19 additions & 3 deletions customer-service-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ public class CustomerClientAdapterImpl implements CustomerClientAdapter {
@Override
public ServiceClientResponse<Page<CustomerDto>> getCustomers(
String name, String email, Integer page, Integer size,
SortField sortBy, SortDirection direction) {
ClientSortField sortBy, ClientSortDirection direction) {
return api.getCustomers(
name, email, page, size,
sortBy != null ? sortBy.value() : SortField.CUSTOMER_ID.value(),
direction != null ? direction.value() : SortDirection.ASC.value());
sortBy != null ? sortBy.value() : ClientSortField.CUSTOMER_ID.value(),
direction != null ? direction.value() : ClientSortDirection.ASC.value());
}
}
```
Expand Down Expand Up @@ -252,6 +252,22 @@ try {

---

### 🧹 Ignoring Redundant Generated DTOs

The following patterns in [`.openapi-generator-ignore`](.openapi-generator-ignore) prevent redundant DTOs from being regenerated.
These classes already exist in the shared `common` package and are excluded from code generation.

```bash
# --- Custom additions for generated DTO cleanup ---
**/src/gen/java/**/generated/dto/Page*.java
**/src/gen/java/**/generated/dto/ServiceResponse.java
**/src/gen/java/**/generated/dto/ServiceResponseVoid.java
**/src/gen/java/**/generated/dto/Meta.java
**/src/gen/java/**/generated/dto/Sort.java
```

---

## 📚 Notes

* **Toolchain:** Java 21, Spring Boot 3.4.10, OpenAPI Generator 7.16.0
Expand Down
31 changes: 29 additions & 2 deletions customer-service-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.bsayli</groupId>
<artifactId>customer-service-client</artifactId>
<version>0.7.0</version>
<version>0.7.2</version>
<name>customer-service-client</name>
<description>Generated client (RestClient) using generics-aware OpenAPI templates</description>
<packaging>jar</packaging>
Expand All @@ -20,7 +20,7 @@
<openapi.generator.version>7.16.0</openapi.generator.version>

<jakarta.validation.version>3.1.1</jakarta.validation.version>
<jakarta.annotation-api.version>3.0.0</jakarta.annotation-api.version>
<jakarta.annotation-api.version>${spotless-maven-plugin.version}</jakarta.annotation-api.version>
<mockwebserver.version>5.1.0</mockwebserver.version>
<httpclient5.version>5.5</httpclient5.version>
<junit-jupiter.version>5.13.4</junit-jupiter.version>
Expand All @@ -32,9 +32,11 @@
<build.helper.plugin.version>3.6.0</build.helper.plugin.version>
<maven.resources.plugin.version>3.3.1</maven.resources.plugin.version>
<maven.dependency.plugin.version>3.8.1</maven.dependency.plugin.version>
<spotless-maven-plugin.version>3.0.0</spotless-maven-plugin.version>

<openapi.templates.upstream>${project.build.directory}/upstream-templates</openapi.templates.upstream>
<openapi.templates.effective>${project.build.directory}/effective-templates</openapi.templates.effective>

</properties>

<dependencies>
Expand Down Expand Up @@ -217,6 +219,7 @@
<additionalProperty>commonPackage=io.github.bsayli.openapi.client.common
</additionalProperty>
</additionalProperties>
<ignoreFileOverride>${project.basedir}/.openapi-generator-ignore</ignoreFileOverride>
</configuration>
</execution>
</executions>
Expand All @@ -241,7 +244,31 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless-maven-plugin.version}</version>

<configuration>
<java>
<includes>
<include>target/generated-sources/openapi/src/gen/java/**/*.java</include>
</includes>
<removeUnusedImports>
<engine>cleanthat-javaparser-unnecessaryimport</engine>
</removeUnusedImports>
</java>
</configuration>
<executions>
<execution>
<id>spotless-apply-generated</id>
<phase>process-sources</phase>
<goals>
<goal>apply</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import io.github.bsayli.openapi.client.common.Page;
import io.github.bsayli.openapi.client.common.ServiceClientResponse;
import io.github.bsayli.openapi.client.common.sort.SortDirection;
import io.github.bsayli.openapi.client.common.sort.SortField;
import io.github.bsayli.openapi.client.common.sort.ClientSortDirection;
import io.github.bsayli.openapi.client.common.sort.ClientSortField;
import io.github.bsayli.openapi.client.generated.dto.CustomerCreateRequest;
import io.github.bsayli.openapi.client.generated.dto.CustomerDeleteResponse;
import io.github.bsayli.openapi.client.generated.dto.CustomerDto;
Expand All @@ -22,8 +22,8 @@ ServiceClientResponse<Page<CustomerDto>> getCustomers(
String email,
Integer page,
Integer size,
SortField sortBy,
SortDirection direction);
ClientSortField sortBy,
ClientSortDirection direction);

ServiceClientResponse<CustomerDto> updateCustomer(
Integer customerId, CustomerUpdateRequest request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

@Configuration
public class CustomerApiClientConfig {


@Bean
RestClientCustomizer problemDetailStatusHandler(ObjectMapper om) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import io.github.bsayli.openapi.client.adapter.CustomerClientAdapter;
import io.github.bsayli.openapi.client.common.Page;
import io.github.bsayli.openapi.client.common.ServiceClientResponse;
import io.github.bsayli.openapi.client.common.sort.SortDirection;
import io.github.bsayli.openapi.client.common.sort.SortField;
import io.github.bsayli.openapi.client.common.sort.ClientSortDirection;
import io.github.bsayli.openapi.client.common.sort.ClientSortField;
import io.github.bsayli.openapi.client.generated.api.CustomerControllerApi;
import io.github.bsayli.openapi.client.generated.dto.*;
import org.springframework.stereotype.Service;
Expand All @@ -30,7 +30,7 @@ public ServiceClientResponse<CustomerDto> getCustomer(Integer customerId) {

@Override
public ServiceClientResponse<Page<CustomerDto>> getCustomers() {
return getCustomers(null, null, 0, 5, SortField.CUSTOMER_ID, SortDirection.ASC);
return getCustomers(null, null, 0, 5, ClientSortField.CUSTOMER_ID, ClientSortDirection.ASC);
}

@Override
Expand All @@ -39,16 +39,16 @@ public ServiceClientResponse<Page<CustomerDto>> getCustomers(
String email,
Integer page,
Integer size,
SortField sortBy,
SortDirection direction) {
ClientSortField sortBy,
ClientSortDirection direction) {

return api.getCustomers(
name,
email,
page,
size,
sortBy != null ? sortBy.value() : SortField.CUSTOMER_ID.value(),
direction != null ? direction.value() : SortDirection.ASC.value());
sortBy != null ? sortBy.value() : ClientSortField.CUSTOMER_ID.value(),
direction != null ? direction.value() : ClientSortDirection.ASC.value());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private ProblemDetailSupport() {}
public static ProblemDetail extract(ObjectMapper om, ClientHttpResponse response) {
ProblemDetail pd;
MediaType contentType =
Optional.ofNullable(response.getHeaders().getContentType()).orElse(MediaType.ALL);
Optional.ofNullable(response.getHeaders().getContentType()).orElse(MediaType.ALL);
HttpStatusCode status;

try {
Expand All @@ -39,10 +39,10 @@ public static ProblemDetail extract(ObjectMapper om, ClientHttpResponse response
}
} catch (IOException e) {
log.warn(
"Unable to deserialize ProblemDetail (status={}, contentType={}); using generic fallback",
status,
contentType,
e);
"Unable to deserialize ProblemDetail (status={}, contentType={}); using generic fallback",
status,
contentType,
e);
pd = fallback(status, "Unparseable problem response");
} catch (Exception e) {
log.warn("Unexpected error while parsing ProblemDetail", e);
Expand All @@ -59,4 +59,4 @@ private static ProblemDetail fallback(HttpStatusCode status, String detail) {
pd.setDetail(detail);
return pd;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.github.bsayli.openapi.client.common.sort;

public record ClientSort(SortField field, SortDirection direction) {
public record ClientSort(ClientSortField field, ClientSortDirection direction) {

public ClientSort {
if (field == null) {
field = SortField.CUSTOMER_ID;
field = ClientSortField.CUSTOMER_ID;
}
if (direction == null) {
direction = SortDirection.ASC;
direction = ClientSortDirection.ASC;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.github.bsayli.openapi.client.common.sort;

public enum SortDirection {
public enum ClientSortDirection {
ASC("asc"),
DESC("desc");

private final String value;

SortDirection(String value) {
ClientSortDirection(String value) {
this.value = value;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.github.bsayli.openapi.client.common.sort;

public enum SortField {
public enum ClientSortField {
CUSTOMER_ID("customerId"),
NAME("name"),
EMAIL("email");

private final String value;

SortField(String value) {
ClientSortField(String value) {
this.value = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.1.0
info:
title: Customer Service API
description: Customer Service API with type-safe generic responses using OpenAPI
version: 0.7.0
version: 0.7.2
servers:
- url: http://localhost:8084/customer-service
description: Local service URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@
import io.github.bsayli.openapi.client.common.ClientMeta;
import io.github.bsayli.openapi.client.common.Page;
import io.github.bsayli.openapi.client.common.ServiceClientResponse;
import io.github.bsayli.openapi.client.common.sort.SortDirection;
import io.github.bsayli.openapi.client.common.sort.SortField;
import io.github.bsayli.openapi.client.common.sort.ClientSortDirection;
import io.github.bsayli.openapi.client.common.sort.ClientSortField;
import io.github.bsayli.openapi.client.generated.api.CustomerControllerApi;
import io.github.bsayli.openapi.client.generated.dto.CustomerCreateRequest;
import io.github.bsayli.openapi.client.generated.dto.CustomerDeleteResponse;
import io.github.bsayli.openapi.client.generated.dto.CustomerDto;
import io.github.bsayli.openapi.client.generated.dto.CustomerUpdateRequest;
import io.github.bsayli.openapi.client.generated.dto.ServiceResponseCustomerDeleteResponse;
import io.github.bsayli.openapi.client.generated.dto.ServiceResponseCustomerDto;
import io.github.bsayli.openapi.client.generated.dto.ServiceResponsePageCustomerDto;
import io.github.bsayli.openapi.client.generated.dto.*;
import java.time.OffsetDateTime;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
Expand Down Expand Up @@ -106,7 +100,7 @@ void getCustomers_delegates_and_returnsPage() {
when(api.getCustomers(any(), any(), any(), any(), any(), any())).thenReturn(wrapper);

ServiceClientResponse<Page<CustomerDto>> res =
adapter.getCustomers(null, null, 0, 5, SortField.CUSTOMER_ID, SortDirection.ASC);
adapter.getCustomers(null, null, 0, 5, ClientSortField.CUSTOMER_ID, ClientSortDirection.ASC);

assertNotNull(res);
assertNotNull(res.getData());
Expand Down
2 changes: 1 addition & 1 deletion customer-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>io.github.bsayli</groupId>
<artifactId>customer-service</artifactId>
<version>0.7.0</version>
<version>0.7.2</version>
<name>customer-service</name>
<description>Spring Boot 3.4 + Springdoc (OpenAPI) for generics-aware client generation</description>

Expand Down
6 changes: 5 additions & 1 deletion docs/_includes/head_custom.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<script async src="https://www.googletagmanager.com/gtag/js?id=G-4NH21XZLBN"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}

function gtag() {
dataLayer.push(arguments);
}

gtag('js', new Date());
gtag('config', 'G-4NH21XZLBN');
</script>
Loading