Skip to content

Swagger Description inside Param extension for Security #1179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 48 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
237b8f0
basic changes to adopt descriptions
seran Feb 24, 2025
d114ba6
exp
seran Feb 25, 2025
eddf461
reverted
seran Feb 25, 2025
1a71239
clean-up
seran Feb 25, 2025
3d1eab9
fixing a stupid mistake
seran Feb 25, 2025
a9c63cf
helper class
seran Feb 26, 2025
25bc4b6
Merge branch 'master' into rest-action-ext
seran Feb 26, 2025
903bf02
changes to Param
seran Feb 27, 2025
e5cdb17
description to Param in RestActionBuilderV3
seran Feb 27, 2025
3c06591
clean-up
seran Feb 27, 2025
6fb1f21
clean-up
seran Feb 27, 2025
a5e272a
minor change
seran Mar 3, 2025
8ed0e8f
Merge branch 'master' into rest-action-ext
seran Mar 10, 2025
9917957
Merge branch 'master' into rest-action-ext
seran Mar 11, 2025
a78ee34
try to find missing description in results
seran Mar 11, 2025
baa8cf3
Merge branch 'master' into rest-action-ext
seran Mar 12, 2025
69cb61f
description field in gene
seran Mar 13, 2025
66d14d6
working: header description
seran Mar 13, 2025
87f3194
Merge branch 'master' into rest-action-ext
seran Mar 19, 2025
401363d
exp with gene description
seran Mar 19, 2025
8ba5741
null check for description
seran Mar 19, 2025
ee95ada
Merge branch 'master' into rest-action-ext
seran Mar 21, 2025
1cb5a03
fix
seran Mar 21, 2025
01bec4f
Merge branch 'master' into rest-action-ext
seran Mar 21, 2025
2276b3d
Merge branch 'master' into rest-action-ext
seran Mar 24, 2025
08e765a
clean-up
seran Mar 24, 2025
caece21
exp
seran Mar 25, 2025
f910c06
fix
seran Mar 26, 2025
6654f6c
clean-up
seran Mar 26, 2025
dcbf06d
more clean-up
seran Mar 26, 2025
8b264e2
comments fix
seran Mar 26, 2025
dcedd01
Merge branch 'master' into rest-action-ext
seran Mar 27, 2025
82f1ae2
clean-up
seran Mar 31, 2025
40ad74a
clean-up
seran Mar 31, 2025
a208428
setter for Param
seran Mar 31, 2025
1c9b128
Merge branch 'master' into rest-action-ext
seran Apr 3, 2025
c5dcd0d
clean-up
seran Apr 7, 2025
3f04802
Merge branch 'master' into rest-action-ext
seran Apr 8, 2025
4ca1405
Merge branch 'master' into rest-action-ext
seran Apr 8, 2025
5d0f0ba
adding exception
seran Apr 9, 2025
b9039bc
updated
seran May 13, 2025
73c4469
Merge branch 'master' into rest-action-ext
seran May 13, 2025
cabfe78
Merge branch 'master' into rest-action-ext
seran May 14, 2025
b7d9336
addressing comments
seran May 19, 2025
c692d00
Merge branch 'master' into rest-action-ext
seran May 19, 2025
2204af4
fix
seran May 19, 2025
6536c0c
Merge branch 'master' into rest-action-ext
seran May 23, 2025
e093dcd
Merge branch 'master' into rest-action-ext
seran May 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions core/src/main/kotlin/org/evomaster/core/problem/api/param/Param.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,44 @@ import org.evomaster.core.search.gene.Gene


