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.

CommentFileSizeAuthor
#2 3419219-2.patch653 bytesaronne

Comments

kopeboy created an issue. See original summary.

aronne’s picture

Status: Active » Needs review
StatusFileSize
new653 bytes

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...
aronne’s picture

Status: Needs review » Fixed
kopeboy’s picture

Status: Fixed » Needs review

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 I also opened an issue in the SDK who's providing the API I'm trying to integrate (there you can find the swagger.yml of it): https://github.com/cosmos/cosmos-sdk/issues/19959

aronne’s picture

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

kopeboy’s picture

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

kopeboy’s picture

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"
        }
      ]

The parameter disappears as an input if I use:

      "parameters": [
        {
          "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()

aronne’s picture

Did you read what I wrote in comment #7?

kopeboy’s picture

Status: Needs review » Reviewed & tested by the community

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 🙃😅

aronne’s picture

Status: Reviewed & tested by the community » Fixed
aronne’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.