Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove compile dependency on javax.ws.rs-api and javax.servlet-api #171

Merged
merged 3 commits into from
Oct 2, 2024
Merged
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
2 changes: 2 additions & 0 deletions openapi-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,13 @@
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${javax-ws-rs-api.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax.servlet-api.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.github.kbuntrock.utils.OpenApiDataType;
import io.github.kbuntrock.utils.OpenApiTypeResolver;
import io.github.kbuntrock.utils.ParameterLocation;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.lang.reflect.Type;
Expand All @@ -22,7 +23,6 @@
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import javax.validation.constraints.NotNull;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.reflect.MethodUtils;
Expand Down Expand Up @@ -168,7 +168,7 @@ protected List<ParameterObject> readParameters(final Method originalMethod, fina
}
parameters.putIfAbsent(paramObj.getName(), paramObj);

final MergedAnnotation<NotNull> notnullMA = mergedAnnotations.get(NotNull.class);
final MergedAnnotation<Annotation> notnullMA = mergedAnnotations.get("javax.validation.constraints.NotNull");
// Detect if required
if(notnullMA.isPresent()) {
paramObj.setRequired(notnullMA.isPresent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import javax.validation.constraints.NotNull;
import javax.ws.rs.BeanParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.reflect.MethodUtils;
Expand Down Expand Up @@ -85,7 +78,7 @@ private void initCustomResponseAnnotation(final ApiConfiguration apiConfiguratio
@Override
public List<String> readBasePaths(final Class<?> clazz, final MergedAnnotations mergedAnnotations) {
List<String> basePaths = Collections.singletonList("");
final MergedAnnotation<Path> requestMappingMergedAnnotation = mergedAnnotations.get(Path.class);
final MergedAnnotation<Annotation> requestMappingMergedAnnotation = mergedAnnotations.get("javax.ws.rs.Path");
if(requestMappingMergedAnnotation.isPresent()) {
final String path = requestMappingMergedAnnotation.getString("value");
if(!StringUtils.isEmpty(path)) {
Expand All @@ -99,13 +92,13 @@ public List<String> readBasePaths(final Class<?> clazz, final MergedAnnotations
public void computeAnnotations(final String basePath, final Method method, final MergedAnnotations mergedAnnotations, final Tag tag,
final ClassGenericityResolver genericityResolver) throws MojoFailureException {

final MergedAnnotation<Path> requestMappingMergedAnnotation = mergedAnnotations.get(Path.class);
final MergedAnnotation<Annotation> requestMappingMergedAnnotation = mergedAnnotations.get("javax.ws.rs.Path");
if(requestMappingMergedAnnotation.isPresent()) {

genericityResolver.initForMethod(method);

for(final JavaxRsHttpVerb verb : JavaxRsHttpVerb.values()) {
final MergedAnnotation m = mergedAnnotations.get(verb.getAnnotationClass());
final MergedAnnotation<Annotation> m = mergedAnnotations.get(verb.getAnnotationClass());
if(m.isPresent()) {
final String methodIdentifier = JavaClassAnalyser.createIdentifier(method);
final List<ParameterObject> parameterObjects = readParameters(method, genericityResolver);
Expand Down Expand Up @@ -157,12 +150,12 @@ protected List<ParameterObject> readParameters(final Method originalMethod, fina
final MergedAnnotations mergedAnnotations = MergedAnnotations.from(parameter,
MergedAnnotations.SearchStrategy.TYPE_HIERARCHY);

if(mergedAnnotations.get(BeanParam.class).isPresent()) {
if(mergedAnnotations.get("javax.ws.rs.BeanParam").isPresent()) {
continue;
}
parameters.putIfAbsent(paramObj.getName(), paramObj);

final MergedAnnotation<NotNull> notnullMA = mergedAnnotations.get(NotNull.class);
final MergedAnnotation<Annotation> notnullMA = mergedAnnotations.get("javax.validation.constraints.NotNull");
// Detect if required
if(notnullMA.isPresent()) {
paramObj.setRequired(notnullMA.isPresent());
Expand All @@ -171,7 +164,7 @@ protected List<ParameterObject> readParameters(final Method originalMethod, fina
}

// Detect if is a path variable
final MergedAnnotation<PathParam> pathVariableMA = mergedAnnotations.get(PathParam.class);
final MergedAnnotation<Annotation> pathVariableMA = mergedAnnotations.get("javax.ws.rs.PathParam");
if(pathVariableMA.isPresent()) {
paramObj.setLocation(ParameterLocation.PATH);
// Path params are required
Expand All @@ -185,7 +178,7 @@ protected List<ParameterObject> readParameters(final Method originalMethod, fina
}

// Detect if is a query variable
final MergedAnnotation<QueryParam> requestParamMA = mergedAnnotations.get(QueryParam.class);
final MergedAnnotation<Annotation> requestParamMA = mergedAnnotations.get("javax.ws.rs.QueryParam");
if(requestParamMA.isPresent()) {

final boolean isMultipartFile = MultipartFile.class == paramObj.getJavaClass() ||
Expand Down Expand Up @@ -237,8 +230,8 @@ protected List<String> readEndpointPaths(final String basePath, final MergedAnno
@Override
protected void setConsumeProduceProperties(final Endpoint endpoint, final MergedAnnotations mergedAnnotations)
throws MojoFailureException {
final MergedAnnotation<Consumes> consumesMergedAnnotation = mergedAnnotations.get(Consumes.class);
final MergedAnnotation<Produces> producesMergedAnnotation = mergedAnnotations.get(Produces.class);
final MergedAnnotation<Annotation> consumesMergedAnnotation = mergedAnnotations.get("javax.ws.rs.Consumes");
final MergedAnnotation<Annotation> producesMergedAnnotation = mergedAnnotations.get("javax.ws.rs.Produces");

final Optional<ParameterObject> body = endpoint.getParameters().stream().filter(x -> ParameterLocation.BODY == x.getLocation())
.findAny();
Expand All @@ -262,21 +255,21 @@ protected int readResponseCode(final MergedAnnotations mergedAnnotations) {
}

private enum JavaxRsHttpVerb {
GET(javax.ws.rs.GET.class),
PUT(javax.ws.rs.PUT.class),
POST(javax.ws.rs.POST.class),
DELETE(javax.ws.rs.DELETE.class),
PATCH(javax.ws.rs.PATCH.class),
OPTIONS(javax.ws.rs.OPTIONS.class),
HEAD(javax.ws.rs.HEAD.class);
GET("javax.ws.rs.GET"),
PUT("javax.ws.rs.PUT"),
POST("javax.ws.rs.POST"),
DELETE("javax.ws.rs.DELETE"),
PATCH("javax.ws.rs.PATCH"),
OPTIONS("javax.ws.rs.OPTIONS"),
HEAD("javax.ws.rs.HEAD");

private final Class annotationClass;
private final String annotationClass;

JavaxRsHttpVerb(final Class annotationClass) {
JavaxRsHttpVerb(final String annotationClass) {
this.annotationClass = annotationClass;
}

public Class getAnnotationClass() {
public String getAnnotationClass() {
return annotationClass;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import org.springframework.web.bind.annotation.RequestMethod;

public enum OperationType {
GET(RequestMethod.GET, javax.ws.rs.GET.class, "jakarta.ws.rs.GET"),
POST(RequestMethod.POST, javax.ws.rs.POST.class, "jakarta.ws.rs.POST"),
PUT(RequestMethod.PUT, javax.ws.rs.PUT.class, "jakarta.ws.rs.PUT"),
PATCH(RequestMethod.PATCH, javax.ws.rs.PATCH.class, "jakarta.ws.rs.PATCH"),
DELETE(RequestMethod.DELETE, javax.ws.rs.DELETE.class, "jakarta.ws.rs.DELETE"),
HEAD(RequestMethod.HEAD, javax.ws.rs.HEAD.class, "jakarta.ws.rs.HEAD"),
OPTIONS(RequestMethod.OPTIONS, javax.ws.rs.OPTIONS.class, "jakarta.ws.rs.OPTIONS"),
GET(RequestMethod.GET, "javax.ws.rs.GET", "jakarta.ws.rs.GET"),
POST(RequestMethod.POST, "javax.ws.rs.POST", "jakarta.ws.rs.POST"),
PUT(RequestMethod.PUT, "javax.ws.rs.PUT", "jakarta.ws.rs.PUT"),
PATCH(RequestMethod.PATCH, "javax.ws.rs.PATCH", "jakarta.ws.rs.PATCH"),
DELETE(RequestMethod.DELETE, "javax.ws.rs.DELETE", "jakarta.ws.rs.DELETE"),
HEAD(RequestMethod.HEAD, "javax.ws.rs.HEAD", "jakarta.ws.rs.HEAD"),
OPTIONS(RequestMethod.OPTIONS, "javax.ws.rs.OPTIONS", "jakarta.ws.rs.OPTIONS"),
TRACE(RequestMethod.TRACE, null, null);

private static final Map<RequestMethod, OperationType> mapBySpringMvcRequestMethod = new HashMap<>();
private static final Map<Class, OperationType> mapByJavaxRsAnnotationClass = new HashMap<>();
private static final Map<String, OperationType> mapByJavaxRsAnnotationClass = new HashMap<>();
private static final Map<String, OperationType> mapByJakartaRsAnnotationClass = new HashMap<>();

static {
Expand All @@ -27,10 +27,10 @@ public enum OperationType {
}

private final RequestMethod springMvcRequestMethod;
private final Class javaxRsVerbAnnotation;
private final String javaxRsVerbAnnotation;
private final String jakartaRsVerbAnnotation;

OperationType(final RequestMethod springMvcRequestMethod, final Class javaxRsVerbAnnotation,
OperationType(final RequestMethod springMvcRequestMethod, final String javaxRsVerbAnnotation,
final String jakartaRsVerbAnnotation) {
this.springMvcRequestMethod = springMvcRequestMethod;
this.javaxRsVerbAnnotation = javaxRsVerbAnnotation;
Expand All @@ -41,7 +41,7 @@ public static OperationType fromJavax(final RequestMethod springMvcRequestMethod
return mapBySpringMvcRequestMethod.get(springMvcRequestMethod);
}

public static OperationType fromJavax(final Class javaxRsVerbAnnotation) {
public static OperationType fromJavax(final String javaxRsVerbAnnotation) {
return mapByJavaxRsAnnotationClass.get(javaxRsVerbAnnotation);
}

Expand Down