Skip to content

Commit 58af5a3

Browse files
committed
final update
1 parent b7af282 commit 58af5a3

3 files changed

Lines changed: 52 additions & 18 deletions

File tree

core/src/main/kotlin/org/evomaster/core/problem/api/param/Param.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,26 @@ abstract class Param(
99
val genes : MutableList<Gene>
1010
) : StructuralElement(genes){
1111

12+
/**
13+
* Contains the description of the parameter.
14+
*/
15+
var description: String? = null
16+
set(value) {
17+
if (!value.isNullOrEmpty() && field.isNullOrEmpty()) {
18+
field = value
19+
}
20+
}
21+
1222
//TODO need refactoring. eg shared abstract class for cases in which only 1 gene for sure
1323
@Deprecated("Assumes there is only 1 gene. Rather use primaryGene()")
1424
val gene : Gene = genes[0]
1525

1626
/**
1727
* Return the most important gene defining this parameter.
18-
* This is parameter type dependent.
28+
* This is parameter-type-dependent.
1929
* Note that a parameter could have more than 1 gene.
2030
* For example, a body param could have a gene for the object, and one for its
21-
* representation (eg, JSON vs XML)
31+
* representation (e.g., JSON vs. XML)
2232
*/
2333
open fun primaryGene() = genes[0] //can be overridden if needed
2434

@@ -34,6 +44,7 @@ abstract class Param(
3444
val copy = super.copy()
3545
if (copy !is Param)
3646
throw IllegalStateException("mismatched type: the type should be Param, but it is ${this::class.java.simpleName}")
47+
copy.description = description
3748
return copy as Param
3849
}
3950

@@ -43,4 +54,4 @@ abstract class Param(
4354
override fun copyContent(): Param {
4455
throw IllegalStateException("${this::class.java.simpleName}: copyContent() IS NOT IMPLEMENTED")
4556
}
46-
}
57+
}

core/src/main/kotlin/org/evomaster/core/problem/rest/builder/RestActionBuilderV3.kt

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,10 @@ object RestActionBuilderV3 {
492492
null
493493
}
494494
} ?: listOf()
495+
495496
val action = RestCallAction(actionId, verb, restPath, params, produces = produces,
496-
operationId = operation.operationId, links = links)
497+
operationId = operation.operationId, links = links
498+
)
497499

