I am implementing Swagger API documentation using ServiceStack's new Swagger plugin and am trying to determine how to use the "container" data type. I need to display a string field that has a list of predetermined values and other parameters that are lists of sub-objects.
Unless I am missing something I believe swagger can only take a text field that you input the JSON for you list of sub-objects. I believe this code should do the trick.
[ApiMember(Name = "Connections", Description = "insert JSON sample here", ParameterType = "body", DataType = "container", IsRequired = false, Verb = "Post")]
What I do not know ( and am hoping someone out there can help me) is if it is possible to have a string field that is from a preset list of values. In Swagger this code snippet illustrates how to do this.
"Pet":{
"id":"Pet",
"properties":{
...
"status":{
"type":"String",
"description":"pet status in the store",
"allowableValues":{
"valueType":"LIST",
"values":[
"available",
"pending",
"sold"
]
}
},
"happiness": {
"type": "Int",
"description": "how happy the Pet appears to be, where 10 is 'extremely happy'",
"allowableValues": {
"valueType": "RANGE",
"min": 1,
"max": 10
}
},
...
Does anyone know how this is accomplished using ServiceStack.Api.Swagger?
I've been struggling with the same issue, but have realised that this feature is currently unsupported. You basically cannot POST or PUT data using Models. This feature is in flux and under development so I guess it is on the todo list.
If you view the source code, you will see that there is no
Models
property supported in the ResourcesResponse data contract:If you compare this to the Petstore example on Wordnik, you'll find that the models are included as a root node:
I think that the only way around this is to post the entire object yourself. Have a request object that takes an entire object, such as Pet. Set the
ParameterType
tobody
and theDataType
toPet
. In the Swagger interface you'll see a textarea, into which you have to paste an actual JSON object. You request will look like this:And your service like this:
The following will be rendered:
Enter the object like so, and the request will be correctly parsed: