Skip to content

Commit

Permalink
Use included JSON and YAML mappers in the Swagger service. Improves s…
Browse files Browse the repository at this point in the history
…pec compatibility. Minor cleanup.
  • Loading branch information
noboomu committed Dec 12, 2018
1 parent 559a7d3 commit cb6afd9
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 178 deletions.
5 changes: 2 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.sinistral</groupId>
<artifactId>proteus-core</artifactId>
<version>0.3.6</version>
<version>0.3.7-SNAPSHOT</version>
<name>proteus core</name>
<description>Proteus is an extremely light, fast, and flexible Java REST API framework built atop Undertow.</description>
<url>http://github.com/noboomu/proteus</url>
Expand All @@ -19,7 +19,7 @@
<developers>
<developer>
<name>Joshua Lee Bauer</name>
<email>[email protected]</email>
<email>[email protected]</email>
</developer>
</developers>

Expand Down Expand Up @@ -178,7 +178,6 @@
<configuration>
<source>1.8</source>
<target>1.8</target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compilerArgument>-parameters</compilerArgument>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ protected void addClassMethodHandlers(TypeSpec.Builder typeBuilder, Class<?> cla

String controllerName = clazz.getSimpleName().toLowerCase() + "Controller";

Integer handlerWrapperIndex = 1;
int handlerWrapperIndex = 1;

HashSet<String> handlerNameSet = new HashSet<>();

Expand Down Expand Up @@ -533,7 +533,7 @@ else if (t.equals(HttpServerExchange.class) || t.equals(ServerRequest.class))
endpointInfo.setControllerMethod(m.getName());

String handlerName = String.format("%c%s%sHandler_%s", Character.toLowerCase(clazz.getSimpleName().charAt(0)), clazz.getSimpleName()
.substring(1, clazz.getSimpleName().length()), StringUtils.capitalize(m.getName()), String.valueOf(nameIndex++));
.substring(1), StringUtils.capitalize(m.getName()), String.valueOf(nameIndex++));

handlerNameSet.add(handlerName);

