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

org.continuity.commons.utils.RemoveParametersFromApplication Maven / Gradle / Ivy

package org.continuity.commons.utils;

import java.io.IOException;

import org.continuity.idpa.application.Application;
import org.continuity.idpa.application.HttpEndpoint;
import org.continuity.idpa.visitor.IdpaByClassSearcher;
import org.continuity.idpa.yaml.IdpaYamlSerializer;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;

/**
 * Can be used to remove all parameters from an application model (helpful, if the parameters were
 * transformed from a Swagger specification but never used).
 *
 * @author Henning Schulz
 *
 */
public class RemoveParametersFromApplication {

	private final String inputFile;

	public RemoveParametersFromApplication(String inputFile) {
		this.inputFile = inputFile;
	}

	public void removeParameters(String[] args) throws JsonParseException, JsonMappingException, IOException {
		IdpaYamlSerializer serializer = new IdpaYamlSerializer<>(Application.class);
		Application application = serializer.readFromYaml(inputFile);

		IdpaByClassSearcher interfaceSearcher = new IdpaByClassSearcher<>(HttpEndpoint.class, this::removeParameters);
		interfaceSearcher.visit(application);

		String newFile = inputFile.substring(0, inputFile.length() - 4) + "-wo-params.yml";
		serializer.writeToYaml(application, newFile);
	}

	private void removeParameters(HttpEndpoint interf) {
		interf.getParameters().clear();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy