All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.qdesrame.openapi.diff.utils.EndpointUtils Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
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 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