Ask a Question

Operating with REST Interfaces and Requests

Question

Create a script which posts REST Interfaces structures of a current project to a text file. Under each method, list names of functional REST Request Test Steps for this method. The format of the file is arbitrary (whatever looks more reasonable and readable for you). Example: 

https://www.screencast.com/t/WVmvALNW2Ds

 

Answer

 

def space = {num -> ' ' * num}
def stringBuilder = new StringBuilder()
project.getInterfaceList().each{p ->
	// interface name
	stringBuilder.append("${p.name}\n")
	p.getOperationList().each{m ->
		//operation name
		stringBuilder.append("${space(5)}${m.name}\n")
		m.getRequestList().each{r ->
			//http method name
			stringBuilder.append("${space(10)}${r.getMethod()}\n")
			//rest method name
			stringBuilder.append("${space(15)}${r.getRestMethod().name}\n")
			}
		}
	}

def writeToFile(def directory, def filename, def extension, def content){
		if(! content.trim().isEmpty()){
			def folder = new File(directory)
			if( ! folder.exists()) folder.mkdirs()
			new File("$directory/$filename$extension").withWriter{out ->
				out << content
			}
		}
	}
writeToFile("C:/", "project_structure", ".txt", stringBuilder.toString())

 

Version history
Last update:
‎09-28-2021 05:19 AM
Updated by:
Labels (1)
Contributors