Details

    • Bug
    • Status: Closed
    • Resolution: Inactive
    • Master
    • None
    • REST Builder
    • None
    • 3

    Description

      As per https://liferay.slack.com/archives/C5E1CRLJY/p1627570183227800?thread_ts=1627552634.222400&cid=C5E1CRLJY

      I'm reporting here my experience with parameter serialization not working for rest APIs.

      This is my parameter part in the rest-openapi.yaml

       parameters:

      • in: path
        name: accountId
        required: true
        schema:
           format: int64
           type: integer
      • in: path
        name: accountRoleIds
        required: true
        schema:
           items:
               type: string
           type: array

      As you can see the accountRoleIds param is an array, so that the builder is creating a java method with this sign:

      public Page<UserAccount> postOrganizationUsersByEmailAddressWithOrganizationRoleIds(@NotNull @Parameter(hidden = true) @PathParam("organizationId") String organizationId, @NotNull @Parameter(hidden = true) @PathParam("organizationRoleIds") String[] organizationRoleIds, String[] strings)

      The issue is how the param is parsed from the request if I make a call like:

      http://localhost:8080/o/headless-admin-user/v1.0/accounts/42323/account-users/by-email-address/44512,44515

      in the organizationRoleIds I will find only 1 element:
      organizationRoleIds[0] = "44512,44515"
      instead of 2 distinct elements:
      organizationRoleIds[0] = "44512"
      organizationRoleIds[1] = "44515"

      Since I'm using strings I end up parsing and splitting the string myself so that I was able to use the 2 values, but in the first iteration I was using a int64 format and it was causing other issues:
      since the param is always a string that is then converted to the type/object we need, I was receiving an error like NumberFormatException when trying to convert "44512,4451" to a number (for obvious reasons).

      The style form is the default one, but explode false is not (default is TRUE), that’s why it doesn’t work sending a request like:
      ?accountRoleIds=44275,44272
      but it works with:
      ?accountRoleIds=44275&accountRoleIds=44272

      Attached there's my rest-openapi-yaml file, pls check path in lines 1911 and 2914

      "/accounts/{accountId}/account-users/by-email-address/{accountRoleIds}"

      "/organizations/{organizationId}/user-accounts/by-email-address/{organizationRoleIds}"

       
      When using query params like:

      in: query
         name: accountRoleIds
         required: true
         schema:
            items:
               format: int64
               type: integer
            type: array
         style: form
         explode: false

      The style form is the default one, but explode false is not (default is TRUE), that’s why it doesn’t work sending a request like:
      ?accountRoleIds=44275,44272
      but it works with:
      ?accountRoleIds=44275&accountRoleIds=44272
       

      For reference this param serialization should be possible as per this documentation:

      https://swagger.io/docs/specification/describing-parameters/#path-parameters
      https://swagger.io/docs/specification/serialization/

       

      Please let me know if I need to configure something differently or if it is indeed a bug.

      Thank you.

      Attachments

        Activity

          People

            support-lep@liferay.com SE Support
            luca.pellizzon Luca Pellizzon
            Kiyoshi Lee Kiyoshi Lee
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              26 weeks, 1 day ago

              Packages

                Version Package