
com.qdesrame.openapi.diff.utils.EndpointUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openapi-diff Show documentation
Show all versions of openapi-diff Show documentation
Utility for comparing two OpenAPI specifications.
package com.qdesrame.openapi.diff.utils;
import com.qdesrame.openapi.diff.model.Endpoint;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.PathItem;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* Created by adarsh.sharma on 26/12/17.
*/
public class EndpointUtils {
public static Collection extends Endpoint> convert2Endpoints(String pathUrl,
Map map) {
List endpoints = new ArrayList();
if (null == map) return endpoints;
for (Map.Entry entry : map.entrySet()) {
PathItem.HttpMethod httpMethod = entry.getKey();
Operation operation = entry.getValue();
Endpoint endpoint = convert2Endpoint(pathUrl, httpMethod, operation);
endpoints.add(endpoint);
}
return endpoints;
}
public static Endpoint convert2Endpoint(String pathUrl, PathItem.HttpMethod httpMethod, Operation operation) {
Endpoint endpoint = new Endpoint();
endpoint.setPathUrl(pathUrl);
endpoint.setMethod(httpMethod);
endpoint.setSummary(operation.getSummary());
endpoint.setOperation(operation);
return endpoint;
}
public static List convert2EndpointList(Map map) {
List endpoints = new ArrayList<>();
if (null == map) return endpoints;
for (Map.Entry entry : map.entrySet()) {
String url = entry.getKey();
PathItem path = entry.getValue();
Map operationMap = path.readOperationsMap();
for (Map.Entry entryOper : operationMap.entrySet()) {
PathItem.HttpMethod httpMethod = entryOper.getKey();
Operation operation = entryOper.getValue();
Endpoint endpoint = new Endpoint();
endpoint.setPathUrl(url);
endpoint.setMethod(httpMethod);
endpoint.setSummary(operation.getSummary());
endpoint.setPath(path);
endpoint.setOperation(operation);
endpoints.add(endpoint);
}
}
return endpoints;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy