net.cpollet.maven.plugins.postman.backend.adapters.PathAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of postman-maven-plugin Show documentation
Show all versions of postman-maven-plugin Show documentation
A maven plugin to export JAX-RS annotated classes and methods to Postman collection
The newest version!
package net.cpollet.maven.plugins.postman.backend.adapters;
import lombok.AllArgsConstructor;
import javax.ws.rs.Path;
@AllArgsConstructor
public class PathAdapter {
private final Path annotation;
/**
* Returns the path, prefixed with / and not suffixed. Example: /index. If not path specified, returns an empty
* string.
*
* @return the path
*/
public String getPath() {
//noinspection ConstantConditions
if (annotation == null || annotation.value() == null) {
return "";
}
return removeTrailingSlashes(
prefixWithSlash(
annotation.value()
)
);
}
private String removeTrailingSlashes(String path) {
while (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
return path;
}
private String prefixWithSlash(String path) {
if (path.startsWith("/")) {
return path;
}
return "/" + path;
}
}