Skip to content

Commit ac31b6d

Browse files
committed
saving work
1 parent 74e75d3 commit ac31b6d

File tree

11 files changed

+1297
-17
lines changed

11 files changed

+1297
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
*/
2323

24-
package org.springdoc.webflux.core.fn.builders;
24+
package org.springdoc.webflux.core.fn;
2525

2626

2727
import java.util.function.BiFunction;

springdoc-openapi-webflux-core/src/test/java/test/org/springdoc/api/app90/HelloRouter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.springframework.context.annotation.Configuration;
3131
import org.springframework.web.reactive.function.server.RouterFunction;
3232

33-
import static org.springdoc.webflux.core.fn.builders.SpringdocRouteBuilder.route;
33+
import static org.springdoc.webflux.core.fn.SpringdocRouteBuilder.route;
3434
import static test.org.springdoc.api.AbstractSpringDocTest.HANDLER_FUNCTION;
3535

3636
@Configuration

springdoc-openapi-webflux-core/src/test/java/test/org/springdoc/api/app90/book/BookRouter.java

+48-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323

2424
package test.org.springdoc.api.app90.book;
2525

26+
import java.util.function.Consumer;
27+
2628
import io.swagger.v3.oas.annotations.enums.ParameterIn;
29+
import org.springdoc.core.fn.builders.OperationBuilder;
2730
import org.springdoc.core.fn.builders.ParameterBuilder;
2831
import reactor.core.publisher.Flux;
2932

@@ -33,8 +36,10 @@
3336
import org.springframework.stereotype.Component;
3437
import org.springframework.web.reactive.function.server.RouterFunction;
3538

36-
import static org.springdoc.webflux.core.fn.builders.SpringdocRouteBuilder.route;
39+
import static org.springdoc.webflux.core.fn.SpringdocRouteBuilder.route;
3740
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;
3843
import static test.org.springdoc.api.AbstractSpringDocTest.HANDLER_FUNCTION;
3944

4045
@Configuration
@@ -43,33 +48,67 @@ class BookRouter {
4348

4449
@Bean
4550
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")
4752
.beanClass(BookRepository.class).beanMethod("findAll")).build()
4853

4954
.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())
5156

5257
.and(route().GET("/books/{author}", HANDLER_FUNCTION, ops -> ops.tag("book")
5358
.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());
5570
}
5671

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+
5794
@Component
58-
class BookRepository {
95+
class BookRepository {
5996

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"));
6299
}
63100

64101
Flux<Book> findAll() {
65-
return Flux.just(new Book("2", "title2","author2"));
102+
return Flux.just(new Book("2", "title2", "author2"));
66103
}
67104
}
68105

