-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from dayman/master
Bugs fixing and minor improvements
- Loading branch information
Showing
17 changed files
with
521 additions
and
559 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
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
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
47 changes: 9 additions & 38 deletions
47
src/main/java/com/knappsack/swagger4springweb/parser/ApiModelParser.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 |
---|---|---|
@@ -1,55 +1,26 @@ | ||
package com.knappsack.swagger4springweb.parser; | ||
|
||
import com.knappsack.swagger4springweb.model.AnnotatedParameter; | ||
import com.knappsack.swagger4springweb.util.AnnotationUtils; | ||
import com.wordnik.swagger.converter.SwaggerSchemaConverter; | ||
import com.knappsack.swagger4springweb.util.ModelUtils; | ||
import com.wordnik.swagger.model.Model; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import scala.Option; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.lang.reflect.Type; | ||
import java.util.Map; | ||
|
||
public class ApiModelParser { | ||
|
||
public Map<String, Model> getResponseBodyModels(Method method) { | ||
Map<String, Model> documentationSchemaMap = new HashMap<String, Model>(); | ||
if(method.getAnnotation(ResponseBody.class) != null) { | ||
Class<?> returnType = method.getReturnType(); | ||
SwaggerSchemaConverter parser = new SwaggerSchemaConverter(); | ||
String schemaName; | ||
if(returnType.isArray()) { | ||
//TODO - possibly reinvestigate what we should do in the case of an array | ||
//parser = new ApiModelParser(returnType.getComponentType()); | ||
schemaName = returnType.getComponentType().getSimpleName(); | ||
} else { | ||
schemaName = returnType.getSimpleName(); | ||
} | ||
Option<Model> model = parser.read(returnType); | ||
if(model.nonEmpty()) { | ||
documentationSchemaMap.put(schemaName, model.get()); | ||
} | ||
} | ||
private final Map<String, Model> models; | ||
|
||
return documentationSchemaMap; | ||
public ApiModelParser(final Map<String, Model> models) { | ||
this.models = models; | ||
} | ||
|
||
public Map<String, Model> getParameterModels(Method method) { | ||
|
||
Map<String, Model> documentationSchemaMap = new HashMap<String, Model>(); | ||
public void parseResponseBodyModels(Method method) { | ||
if (method.getAnnotation(ResponseBody.class) != null) { | ||
Type type = method.getGenericReturnType(); | ||
|
||
List<AnnotatedParameter> annotatedParameters = AnnotationUtils.getAnnotatedParameters(method); | ||
for (AnnotatedParameter annotatedParameter : annotatedParameters) { | ||
Class<?> parameterType = annotatedParameter.getParameterType(); | ||
SwaggerSchemaConverter parser = new SwaggerSchemaConverter(); | ||
Option<Model> model = parser.read(parameterType); | ||
if(model.nonEmpty()) { | ||
documentationSchemaMap.put(parameterType.getSimpleName(), model.get()); | ||
} | ||
ModelUtils.addModels(type, models); | ||
} | ||
|
||
return documentationSchemaMap; | ||
} | ||
} |
Oops, something went wrong.