Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger PHP: how to declare property to use schema definition?

My App's response looks like this:

{
  "status": "success",
  "data": {
      "status": "ready"
   },
  "request_id": "string"
}

I tried to define response in Swagger

 *           @SWG\Response (
 *              response=200,
 *              description="Success response",
 *              @SWG\Schema (
 *                  @SWG\Property(
 *                      property="status",
 *                      type="string",
 *                      default="success"
 *                  ),
 *                  @SWG\Property(
 *                      property="data",
 *                      @SWG\Schema(
 *                          ref="#/definitions/Service/models/Status"
 *                      )
 *                  ),
 *                  @SWG\Property(
 *                      property="request_id",
 *                      type="string"
 *                  ),
 *              )
 *          ),

But it does not use Schema definition for Status, so my response actually looks like:

{
  "status": "success",
  "data": {},
  "request_id": "string"
}

How can I define data property to use schema definition? Or can it can be done in a different way?

like image 387
JJHunter Avatar asked Dec 16 '15 08:12

JJHunter


People also ask

What is schema in swagger?

OpenAPI 3.0 data types are based on an extended subset JSON Schema Specification Wright Draft 00 (aka Draft 5). The data types are described using a Schema object. To learn how to model various data types, see the following topics: Data Types.

What is discriminator in swagger?

The discriminator is the schema property name that is used to differentiate between other schema that inherit this schema. The property name used MUST be defined at this schema and it MUST be in the required property list. When used, the value MUST be the name of this schema or any schema that inherits it.


1 Answers

How funny can be the fact, that people sometimes find the answer just after posting a question.

Answer is:

*           @SWG\Response (
 *              response=200,
 *              description="Success response",
 *              @SWG\Schema (
 *                  @SWG\Property(
 *                      property="status",
 *                      type="string",
 *                      default="success"
 *                  ),
 *                  @SWG\Property(
 *                      property="data",
 *                      ref="#/definitions/Service/models/Status"
 *                  ),
 *                  @SWG\Property(
 *                      property="request_id",
 *                      type="string"
 *                  ),
 *              )
 *          ),
like image 142
JJHunter Avatar answered Sep 29 '22 05:09

JJHunter