Skip to content

Instantly share code, notes, and snippets.

@puncoz
Created July 4, 2019 05:15
Show Gist options
  • Save puncoz/01a446a81081544ae8e9f128c5cc9df5 to your computer and use it in GitHub Desktop.
Save puncoz/01a446a81081544ae8e9f128c5cc9df5 to your computer and use it in GitHub Desktop.
<?php
class UserController
{
/**
* @SWG\Post(path="/user",
* tags={"user"},
* summary="Create user",
* description="This can only be done by the logged in user.",
* operationId="createUser",
* produces={"application/xml", "application/json"},
* @SWG\Parameter(
* in="body",
* name="body",
* description="Created user object",
* required=true,
* @SWG\Schema(ref="#/definitions/User")
* ),
* @SWG\Response(response="default", description="successful operation")
* )
*/
public function createUser()
{
}
/**
* @SWG\Post(path="/user/createWithArray",
* tags={"user"},
* summary="Creates list of users with given input array",
* description="",
* operationId="createUsersWithArrayInput",
* produces={"application/xml", "application/json"},
* @SWG\Parameter(
* in="body",
* name="body",
* description="List of user object",
* required=true,
* @SWG\Schema(
* type="array",
* @SWG\Items(ref="#/definitions/User")
* )
* ),
* @SWG\Response(response="default", description="successful operation")
* )
*/
public function createUsersWithArrayInput()
{
}
/**
* @SWG\Post(path="/user/createWithList",
* tags={"user"},
* summary="Creates list of users with given input array",
* description="",
* operationId="createUsersWithListInput",
* produces={"application/xml", "application/json"},
* @SWG\Parameter(
* in="body",
* name="body",
* description="List of user object",
* required=true,
* @SWG\Schema(
* type="array",
* @SWG\Items(ref="#/definitions/User")
* )
* ),
* @SWG\Response(response="default", description="successful operation")
* )
*/
/**
* @SWG\Get(path="/user/login",
* tags={"user"},
* summary="Logs user into the system",
* description="",
* operationId="loginUser",
* produces={"application/xml", "application/json"},
* @SWG\Parameter(
* name="username",
* in="query",
* description="The user name for login",
* required=true,
* type="string"
* ),
* @SWG\Parameter(
* name="password",
* in="query",
* description="The password for login in clear text",
* required=true,
* type="string"
* ),
* @SWG\Response(
* response=200,
* description="successful operation",
* @SWG\Schema(type="string"),
* @SWG\Header(
* header="X-Rate-Limit",
* type="integer",
* format="int32",
* description="calls per hour allowed by the user"
* ),
* @SWG\Header(
* header="X-Expires-After",
* type="string",
* format="date-time",
* description="date in UTC when token expires"
* )
* ),
* @SWG\Response(response=400, description="Invalid username/password supplied")
* )
*/
public function loginUser()
{
}
/**
* @SWG\Get(path="/user/logout",
* tags={"user"},
* summary="Logs out current logged in user session",
* description="",
* operationId="logoutUser",
* produces={"application/xml", "application/json"},
* parameters={},
* @SWG\Response(response="default", description="successful operation")
* )
*/
public function logoutUser()
{
}
/**
* @SWG\Get(path="/user/{username}",
* tags={"user"},
* summary="Get user by user name",
* description="",
* operationId="getUserByName",
* produces={"application/xml", "application/json"},
* @SWG\Parameter(
* name="username",
* in="path",
* description="The name that needs to be fetched. Use user1 for testing. ",
* required=true,
* type="string"
* ),
* @SWG\Response(response=200, description="successful operation", @SWG\Schema(ref="#/definitions/User")),
* @SWG\Response(response=400, description="Invalid username supplied"),
* @SWG\Response(response=404, description="User not found")
* )
*/
public function getUserByName($username)
{
}
/**
* @SWG\Put(path="/user/{username}",
* tags={"user"},
* summary="Updated user",
* description="This can only be done by the logged in user.",
* operationId="updateUser",
* produces={"application/xml", "application/json"},
* @SWG\Parameter(
* name="username",
* in="path",
* description="name that need to be updated",
* required=true,
* type="string"
* ),
* @SWG\Parameter(
* in="body",
* name="body",
* description="Updated user object",
* required=true,
* @SWG\Schema(ref="#/definitions/User")
* ),
* @SWG\Response(response=400, description="Invalid user supplied"),
* @SWG\Response(response=404, description="User not found")
* )
*/
public function updateUser()
{
}
/**
* @SWG\Delete(path="/user/{username}",
* tags={"user"},
* summary="Delete user",
* description="This can only be done by the logged in user.",
* operationId="deleteUser",
* produces={"application/xml", "application/json"},
* @SWG\Parameter(
* name="username",
* in="path",
* description="The name that needs to be deleted",
* required=true,
* type="string"
* ),
* @SWG\Response(response=400, description="Invalid username supplied"),
* @SWG\Response(response=404, description="User not found")
* )
*/
public function deleteUser()
{
}
}
<?php
/**
* @SWG\Definition(type="object", @SWG\Xml(name="User"))
*/
class User
{
/**
* @SWG\Property(format="int64")
* @var int
*/
public $id;
/**
* @SWG\Property()
* @var string
*/
public $username;
/**
* @SWG\Property()
* @var string
*/
public $firstName;
/**
* @SWG\Property()
* @var string
*/
public $lastName;
/**
* @var string
* @SWG\Property()
*/
public $email;
/**
* @var string
* @SWG\Property()
*/
public $password;
/**
* @var string
* @SWG\Property()
*/
public $phone;
/**
* User Status
* @var int
* @SWG\Property(format="int32")
*/
public $userStatus;
}
<?php
use League\Fractal\TransformerAbstract;
/**
* Class UserTransformer
* @package App\Transformer\UserTransformer
*
* @SWG\Definition(
* definition="User",
* @SWG\Property(property="id", type="integer", description="User Id"),
* @SWG\Property(property="email", type="string", description="Email"),
* @SWG\Property(property="username", type="string", description="Username"),
* @SWG\Property(property="full_name", type="string", description="User Full name"),
* )
*/
class UserTransformer extends TransformerAbstract
{
/**
* @param App\User $user
*
* @return array
*/
public function transform(App\User $user): array
{
return [
'id' => $user->id,
'email' => $user->email,
'username' => $user->username ?? '',
'full_name' => $user->first_name . ' ' . $user->last_name,
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment