Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

PetroGromovo's avatar

Updating profile in swagger how set Array of data

Hello, In my @vue/cli 4.0.5 app I save my profile data as array of profile :

     axios.put(this.apiUrl + '/personal/profile/' + this.userProfileRow.id, {
         profile: {
             first_name: this.userProfileRow.first_name,
             last_name: this.userProfileRow.last_name,
             phone: this.userProfileRow.phone,
             website: this.userProfileRow.website
         },
     }, this.credentialsConfig).then((/*response*/) => {

and in console of browser I see PUT request with array

profile: {first_name: "a", last_name: "b", phone: "c", website: "d"}

Now I make description in swagger with api 3 version as :

  /personal/profile/{user_id}:
    put:
      tags:
        - profile
      summary: personal profile update editable fields

      responses:
        '200':
          description: Successful update
        '400':
          description: Invalid profile editable fields updating

      operationId: updateProfileEditableFieldsByBearerToken

      parameters:
        - name: user_id
          in: path
          description: The user_id update editable fields.
          required: true
          schema:
            type: integer
            default: 1
            example: 1

      requestBody:
        description: Editable fields
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                profile:
                  type: array
                  items:
                    $ref: '#/components/schemas/ProfileEditableFields'
                  
              required:
                - profile

components:

  schemas:

    ProfileEditableFields:
      properties:
        first_name:
          type: string
        last_name:
          type: string
        phone:
          type: string
        website:
          type: string

But I can not fill ProfileEditableFields, in my console I have : https://prnt.sc/rugv28

  1. I do not know which is valid format for any parameter of ProfileEditableFields ? With fhe fileld data above next curl request was generated :
curl -X PUT "http://myserver.com/api/personal/profile/1" -H "accept: */*" -H "Authorization: Bearer TOKEN" -H "Content-Type: application/x-www-form-urlencoded" -d "profile=first_name%20%3A%20111%0A%2Clast_name%20%3A%20222%0A%2Cphone%3A%20333333%2Cwebsite%3A%204444444"

But with 200 code returned all fields first_name, last_name... were cleared at db, as if empty values were sent(API permits empty fields).

  1. How can I set some default data for any elements of ProfileEditableFields structure ?

Thanks!

0 likes
1 reply
PetroGromovo's avatar

In app/Http/Controllers/API/PersonalController.php conrtoller of my backend app I added loging in update method:

    public function update(Request $request, $id)
    {
        $loggedUser = Auth::guard('api')->user();

        \Log::info('PersonalController update $this->requestData::');
        \Log::info(print_r(  $this->requestData, true  ));

        $loggedUser->first_name    = !empty($this->requestData['profile']['first_name']) ? $this->requestData['profile']['first_name'] : '';

and when update profile from my client @vue/cli 4.0.5 app I see logging like:

2020-04-13 03:28:10] local.INFO: PersonalController update $this->requestData:: [2020-04-13 03:28:10] local.INFO: Array ( [profile] => Array ( [first_name] => John [last_name] => Glads [phone] => 252-129-0916 [website] => [email protected] ) )

But when I make run update method from swagger I do not see any update logging string like above But I see 200 responce in swagger : https://prnt.sc/ry6con and in request : https://prnt.sc/ry6drl I suppose that I have invalid profile parameter, but I do not see why?

Please or to participate in this conversation.