Skip to content

Commit

Permalink
[plugins/openapi-controllers] **breaking** useOptional for method p…
Browse files Browse the repository at this point in the history
…arameters defaults to false
  • Loading branch information
ivangsa committed Dec 1, 2024
1 parent 3051132 commit bfaf37c
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
<useSpringBoot3>true</useSpringBoot3>
<documentationProvider>none</documentationProvider>
<openApiNullable>false</openApiNullable>
<useOptional>true</useOptional>
<useOptional>false</useOptional>
<useTags>true</useTags>
<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
<useSpringBoot3>true</useSpringBoot3>
<documentationProvider>none</documentationProvider>
<openApiNullable>false</openApiNullable>
<useOptional>true</useOptional>
<useOptional>false</useOptional>
<useTags>true</useTags>
<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<useJakartaEe>true</useJakartaEe>
<documentationProvider>none</documentationProvider>
<openApiNullable>false</openApiNullable>
<useOptional>true</useOptional>
<useOptional>false</useOptional>
<useTags>true</useTags>
</configOptions>
</configuration>
Expand All @@ -158,7 +158,7 @@
<useJakartaEe>true</useJakartaEe>
<documentationProvider>none</documentationProvider>
<openApiNullable>false</openApiNullable>
<useOptional>true</useOptional>
<useOptional>false</useOptional>
<useTags>true</useTags>
</configOptions>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
<useSpringBoot3>true</useSpringBoot3>
<documentationProvider>none</documentationProvider>
<openApiNullable>false</openApiNullable>
<useOptional>true</useOptional>
<useOptional>false</useOptional>
<useTags>true</useTags>
<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
<useSpringBoot3>true</useSpringBoot3>
<documentationProvider>none</documentationProvider>
<openApiNullable>false</openApiNullable>
<useOptional>true</useOptional>
<useOptional>false</useOptional>
<useTags>true</useTags>
<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public class {{serviceName}}ApiController implements {{serviceName}}Api {
}
{{~/each}}

{{~#if useOptional~}}
protected Pageable pageOf(Optional<Integer> page, Optional<Integer> limit, Optional<List<String>> sort) {
Sort sortOrder = sort.map(s -> Sort.by(s.stream().map(sortParam -> {
String[] parts = sortParam.split(":");
Expand All @@ -110,4 +111,15 @@ public class {{serviceName}}ApiController implements {{serviceName}}Api {
}).toList())).orElse(Sort.unsorted());
return PageRequest.of(page.orElse(0), limit.orElse(10), sortOrder);
}
{{~else}}
protected Pageable pageOf(Integer page, Integer limit, List<String> sort) {
Sort sortOrder = sort != null ? Sort.by(sort.stream().map(sortParam -> {
String[] parts = sortParam.split(":");
String property = parts[0];
Sort.Direction direction = parts.length > 1 ? Sort.Direction.fromString(parts[1]) : Sort.Direction.ASC;
return new Sort.Order(direction, property);
}).toList()) : Sort.unsorted();
return PageRequest.of(page != null ? page : 0, limit != null ? limit : 10, sortOrder);
}
{{~/if}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
<configOptions>
<documentationProvider>none</documentationProvider>
<openApiNullable>false</openApiNullable>
<useOptional>true</useOptional>
<useOptional>false</useOptional>
<useTags>true</useTags>
<interfaceOnly>true</interfaceOnly>
<delegatePattern>false</delegatePattern>
Expand Down

0 comments on commit bfaf37c

Please sign in to comment.