Use the name property of Guzzle service description

Created on 5 February 2024, 9 months ago
Updated 6 June 2024, 5 months 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 Milan

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 9 months ago
  • Open on Drupal.org →
    Core: 10.2.1 + Environment: PHP 8.2 & MySQL 8
    last update 9 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 8 months ago
  • Status changed to Needs review 7 months ago
  • 🇮🇹Italy kopeboy Milan

    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 Milan

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

  • 🇮🇹Italy kopeboy Milan

    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 7 months ago
  • 🇮🇹Italy kopeboy Milan

    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 6 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024