Skip to content

Commit

Permalink
Merge pull request #4832 from jGauravGupta/FISH-48
Browse files Browse the repository at this point in the history
FISH-48 OpenAPI document failed to use Generics within @Schema
  • Loading branch information
jGauravGupta authored Aug 21, 2020
2 parents c879b92 + d927c1b commit 3f05779
Show file tree
Hide file tree
Showing 5 changed files with 456 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.function.BiFunction;
import static java.util.logging.Level.WARNING;
import java.util.logging.Logger;
Expand All @@ -67,7 +66,6 @@
import javax.ws.rs.PATCH;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
Expand All @@ -79,11 +77,9 @@
import org.eclipse.microprofile.openapi.models.PathItem.HttpMethod;
import org.eclipse.microprofile.openapi.models.media.Schema.SchemaType;
import org.eclipse.microprofile.openapi.models.parameters.Parameter.In;
import org.glassfish.hk2.classmodel.reflect.AnnotatedElement;
import org.glassfish.hk2.classmodel.reflect.AnnotationModel;
import org.glassfish.hk2.classmodel.reflect.ClassModel;
import org.glassfish.hk2.classmodel.reflect.MethodModel;
import org.glassfish.hk2.classmodel.reflect.Type;
import org.glassfish.hk2.classmodel.reflect.ParameterizedType;

public final class ModelUtils {

Expand Down Expand Up @@ -271,7 +267,7 @@ public static void removeOperation(PathItem pathItem, Operation operation) {
}
}

public static SchemaType getSchemaType(org.glassfish.hk2.classmodel.reflect.ParameterizedType type, ApiContext context) {
public static SchemaType getSchemaType(ParameterizedType type, ApiContext context) {
if(type.isArray()) {
return SchemaType.ARRAY;
} else {
Expand Down Expand Up @@ -320,6 +316,19 @@ public static SchemaType getSchemaType(String typeName, ApiContext context) {
return SchemaType.OBJECT;
}

public static boolean isMap(String typeName, ApiContext context) {
Class clazz = null;
try {
clazz = context.getApplicationClassLoader().loadClass(typeName);
} catch (Throwable app) {
try {
clazz = Class.forName(typeName);
} catch (Throwable t) {
}
}
return Map.class.isAssignableFrom(clazz);
}

/**
* Finds a {@link SchemaType} that can represent both of the given types. If one
* of the input values are null, this function returns the other. If both are
Expand Down
Loading

0 comments on commit 3f05779

Please sign in to comment.