Permalink
Browse files

add function to remove duplicated params

add a test for it
  • Loading branch information...
ZhangMan1126 committed Dec 20, 2018
1 parent c71c0c2 commit 5b95e91bb7112d6a110a22b2dbc05334e083154d
@@ -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 5b95e91

Please sign in to comment.