swagger JSON produces null value it stops UI - json

I am using swaggerspring mvc -1.0.2 and jackson-databind 2.6.3.why it produce null value.how stop it?.it stopping swagger UI.
JSON
{
"parameterType": {
"absoluteType": "array"
},
"name": "file",
"description": "Pass File as input",
"defaultValue": "",
"required": true,
"allowMultiple": false,
"allowableValues": null,
"paramType": "query",
"paramAccess": null
}

You need to configure your JSON mapper to not write null values:
http://docs.spring.io/spring-boot/docs/current/reference/html/howto-spring-mvc.html#howto-customize-the-jackson-objectmapper
And adding the specific serialization option is like such:
spring.jackson.serialization-inclusion:non_null

Related

convert null values corresponding to an Array to empty array in nifi jolt

I want to achieve following JSON transformation using Jolt processor in NIFI
By focusing on values field, in the first input in json (id 900551), values are populated as the following
input JSON
{
"id": 900551,
"internal_name": [],
"values": [
{
"id": 1430156,
"form_field_id": 900551,
"pos": 0,
"weight": null,
"category": null,
"created_at": "2020-10-15 12:55:02",
"updated_at": "2020-11-27 10:45:09",
"deleted_at": null,
"settings": {
"image": "myimage.png"
"fix": false,
"bold": false,
"exclusive": false
},
"internal_value": "494699DV7271000,6343060SX0W1000,619740BWR0W1000",
"css_class": null,
"value": "DIFFERENCE",
"settings_lang": {},
"value_html": ""
}
]
}
On the second input Json file to parse, values is null.
{
"id": 900552,
"internal_name": [],
"values": []
}
I would like to convert null values to an empty array in my conversion
Is there a way to do this using existing Jolt operations ?
Thanks.
The default operation is what you are looking for:
Defaultr walks the spec and asks "Does this exist in the data? If not, add it."
In our case:
if the value for "values" key is null, put the empty array instead
Here is the spec:
[
{
"operation": "default",
"spec": {
"values": []
}
}
]
tested with https://jolt-demo.appspot.com/
edit: answering the question from the comment:
Maybe this workaround will work for you

Springdoc-openapi - Is there any way to override default value as null or empty in the POST request?

