2023-12-25 17:15:42 +01:00
|
|
|
package stirling.software.SPDF.model;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
2023-12-25 17:16:50 +01:00
|
|
|
import java.util.Map;
|
|
|
|
|
2023-12-25 17:15:42 +01:00
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
|
|
|
|
public class ApiEndpoint {
|
|
|
|
private String name;
|
|
|
|
private Map<String, JsonNode> parameters;
|
2023-12-28 18:23:19 +01:00
|
|
|
private String description;
|
2023-12-30 20:11:27 +01:00
|
|
|
|
2023-12-25 17:15:42 +01:00
|
|
|
public ApiEndpoint(String name, JsonNode postNode) {
|
|
|
|
this.name = name;
|
|
|
|
this.parameters = new HashMap<>();
|
|
|
|
postNode.path("parameters")
|
|
|
|
.forEach(
|
|
|
|
paramNode -> {
|
|
|
|
String paramName = paramNode.path("name").asText();
|
|
|
|
parameters.put(paramName, paramNode);
|
|
|
|
});
|
2023-12-28 18:23:19 +01:00
|
|
|
this.description = postNode.path("description").asText();
|
2023-12-25 17:15:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean areParametersValid(Map<String, Object> providedParams) {
|
|
|
|
for (String requiredParam : parameters.keySet()) {
|
|
|
|
if (!providedParams.containsKey(requiredParam)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2023-12-25 21:51:32 +01:00
|
|
|
|
2023-12-28 18:23:19 +01:00
|
|
|
public String getDescription() {
|
|
|
|
return description;
|
|
|
|
}
|
2023-12-30 20:11:27 +01:00
|
|
|
|
2023-12-25 21:51:32 +01:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "ApiEndpoint [name=" + name + ", parameters=" + parameters + "]";
|
|
|
|
}
|
2023-12-25 17:15:42 +01:00
|
|
|
}
|