I want to create a api for order, I post the shopping cart data as cart like this:
{
sku_id: order_quantity,
....,
}
example:
cart: {
23: 1,
34: 2
},
The sku_id represent product id, order_quantity means the number user want to book. And I write my swagger code like this.
@SWG\Parameter(
name="cart",
description="cart data",
type="object",
required=true,
??? How to define the object key here?
)
Would you please teach me How to define the object key? Thank you.
The JSON spec has patternProperties
But this isn't supported in the Swagger v2.0 specification.
If you change the request into:
"cart":[
{ "product_id": 23, "amount": 1 },
{ "product_id": 34, "amount": 2 }
]
You'd be able to document that with:
* @SWG\Parameter(
* name="body",
* in="body",
* description="cart data",
* required=true,
* @SWG\Schema(
* type="object",
* @SWG\Property(
* property="cart",
* type="array",
* @SWG\Items(
* type="object",
* @SWG\Property(property="product_id", type="integer"),
* @SWG\Property(property="amount", type="integer")
* )
* )
* )
* )
* ),
@bfanger I know how to do now, thank you.
@WenXuanYuan How do you solve this problem?
Changed object model
Most helpful comment
The JSON spec has patternProperties
But this isn't supported in the Swagger v2.0 specification.
If you change the request into:
You'd be able to document that with: