Use the name property of Guzzle service description

Created on 5 February 2024, 5 months ago
Updated 6 June 2024, 17 days ago

Problem/Motivation

When defining operations parameters in API resources' yml files, the "name" property is ignored and the key is always used as label (for example when manually adding http config request from the UI).

If it would be possible to have different parameter's key and name, I would also change the mapping to the action plugins: currently the parameter's "description" is used as label there, so we have no way of defining an actual description for Drupal actions fields.

Feature request
Status

Fixed

Version

9.3

Component

Code

Created by

🇮🇹Italy kopeboy Mainland

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @kopeboy
  • Status changed to Needs review 4 months ago
  • Open on Drupal.org →
    Core: 10.2.1 + Environment: PHP 8.2 & MySQL 8
    last update 4 months ago
    Waiting for branch to pass
  • 🇮🇹Italy aronne

    Hi @kopeboy,
    here it is the patch which should do the work you were looking for.
    You can now add a "label" property in your guzzle service description and it will be used as label for your parameter in the http config request form.

    Regards,
    aronne

    • aronne authored dfdbc9b1 on 3.x
      Issue #3419219 by aronne, kopeboy: Use the name property of Guzzle...
    • aronne authored 9965c5d7 on 9.3.x
      Issue #3419219 by aronne, kopeboy: Use the name property of Guzzle...
  • Status changed to Fixed 3 months ago
  • Status changed to Needs review 3 months ago
  • 🇮🇹Italy kopeboy Mainland

    Thank you. That solves the form in the UI, but actually I have still a related unsolved issue about the actual name of the operation's parameter described in the yml.

    The problem arises because there is a dot (".") in the name of a query parameter (of an API which I cannot change), and I can't find a way to use it with your module.

    This gives me the error pagination.limit key contains a dot which is not supported.:

    operations:
      GetProposals:
        httpMethod: GET
        uri: "juno/cosmos/gov/v1beta1/proposals"
        summary: "Gov Last Proposals"
        responseModel: Proposals
        parameters:
          pagination.limit:
            location: query
            description: Pagination limit
            type: string
            required: false
            default: '10'
    

    It seems like there is no way to escape the dot in a key, so I would need to use the "name", like:

    operations:
      GetProposals:
        httpMethod: GET
        uri: "juno/cosmos/gov/v1beta1/proposals"
        summary: "Gov Last Proposals"
        responseModel: Proposals
        parameters:
          - name: 'pagination.limit'
             location: query
             description: Pagination limit
             type: string
             required: false
             default: '10'
    

    But this seems unsupported, as the operation disappears (no errors logged).

    If instead this is already supported, what syntax should I use? 🙏

    FYI this is the API I'm trying to integrate: https://raw.githubusercontent.com/cosmos/cosmos-sdk/main/client/docs/swa...

  • 🇮🇹Italy aronne

    Hi there,
    you can use another name in your service description and then use the "sentAs" property to send it as "pagination.limit"

    operations:
      GetProposals:
        httpMethod: GET
        uri: "juno/cosmos/gov/v1beta1/proposals"
        summary: "Gov Last Proposals"
        responseModel: Proposals
        parameters:
          limit:
            location: query
            description: Pagination limit
            type: string
            required: false
            default: '10'
            sentAs: "pagination.limit"
    

    Regards,
    aronne

  • 🇮🇹Italy kopeboy Mainland

    I just realized I can define the resource in json in the meantime! 😅

  • 🇮🇹Italy kopeboy Mainland

    Actually I can't solve it even with JSON.
    Still getting the key contains a dot which is not supported error when I use:

    {
          "parameters": {
            "pagination.limit": {
              "location": "query",
              "description": "Pagination limit",
              "type": "string",
              "required": false,
              "default": "10"
            }
    

    The action still disappears with:

    "parameters": [
            {
              "name": "pagination.limit",
              "location": "query",
              "description": "Pagination limit",
              "type": "string",
              "required": false,
              "default": "10"
            }
          ]

    And by removing the [] array I get InvalidArgumentException: Parameters must be arrays, GetProposals.name is string in GuzzleHttp\Command\Guzzle\Operation->resolveParameters()

  • 🇮🇹Italy aronne

    Did you read what I wrote in comment #7 Use the name property of Guzzle service description Needs review ?

  • Status changed to RTBC 3 months ago
  • 🇮🇹Italy kopeboy Mainland

    Sorry, I hadn't! Yep, that works, thank you very much! And sorry for the noise.

    This could be another nice addition to the docs for noobs like me 🙃😅

  • Status changed to Fixed about 1 month ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024