69-
public class Book {
106+
class Book {
70107

71108
private String id;
109+
72110
private String title;
111+
73112
private String author;
74113

75114
public Book(String id, String title, String author) {

springdoc-openapi-webflux-core/src/test/java/test/org/springdoc/api/app90/employee/EmployeeRouter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import org.springframework.web.reactive.function.server.RouterFunction;
3434
import org.springframework.web.reactive.function.server.ServerResponse;
3535

36-
import static org.springdoc.webflux.core.fn.builders.SpringdocRouteBuilder.route;
36+
import static org.springdoc.webflux.core.fn.SpringdocRouteBuilder.route;
3737
import static test.org.springdoc.api.AbstractSpringDocTest.HANDLER_FUNCTION;
3838

3939
@Configuration

springdoc-openapi-webflux-core/src/test/java/test/org/springdoc/api/app90/position/PositionRouter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import org.springframework.web.reactive.function.server.RouterFunction;
3737
import org.springframework.web.reactive.function.server.ServerResponse;
3838

39-
import static org.springdoc.webflux.core.fn.builders.SpringdocRouteBuilder.route;
39+
import static org.springdoc.webflux.core.fn.SpringdocRouteBuilder.route;
4040
import static org.springframework.web.reactive.function.server.RequestPredicates.accept;
4141
import static test.org.springdoc.api.AbstractSpringDocTest.HANDLER_FUNCTION;
4242

springdoc-openapi-webflux-core/src/test/java/test/org/springdoc/api/app90/quotes/QuotesRouter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import org.springframework.web.reactive.function.server.RouterFunction;
3838
import org.springframework.web.reactive.function.server.ServerResponse;
3939

40-
import static org.springdoc.webflux.core.fn.builders.SpringdocRouteBuilder.route;
40+
import static org.springdoc.webflux.core.fn.SpringdocRouteBuilder.route;
4141
import static org.springframework.http.MediaType.APPLICATION_JSON;
4242
import static org.springframework.http.MediaType.APPLICATION_STREAM_JSON;
4343
import static org.springframework.http.MediaType.TEXT_PLAIN;

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

+171-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
"/books": {
4646
"get": {
4747
"tags": [
48-
"book-repository"
48+
"book"
4949
],
50-
"operationId": "findAll_1",
50+
"operationId": "findAll_1_1",
5151
"responses": {
5252
"200": {
5353
"description": "OK",
@@ -84,6 +84,7 @@
8484
"/books/{author}": {
8585
"get": {
8686
"tags": [
87+
"book",
8788
"book"
8889
],
8990
"operationId": "findByAuthor",
@@ -114,6 +115,173 @@
114115
}
115116
}
116117
},
118+
"/books/nest": {
119+
"get": {
120+
"tags": [
121+
"book"
122+
],
123+
"operationId": "findAll",
124+
"responses": {
125+
"200": {
126+
"description": "OK",
127+
"content": {
128+
"application/xml": {
129+
"schema": {
130+
"type": "array",
131+
"items": {
132+
"$ref": "#/components/schemas/Book"
133+
}
134+
}
135+
},
136+
"text/plain": {
137+
"schema": {
138+
"type": "array",
139+
"items": {
140+
"$ref": "#/components/schemas/Book"
141+
}
142+
}
143+
}
144+
}
145+
}
146+
}
147+
}
148+
},
149+
"/books/nest/{author}": {
150+
"get": {
151+
"tags": [
152+
"book"
153+
],
154+
"operationId": "findByAuthor_1",
155+
"parameters": [
156+
{
157+
"name": "author",
158+
"in": "path",
159+
"required": true,
160+
"schema": {
161+
"type": "string"
162+
}
163+
}
164+
],
165+
"responses": {
166+
"200": {
167+
"description": "OK",
168+
"content": {
169+
"*/*": {
170+
"schema": {
171+
"type": "array",
172+
"items": {
173+
"$ref": "#/components/schemas/Book"
174+
}
175+
}
176+
}
177+
}
178+
}
179+
}
180+
}
181+
},
182+
"/greeter/greeter2/books": {
183+
"get": {
184+
"tags": [
185+
"book"
186+
],
187+
"operationId": "findAll_1",
188+
"responses": {
189+
"200": {
190+
"description": "OK",
191+
"content": {
192+
"application/xml": {
193+
"schema": {
194+
"type": "array",
195+
"items": {
196+
"$ref": "#/components/schemas/Book"
197+
}
198+
}
199+
},
200+
"application/json": {
201+
"schema": {
202+
"type": "array",
203+
"items": {
204+
"$ref": "#/components/schemas/Book"
205+
}
206+
}
207+
}
208+
}
209+
}
210+
}
211+
}
212+
},
213+
"/test/greeter/greeter2/books": {
214+
"get": {
215+
"tags": [
216+
"book"
217+
],
218+
"operationId": "findAll_3_1",
219+
"responses": {
220+
"200": {
221+
"description": "OK",
222+
"content": {
223+
"application/xml": {
224+
"schema": {
225+
"type": "array",
226+
"items": {
227+
"$ref": "#/components/schemas/Book"
228+
}
229+
}
230+
},
231+
"application/json": {
232+
"schema": {
233+
"type": "array",
234+
"items": {
235+
"$ref": "#/components/schemas/Book"
236+
}
237+
}
238+
},
239+
"text/plain": {
240+
"schema": {
241+
"type": "array",
242+
"items": {
243+
"$ref": "#/components/schemas/Book"
244+
}
245+
}
246+
}
247+
}
248+
}
249+
}
250+
}
251+
},
252+
"/test/greeter/greeter2/books/{author}": {
253+
"get": {
254+
"tags": [
255+
"book"
256+
],
257+
"operationId": "findByAuthor_2",
258+
"parameters": [
259+
{
260+
"name": "author",
261+
"in": "path",
262+
"required": true,
263+
"schema": {
264+
"type": "string"
265+
}
266+
}
267+
],
268+
"responses": {
269+
"200": {
270+
"description": "OK",
271+
"content": {
272+
"*/*": {
273+
"schema": {
274+
"type": "array",
275+
"items": {
276+
"$ref": "#/components/schemas/Book"
277+
}
278+
}
279+
}
280+
}
281+
}
282+
}
283+
}
284+
},
117285
"/employees/{id}": {
118286
"get": {
119287
"tags": [
@@ -213,7 +381,7 @@
213381
"positions"
214382
],
215383
"description": "Get all positions",
216-
"operationId": "findAll",
384+
"operationId": "findAll_2",
217385
"responses": {
218386
"200": {
219387
"description": "OK",

0 commit comments

Comments
 (0)