Making a data mock for an API I have found that having the example in the Swagger editor, after executing the project spring generated by Swagger I find that the input of the endpoint is not acceptable. It is a Json and the example autogenerates it as a string, so you must use escape characters to include the quotes. But then the service hits it as it comes from there, I explain:
This is the swagger with the tags example
swagger: '2.0'
info:
description: Test
version: 0.0.1
title: Test
tags:
- name: Test
description: ''
schemes:
- http
paths:
/testOperation:
get:
tags:
- Test
summary: Test
description: Test
operationId: testOperation
produces:
- application/json
parameters:
- name: testInput
in: body
schema:
$ref: '#/definitions/testInput'
required: true
responses:
'200':
description: Successful operation
schema:
$ref: '#/definitions/testOutput'
'405':
description: Error operation
definitions:
testInput:
type: object
properties:
mainId:
type: integer
example: 0001
additional:
type: array
items:
type: object
properties:
id:
type: integer
example: 1
property1:
type: string
example: property1
property2:
type: string
example: property2
example:
- id: 1
property1: property1
property2: property2
- id: 2
property1: property11
property2: property22
testOutput:
type: object
properties:
id:
type: integer
example: 1
And there's the Java line that handles the example the service
@ApiModelProperty(example = "
[{\"id\":1,\"property1\":\"property1\",\"property2\":\"property2\"},
{\"id\":2,\"property1\":\"property11\",\"property2\":\"property22\"}]",
value = "")
When I upload it and click on the input example I get this
And when I execute it I get an error because it does not read the escape characters correctly, my question is:
How can I write the string in Java so that it receives the Swagger example? I would have to return something like that when I clicked on the input example
{
"mainId": 1,
"additional": [
{
"id": 1,
"property1": "property1",
"property2": "property2"
},
{
"id": 2,
"property1": "property11",
"property2": "property22"
}
]
}
Thanks in advance.