Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
/**
* The type Generic response builder.
*
* @author bnasslahsen
* @author bnasslahsen, Max Freedom Pollard
*/
public class GenericResponseService implements ApplicationContextAware {

Expand Down Expand Up @@ -450,7 +450,7 @@ private void buildGenericApiResponses(Components components, MethodParameter met
else {
// Use response parameters with no description filled - No documentation
// available
String httpCode = evaluateResponseStatus(methodParameter.getMethod(), Objects.requireNonNull(methodParameter.getMethod()).getClass(), true);
String httpCode = evaluateResponseStatus(methodParameter.getMethod(), methodParameter.getContainingClass(), true);
if (Objects.nonNull(httpCode)) {
apiResponse = methodAttributes.getGenericMapResponse().containsKey(httpCode) ? methodAttributes.getGenericMapResponse().get(httpCode)
: new ApiResponse();
Expand Down Expand Up @@ -491,16 +491,17 @@ private void buildApiResponses(Components components, MethodParameter methodPara
buildApiResponses(components, methodParameter, apiResponsesOp, methodAttributes, httpCode, apiResponse, false);
}
}
if (AnnotatedElementUtils.hasAnnotation(methodParameter.getMethod(), ResponseStatus.class)) {
if (AnnotatedElementUtils.hasAnnotation(methodParameter.getMethod(), ResponseStatus.class)
|| AnnotatedElementUtils.hasAnnotation(methodParameter.getContainingClass(), ResponseStatus.class)) {
// Handles the case with @ResponseStatus, if the specified response is not already handled explicitly
String httpCode = evaluateResponseStatus(methodParameter.getMethod(), Objects.requireNonNull(methodParameter.getMethod()).getClass(), false);
String httpCode = evaluateResponseStatus(methodParameter.getMethod(), methodParameter.getContainingClass(), false);
if (Objects.nonNull(httpCode) && !apiResponsesOp.containsKey(httpCode) && !apiResponsesOp.containsKey(ApiResponses.DEFAULT)) {
buildApiResponses(components, methodParameter, apiResponsesOp, methodAttributes, httpCode, new ApiResponse(), false);
}
}
}
else {
String httpCode = evaluateResponseStatus(methodParameter.getMethod(), Objects.requireNonNull(methodParameter.getMethod()).getClass(), false);
String httpCode = evaluateResponseStatus(methodParameter.getMethod(), methodParameter.getContainingClass(), false);
if (Objects.nonNull(httpCode))
buildApiResponses(components, methodParameter, apiResponsesOp, methodAttributes, httpCode, new ApiResponse(), false);
}
Expand Down Expand Up @@ -812,7 +813,7 @@ private boolean isValidHttpCode(String httpCode, MethodParameter methodParameter
if (isHttpCodePresent(httpCode, responseSet))
result = true;
}
if (httpCode.equals(evaluateResponseStatus(method, method.getClass(), false)))
if (httpCode.equals(evaluateResponseStatus(method, methodParameter.getContainingClass(), false)))
result = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2019-2026 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.app273;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

/**
* A controller that sets a status code for all of its handler methods, and one method that
* sets its own.
*
* @author Max Freedom Pollard
*/
@RestController
@ResponseStatus(HttpStatus.CREATED)
public class HelloController {

@PostMapping("/hello")
public String hello() {
return null;
}

@GetMapping("/bye")
@ResponseStatus(HttpStatus.ACCEPTED)
public String bye() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2019-2026 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.app273;

import test.org.springdoc.api.v30.AbstractSpringDocV30Test;

import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* A @ResponseStatus on the controller class applies to every handler method it declares.
*
* @author Max Freedom Pollard
*/
public class SpringDocApp273Test extends AbstractSpringDocV30Test {

@SpringBootApplication
static class SpringDocTestApp {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2019-2026 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.v31.app273;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

/**
* A controller that sets a status code for all of its handler methods, and one method that
* sets its own.
*
* @author Max Freedom Pollard
*/
@RestController
@ResponseStatus(HttpStatus.CREATED)
public class HelloController {

@PostMapping("/hello")
public String hello() {
return null;
}

@GetMapping("/bye")
@ResponseStatus(HttpStatus.ACCEPTED)
public String bye() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2019-2026 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.v31.app273;

import test.org.springdoc.api.v31.AbstractSpringDocTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* A @ResponseStatus on the controller class applies to every handler method it declares.
*
* @author Max Freedom Pollard
*/
public class SpringDocApp273Test extends AbstractSpringDocTest {

@SpringBootApplication
static class SpringDocTestApp {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"openapi" : "3.0.1",
"info" : {
"title" : "OpenAPI definition",
"version" : "v0"
},
"servers" : [ {
"url" : "http://localhost",
"description" : "Generated server url"
} ],
"paths" : {
"/hello" : {
"post" : {
"tags" : [ "hello-controller" ],
"operationId" : "hello",
"responses" : {
"201" : {
"description" : "Created",
"content" : {
"*/*" : {
"schema" : {
"type" : "string"
}
}
}
}
}
}
},
"/bye" : {
"get" : {
"tags" : [ "hello-controller" ],
"operationId" : "bye",
"responses" : {
"202" : {
"description" : "Accepted",
"content" : {
"*/*" : {
"schema" : {
"type" : "string"
}
}
}
}
}
}
}
},
"components" : { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"openapi" : "3.1.0",
"info" : {
"title" : "OpenAPI definition",
"version" : "v0"
},
"servers" : [ {
"url" : "http://localhost",
"description" : "Generated server url"
} ],
"paths" : {
"/hello" : {
"post" : {
"tags" : [ "hello-controller" ],
"operationId" : "hello",
"responses" : {
"201" : {
"description" : "Created",
"content" : {
"*/*" : {
"schema" : {
"type" : "string"
}
}
}
}
}
}
},
"/bye" : {
"get" : {
"tags" : [ "hello-controller" ],
"operationId" : "bye",
"responses" : {
"202" : {
"description" : "Accepted",
"content" : {
"*/*" : {
"schema" : {
"type" : "string"
}
}
}
}
}
}
}
},
"components" : { }
}