23
23
24
24
package test .org .springdoc .api .app90 .book ;
25
25
26
+ import java .util .function .Consumer ;
27
+
26
28
import io .swagger .v3 .oas .annotations .enums .ParameterIn ;
29
+ import org .springdoc .core .fn .builders .OperationBuilder ;
27
30
import org .springdoc .core .fn .builders .ParameterBuilder ;
28
31
import reactor .core .publisher .Flux ;
29
32
33
36
import org .springframework .stereotype .Component ;
34
37
import org .springframework .web .reactive .function .server .RouterFunction ;
35
38
36
- import static org .springdoc .webflux .core .fn .builders . SpringdocRouteBuilder .route ;
39
+ import static org .springdoc .webflux .core .fn .SpringdocRouteBuilder .route ;
37
40
import static org .springframework .web .reactive .function .server .RequestPredicates .accept ;
41
+ import static org .springframework .web .reactive .function .server .RequestPredicates .path ;
42
+ import static org .springframework .web .reactive .function .server .RouterFunctions .nest ;
38
43
import static test .org .springdoc .api .AbstractSpringDocTest .HANDLER_FUNCTION ;
39
44
40
45
@ Configuration
@@ -43,33 +48,67 @@ class BookRouter {
43
48
44
49
@ Bean
45
50
RouterFunction <?> bookRoute (BookRepository br ) {
46
- return route ().GET ("/books" , accept (MediaType .APPLICATION_JSON , MediaType .APPLICATION_XML ), HANDLER_FUNCTION , ops -> ops
51
+ return route ().GET ("/books" , accept (MediaType .APPLICATION_JSON , MediaType .APPLICATION_XML ), HANDLER_FUNCTION , ops -> ops . operationId ( "findAll" ). tag ( "book" )
47
52
.beanClass (BookRepository .class ).beanMethod ("findAll" )).build ()
48
53
49
54
.and (route ().GET ("/books" , accept (MediaType .APPLICATION_XML , MediaType .TEXT_PLAIN ), HANDLER_FUNCTION ,
50
- ops -> ops .tag ("book" ).beanClass (BookRepository .class ).beanMethod ("findAll" )).build ())
55
+ ops -> ops .operationId ( "findAll" ). tag ("book" ).beanClass (BookRepository .class ).beanMethod ("findAll" )).build ())
51
56
52
57
.and (route ().GET ("/books/{author}" , HANDLER_FUNCTION , ops -> ops .tag ("book" )
53
58
.beanClass (BookRepository .class ).beanMethod ("findByAuthor" )
54
- .operationId ("findByAuthor" ).parameter (ParameterBuilder .builder ().in (ParameterIn .PATH ).name ("author" ))).build ());
59
+ .operationId ("findByAuthor" ).tag ("book" ).parameter (ParameterBuilder .builder ().in (ParameterIn .PATH ).name ("author" ))).build ());
60
+ }
61
+
62
+ @ Bean
63
+ RouterFunction <?> routes2 () {
64
+ return nest (path ("/greeter" ).and (path ("/greeter2" )),
65
+ route ().GET ("/books" , accept (MediaType .APPLICATION_JSON , MediaType .APPLICATION_XML ), HANDLER_FUNCTION , getOperation1 ()).build ())
66
+
67
+ .and (route ().GET ("/books/nest" , accept (MediaType .APPLICATION_XML , MediaType .TEXT_PLAIN ), HANDLER_FUNCTION , getOperation1 ()).build ())
68
+
69
+ .and (route ().GET ("/books/nest/{author}" , HANDLER_FUNCTION , getOperation2 ()).build ());
55
70
}
56
71
72
+ @ Bean
73
+ RouterFunction <?> routes4 () {
74
+ return nest (path ("/test" ), nest (path ("/greeter" ).and (path ("/greeter2" )),
75
+ route ().GET ("/books" , accept (MediaType .APPLICATION_JSON , MediaType .APPLICATION_XML ), HANDLER_FUNCTION , getOperation1 ()).build ()
76
+
77
+ .and (route ().GET ("/books" , accept (MediaType .APPLICATION_XML , MediaType .TEXT_PLAIN ), HANDLER_FUNCTION , getOperation1 ()).build ())
78
+
79
+ .and (route ().GET ("/books/{author}" , HANDLER_FUNCTION , getOperation2 ()).build ())));
80
+ }
81
+
82
+
83
+ private Consumer <OperationBuilder > getOperation1 () {
84
+ return ops -> ops .operationId ("findAll" ).tag ("book" ).beanClass (BookRepository .class ).beanMethod ("findAll" );
85
+ }
86
+
87
+ private Consumer <OperationBuilder > getOperation2 () {
88
+ return ops -> ops .operationId ("findAll" ).tag ("book" )
89
+ .operationId ("findByAuthor" ).parameter (ParameterBuilder .builder ().name ("author" ).in (ParameterIn .PATH ))
90
+ .beanClass (BookRepository .class ).beanMethod ("findByAuthor" );
91
+ }
92
+
93
+
57
94
@ Component
58
- class BookRepository {
95
+ class BookRepository {
59
96
60
- Flux <Book > findByAuthor (String author ){
61
- return Flux .just (new Book ("1" , "title1" ,"author1" ));
97
+ Flux <Book > findByAuthor (String author ) {
98
+ return Flux .just (new Book ("1" , "title1" , "author1" ));
62
99
}
63
100
64
101
Flux <Book > findAll () {
65
- return Flux .just (new Book ("2" , "title2" ,"author2" ));
102
+ return Flux .just (new Book ("2" , "title2" , "author2" ));
66
103
}
67
104
}
68
105
69
- public class Book {
106
+ class Book {
70
107
71
108
private String id ;
109
+
72
110
private String title ;
111
+
73
112
private String author ;
74
113
75
114
public Book (String id , String title , String author ) {
0 commit comments