InfyOmLabs / swagger-generator

Swagger Generator & Templates for InfyOm Laravel Generator
MIT License
117 stars 61 forks source link

Model swagger docs should have 2 definitions: 1 for writeable only and 1 for all #4

Closed aydinbulut closed 2 years ago

aydinbulut commented 4 years ago

Each model should have 2 definitions. The first definition will contain only writeable by user properties and the second definition will contain all properties with reference to writeable ones.

This helps to tell API consumers to send only writeable properties to CREATE & UPDATE request in Swagger UI.

Example of swagger definitions.


/**
 * @SWG\Definition(
 *      definition="Project:write",
 *      required={"name"},
 *      @SWG\Property(
 *          property="name",
 *          description="name",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="description",
 *          description="description",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="starts_at",
 *          description="starts_at",
 *          type="string",
 *          format="date-time"
 *      ),
 *      @SWG\Property(
 *          property="ends_at",
 *          description="ends_at",
 *          type="string",
 *          format="date-time"
 *      ),
 *      @SWG\Property(
 *          property="expertise_id",
 *          description="expertise_id",
 *          type="integer",
 *          format="int32"
 *      ),
 *      @SWG\Property(
 *          property="user_id",
 *          description="user_id",
 *          type="integer",
 *          format="int32"
 *      )
 * )
 *
 * @SWG\Definition(
 *      definition="Project",
 *      required={"name"},
 *      allOf={
 *          @SWG\Schema(ref="#/definitions/Project:write")
 *      },
 *      @SWG\Property(
 *          property="id",
 *          description="id",
 *          type="integer",
 *          format="int32"
 *      ),
 *      @SWG\Property(
 *          property="created_at",
 *          description="created_at",
 *          type="string",
 *          format="date-time"
 *      ),
 *      @SWG\Property(
 *          property="updated_at",
 *          description="updated_at",
 *          type="string",
 *          format="date-time"
 *      )
 * )
 */
`
``

SS for Swagger UI of CREATE endpoint
![image](https://user-images.githubusercontent.com/2726365/79454217-8007d980-7ff3-11ea-8298-050a31e18070.png)
mitulgolakiya commented 2 years ago

As per the new version 2.0, we moved to Open API specs with swagger v3. Where there is a dedicated option for readOnly specification. so I think it will be resolved automatically.