I am using Spring Boot and Open API 3. Through OAS2 Swagger when I make a POST request, I see that all String fields are coming default value as a Spring and I dont see a way to remove it, either through SpringDoc Open UI nor through code.
{
"firstName": "string",
"lastName": "string",
"age": 0,
"email": "string",
"address1": "string",
"address2": "string",
"address3": "string",
"telephone" : "0",
"department" : "string",
.....
}
Here consumer not willing to remove the string from field while making the request. Is there any way
1) If we can remove "string" as a value and set null or "" as default value ?
2) Is there any way if we can read the custom object and reset all values to null where it finds the "string"?
You could use
#Schema(example = "<your example here>")
to provide another example for swagger-ui.
For "" you can do (yes, it's a space):
#Schema(example = " ")

How to set default value for a field in Azure Logic Apps' trigger JSON Schema?

I'm setting up an Azure Logic Apps Workflow with a trigger, but am currently unable to define default values for such trigger's fields in the JSON Schema.
I have enabled JSON Schema validation and Required fields as described here: https://www.danrigby.com/2018/08/27/enable-schema-validation-and-required-fields-in-logicapps/
My JSON Schema currently looks as follows:
{
"anyOf": [
{
"required": [
"delay"
]
},
{
"required": [
"startTime"
]
}
],
"properties": {
"callbackUrl": {
"type": "string"
},
"delay": {
"default": 0,
"minimum": 0,
"type": "integer"
},
"startTime": {
"type": "string"
}
},
"required": [
"callbackUrl"
],
"type": "object"
}
I've also tried replacing default with defaultValue but without luck.
I expected delay to be populated as 0 when absent, instead it is interpreted as null within Azure Logic Apps Workflow, causing the failure of following boolean conditions such as delay is greater than 0 because they don't expect null values to get evaluated.
I believe the JSON Schema is just used for validation here, as it is in many scenarios. The default property is ignored by many implementations as mentioned in the official docs.
Instead, you can use this expression where you need the default value on null
if (equals(triggerBody()?['delay'], null), triggerBody()?['delay'], 0)

JMeter - JSON Extractor extracts correct value in one case but null in other case

I have two requests that return response with similar JSON structure. When I try to use JSON extractor on one, it works properly but when I try to extract value in the same way from the second one, it doesn't work. But let's cut to the chase.
My first response looks like this:
{
"values": [
{
"id": 1,
"name": "Fendi",
"logoId": null,
"belongsToUser": true
},
{
"id": 2,
"name": "Jean Paul Gaultier",
"logoId": null,
"belongsToUser": true
},
{
"id": 3,
"name": "Nike",
"logoId": null,
"belongsToUser": false
},
{
"id": 4,
"name": "Adidas",
"logoId": null,
"belongsToUser": true
}
]
}
And I try to extract ID of the object that "belongsToUser": false in this JSON Extractor:
JSON path expression: values[?(#.belongsToUser == false)].id
Match No.: 0
Default Values: null
And it works perfecty fine.
However, when I try this way on my second response, it doesn't work.
The response looks like this:
{
"values": [
{
"id": 12,
"brandName": "Fendi",
"productCategoryName": "Shoes",
"size": "38",
"colorNames": [
"color_green"
],
"date": 1536537600000,
"imageId": null,
"title": "Money",
"numberOfOffers": 0,
"status": "ONGOING"
},
{
"id": 13,
"brandName": "Fendi",
"productCategoryName": "Shoes",
"size": "38",
"colorNames": [
"color_green"
],
"date": 1536537600000,
"imageId": null,
"title": "Exchange",
"numberOfOffers": 0,
"status": "ONGOING"
}
]
}
I try to get id of object that has title variable = "Money" with JSON extractor:
JSON path expression: values[?(#.title == 'Money')].id
Match No.: 0
Default Values: null
But it doesn't find id value and sets my JMeter variable to null.
I also tried to leave Money unquoted or in double quotes and tried different JSON path expresions, like
$.values[?(#.title == 'Money')].id
$..[?(#.title == 'Money')].id
$.[?(#.title == 'Money')].id
But none of these seems to work. Do you have any idea how my JSON path expression shoud look to work properly?
And why doesn't it work in second case when it works in first? Is it because objets in second response have inside array?
I have used your code and it is giving the correct results. Please check the below images.
I have tried with version 3.1 also and it is working fine.
Hope this helps.
Check the below image for different types of options in view result tree.
The $..[?(#.title == 'Money')].id expression should work just fine:
Most probably your JMeter installation is corrupt and you experience some form of jar hell due to some clashing library in JMeter Classpath (it might be caused by presence of deprecated JSON Plugins or similar) . So I would recommend obtaining clean latest version of JMeter and trying out your test on it. If you're using any plugins - install them using JMeter Plugin Manager
If you are not in position to re-install JMeter you can try to get to the bottom of the issue by looking into jmeter.log file. If there are no suspicious entries - add the next line to log4j2.xml file:
<Logger name="org.apache.jmeter.extractor.json" level="debug" />

Access Extended Choice Parameter Script plugin parameters in Groovy script

I used Extended Choice Parameter Script plugin and created a JSON editor with Array type as below:
disable_edit_json: true,
disable_properties: true,
disable_collapse: true,
theme: "jqueryui",
iconlib:"fontawesome4",
schema: {
"type": "object",
"title": "instances",
"properties": {
"instance": {
"type": "array",
"propertyOrder" : 1,
"format": "table",
"uniqueItems": true,
"items": {
"title": "instance",
"type": "object",
"properties": {
"url": {
"type": "string"
}
}
}
}
}
}
The parameter name is "ServerUrls". Using this I can pass one or many URLs to my Jenkins job, and I want to know the size of the array and access each of these parameter values from within a Groovy script. Conceptually something like ServerUrls.instance[0], ServerUrls.instance1 etc.
Just doing println params["ServerUrls"] throws an Exception.
Can someone please help?
It worked. The solution is as below, and it returns the value as JSON in a string format. It should be fairly easy to parse the JSON to obtain the internals of it.
def hardcoded_param = "ServerUrls"
def resolver = build.buildVariableResolver
def hardcoded_param_value = resolver.resolve(hardcoded_param)
println hardcoded_param_value