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
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+
}
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

+29
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

+3-3
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

+2-2
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

+2-2
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

+2-2
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

+3-3
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

+1-1
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

+2-2
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) {

springdoc-openapi-common/src/main/java/org/springdoc/ui/AbstractSwaggerIndexTransformer.java

+19-7
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public class AbstractSwaggerIndexTransformer {
5858
/**
5959
* Instantiates a new Abstract swagger index transformer.
6060
*
61-
* @param swaggerUiConfig the swagger ui config
62-
* @param swaggerUiOAuthProperties the swagger ui o auth properties
61+
* @param swaggerUiConfig the swagger ui config
62+
* @param swaggerUiOAuthProperties the swagger ui o auth properties
6363
* @param objectMapper the object mapper
6464
*/
6565
public AbstractSwaggerIndexTransformer(SwaggerUiConfigProperties swaggerUiConfig, SwaggerUiOAuthProperties swaggerUiOAuthProperties, ObjectMapper objectMapper) {
@@ -71,8 +71,8 @@ public AbstractSwaggerIndexTransformer(SwaggerUiConfigProperties swaggerUiConfig
7171
/**
7272
* Add init oauth string.
7373
*
74-
* @param html the html
75-
* @return the string
74+
* @param html the html
75+
* @return the string
7676
* @throws JsonProcessingException the json processing exception
7777
*/
7878
protected String addInitOauth(String html) throws JsonProcessingException {
@@ -87,8 +87,8 @@ protected String addInitOauth(String html) throws JsonProcessingException {
8787
/**
8888
* Read fully as string string.
8989
*
90-
* @param inputStream the input stream
91-
* @return the string
90+
* @param inputStream the input stream
91+
* @return the string
9292
* @throws IOException the io exception
9393
*/
9494
protected String readFullyAsString(InputStream inputStream)
@@ -105,18 +105,30 @@ protected String readFullyAsString(InputStream inputStream)
105105
/**
106106
* Overwrite swagger default url string.
107107
*
108-
* @param html the html
108+
* @param html the html
109109
* @return the string
110110
*/
111111
protected String overwriteSwaggerDefaultUrl(String html) {
112112
return html.replace(Constants.SWAGGER_UI_DEFAULT_URL, StringUtils.EMPTY);
113113
}
114114

115+
/**
116+
* Has default transformations boolean.
117+
*
118+
* @return the boolean
119+
*/
115120
protected boolean hasDefaultTransformations() {
116121
boolean oauth2Configured = !CollectionUtils.isEmpty(swaggerUiOAuthProperties.getConfigParameters());
117122
return oauth2Configured || swaggerUiConfig.isDisableSwaggerDefaultUrl();
118123
}
119124

125+
/**
126+
* Default transformations string.
127+
*
128+
* @param inputStream the input stream
129+
* @return the string
130+
* @throws IOException the io exception
131+
*/
120132
protected String defaultTransformations(InputStream inputStream) throws IOException {
121133
String html = readFullyAsString(inputStream);
122134
if (!CollectionUtils.isEmpty(swaggerUiOAuthProperties.getConfigParameters())) {

springdoc-openapi-common/src/main/java/org/springdoc/ui/AbstractSwaggerWelcome.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public abstract class AbstractSwaggerWelcome implements InitializingBean {
5858
/**
5959
* Instantiates a new Abstract swagger welcome.
6060
*
61-
* @param swaggerUiConfig the swagger ui config
62-
* @param springDocConfigProperties the spring doc config properties
61+
* @param swaggerUiConfig the swagger ui config
62+
* @param springDocConfigProperties the spring doc config properties
6363
* @param swaggerUiConfigParameters the swagger ui config parameters
6464
*/
6565
public AbstractSwaggerWelcome(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties, SwaggerUiConfigParameters swaggerUiConfigParameters) {
@@ -77,8 +77,8 @@ public void afterPropertiesSet() {
7777
/**
7878
* Build url string.
7979
*
80-
* @param contextPath the context path
81-
* @param docsUrl the docs url
80+
* @param contextPath the context path
81+
* @param docsUrl the docs url
8282
* @return the string
8383
*/
8484
protected String buildUrl(String contextPath, final String docsUrl) {
@@ -91,7 +91,7 @@ protected String buildUrl(String contextPath, final String docsUrl) {
9191
/**
9292
* Build config url.
9393
*
94-
* @param contextPath the context path
94+
* @param contextPath the context path
9595
* @param uriComponentsBuilder the uri components builder
9696
*/
9797
protected void buildConfigUrl(String contextPath, UriComponentsBuilder uriComponentsBuilder) {
@@ -116,7 +116,7 @@ protected void buildConfigUrl(String contextPath, UriComponentsBuilder uriCompon
116116
/**
117117
* Gets uri components builder.
118118
*
119-
* @param sbUrl the sb url
119+
* @param sbUrl the sb url
120120
* @return the uri components builder
121121
*/
122122
protected UriComponentsBuilder getUriComponentsBuilder(String sbUrl) {

springdoc-openapi-common/src/main/java/org/springdoc/ui/SpringDocUIException.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class SpringDocUIException extends RuntimeException {
2929
/**
3030
* Instantiates a new Spring doc ui exception.
3131
*
32-
* @param message the message
32+
* @param message the message
3333
* @param cause the cause
3434
*/
3535
public SpringDocUIException(String message, Throwable cause) {

0 commit comments

Comments
 (0)