Skip to content

Commit 3bb697f

Browse files
committed
reformat by google java formatter.
1 parent 7014032 commit 3bb697f

File tree

2 files changed

+65
-68
lines changed

2 files changed

+65
-68
lines changed

customer-service/src/main/java/com/example/demo/common/openapi/autoreg/AutoWrapperSchemaCustomizer.java

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,32 @@
1717
@Configuration
1818
public class AutoWrapperSchemaCustomizer {
1919

20-
private final Set<String> dataRefs;
20+
private final Set<String> dataRefs;
2121

22-
public AutoWrapperSchemaCustomizer(
23-
ListableBeanFactory beanFactory, ResponseTypeIntrospector introspector) {
24-
Set<String> refs = new LinkedHashSet<>();
25-
Map<String, RequestMappingHandlerMapping> mappings =
26-
beanFactory.getBeansOfType(RequestMappingHandlerMapping.class);
27-
mappings
28-
.values()
29-
.forEach(
30-
rmh ->
31-
rmh.getHandlerMethods()
32-
.values()
33-
.stream()
34-
.map(HandlerMethod::getMethod)
35-
.forEach(
36-
m ->
37-
introspector.extractDataRefName(m).ifPresent(refs::add)));
38-
this.dataRefs = Collections.unmodifiableSet(refs);
39-
}
22+
public AutoWrapperSchemaCustomizer(
23+
ListableBeanFactory beanFactory, ResponseTypeIntrospector introspector) {
24+
Set<String> refs = new LinkedHashSet<>();
25+
Map<String, RequestMappingHandlerMapping> mappings =
26+
beanFactory.getBeansOfType(RequestMappingHandlerMapping.class);
27+
mappings
28+
.values()
29+
.forEach(
30+
rmh ->
31+
rmh.getHandlerMethods().values().stream()
32+
.map(HandlerMethod::getMethod)
33+
.forEach(m -> introspector.extractDataRefName(m).ifPresent(refs::add)));
34+
this.dataRefs = Collections.unmodifiableSet(refs);
35+
}
4036

41-
@Bean
42-
public OpenApiCustomizer autoResponseWrappers() {
43-
return openApi -> dataRefs.forEach(
44-
ref -> {
45-
String name = OpenApiSchemas.SCHEMA_SERVICE_RESPONSE + ref;
46-
openApi
47-
.getComponents()
48-
.addSchemas(name, ApiResponseSchemaFactory.createComposedWrapper(ref));
49-
});
50-
}
51-
}
37+
@Bean
38+
public OpenApiCustomizer autoResponseWrappers() {
39+
return openApi ->
40+
dataRefs.forEach(
41+
ref -> {
42+
String name = OpenApiSchemas.SCHEMA_SERVICE_RESPONSE + ref;
43+
openApi
44+
.getComponents()
45+
.addSchemas(name, ApiResponseSchemaFactory.createComposedWrapper(ref));
46+
});
47+
}
48+
}

customer-service/src/main/java/com/example/demo/common/openapi/introspector/ResponseTypeIntrospector.java

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,52 +12,52 @@
1212
@Component
1313
public class ResponseTypeIntrospector {
1414

15-
private static final List<String> ASYNC_WRAPPERS = List.of(
16-
"reactor.core.publisher.Mono",
17-
"reactor.core.publisher.Flux",
18-
"java.util.concurrent.CompletionStage",
19-
"java.util.concurrent.Future",
20-
"org.springframework.web.context.request.async.DeferredResult",
21-
"org.springframework.web.context.request.async.WebAsyncTask"
22-
);
15+
private static final List<String> ASYNC_WRAPPERS =
16+
List.of(
17+
"reactor.core.publisher.Mono",
18+
"reactor.core.publisher.Flux",
19+
"java.util.concurrent.CompletionStage",
20+
"java.util.concurrent.Future",
21+
"org.springframework.web.context.request.async.DeferredResult",
22+
"org.springframework.web.context.request.async.WebAsyncTask");
2323

24-
public Optional<String> extractDataRefName(Method method) {
25-
if (method == null) return Optional.empty();
24+
public Optional<String> extractDataRefName(Method method) {
25+
if (method == null) return Optional.empty();
2626

27-
ResolvableType rt = ResolvableType.forMethodReturnType(method);
27+
ResolvableType rt = ResolvableType.forMethodReturnType(method);
2828

29-
rt = unwrapIf(rt);
29+
rt = unwrapIf(rt);
3030

31-
for (String wrapper : ASYNC_WRAPPERS) {
32-
rt = unwrapIf(rt, wrapper);
33-
}
34-
35-
Class<?> raw = rt.resolve();
36-
if (raw == null || !ServiceResponse.class.isAssignableFrom(raw)) {
37-
return Optional.empty();
38-
}
31+
for (String wrapper : ASYNC_WRAPPERS) {
32+
rt = unwrapIf(rt, wrapper);
33+
}
3934

40-
if (rt.getGenerics().length == 0) {
41-
return Optional.empty();
42-
}
35+
Class<?> raw = rt.resolve();
36+
if (raw == null || !ServiceResponse.class.isAssignableFrom(raw)) {
37+
return Optional.empty();
38+
}
4339

44-
Class<?> dataClass = rt.getGeneric(0).resolve();
45-
return Optional.ofNullable(dataClass).map(Class::getSimpleName);
40+
if (rt.getGenerics().length == 0) {
41+
return Optional.empty();
4642
}
4743

48-
private ResolvableType unwrapIf(ResolvableType type) {
49-
Class<?> raw = type.resolve();
50-
if (raw != null && ResponseEntity.class.isAssignableFrom(raw)) {
51-
return type.getGeneric(0);
52-
}
53-
return type;
44+
Class<?> dataClass = rt.getGeneric(0).resolve();
45+
return Optional.ofNullable(dataClass).map(Class::getSimpleName);
46+
}
47+
48+
private ResolvableType unwrapIf(ResolvableType type) {
49+
Class<?> raw = type.resolve();
50+
if (raw != null && ResponseEntity.class.isAssignableFrom(raw)) {
51+
return type.getGeneric(0);
5452
}
53+
return type;
54+
}
5555

56-
private ResolvableType unwrapIf(ResolvableType type, String wrapperClassName) {
57-
Class<?> raw = type.resolve();
58-
if (raw != null && Objects.equals(raw.getName(), wrapperClassName)) {
59-
return type.getGeneric(0);
60-
}
61-
return type;
56+
private ResolvableType unwrapIf(ResolvableType type, String wrapperClassName) {
57+
Class<?> raw = type.resolve();
58+
if (raw != null && Objects.equals(raw.getName(), wrapperClassName)) {
59+
return type.getGeneric(0);
6260
}
63-
}
61+
return type;
62+
}
63+
}

0 commit comments

Comments
 (0)