-
-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix_exceptionhandler_response_status' of https://github…
….com/uc4w6c/springdoc-openapi into uc4w6c-fix_exceptionhandler_response_status
- Loading branch information
Showing
6 changed files
with
206 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...enapi-webmvc-core/src/test/java/test/org/springdoc/api/v30/app197/Example2Controller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package test.org.springdoc.api.v30.app197; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/example2") | ||
public class Example2Controller { | ||
@GetMapping("/") | ||
public void index() { | ||
throw new IllegalArgumentException(); | ||
} | ||
|
||
@ExceptionHandler(IllegalArgumentException.class) | ||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
public String customControllerException() { | ||
return "example"; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...penapi-webmvc-core/src/test/java/test/org/springdoc/api/v30/app197/ExampleController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package test.org.springdoc.api.v30.app197; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/example") | ||
public class ExampleController { | ||
@GetMapping("/") | ||
public void index() { | ||
throw new IllegalArgumentException(); | ||
} | ||
|
||
@ExceptionHandler(IllegalArgumentException.class) | ||
@ResponseStatus(HttpStatus.NOT_FOUND) | ||
public String customControllerException() { | ||
return "example"; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...enapi-webmvc-core/src/test/java/test/org/springdoc/api/v30/app197/MyExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package test.org.springdoc.api.v30.app197; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.HttpRequestMethodNotSupportedException; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@ControllerAdvice | ||
public class MyExceptionHandler { | ||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) | ||
@ExceptionHandler({ HttpRequestMethodNotSupportedException.class }) | ||
@ResponseBody | ||
public Map<String, Object> handleError() { | ||
Map<String, Object> errorMap = new HashMap<String, Object>(); | ||
errorMap.put("message", "error"); | ||
return errorMap; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...napi-webmvc-core/src/test/java/test/org/springdoc/api/v30/app197/SpringDocApp197Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* | ||
* * | ||
* * * | ||
* * * * Copyright 2019-2022 the original author or authors. | ||
* * * * | ||
* * * * Licensed under the Apache License, Version 2.0 (the "License"); | ||
* * * * you may not use this file except in compliance with the License. | ||
* * * * You may obtain a copy of the License at | ||
* * * * | ||
* * * * https://www.apache.org/licenses/LICENSE-2.0 | ||
* * * * | ||
* * * * Unless required by applicable law or agreed to in writing, software | ||
* * * * distributed under the License is distributed on an "AS IS" BASIS, | ||
* * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* * * * See the License for the specific language governing permissions and | ||
* * * * limitations under the License. | ||
* * * | ||
* * | ||
* | ||
*/ | ||
|
||
package test.org.springdoc.api.v30.app197; | ||
|
||
import test.org.springdoc.api.v30.AbstractSpringDocV30Test; | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
public class SpringDocApp197Test extends AbstractSpringDocV30Test { | ||
|
||
@SpringBootApplication | ||
static class SpringDocTestApp {} | ||
|
||
} |
88 changes: 88 additions & 0 deletions
88
springdoc-openapi-webmvc-core/src/test/resources/results/3.0.1/app197.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
{ | ||
"openapi": "3.0.1", | ||
"info": { | ||
"title": "OpenAPI definition", | ||
"version": "v0" | ||
}, | ||
"servers": [ | ||
{ | ||
"url": "http://localhost", | ||
"description": "Generated server url" | ||
} | ||
], | ||
"paths": { | ||
"/example2/": { | ||
"get": { | ||
"tags": [ | ||
"example-2-controller" | ||
], | ||
"operationId": "index", | ||
"responses": { | ||
"200": { | ||
"description": "OK" | ||
}, | ||
"400": { | ||
"description": "Bad Request", | ||
"content": { | ||
"*/*": { | ||
"schema": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
}, | ||
"500": { | ||
"description": "Internal Server Error", | ||
"content": { | ||
"*/*": { | ||
"schema": { | ||
"type": "object", | ||
"additionalProperties": { | ||
"type": "object" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"/example/": { | ||
"get": { | ||
"tags": [ | ||
"example-controller" | ||
], | ||
"operationId": "index_1", | ||
"responses": { | ||
"200": { | ||
"description": "OK" | ||
}, | ||
"404": { | ||
"description": "Not Found", | ||
"content": { | ||
"*/*": { | ||
"schema": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
}, | ||
"500": { | ||
"description": "Internal Server Error", | ||
"content": { | ||
"*/*": { | ||
"schema": { | ||
"type": "object", | ||
"additionalProperties": { | ||
"type": "object" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": {} | ||
} |