-
-
Notifications
You must be signed in to change notification settings - Fork 467
/
ConverterUtils.java
160 lines (142 loc) · 4.28 KB
/
ConverterUtils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
*
* *
* * *
* * * *
* * * * * Copyright 2019-2022 the original author or authors.
* * * * *
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
* * * * * you may not use this file except in compliance with the License.
* * * * * You may obtain a copy of the License at
* * * * *
* * * * * https://www.apache.org/licenses/LICENSE-2.0
* * * * *
* * * * * Unless required by applicable law or agreed to in writing, software
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * * * * See the License for the specific language governing permissions and
* * * * * limitations under the License.
* * * *
* * *
* *
*
*/
package org.springdoc.core.converters;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletionStage;
import org.springframework.http.HttpEntity;
import org.springframework.http.ResponseEntity;
/**
* The type Converter utils.
* @author bnasslahsen
*/
public class ConverterUtils {
/**
* The constant RESULT_WRAPPERS_TO_IGNORE.
*/
private static final List<Class<?>> RESULT_WRAPPERS_TO_IGNORE = Collections.synchronizedList(new ArrayList<>());
/**
* The constant RESPONSE_TYPES_TO_IGNORE.
*/
private static final List<Class<?>> RESPONSE_TYPES_TO_IGNORE = Collections.synchronizedList(new ArrayList<>());
/**
* The constant FLUX_WRAPPERS_TO_IGNORE.
*/
private static final List<Class<?>> FLUX_WRAPPERS_TO_IGNORE = Collections.synchronizedList(new ArrayList<>());
static {
RESULT_WRAPPERS_TO_IGNORE.add(Callable.class);
RESULT_WRAPPERS_TO_IGNORE.add(ResponseEntity.class);
RESULT_WRAPPERS_TO_IGNORE.add(HttpEntity.class);
RESULT_WRAPPERS_TO_IGNORE.add(CompletionStage.class);
}
/**
* Instantiates a new Converter utils.
*/
private ConverterUtils() {
}
/**
* Add response wrapper to ignore.
*
* @param cls the cls
*/
public static void addResponseWrapperToIgnore(Class<?> cls) {
RESULT_WRAPPERS_TO_IGNORE.add(cls);
}
/**
* Add response type to ignore.
*
* @param cls the cls
*/
public static void addResponseTypeToIgnore(Class<?> cls) {
RESPONSE_TYPES_TO_IGNORE.add(cls);
}
/**
* Is response type wrapper boolean.
*
* @param rawClass the raw class
* @return the boolean
*/
public static boolean isResponseTypeWrapper(Class<?> rawClass) {
return RESULT_WRAPPERS_TO_IGNORE.stream().anyMatch(clazz -> clazz.isAssignableFrom(rawClass));
}
/**
* Is response type to ignore boolean.
*
* @param rawClass the raw class
* @return the boolean
*/
public static boolean isResponseTypeToIgnore(Class<?> rawClass) {
return RESPONSE_TYPES_TO_IGNORE.stream().anyMatch(clazz -> clazz.isAssignableFrom(rawClass));
}
/**
* Remove response wrapper to ignore.
*
* @param classes the classes
*/
public static void removeResponseWrapperToIgnore(Class<?> classes) {
List classesToIgnore = Arrays.asList(classes);
if (RESULT_WRAPPERS_TO_IGNORE.containsAll(classesToIgnore))
RESULT_WRAPPERS_TO_IGNORE.removeAll(Arrays.asList(classes));
}
/**
* Remove response type to ignore.
*
* @param classes the classes
*/
public static void removeResponseTypeToIgnore(Class<?> classes) {
List classesToIgnore = Arrays.asList(classes);
if (RESPONSE_TYPES_TO_IGNORE.containsAll(classesToIgnore))
RESPONSE_TYPES_TO_IGNORE.removeAll(Arrays.asList(classes));
}
/**
* Is flux type wrapper boolean.
*
* @param rawClass the raw class
* @return the boolean
*/
public static boolean isFluxTypeWrapper(Class<?> rawClass) {
return FLUX_WRAPPERS_TO_IGNORE.stream().anyMatch(clazz -> clazz.isAssignableFrom(rawClass));
}
/**
* Remove flux wrapper to ignore.
*
* @param classes the classes
*/
public static void removeFluxWrapperToIgnore(Class<?> classes) {
List classesToIgnore = Arrays.asList(classes);
if (FLUX_WRAPPERS_TO_IGNORE.containsAll(classesToIgnore))
FLUX_WRAPPERS_TO_IGNORE.removeAll(Arrays.asList(classes));
}
/**
* Add flux wrapper to ignore.
*
* @param cls the cls
*/
public static void addFluxWrapperToIgnore(Class<?> cls) {
FLUX_WRAPPERS_TO_IGNORE.add(cls);
}
}