Skip to content

Commit

Permalink
Support backward compatability with Swagger 2.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Dec 4, 2018
1 parent 56f4eb7 commit 5cdd18d
Show file tree
Hide file tree
Showing 6 changed files with 441 additions and 302 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import io.sinistral.proteus.server.ServerRequest;
import io.sinistral.proteus.server.ServerResponse;
import io.sinistral.proteus.server.endpoints.EndpointInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tags;
Expand Down Expand Up @@ -282,7 +283,7 @@ protected void addClassMethodHandlers(TypeSpec.Builder typeBuilder, Class<?> cla
.addStatement("final $T router = new $T()", io.undertow.server.RoutingHandler.class, io.undertow.server.RoutingHandler.class);

final Map<Type, String> parameterizedLiteralsNameMap = Arrays.stream(clazz.getDeclaredMethods())
.filter(m -> m.getAnnotation(Operation.class) != null)
.filter(m -> m.getAnnotation(Operation.class) != null || m.getAnnotation(ApiOperation.class) != null)
.flatMap(
m -> Arrays.stream(m.getParameters()).map(Parameter::getParameterizedType)
.filter(t -> t.getTypeName().contains("<") && !t.getTypeName().contains("concurrent")))
Expand All @@ -293,9 +294,11 @@ protected void addClassMethodHandlers(TypeSpec.Builder typeBuilder, Class<?> cla
return (handler.equals(TypeHandler.ModelType) || handler.equals(TypeHandler.OptionalModelType));

}).collect(Collectors.toMap(java.util.function.Function.identity(), HandlerGenerator::typeReferenceNameForParameterizedType));



Arrays.stream(clazz.getDeclaredMethods())
.filter(m -> m.getAnnotation(Operation.class) != null)
.filter(m -> m.getAnnotation(Operation.class) != null || m.getAnnotation(ApiOperation.class) != null)
.flatMap(m -> Arrays.stream(m.getParameters()))
.forEach(p ->
{
Expand All @@ -318,7 +321,7 @@ protected void addClassMethodHandlers(TypeSpec.Builder typeBuilder, Class<?> cla
});

final Map<Type, String> literalsNameMap = Arrays.stream(clazz.getDeclaredMethods())
.filter(m -> m.getAnnotation(Operation.class) != null)
.filter(m -> m.getAnnotation(Operation.class) != null || m.getAnnotation(ApiOperation.class) != null)
.flatMap(m -> Arrays.stream(m.getParameters())
.map(Parameter::getParameterizedType)).filter(t ->
{
Expand Down Expand Up @@ -883,7 +886,7 @@ else if (producesContentType.contains(MediaType.TEXT_HTML))
* @TODO wrap blocking in BlockingHandler
*/

if (Optional.ofNullable(m.getAnnotation(Operation.class)).isPresent())
if (Optional.ofNullable(m.getAnnotation(Operation.class)).isPresent() || Optional.ofNullable(m.getAnnotation(ApiOperation.class)).isPresent())
{
SecurityRequirement securityRequirementAnnotation = m.getAnnotation(SecurityRequirement.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Enum that assists in code generation for different method parameter types
*/


public enum TypeHandler
{

Expand Down Expand Up @@ -254,6 +255,10 @@ public static void addStatement(MethodSpec.Builder builder, Parameter parameter)

TypeHandler handler = TypeHandler.forType(parameter.getParameterizedType(), isBeanParameter);

// if(handler.equals(TypeHandler.ModelType))
// {
// HandlerGenerator.log.warn("found modeltype for " + parameter.getParameterizedType());
// }
addStatement(builder, parameter, handler);

}
Expand Down
Loading

0 comments on commit 5cdd18d

Please sign in to comment.