abstract class Param(
val name: String,
val genes : MutableList<Gene>
) : StructuralElement(genes){
val name: String,
val genes: MutableList<Gene>
) : StructuralElement(genes) {

/**
* Contains the description of the parameter.
* Parameter description can be only set once.
* If the parameter description is already set, it will throw
* an IllegalStateException.
*/
var description: String? = null
set(value) {
if (!value.isNullOrEmpty()) {
if (field.isNullOrEmpty()) {
field = value
} else {
throw IllegalStateException("Parameter description is already set for $name")
}
}
}

//TODO need refactoring. eg shared abstract class for cases in which only 1 gene for sure
@Deprecated("Assumes there is only 1 gene. Rather use primaryGene()")
val gene : Gene = genes[0]
val gene: Gene = genes[0]

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

constructor(name: String, gene : Gene) : this(name, mutableListOf(gene))
constructor(name: String, gene: Gene) : this(name, mutableListOf(gene))

init{
if (name.isBlank()){
init {
if (name.isBlank()) {
throw IllegalArgumentException("Empty name")
}
}
Expand All @@ -34,13 +51,14 @@ abstract class Param(
val copy = super.copy()
if (copy !is Param)
throw IllegalStateException("mismatched type: the type should be Param, but it is ${this::class.java.simpleName}")
copy.description = description
return copy as Param
}


open fun seeGenes() : List<Gene> = genes
open fun seeGenes(): List<Gene> = genes

override fun copyContent(): Param {
throw IllegalStateException("${this::class.java.simpleName}: copyContent() IS NOT IMPLEMENTED")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,10 @@ object RestActionBuilderV3 {
null
}
} ?: listOf()

val action = RestCallAction(actionId, verb, restPath, params, produces = produces,
operationId = operation.operationId, links = links)
operationId = operation.operationId, links = links
)

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

if(p.schema == null){
messages.add("No schema definition for parameter $name")
Expand Down Expand Up @@ -620,17 +623,18 @@ object RestActionBuilderV3 {
gene = OptionalGene(name, gene)
}

// TODO: Adding description to the parameter occurs in multiple places. This can be refactored.
when (p.`in`) {

"query" -> {
params.add(QueryParam(name, gene, p.explode ?: true, p.style ?: Parameter.StyleEnum.FORM))
}
"query" -> params.add(QueryParam(name, gene, p.explode ?: true, p.style ?: Parameter.StyleEnum.FORM)
.apply { this.description = description })
/*
a path is inside a Disruptive Gene, because there are cases in which we want to prevent
mutation. Note that 1.0 means can always be mutated
*/
"path" -> params.add(PathParam(name, CustomMutationRateGene("d_", gene, 1.0)))
"header" -> params.add(HeaderParam(name, gene))
"path" -> params.add(PathParam(name, CustomMutationRateGene("d_", gene, 1.0))
.apply { this.description = description }
)
"header" -> params.add(HeaderParam(name, gene).apply { this.description = description })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this apply to all kinds of param? so could have the apply outside of the when

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are directly add the Param to the MutableList. So I added the description directly to other types also.

"cookie" -> params // do nothing?
//TODO "cookie" does it need any special treatment? as anyway handled in auth configs
else -> throw IllegalStateException("Unrecognized: ${p.getIn()}")
Expand Down Expand Up @@ -706,6 +710,7 @@ object RestActionBuilderV3 {
}

val name = "body"
val description = operation.description ?: null

val bodies = resolvedBody.content?.filter {
/*
Expand Down Expand Up @@ -752,6 +757,8 @@ object RestActionBuilderV3 {

val contentTypeGene = EnumGene<String>("contentType", bodies.keys)
val bodyParam = BodyParam(gene, contentTypeGene)
.apply { this.description = description }

val ns = bodyParam.notSupportedContentTypes
if(ns.isNotEmpty()){
messages.add("Not supported content types for body payload in $verb:$restPath : ${ns.joinToString()}")
Expand Down Expand Up @@ -810,17 +817,22 @@ object RestActionBuilderV3 {
if (schema.enum?.isNotEmpty() == true) {

when (type) {
"string" ->
"string" -> {
return EnumGene(name, (schema.enum.map {
if (it !is String)
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")
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"
)
it.toString()
} as MutableList<String>).apply {
if(options.invalidData) {
if (options.invalidData) {
//Besides the defined values, add one to test robustness
add("EVOMASTER")
}
})
.apply { this.description = schema.description }
}
/*
Looks like a possible bug in the parser, where numeric enums can be read as strings... got this
issue in GitLab schemas, eg for visibility_level
Expand Down Expand Up @@ -1509,6 +1521,11 @@ object RestActionBuilderV3 {
else -> throw IllegalStateException("cannot create gene with constraints for gene:${geneClass.name}")
}

// TODO: Seran: Investigate
if (mainGene.description.isNullOrBlank()) {
mainGene.description = schema.description
}

/*
See:
https://swagger.io/docs/specification/adding-examples/
Expand Down Expand Up @@ -1668,6 +1685,7 @@ object RestActionBuilderV3 {
minLength = max(defaultMin, if (options.enableConstraintHandling) schema.minLength ?: 0 else 0),
invalidChars = if(isInPath) listOf('/','.') else listOf()
)
.apply { this.description = schema.description }
}

private fun createObjectFromReference(name: String,
Expand Down
Loading