I want to know json path for "/v1/test/anySales" first element in consume node. I dont want list of items from that content node but the very first element like [0].
Basically i want to use assertj java lib and want to check if first content is "application/json" or not.
{
"openapi":"3.0.1",
"info":{
"title":"swagger-app-name",
"description":"swagger test",
"version":"a version"
},
"servers":[
{
"url":"http://localhost",
"description":"Generated server url"
}
],
"security":[
{
"bearer-jwt":[
]
}
],
"paths":{
"/v1/test/sales":{
"get":{
"tags":[
"user-controller"
],
"description":"This api is **public**",
"operationId":"getSales",
"parameters":[
{
"name":"id",
"in":"query",
"description":"sale's id",
"required":true,
"schema":{
"type":"string",
"description":"sale's id"
}
}
],
"responses":{
"200":{
"description":"OK",
"content":{
"application/json":{
"schema":{
"$ref":"#/components/schemas/Sale"
}
}
}
}
}
},
"post":{
"tags":[
"user-controller"
],
"description":"This api requires `hasAuthority('write')` permission.",
"operationId":"updateSale",
"requestBody":{
"content":{
"application/json":{
"schema":{
"$ref":"#/components/schemas/Sale"
}
}
}
},
"responses":{
"200":{
"description":"OK"
}
}
}
},
"/v1/test/anySales":{
"post":{
"tags":[
"user-controller"
],
"description":"This api requires `hasAuthority('write')` permission.",
"operationId":"updateAnySale",
"requestBody":{
"content":{
"application/json":{
"schema":{
"$ref":"#/components/schemas/Sale"
}
},
"application/vnd.smbc.mdl+json":{
"schema":{
"$ref":"#/components/schemas/Sale"
}
},
"application/vnd.smbc.mdl+jsonb":{
"schema":{
"$ref":"#/components/schemas/Sale"
}
}
}
},
"responses":{
"200":{
"description":"OK"
}
}
}
}
},
"components":{
"schemas":{
"Sale":{
"type":"object"
}
},
"securitySchemes":{
"bearer-jwt":{
"type":"http",
"name":"Authorization",
"in":"header",
"scheme":"bearer",
"bearerFormat":"JWT"
}
}
}
}
2
Answers
I am getting what i am looking for by : mapper.readTree(json).path("paths").path( "/v1/test/anySales").path("post").path("requestBody").path("content")
any better approach use path expression?