Mocking the data for an API i found that having the examples in the swagger
editor, after running the auto-generated spring proyect i realised that the
input of the endpoint is not acceptable. Its a Json and the example
generates it like a string, so it must use scape characters like "\" to
incluide the "". But, the service copy it literally, heres a explanation:
This is the swagger code with example label
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 this is the line that handles the exaple in the Java Service
@ApiModelProperty(example = " [{\"id\":1,\"property1\":\"property1\",
\"property2\":\"property2\"}, {\"id\":2,\"property1\":\"property11\",
\"property2\":\"property22\"}]", value = "")
When i run it y then i click the imput example to copy I get this
{ "additional":
"[{\"id\":1,\"property1\":\"property1\",\"property2\":\"property2\"},{\"id\":2,\"property1\":\"property11\",\"property2\":\"property22\"}]"
, "mainId": 1 }
When i run it it gives me a error because it doesnt read the scape
characters of the input right , my question is
What wat i can write the string in Java so it can recive the correct
swagger examples? It should retrive something like this when i do a click
in the example input
{
"mainId": 1,
"additional": [
{
"id": 1,
"property1": "property1",
"property2": "property2"
},
{
"id": 2,
"property1": "property11",
"property2": "property22"
}
]}
Thanks and sorry for my bad english.
--
You received this message because you are subscribed to the Google Groups
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.