Skip to content

Commit b3f258b

Browse files
authored
Merge pull request #1290 from sokomishalov/feature/use-publisher-as-response-type-wrapper
Use Publisher as response wrapper to ignore instead of Mono
2 parents 8935bac + 865e47f commit b3f258b

File tree

9 files changed

+183
-90
lines changed

9 files changed

+183
-90
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/core/converters/ResponseSupportConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import static org.springdoc.core.converters.ConverterUtils.isResponseTypeToIgnore;
3535
import static org.springdoc.core.converters.ConverterUtils.isResponseTypeWrapper;
36+
import static org.springdoc.core.converters.ConverterUtils.isFluxTypeWrapper;
3637

3738
/**
3839
* The type Response support converter.
@@ -45,7 +46,7 @@ public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterato
4546
JavaType javaType = Json.mapper().constructType(type.getType());
4647
if (javaType != null) {
4748
Class<?> cls = javaType.getRawClass();
48-
if (isResponseTypeWrapper(cls)) {
49+
if (isResponseTypeWrapper(cls) && !isFluxTypeWrapper(cls)) {
4950
JavaType innerType = javaType.getBindings().getBoundType(0);
5051
if (innerType == null)
5152
return new StringSchema();

springdoc-openapi-webflux-core/src/main/java/org/springdoc/webflux/core/converters/WebFluxSupportConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
import io.swagger.v3.core.util.Json;
3131
import io.swagger.v3.oas.models.media.Schema;
3232
import io.swagger.v3.oas.models.media.StringSchema;
33+
import org.reactivestreams.Publisher;
3334
import reactor.core.publisher.Flux;
34-
import reactor.core.publisher.Mono;
3535

3636
import static org.springdoc.core.SpringDocUtils.getConfig;
3737
import static org.springdoc.core.converters.ConverterUtils.isFluxTypeWrapper;
@@ -45,7 +45,7 @@
4545
public class WebFluxSupportConverter implements ModelConverter {
4646

4747
static {
48-
getConfig().addResponseWrapperToIgnore(Mono.class)
48+
getConfig().addResponseWrapperToIgnore(Publisher.class)
4949
.addFluxWrapperToIgnore(Flux.class);
5050
}
5151

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
*
3+
* * Copyright 2019-2021 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.app152;
20+
21+
import org.reactivestreams.Publisher;
22+
import org.springdoc.core.GroupedOpenApi;
23+
import org.springframework.context.annotation.Bean;
24+
import org.springframework.web.bind.annotation.GetMapping;
25+
import org.springframework.web.bind.annotation.RestController;
26+
import reactor.core.publisher.Mono;
27+
28+
@RestController
29+
public class HelloController {
30+
31+
@GetMapping("/persons")
32+
public Publisher<String> persons() {
33+
return Mono.just("OK");
34+
}
35+
36+
@Bean
37+
public GroupedOpenApi userOpenApi() {
38+
return GroupedOpenApi.builder()
39+
.group("users")
40+
.packagesToScan("test.org.springdoc.api.app152")
41+
.build();
42+
}
43+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
*
3+
* *
4+
* * * Copyright 2019-2021 the original author or authors.
5+
* * *
6+
* * * Licensed under the Apache License, Version 2.0 (the "License");
7+
* * * you may not use this file except in compliance with the License.
8+
* * * You may obtain a copy of the License at
9+
* * *
10+
* * * https://www.apache.org/licenses/LICENSE-2.0
11+
* * *
12+
* * * Unless required by applicable law or agreed to in writing, software
13+
* * * distributed under the License is distributed on an "AS IS" BASIS,
14+
* * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* * * See the License for the specific language governing permissions and
16+
* * * limitations under the License.
17+
* *
18+
*
19+
*/
20+
21+
package test.org.springdoc.api.app152;
22+
23+
import org.springframework.boot.autoconfigure.SpringBootApplication;
24+
import org.springframework.context.annotation.ComponentScan;
25+
import test.org.springdoc.api.AbstractSpringDocTest;
26+
27+
public class SpringDocApp152Test extends AbstractSpringDocTest {
28+
29+
@SpringBootApplication
30+
@ComponentScan(basePackages = { "org.springdoc", "test.org.springdoc.api.app152" })
31+
static class SpringDocTestApp {}
32+
}

