-
Notifications
You must be signed in to change notification settings - Fork 116
Feature Flags for Json Patch and XML #1645
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
base: master
Are you sure you want to change the base?
Changes from all commits
9910ba2
65a5e43
cbe09b1
0db5301
d4750d7
9ee82c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1378,6 +1378,16 @@ class EMConfig { | |
| "Only available for JVM languages") | ||
| var dtoForRequestPayload = false | ||
|
|
||
| @Experimental | ||
| @Cfg("Disable JSON Patch (RFC 6902) gene support when the request Content-Type is 'application/json-patch+json'." + | ||
| " When true, such endpoints are treated as regular JSON bodies, reproducing the behavior before this feature was introduced.") | ||
| var disableJsonPatchSupport = false | ||
|
|
||
| @Experimental | ||
| @Cfg("Disable XML-aware field naming for body genes when the request Content-Type is XML." + | ||
| " When true, body gene names fall back to the pre-feature behavior (schema ref name or 'body').") | ||
| var disableXMLSupport = false | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename |
||
|
|
||
| @Important(6.0) | ||
| @Cfg("Host name or IP address of where the SUT EvoMaster Controller Driver is listening on." + | ||
| " This option is only needed for white-box testing.") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,6 +117,10 @@ object RestActionBuilderV3 { | |
| val enableAdvancedFormats: Boolean = true, | ||
|
|
||
| val inferFormatFromNames: Boolean = true, | ||
|
|
||
| val disableJsonPatchSupport: Boolean = false, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. property should be in "positive" sense, not negative. ie, this should be renamed into |
||
|
|
||
| val disableXMLSupport: Boolean = false, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see previous comment. this should be renamed |
||
| ){ | ||
| constructor(config: EMConfig): this( | ||
| enableConstraintHandling = config.enableSchemaConstraintHandling, | ||
|
|
@@ -125,7 +129,9 @@ object RestActionBuilderV3 { | |
| probUseExamples = config.probRestExamples, | ||
| usingWhiteBox = !config.blackBox, | ||
| enableAdvancedFormats = config.enableAdvancedFormats, | ||
| inferFormatFromNames = config.inferFormatFromNames | ||
| inferFormatFromNames = config.inferFormatFromNames, | ||
| disableJsonPatchSupport = config.disableJsonPatchSupport, | ||
| disableXMLSupport = config.disableXMLSupport, | ||
| ) | ||
|
|
||
| init { | ||
|
|
@@ -750,7 +756,8 @@ object RestActionBuilderV3 { | |
| listOf() | ||
| } | ||
|
|
||
| val isJsonPatch = verb == HttpVerb.PATCH && bodies.keys.any { it.contains("json-patch") } | ||
| val isJsonPatch = !options.disableJsonPatchSupport && | ||
| verb == HttpVerb.PATCH && bodies.keys.any { it.contains("json-patch") } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should check for ignoring case of |
||
|
|
||
| val name: String | ||
| var gene: Gene | ||
|
|
@@ -776,9 +783,13 @@ object RestActionBuilderV3 { | |
| } | ||
| gene = JsonPatchDocumentGene(name, resourceGene) | ||
| } else { | ||
| // $ref schemas do not carry XML metadata; resolving the reference is required to obtain the correct XML element name from the target schema | ||
| val deref = obj.schema.`$ref`?.let { ref -> SchemaUtils.getReferenceSchema(schemaHolder, currentSchema, ref, messages) } ?: obj.schema | ||
| name = deref?.xml?.name ?: deref?.`$ref`?.substringAfterLast("/") ?: "body" | ||
| if (!options.disableXMLSupport) { | ||
| // $ref schemas do not carry XML metadata; resolving the reference is required to obtain the correct XML element name from the target schema | ||
| val deref = obj.schema.`$ref`?.let { ref -> SchemaUtils.getReferenceSchema(schemaHolder, currentSchema, ref, messages) } ?: obj.schema | ||
| name = deref?.xml?.name ?: deref?.`$ref`?.substringAfterLast("/") ?: "body" | ||
| } else { | ||
| name = obj.schema.`$ref`?.substringAfterLast("/") ?: "body" | ||
| } | ||
| gene = getGene(name, obj.schema, schemaHolder, currentSchema, referenceClassDef = null, options = options, messages = messages, examples = examples) | ||
| } | ||
|
|
||
|
|
@@ -1135,8 +1146,14 @@ object RestActionBuilderV3 { | |
| } | ||
|
|
||
| // Use the XML name from schema.xml.name (the name of the array element in XML) | ||
| // if available, otherwise fallback to name + "_item" | ||
| val itemName = schema.xml?.name ?: (name + "_item") | ||
| // if available, otherwise fallback to name + "_item". | ||
| // When XML support is disabled, ignore xml.name and always use the generic | ||
| // fallback, so we emulate the pre-XML-support behaviour of EvoMaster. | ||
| val itemName = if (!options.disableXMLSupport) { | ||
| schema.xml?.name ?: (name + "_item") | ||
| } else { | ||
| name + "_item" | ||
| } | ||
| val template = getGene( | ||
| itemName, | ||
| arrayType, | ||
|
|
@@ -1168,9 +1185,16 @@ object RestActionBuilderV3 { | |
| "object" -> { | ||
| val properties = schema.properties ?: emptyMap() | ||
|
|
||
| val attributeNames = properties | ||
| .filterValues { it.xml?.attribute == true } | ||
| .keys | ||
| // Only detect XML attribute fields when XML support is enabled. When disabled, | ||
| // this stays empty so we fall back to a plain ObjectGene (attributes rendered as | ||
| // child elements), matching how EvoMaster behaved before ObjectWithAttributesGene. | ||
| val attributeNames = if (!options.disableXMLSupport) { | ||
| properties | ||
| .filterValues { it.xml?.attribute == true } | ||
| .keys | ||
| } else { | ||
| emptySet() | ||
| } | ||
|
|
||
| if (attributeNames.isNotEmpty()) { | ||
| val fields = properties.map { (propName, propSchema) -> | ||
|
|
@@ -1625,10 +1649,16 @@ object RestActionBuilderV3 { | |
| valueTemplate.copy()) | ||
| } | ||
|
|
||
| val attributeNames = schema.properties | ||
| ?.filter { (_, propSchema) -> propSchema.xml?.attribute == true } | ||
| ?.map { it.key } | ||
| ?: emptyList() | ||
| // Same as above: skip XML attribute detection when XML support is disabled, so the object | ||
| // is assembled as a plain ObjectGene (pre-XML-support behaviour). | ||
| val attributeNames = if (!options.disableXMLSupport) { | ||
| schema.properties | ||
| ?.filter { (_, propSchema) -> propSchema.xml?.attribute == true } | ||
| ?.map { it.key } | ||
| ?: emptyList() | ||
| } else { | ||
| emptyList() | ||
| } | ||
|
|
||
| if (attributeNames.isNotEmpty()) { | ||
| return ObjectWithAttributesGene( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be renamed
enableJsonPatchSupport.also, experimental options should not be on by default.
once we run experiments, and we are happy with them, we put them on by default, and remove the tag
Experimental