2

I'm new to PHP Swagger and using the Laravel package L5-Swagger to create documentation for my API. Now I'm trying to let one model contain an array of the other model, an Order can have several OrderItems.

Unfortuantly I cannot get the linking to work. See attached screen shot.

enter image description here

What am I doing wrong?

This is my Order model:

/**
 * @SWG\Definition(
 *   required={"order_id","order_items"},
 *   type="object",
 *   @SWG\Xml(name="Order")
 * )
 */
class Order
{
    /**
     * @SWG\Property(example="O-789456123")
     * @var string
     */
    public $order_id;

    /**
     * @SWG\Property(type="array", items="$ref:OrderItem")
     * @var array
     */
    public $order_items = [];
}

This is my OrderItem model:

/**
 * @SWG\Definition(
 *   required={"sku","quantity", "price_including_tax"},
 *   type="object",
 *   @SWG\Xml(name="OrderItem")
 * )
 */
class OrderItem
{
    /**
     * @SWG\Property(example="SKU-123")
     * @var string
     */
    public $sku;

    /**
     * @SWG\Property(example=2)
     * @var integer
     */
    public $quantity;

    /**
     * @SWG\Property(example=199.75)
     * @var float
     */
    public $price_including_tax;
}

1 Answer 1

2

I think items="$ref:OrderItem" should be @SWG\Items(ref="#/definitions/OrderItem")

Ps. Checking the intermediate format (the swagger.json) can provide insight into what going wrong.

Sign up to request clarification or add additional context in comments.

1 Comment

Worked like a charm! Thank you very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.