498500
//TODO update for new parser
499501
// /*This section collects information regarding the types of data that are
@@ -591,6 +593,7 @@ object RestActionBuilderV3 {
591593
messages: MutableList<String>
592594
) {
593595
val name = p.name ?: "undefined"
596+
val description = p.description
594597

595598
if(p.schema == null){
596599
messages.add("No schema definition for parameter $name")
@@ -621,16 +624,14 @@ object RestActionBuilderV3 {
621624
}
622625

623626
when (p.`in`) {
624-
625-
"query" -> {
626-
params.add(QueryParam(name, gene, p.explode ?: true, p.style ?: Parameter.StyleEnum.FORM))
627-
}
627+
"query" -> params.add(QueryParam(name, gene, p.explode ?: true, p.style ?: Parameter.StyleEnum.FORM)
628+
.apply { this.description = description })
628629
/*
629630
a path is inside a Disruptive Gene, because there are cases in which we want to prevent
630631
mutation. Note that 1.0 means can always be mutated
631632
*/
632633
"path" -> params.add(PathParam(name, CustomMutationRateGene("d_", gene, 1.0)))
633-
"header" -> params.add(HeaderParam(name, gene))
634+
"header" -> params.add(HeaderParam(name, gene).apply { this.description = description })
634635
"cookie" -> params // do nothing?
635636
//TODO "cookie" does it need any special treatment? as anyway handled in auth configs
636637
else -> throw IllegalStateException("Unrecognized: ${p.getIn()}")
@@ -706,6 +707,7 @@ object RestActionBuilderV3 {
706707
}
707708

708709
val name = "body"
710+
val description = operation.description ?: null
709711

710712
val bodies = resolvedBody.content?.filter {
711713
/*
@@ -752,6 +754,8 @@ object RestActionBuilderV3 {
752754

753755
val contentTypeGene = EnumGene<String>("contentType", bodies.keys)
754756
val bodyParam = BodyParam(gene, contentTypeGene)
757+
.apply { this.description = description }
758+
755759
val ns = bodyParam.notSupportedContentTypes
756760
if(ns.isNotEmpty()){
757761
messages.add("Not supported content types for body payload in $verb:$restPath : ${ns.joinToString()}")
@@ -810,17 +814,22 @@ object RestActionBuilderV3 {
810814
if (schema.enum?.isNotEmpty() == true) {
811815

812816
when (type) {
813-
"string" ->
817+
"string" -> {
814818
return EnumGene(name, (schema.enum.map {
815819
if (it !is String)
816-
LoggingUtil.uniqueWarn(log, "an item of enum is not string (ie, ${it::class.java.simpleName}) for a property whose `type` is string and `name` is $name")
820+
LoggingUtil.uniqueWarn(
821+
log,
822+
"an item of enum is not string (ie, ${it::class.java.simpleName}) for a property whose `type` is string and `name` is $name"
823+
)
817824
it.toString()
818825
} as MutableList<String>).apply {
819-
if(options.invalidData) {
826+
if (options.invalidData) {
820827
//Besides the defined values, add one to test robustness
821828
add("EVOMASTER")
822829
}
823830
})
831+
.apply { this.description = schema.description }
832+
}
824833
/*
825834
Looks like a possible bug in the parser, where numeric enums can be read as strings... got this
826835
issue in GitLab schemas, eg for visibility_level
@@ -1509,6 +1518,8 @@ object RestActionBuilderV3 {
15091518
else -> throw IllegalStateException("cannot create gene with constraints for gene:${geneClass.name}")
15101519
}
15111520

1521+
mainGene.description = schema.description
1522+
15121523
/*
15131524
See:
15141525
https://swagger.io/docs/specification/adding-examples/
@@ -1668,6 +1679,7 @@ object RestActionBuilderV3 {
16681679
minLength = max(defaultMin, if (options.enableConstraintHandling) schema.minLength ?: 0 else 0),
16691680
invalidChars = if(isInPath) listOf('/','.') else listOf()
16701681
)
1682+
.apply { this.description = schema.description }
16711683
}
16721684

16731685
private fun createObjectFromReference(name: String,

core/src/main/kotlin/org/evomaster/core/search/gene/Gene.kt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import org.evomaster.core.search.service.monitor.ProcessMonitorExcludeField
5050
abstract class Gene(
5151
/**
5252
* The name for this gene, mainly needed for debugging.
53-
* One actual use is for binding, e.g., paremeters in HTTP requests
53+
* One actual use is for binding, e.g., parameters in HTTP requests
5454
*/
5555
var name: String,
5656
/**
@@ -77,6 +77,17 @@ abstract class Gene(
7777
private val log: Logger = LoggerFactory.getLogger(Gene::class.java)
7878
}
7979

80+
/**
81+
* Description about the gene.
82+
*/
83+
var description: String? = null
84+
set(value) {
85+
if (!value.isNullOrEmpty() && field.isNullOrEmpty()) {
86+
field = value
87+
}
88+
}
89+
90+
8091
/**
8192
* Whether this gene has been initialized, and can be used.
8293
* Note that gene can have validity constraints, and those might not be satisfied
@@ -93,7 +104,7 @@ abstract class Gene(
93104
* The type can be different, eg strings vs numbers, but still consistent.
94105
*
95106
* WARNING: genes are mutable, but here we check for references. this implies
96-
* NO gene can overridde hashcode.
107+
* NO gene can override hashcode.
97108
*
98109
* If A is bound to B, then as well B is bound to A.
99110
* If [this] is A, then binding genes will contain only B, and the binding genes of B
@@ -130,7 +141,6 @@ abstract class Gene(
130141
throw IllegalStateException("Trying to use a gene that is not initialized")
131142
}
132143

133-
134144
/**
135145
* Return all direct children of this gene.
136146
* Note that a gene can only have genes inside, and not other types of structural elements.
@@ -250,6 +260,7 @@ abstract class Gene(
250260
if (copy !is Gene)
251261
throw IllegalStateException("mismatched type: the type should be Gene, but it is ${this::class.java.simpleName}")
252262
copy.initialized = initialized
263+
copy.description = description
253264
//this was incorrect, as subchildren might had different init state compared to this
254265
//copy.flatView().forEach{it.initialized = initialized}
255266
return copy
@@ -269,7 +280,7 @@ abstract class Gene(
269280
a gene can refer to other genes outside of its tree.
270281
when we make a copy we need to make sure that we refer to the new gene in the copied
271282
individual, not the original individual.
272-
so, this is applied only when the root is an individual, otherswise skipped, because
283+
so, this is applied only when the root is an individual, otherwise skipped, because
273284
would not be able to find those genes anyway
274285
*/
275286
val postBinding = (original as Gene).bindingGenes.map { b ->
@@ -531,7 +542,7 @@ abstract class Gene(
531542
* can be mutated, the choice is based with different strategies
532543
*
533544
* @param randomness the source of non-determinism
534-
* @param apc adatpive parameter control singleton
545+
* @param apc adaptive parameter control singleton
535546
* @param mwc mutation weight control
536547
* @param interalGeneSelectionStrategy a strategy to select internal genes to mutate.
537548
* In hypermutation, several genes could be mutated at same time.
@@ -1084,7 +1095,7 @@ abstract class Gene(
10841095

10851096

10861097
/**
1087-
* here `valid` means that 1) [updateValue] performs correctly, ie, returns true AND 2) isLocallyValid is true
1098+
* here `valid` means that 1) [updateValue] performs correctly, i.e., returns true AND 2) isLocallyValid is true
10881099
*
10891100
* @param updateValue lambda performs update of value of the gene
10901101
* @param undoIfUpdateFails represents whether it needs to undo the value update if [undoIfUpdateFails] returns false

0 commit comments

Comments
 (0)