Expand Down Expand Up @@ -603,15 +603,11 @@ else if (t.equals(HttpServerExchange.class) || t.equals(ServerRequest.class))
methodBuilder.addStatement("$T $L = new $T(exchange)", ServerRequest.class, p.getName(), ServerRequest.class);

}
else if (p.getType().equals(HttpServerExchange.class))
{
// methodBuilder.addCode("$L", "\n");
}
else if (p.getType().equals(HttpHandler.class))
{
methodBuilder.addStatement("$T $L = this", HttpHandler.class, p.getName());
}
else
else if(!p.getType().equals(HttpServerExchange.class))
{
if (p.isAnnotationPresent(HeaderParam.class))
{
Expand Down Expand Up @@ -679,7 +675,7 @@ else if (handler.equals(TypeHandler.FromStringType))

String typeName = type.getTypeName();

if (typeName.indexOf("$") > -1)
if (typeName.contains("$"))
{
typeName = typeName.replace("$", ".");
}
Expand All @@ -695,7 +691,7 @@ else if (t.equals(TypeHandler.BeanListFromStringType) || t.equals(TypeHandler.Be

String typeName = type.getTypeName();

if (typeName.indexOf("$") > -1)
if (typeName.contains("$"))
{
typeName = typeName.replace("$", ".");
}
Expand All @@ -712,8 +708,8 @@ else if (t.equals(TypeHandler.OptionalFromStringType) || t.equals(TypeHandler.Op
}
else if (t.equals(TypeHandler.QueryOptionalListFromStringType)
|| t.equals(TypeHandler.QueryOptionalListValueOfType)
|| t.equals(TypeHandler.QueryOptionalSetValueOfType)
|| t.equals(TypeHandler.QueryOptionalSetValueOfType))
|| t.equals(TypeHandler.QueryOptionalSetValueOfType)
|| t.equals(TypeHandler.QueryOptionalSetFromStringType))
{
ParameterizedType pType = (ParameterizedType) type;

Expand Down Expand Up @@ -920,12 +916,10 @@ else if( isDebug )
{
io.sinistral.proteus.annotations.Chain w = wrapAnnotation.get();

Class<? extends HandlerWrapper> wrapperClasses[] = w.value();
Class<? extends HandlerWrapper>[] wrapperClasses = w.value();

for (int i = 0; i < wrapperClasses.length; i++)
for(Class<? extends HandlerWrapper> wrapperClass : wrapperClasses)
{
Class<? extends HandlerWrapper> wrapperClass = wrapperClasses[i];

String wrapperName = typeLevelHandlerWrapperMap.get(wrapperClass);

if (wrapperName == null)
Expand Down Expand Up @@ -1057,7 +1051,7 @@ protected static Set<Class<?>> getApiClasses(String basePath, Predicate<String>

}

protected static Type extractErasedType(Type type) throws Exception
protected static Type extractErasedType(Type type)
{
String typeName = type.getTypeName();

Expand Down Expand Up @@ -1097,36 +1091,24 @@ protected static Type extractErasedType(Type type) throws Exception
}
else if (matches > 2)
{

String erasedType = matcher.group(3);

String clearDollarType = erasedType.replaceAll("\\$", ".");

try
{
Class<?> clazz = Class.forName(clearDollarType);
return clazz;

return Class.forName(clearDollarType);
} catch (Exception e1)
{
try
{
Class<?> clazz = Class.forName(erasedType);

return clazz;

return Class.forName(erasedType);
} catch (Exception e2)
{
return type;
}
}

}

}
else
{
// log.warn("No type found for " + typeName);
}

return null;
Expand Down Expand Up @@ -1154,9 +1136,6 @@ protected static String typeReferenceNameForParameterizedType(Type type)
String genericInterface = matcher.group(1);
String erasedType = matcher.group(2).replaceAll("\\$", ".");

// log.debug("genericInterface: " + genericInterface);
// log.debug("erasedType: " + erasedType);

String[] genericParts = genericInterface.split("\\.");
String[] erasedParts = erasedType.split("\\.");

Expand Down Expand Up @@ -1191,9 +1170,6 @@ protected static String typeReferenceNameForParameterizedType(Type type)
String genericInterface = matcher.group(1);
String erasedType = matcher.group(2).replaceAll("\\$", ".");

// log.debug("genericInterface: " + genericInterface);
// log.debug("erasedType: " + erasedType);

String[] genericParts = genericInterface.split("\\.");
String[] erasedParts = erasedType.split("\\.");

Expand Down Expand Up @@ -1281,12 +1257,12 @@ protected static void generateParameterReference(MethodSpec.Builder builder, Cla

protected static boolean hasValueOfMethod(Class<?> clazz)
{
return Arrays.stream(clazz.getMethods()).filter(m -> m.getName().equals("valueOf")).findFirst().isPresent();
return Arrays.stream(clazz.getMethods()).anyMatch(m -> m.getName().equals("valueOf"));
}

protected static boolean hasFromStringMethod(Class<?> clazz)
{
return Arrays.stream(clazz.getMethods()).filter(m -> m.getName().equals("fromString")).findFirst().isPresent();
return Arrays.stream(clazz.getMethods()).anyMatch(m -> m.getName().equals("fromString"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public Swagger read(Set<Class<?>> classes) {
}

for (Class<?> cls : sortedClasses) {
read(cls, "", null, false, new String[0], new String[0], new LinkedHashMap<String, Tag>(), new ArrayList<Parameter>(), new HashSet<>());
read(cls, "", null, false, new String[0], new String[0], new LinkedHashMap<>(), new ArrayList<>(), new HashSet<>());
}

// for (ReaderListener listener : listeners.values()) {
Expand All @@ -199,7 +199,7 @@ public Swagger read(Class<?> cls) {
readSwaggerConfig(cls, swaggerDefinition);
}

return read(cls, "", null, false, new String[0], new String[0], new LinkedHashMap<String, Tag>(), new ArrayList<Parameter>(), new HashSet<>());
return read(cls, "", null, false, new String[0], new String[0], new LinkedHashMap<>(), new ArrayList<>(), new HashSet<>());
}

protected Swagger read(Class<?> cls, String parentPath, String parentMethod, boolean isSubresource, String[] parentConsumes, String[] parentProduces, Map<String, Tag> parentTags, List<Parameter> parentParameters) {
Expand All @@ -209,10 +209,10 @@ protected Swagger read(Class<?> cls, String parentPath, String parentMethod, boo
@SuppressWarnings("deprecation")
private Swagger read(Class<?> cls, String parentPath, String parentMethod, boolean isSubresource, String[] parentConsumes, String[] parentProduces, Map<String, Tag> parentTags, List<Parameter> parentParameters, Set<Class<?>> scannedResources) {

Map<String, Tag> tags = new TreeMap<String, Tag>();
Map<String, Tag> tags = new TreeMap<>();


List<SecurityRequirement> securities = new ArrayList<SecurityRequirement>();
List<SecurityRequirement> securities = new ArrayList<>();

String[] consumes = new String[0];
String[] produces = new String[0];
Expand Down Expand Up @@ -815,7 +815,7 @@ private Map<String, Property> parseResponseHeaders(ResponseHeader[] headers) {
String name = header.name();
if (!"".equals(name)) {
if (responseHeaders == null) {
responseHeaders = new LinkedHashMap<String, Property>();
responseHeaders = new LinkedHashMap<>();
}
String description = header.description();
Class<?> cls = header.response();
Expand Down Expand Up @@ -873,7 +873,7 @@ private Operation parseMethod(Class<?> cls, Method method, AnnotatedMethod annot
operationId = this.getOperationId(method.getName());
}

String responseContainer = null;
String responseContainer = null;

Type responseType = null;
Map<String, Property> defaultResponseHeaders = new LinkedHashMap<String, Property>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ public AssetsService()
{
}

@Override
protected void shutDown() throws Exception
{
super.shutDown();
}

@Override
protected void startUp() throws Exception
{
Expand Down
Loading

0 comments on commit cb6afd9

Please sign in to comment.