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 @@ -12,8 +12,10 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.ws.rs.Consumes;
Expand Down Expand Up @@ -155,7 +157,8 @@ public Class<? extends Annotation> annotationType() {

String httpMethod = extractOperationMethod(apiOperation, method, SwaggerExtensions.chain());

Operation operation = parseMethod(httpMethod, method);
final LinkedHashMap<String, Model> resultModels = new LinkedHashMap<>();
final Operation operation = parseMethod(httpMethod, method, resultModels);
updateOperationParameters(parentParameters, regexMap, operation);
updateOperationProtocols(apiOperation, operation);

Expand All @@ -178,9 +181,14 @@ public Class<? extends Annotation> annotationType() {

// can't continue without a valid http method
httpMethod = (httpMethod == null) ? parentMethod : httpMethod;
updateTagsForOperation(operation, apiOperation);
updateOperation(apiConsumes, apiProduces, tags, securities, operation);
updatePath(operationPath, httpMethod, operation);
if (httpMethod != null) {
for (Entry<String, Model> m : resultModels.entrySet()) {
swagger.model(m.getKey(), m.getValue());
}
updateTagsForOperation(operation, apiOperation);
updateOperation(apiConsumes, apiProduces, tags, securities, operation);
updatePath(operationPath, httpMethod, operation);
}
}
updateTagDescriptions(discoveredTags);
}
Expand All @@ -202,7 +210,7 @@ private List<Method> getFilteredMethods(Class<?> cls) {
/**
* Returns true when the swagger object already contains a common parameter
* with the same name and type as the passed parameter.
*
*
* @param parameter The parameter to check.
* @return true if the swagger object already contains a common parameter with the same name and type
*/
Expand Down Expand Up @@ -331,7 +339,7 @@ private String getPath(Path classLevelPath, Path methodLevelPath, String parentP
}


public Operation parseMethod(String httpMethod, Method method) {
public Operation parseMethod(String httpMethod, Method method, LinkedHashMap<String, Model> resultModels) {
int responseCode = 200;
Operation operation = new Operation();
ApiOperation apiOperation = AnnotationUtils.findAnnotation(method, ApiOperation.class);
Expand Down Expand Up @@ -392,6 +400,7 @@ public Operation parseMethod(String httpMethod, Method method) {
if (responseClassType instanceof Class) {
hasApiAnnotation = AnnotationUtils.findAnnotation((Class) responseClassType, Api.class) != null;
}

if ((responseClassType != null)
&& !responseClassType.equals(Void.class)
&& !responseClassType.equals(void.class)
Expand All @@ -417,20 +426,21 @@ public Operation parseMethod(String httpMethod, Method method) {
.schema(p)
.headers(defaultResponseHeaders));
}
for (String key : models.keySet()) {
Property responseProperty = RESPONSE_CONTAINER_CONVERTER.withResponseContainer(responseContainer, new RefProperty().asDefault(key));

for (Map.Entry<String, Model> entry : models.entrySet()) {
final String key = entry.getKey();
Property responseProperty = RESPONSE_CONTAINER_CONVERTER
.withResponseContainer(responseContainer, new RefProperty().asDefault(key));

operation.response(responseCode, new Response()
.description("successful operation")
.schema(responseProperty)
.headers(defaultResponseHeaders));
swagger.model(key, models.get(key));
resultModels.put(entry.getKey(), entry.getValue());
}
}
Map<String, Model> models = readAllModels(responseClassType);
for (Map.Entry<String, Model> entry : models.entrySet()) {
swagger.model(entry.getKey(), entry.getValue());
resultModels.put(entry.getKey(), entry.getValue());
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/test/java/com/wordnik/jaxrs/ParentResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
*/
package com.wordnik.jaxrs;

import java.sql.SQLException;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.net.ssl.SSLException;
import javax.ws.rs.Path;

/**
Expand All @@ -21,4 +25,14 @@ public class ParentResource {
public SubResource getStudyResource() {
return new SubResource();
}

// this static method and return type should not be included in the swagger as there is no Path nor Api
public static SQLException getCauseSQLException(Throwable e) {
return null;
}

// this method and return type should not be included in the swagger as there is no Path nor Api
public SSLException getCauseSSLException(Throwable e) {
return null;
}
}