springdoc-openapi-webflux-core/src/test/resources/results/app146-1.json

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"content": {
4444
"*/*": {
4545
"schema": {
46-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
46+
"type": "object"
4747
}
4848
}
4949
}
@@ -71,7 +71,7 @@
7171
"content": {
7272
"*/*": {
7373
"schema": {
74-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
74+
"type": "object"
7575
}
7676
}
7777
}
@@ -91,7 +91,7 @@
9191
"content": {
9292
"*/*": {
9393
"schema": {
94-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
94+
"type": "object"
9595
}
9696
}
9797
}
@@ -111,7 +111,7 @@
111111
"content": {
112112
"*/*": {
113113
"schema": {
114-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
114+
"type": "object"
115115
}
116116
}
117117
}
@@ -141,7 +141,7 @@
141141
"content": {
142142
"*/*": {
143143
"schema": {
144-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
144+
"type": "object"
145145
}
146146
}
147147
}
@@ -161,7 +161,7 @@
161161
"content": {
162162
"*/*": {
163163
"schema": {
164-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
164+
"type": "object"
165165
}
166166
}
167167
}
@@ -181,7 +181,7 @@
181181
"content": {
182182
"*/*": {
183183
"schema": {
184-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
184+
"type": "object"
185185
}
186186
}
187187
}
@@ -201,7 +201,7 @@
201201
"content": {
202202
"*/*": {
203203
"schema": {
204-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
204+
"type": "object"
205205
}
206206
}
207207
}
@@ -221,7 +221,7 @@
221221
"content": {
222222
"*/*": {
223223
"schema": {
224-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
224+
"type": "object"
225225
}
226226
}
227227
}
@@ -241,7 +241,7 @@
241241
"content": {
242242
"*/*": {
243243
"schema": {
244-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
244+
"type": "object"
245245
}
246246
}
247247
}
@@ -261,7 +261,7 @@
261261
"content": {
262262
"*/*": {
263263
"schema": {
264-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
264+
"type": "object"
265265
}
266266
}
267267
}
@@ -291,7 +291,7 @@
291291
"content": {
292292
"*/*": {
293293
"schema": {
294-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
294+
"type": "object"
295295
}
296296
}
297297
}
@@ -311,7 +311,7 @@
311311
"content": {
312312
"*/*": {
313313
"schema": {
314-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
314+
"type": "object"
315315
}
316316
}
317317
}
@@ -341,7 +341,7 @@
341341
"content": {
342342
"*/*": {
343343
"schema": {
344-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
344+
"type": "object"
345345
}
346346
}
347347
}
@@ -361,7 +361,7 @@
361361
"content": {
362362
"*/*": {
363363
"schema": {
364-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
364+
"type": "object"
365365
}
366366
}
367367
}
@@ -381,7 +381,7 @@
381381
"content": {
382382
"*/*": {
383383
"schema": {
384-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
384+
"type": "object"
385385
}
386386
}
387387
}
@@ -411,7 +411,7 @@
411411
"content": {
412412
"*/*": {
413413
"schema": {
414-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
414+
"type": "object"
415415
}
416416
}
417417
}
@@ -439,7 +439,7 @@
439439
"content": {
440440
"*/*": {
441441
"schema": {
442-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
442+
"type": "object"
443443
}
444444
}
445445
}
@@ -459,7 +459,7 @@
459459
"content": {
460460
"*/*": {
461461
"schema": {
462-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
462+
"type": "object"
463463
}
464464
}
465465
}
@@ -477,7 +477,7 @@
477477
"content": {
478478
"*/*": {
479479
"schema": {
480-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
480+
"type": "object"
481481
}
482482
}
483483
}
@@ -497,7 +497,7 @@
497497
"content": {
498498
"*/*": {
499499
"schema": {
500-
"$ref": "#/components/schemas/PublisherResponseEntityObject"
500+
"type": "object"
501501
}
502502
}
503503
}
@@ -535,9 +535,6 @@
535535
},
536536
"components": {
537537
"schemas": {
538-
"PublisherResponseEntityObject": {
539-
"type": "object"
540-
},
541538
"Link": {
542539
"type": "object",
543540
"properties": {
@@ -551,4 +548,4 @@
551548
}
552549
}
553550
}
554-
}
551+
}

0 commit comments

Comments
 (0)