Skip to content

Commit e74e325

Browse files
committed
fixing the responses object
1 parent 56f6587 commit e74e325

File tree

2 files changed

+18
-32
lines changed

2 files changed

+18
-32
lines changed

modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/Reader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ private Operation parseMethod(Class<?> cls, Method method, AnnotatedMethod annot
855855
if (apiOperation != null && StringUtils.isNotEmpty(apiOperation.responseReference())) {
856856
Response response = new Response().description(SUCCESSFUL_OPERATION);
857857
response.schema(new RefProperty(apiOperation.responseReference()));
858-
operation.addResponseObject(String.valueOf(apiOperation.code()), response);
858+
operation.addResponse(String.valueOf(apiOperation.code()), response);
859859
} else if (responseType == null) {
860860
// pick out response from method declaration
861861
LOGGER.debug("picking up response class from method {}", method);

modules/swagger-models/src/main/java/io/swagger/models/Operation.java

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.fasterxml.jackson.annotation.JsonAnyGetter;
44
import com.fasterxml.jackson.annotation.JsonAnySetter;
55
import io.swagger.models.parameters.Parameter;
6+
import io.swagger.models.properties.Property;
7+
import io.swagger.models.utils.PropertyModelConverter;
68

79
import java.util.ArrayList;
810
import java.util.LinkedHashMap;
@@ -81,13 +83,12 @@ public Operation parameter(Parameter parameter) {
8183
return this;
8284
}
8385
public Operation response(int key, Response response) {
84-
this.addResponseObject(String.valueOf(key),response);
86+
this.addResponse(String.valueOf(key),response);
8587
return this;
8688
}
8789

88-
8990
public Operation defaultResponse(Response response) {
90-
this.addResponseObject("default",response);
91+
this.addResponse("default",response);
9192
return this;
9293
}
9394

@@ -213,23 +214,20 @@ public void addParameter(Parameter parameter) {
213214
}
214215

215216
public Map<String, Response> getResponses() {
216-
if (this.responsesObject == null && responses != null) {
217-
this.responsesObject = new Responses();
218-
219-
for (String key : responses.keySet()) {
220-
this.responsesObject.put(key, responses.get(key));
221-
}
217+
if (this.responses == null && responsesObject != null) {
218+
responses = new Responses();
219+
responses.putAll(responsesObject);
220+
return responses;
222221
}
223222
return responses;
224223
}
225224

226-
public Responses getResponsesObject() {
227-
if (responses == null && responsesObject != null) {
228-
responses = new LinkedHashMap<String, Response>();
229225

230-
for (String key : this.responsesObject.keySet()) {
231-
responses.put(key, responsesObject.get(key));
232-
}
226+
public Responses getResponsesObject() {
227+
if (responsesObject == null && responses != null) {
228+
responsesObject = new Responses();
229+
responsesObject.putAll(responses);
230+
return responsesObject;
233231
}
234232
return responsesObject;
235233
}
@@ -240,12 +238,11 @@ public void setResponses(Map<String, Response> responses) {
240238

241239
public void setResponsesObject(Responses responsesObject) {
242240
this.responsesObject = responsesObject;
243-
244241
}
245242

246243
public void addResponse(String key, Response response) {
247244
if (responses == null) {
248-
responses = new LinkedHashMap<String, Response>();
245+
responses = new LinkedHashMap<>();
249246
}
250247
responses.put(key, response);
251248
if (responsesObject == null) {
@@ -254,17 +251,6 @@ public void addResponse(String key, Response response) {
254251
responsesObject.put(key, response);
255252
}
256253

257-
public void addResponseObject(String key, Response response) {
258-
if (this.responsesObject == null) {
259-
this.responsesObject = new Responses();
260-
}
261-
this.responsesObject.put(key, response);
262-
if (this.responses == null) {
263-
this.responses = new LinkedHashMap<String, Response>();
264-
}
265-
this.responses.put(key, response);
266-
}
267-
268254
public List<Map<String, List<String>>> getSecurity() {
269255
return security;
270256
}
@@ -275,11 +261,11 @@ public void setSecurity(List<Map<String, List<String>>> security) {
275261

276262
public void addSecurity(String name, List<String> scopes) {
277263
if (this.security == null) {
278-
this.security = new ArrayList<Map<String, List<String>>>();
264+
this.security = new ArrayList<>();
279265
}
280-
Map<String, List<String>> req = new LinkedHashMap<String, List<String>>();
266+
Map<String, List<String>> req = new LinkedHashMap<>();
281267
if (scopes == null) {
282-
scopes = new ArrayList<String>();
268+
scopes = new ArrayList<>();
283269
}
284270
req.put(name, scopes);
285271
this.security.add(req);

0 commit comments

Comments
 (0)