Permalink
Browse files

Merge pull request #23 from EMResearch/master-update

add function to remove duplicated params
  • Loading branch information...
arcuri82 committed Dec 20, 2018
2 parents 3181d80 + 5b95e91 commit 1f61f852e0585c655445475bd9c8881b302f5791
@@ -3,6 +3,7 @@ package org.evomaster.core.problem.rest
import io.swagger.models.*
import io.swagger.models.parameters.AbstractSerializableParameter
import io.swagger.models.parameters.BodyParameter
import io.swagger.models.parameters.Parameter
import io.swagger.models.properties.*
import org.evomaster.core.LoggingUtil
import org.evomaster.core.problem.rest.param.*
@@ -120,7 +121,8 @@ class RestActionBuilder {
val params: MutableList<Param> = mutableListOf()
val operation = opEntry.value

operation.parameters.forEach { p ->
removeDuplicatedParams(operation.parameters)
.forEach { p ->

val name = p.name ?: "undefined"

@@ -449,6 +451,8 @@ class RestActionBuilder {

throw IllegalArgumentException("Cannot handle combination $type/$format")
}

private fun removeDuplicatedParams(params : List<Parameter>) : List<Parameter>{
return params.distinctBy { it.name}
}
}
}
@@ -95,4 +95,12 @@ internal class RestActionBuilderTest {
assertEquals(2, a.parameters.size)
assertEquals(2, a.parameters.filter { p -> p is FormParam }.size)
}

@Test
fun testDuplicatedParamsInFeaturesServices() {
val actions = loadAndAssertActions("/swagger/features_service.json", 18)
(actions["POST:/products/{productName}/configurations/{configurationName}/features/{featureName}"] as RestCallAction).apply {
assertEquals(3, parameters.size)
}
}
}

0 comments on commit 1f61f85

Please sign in to comment.