Skip to content

Commit 76b9c18

Browse files
author
bnasslahsen
committed
MultipleOpenApiResource issue?. Fixes #771
1 parent 39a14dd commit 76b9c18

24 files changed

+310
-160
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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 org.springdoc.api;
20+
21+
import java.util.UUID;
22+
23+
/**
24+
* The type Error message.
25+
*/
26+
public class ErrorMessage {
27+
28+
private UUID id;
29+
30+
private String message;
31+
32+
/**
33+
* Instantiates a new Error message.
34+
*
35+
* @param message the message
36+
*/
37+
public ErrorMessage(String message) {
38+
this.id = UUID.randomUUID();
39+
this.message = message;
40+
}
41+
42+
/**
43+
* Gets id.
44+
*
45+
* @return the id
46+
*/
47+
public UUID getId() {
48+
return id;
49+
}
50+
51+
/**
52+
* Sets id.
53+
*
54+
* @param id the id
55+
*/
56+
public void setId(UUID id) {
57+
this.id = id;
58+
}
59+
60+
/**
61+
* Gets message.
62+
*
63+
* @return the message
64+
*/
65+
public String getMessage() {
66+
return message;
67+
}
68+
69+
/**
70+
* Sets message.
71+
*
72+
* @param message the message
73+
*/
74+
public void setMessage(String message) {
75+
this.message = message;
76+
}
77+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.springdoc.api;
2+
3+
/**
4+
* The type Open api resource not found exception.
5+
* @author bnasslahsen
6+
*/
7+
public class OpenApiResourceNotFoundException extends RuntimeException {
8+
9+
/**
10+
* Instantiates a new Open api resource not found exception.
11+
*
12+
* @param message the message
13+
*/
14+
public OpenApiResourceNotFoundException(String message) {
15+
super(message);
16+
}
17+
}

springdoc-openapi-common/src/main/java/org/springdoc/core/SpringDocConfiguration.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@
2727

2828
import com.fasterxml.jackson.databind.node.ObjectNode;
2929
import io.swagger.v3.core.converter.ModelConverter;
30+
import io.swagger.v3.oas.annotations.Hidden;
3031
import io.swagger.v3.oas.models.Components;
3132
import io.swagger.v3.oas.models.OpenAPI;
3233
import io.swagger.v3.oas.models.media.ObjectSchema;
3334
import io.swagger.v3.oas.models.media.Schema;
35+
import org.springdoc.api.ErrorMessage;
36+
import org.springdoc.api.OpenApiResourceNotFoundException;
3437
import org.springdoc.core.converters.AdditionalModelsConverter;
3538
import org.springdoc.core.converters.FileSupportConverter;
3639
import org.springdoc.core.converters.ModelConverterRegistrar;
@@ -55,6 +58,12 @@
5558
import org.springframework.context.annotation.Configuration;
5659
import org.springframework.context.annotation.Lazy;
5760
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
61+
import org.springframework.http.HttpStatus;
62+
import org.springframework.http.ResponseEntity;
63+
import org.springframework.web.bind.annotation.ExceptionHandler;
64+
import org.springframework.web.bind.annotation.ResponseStatus;
65+
import org.springframework.web.bind.annotation.RestControllerAdvice;
66+
import org.springframework.web.context.request.WebRequest;
5867

5968
import static org.springdoc.core.Constants.SPRINGDOC_DEPRECATING_CONVERTER_ENABLED;
6069
import static org.springdoc.core.Constants.SPRINGDOC_ENABLED;
@@ -313,4 +322,24 @@ static BeanFactoryPostProcessor springdocBeanFactoryPostProcessor2() {
313322
return SpringdocBeanFactoryConfigurer::initBeanFactoryPostProcessor;
314323
}
315324

325+
/**
326+
* The type Open api resource advice.
327+
*/
328+
@RestControllerAdvice
329+
@Hidden
330+
class OpenApiResourceAdvice {
331+
/**
332+
* Handle no handler found response entity.
333+
*
334+
* @param e the e
335+
* @param request the request
336+
* @return the response entity
337+
*/
338+
@ExceptionHandler(OpenApiResourceNotFoundException.class)
339+
@ResponseStatus(HttpStatus.NOT_FOUND)
340+
public ResponseEntity<ErrorMessage> handleNoHandlerFound(OpenApiResourceNotFoundException e, WebRequest request) {
341+
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorMessage(e.getMessage()));
342+
}
343+
}
344+
316345
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static void addResponseTypeToIgnore(Class<?> cls) {
8484
/**
8585
* Is response type wrapper boolean.
8686
*
87-
* @param rawClass the raw class
87+
* @param rawClass the raw class
8888
* @return the boolean
8989
*/
9090
public static boolean isResponseTypeWrapper(Class<?> rawClass) {
@@ -94,7 +94,7 @@ public static boolean isResponseTypeWrapper(Class<?> rawClass) {
9494
/**
9595
* Is response type to ignore boolean.
9696
*
97-
* @param rawClass the raw class
97+
* @param rawClass the raw class
9898
* @return the boolean
9999
*/
100100
public static boolean isResponseTypeToIgnore(Class<?> rawClass) {
@@ -126,7 +126,7 @@ public static void removeResponseTypeToIgnore(Class<?> classes) {
126126
/**
127127
* Is flux type wrapper boolean.
128128
*
129-
* @param rawClass the raw class
129+
* @param rawClass the raw class
130130
* @return the boolean
131131
*/
132132
public static boolean isFluxTypeWrapper(Class<?> rawClass) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public class DefaultPageable extends Pageable {
3434
/**
3535
* Instantiates a new Default pageable.
3636
*
37-
* @param page the page
38-
* @param size the size
37+
* @param page the page
38+
* @param size the size
3939
* @param sort the sort
4040
*/
4141
public DefaultPageable(int page, int size, List<String> sort) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public class Pageable {
6161
/**
6262
* Instantiates a new Pageable.
6363
*
64-
* @param page the page
65-
* @param size the size
64+
* @param page the page
65+
* @param size the size
6666
* @param sort the sort
6767
*/
6868
public Pageable(int page, int size, List<String> sort) {

springdoc-openapi-common/src/main/java/org/springdoc/core/customizers/ParameterCustomizer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public interface ParameterCustomizer {
3434
/**
3535
* Customize parameter.
3636
*
37-
* @param parameterModel to be customized
38-
* @param methodParameter original parameter from handler method
37+
* @param parameterModel to be customized
38+
* @param methodParameter original parameter from handler method
3939
* @return customized parameter
4040
*/
4141
Parameter customize(Parameter parameterModel, MethodParameter methodParameter);

springdoc-openapi-common/src/main/java/org/springdoc/core/fn/AbstractRouterFunctionVisitor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void path(String pattern) {
6464
/**
6565
* Header.
6666
*
67-
* @param name the name
67+
* @param name the name
6868
* @param value the value
6969
*/
7070
public void header(String name, String value) {
@@ -88,7 +88,7 @@ public List<RouterFunctionData> getRouterFunctionDatas() {
8888
/**
8989
* Query param.
9090
*
91-
* @param name the name
91+
* @param name the name
9292
* @param value the value
9393
*/
9494
public void queryParam(String name, String value) {
@@ -107,7 +107,7 @@ public void pathExtension(String extension) {
107107
/**
108108
* Param.
109109
*
110-
* @param name the name
110+
* @param name the name
111111
* @param value the value
112112
*/
113113
public void param(String name, String value) {

springdoc-openapi-common/src/main/java/org/springdoc/core/fn/RouterFunctionData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public Map<String, String> getQueryParams() {
9999
/**
100100
* Add query params.
101101
*
102-
* @param name the name
102+
* @param name the name
103103
* @param value the value
104104
*/
105105
public void addQueryParams(String name, String value) {

springdoc-openapi-common/src/main/java/org/springdoc/core/fn/RouterOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public RouterOperation(org.springdoc.core.annotations.RouterOperation routerOper
112112
/**
113113
* Instantiates a new Router operation.
114114
*
115-
* @param routerOperationAnnotation the router operation annotation
115+
* @param routerOperationAnnotation the router operation annotation
116116
* @param routerFunctionData the router function data
117117
*/
118118
public RouterOperation(org.springdoc.core.annotations.RouterOperation routerOperationAnnotation, RouterFunctionData routerFunctionData) {
@@ -131,7 +131,7 @@ public RouterOperation(org.springdoc.core.annotations.RouterOperation routerOper
131131
/**
132132
* Instantiates a new Router operation.
133133
*
134-
* @param path the path
134+
* @param path the path
135135
* @param methods the methods
136136
*/
137137
public RouterOperation(String path, RequestMethod[] methods) {

0 commit comments

Comments
 (0)