File tree 7 files changed +119
-35
lines changed
springdoc-openapi-common/src/main/java/org/springdoc/core
springdoc-openapi-kotlin/src
main/java/org/springdoc/kotlin
kotlin/test/org/springdoc/api/app5
springdoc-openapi-webflux-core/src/main/java/org/springdoc/webflux/core/converters
7 files changed +119
-35
lines changed Original file line number Diff line number Diff line change @@ -103,5 +103,15 @@ public SpringDocUtils removeAnnotationsToIgnore(Class<?>... classes) {
103
103
GenericParameterBuilder .removeAnnotationsToIgnore (classes );
104
104
return this ;
105
105
}
106
+
107
+ public SpringDocUtils addFluxWrapperToIgnore (Class <?> cls ) {
108
+ ConverterUtils .addFluxWrapperToIgnore (cls );
109
+ return this ;
110
+ }
111
+
112
+ public SpringDocUtils removeFluxWrapperToIgnore (Class <?> cls ) {
113
+ ConverterUtils .removeFluxWrapperToIgnore (cls );
114
+ return this ;
115
+ }
106
116
}
107
117
Original file line number Diff line number Diff line change @@ -33,6 +33,8 @@ public class ConverterUtils {
33
33
34
34
private static final List <Class <?>> RESPONSE_TYPES_TO_IGNORE = new ArrayList <>();
35
35
36
+ private static final List <Class <?>> FLUX_WRAPPERS_TO_IGNORE = new ArrayList <>();
37
+
36
38
static {
37
39
RESULT_WRAPPERS_TO_IGNORE .add (Callable .class );
38
40
RESULT_WRAPPERS_TO_IGNORE .add (ResponseEntity .class );
@@ -70,4 +72,18 @@ public static void removeResponseTypeToIgnore(Class<?> classes) {
70
72
if (RESPONSE_TYPES_TO_IGNORE .containsAll (classesToIgnore ))
71
73
RESPONSE_TYPES_TO_IGNORE .removeAll (Arrays .asList (classes ));
72
74
}
75
+
76
+ public static boolean isFluxTypeWrapper (Class <?> rawClass ) {
77
+ return FLUX_WRAPPERS_TO_IGNORE .stream ().anyMatch (clazz -> clazz .isAssignableFrom (rawClass ));
78
+ }
79
+
80
+ public static void removeFluxWrapperToIgnore (Class <?> classes ) {
81
+ List classesToIgnore = Arrays .asList (classes );
82
+ if (FLUX_WRAPPERS_TO_IGNORE .containsAll (classesToIgnore ))
83
+ FLUX_WRAPPERS_TO_IGNORE .removeAll (Arrays .asList (classes ));
84
+ }
85
+
86
+ public static void addFluxWrapperToIgnore (Class <?> cls ) {
87
+ FLUX_WRAPPERS_TO_IGNORE .add (cls );
88
+ }
73
89
}
Original file line number Diff line number Diff line change 22
22
import io .swagger .v3 .core .util .Json ;
23
23
import kotlin .Deprecated ;
24
24
import kotlin .coroutines .Continuation ;
25
+ import kotlinx .coroutines .flow .Flow ;
25
26
26
27
import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
27
28
import org .springframework .context .annotation .Bean ;
@@ -37,7 +38,8 @@ public class SpringDocKotlinConfiguration {
37
38
38
39
static {
39
40
getConfig ().addRequestWrapperToIgnore (Continuation .class )
40
- .addDeprecatedType (Deprecated .class );
41
+ .addDeprecatedType (Deprecated .class )
42
+ .addFluxWrapperToIgnore (Flow .class );
41
43
Json .mapper ().registerModule (new KotlinModule ());
42
44
}
43
45
Original file line number Diff line number Diff line change
1
+ /*
2
+ *
3
+ * * Copyright 2019-2020 the original author or authors.
4
+ * *
5
+ * * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * * you may not use this file except in compliance with the License.
7
+ * * You may obtain a copy of the License at
8
+ * *
9
+ * * https://www.apache.org/licenses/LICENSE-2.0
10
+ * *
11
+ * * Unless required by applicable law or agreed to in writing, software
12
+ * * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * * See the License for the specific language governing permissions and
15
+ * * limitations under the License.
16
+ *
17
+ */
18
+
19
+ package test.org.springdoc.api.app5
20
+
21
+ import kotlinx.coroutines.delay
22
+ import kotlinx.coroutines.flow.Flow
23
+ import kotlinx.coroutines.flow.flow
24
+ import org.springframework.web.bind.annotation.GetMapping
25
+ import org.springframework.web.bind.annotation.RequestMapping
26
+ import org.springframework.web.bind.annotation.RestController
27
+
28
+
29
+ data class Person (
30
+ val name : String ,
31
+ val nickname : String?
32
+ )
33
+
34
+ @RestController
35
+ @RequestMapping(" /test" )
36
+ class HelloController {
37
+
38
+ @GetMapping(" /" )
39
+ fun foo (): Flow <Int > = flow { // flow builder
40
+ for (i in 1 .. 3 ) {
41
+ delay(100 ) // pretend we are doing something useful here
42
+ emit(i) // emit next value
43
+ }
44
+ }
45
+
46
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ *
3
+ * * Copyright 2019-2020 the original author or authors.
4
+ * *
5
+ * * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * * you may not use this file except in compliance with the License.
7
+ * * You may obtain a copy of the License at
8
+ * *
9
+ * * https://www.apache.org/licenses/LICENSE-2.0
10
+ * *
11
+ * * Unless required by applicable law or agreed to in writing, software
12
+ * * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * * See the License for the specific language governing permissions and
15
+ * * limitations under the License.
16
+ *
17
+ */
18
+
19
+ package test.org.springdoc.api.app5
20
+
21
+ import org.springframework.boot.autoconfigure.SpringBootApplication
22
+ import org.springframework.context.annotation.ComponentScan
23
+ import test.org.springdoc.api.AbstractKotlinSpringDocTest
24
+
25
+ @ComponentScan(basePackages = [" org.springdoc" , " test.org.springdoc.api.app5" ])
26
+ class SpringDocApp5Test : AbstractKotlinSpringDocTest () {
27
+
28
+ @SpringBootApplication
29
+ open class DemoApplication
30
+
31
+ }
Original file line number Diff line number Diff line change 11
11
}
12
12
],
13
13
"paths" : {
14
- "/test" : {
14
+ "/test/ " : {
15
15
"get" : {
16
16
"tags" : [
17
17
" hello-controller"
18
18
],
19
- "operationId" : " index" ,
20
- "parameters" : [
21
- {
22
- "name" : " s" ,
23
- "in" : " query" ,
24
- "required" : true ,
25
- "schema" : {
26
- "$ref" : " #/components/schemas/Person"
27
- }
28
- }
29
- ],
19
+ "operationId" : " foo" ,
30
20
"responses" : {
31
21
"200" : {
32
22
"description" : " default response" ,
33
23
"content" : {
34
24
"*/*" : {
35
25
"schema" : {
36
- "$ref" : " #/components/schemas/Person"
26
+ "type" : " array" ,
27
+ "items" : {
28
+ "type" : " integer" ,
29
+ "format" : " int32"
30
+ }
37
31
}
38
32
}
39
33
}
42
36
}
43
37
}
44
38
},
45
- "components" : {
46
- "schemas" : {
47
- "Person" : {
48
- "required" : [
49
- " name"
50
- ],
51
- "type" : " object" ,
52
- "properties" : {
53
- "name" : {
54
- "type" : " string"
55
- },
56
- "nickname" : {
57
- "type" : " string"
58
- }
59
- }
60
- }
61
- }
62
- }
63
- }
39
+ "components" : {}
40
+ }
Original file line number Diff line number Diff line change 32
32
import reactor .core .publisher .Mono ;
33
33
34
34
import static org .springdoc .core .SpringDocUtils .getConfig ;
35
+ import static org .springdoc .core .converters .ConverterUtils .isFluxTypeWrapper ;
35
36
import static org .springdoc .core .converters .ConverterUtils .isResponseTypeWrapper ;
36
37
37
38
38
39
public class WebFluxSupportConverter implements ModelConverter {
39
40
40
41
static {
41
- getConfig ().addResponseWrapperToIgnore (Mono .class );
42
+ getConfig ().addResponseWrapperToIgnore (Mono .class )
43
+ .addFluxWrapperToIgnore (Flux .class );
42
44
}
43
45
44
46
@ Override
45
47
public Schema resolve (AnnotatedType type , ModelConverterContext context , Iterator <ModelConverter > chain ) {
46
48
JavaType javaType = Json .mapper ().constructType (type .getType ());
47
49
if (javaType != null ) {
48
50
Class <?> cls = javaType .getRawClass ();
49
- if (Flux . class . isAssignableFrom (cls )) {
51
+ if (isFluxTypeWrapper (cls )) {
50
52
JavaType innerType = javaType .getBindings ().getBoundType (0 );
51
53
if (innerType == null )
52
54
return new StringSchema ();
You can’t perform that action at this time.
0 commit comments