Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nested query params #66

Open
paulsturgess opened this issue Aug 20, 2024 · 1 comment
Open

Support nested query params #66

paulsturgess opened this issue Aug 20, 2024 · 1 comment

Comments

@paulsturgess
Copy link
Contributor

Currently the schema will throw an error if we declare an argument for a LookupArgumentSet that points to another ArgumentSet.

This allows us to support nested query params:

?annotation[key]="my-key"&annotation[value]="my-value"

For example:

module CoreAPI
  module ArgumentSets
    class MyLookup < Apia::LookupArgumentSet
      argument :annotation, type: KeyValue
  
      [...]
    end
  end
end
class KeyValue < Apia::ArgumentSet

  argument :key, type: :string, required: true
  argument :value, type: :string

end

Currently we only support string as a valid type an argument of LookupArgumentSet.

paulsturgess added a commit that referenced this issue Aug 20, 2024
Currently the schema generation will throw an error if the Apia API declare nested query params.

Full details are explained in:
#66

This PR just omits nested params from the schema generation so that it can continue to generate.
@paulsturgess
Copy link
Contributor Author

paulsturgess commented Aug 20, 2024

I tried adding support for nested query params.

The Ruby generated client will support it ok. But the jane-php client throws an error:

Fatal error: Uncaught TypeError: Jane\Component\OpenApi3\Generator\Parameter\NonBodyParameterGenerator::convertParameterType():
Return value must be of type array, null returned in /app/php/vendor/jane-php/open-api-3/Generator/Parameter/NonBodyParameterGenerator.php:197

The change I made to try it was in generate_argument_set_params in lib/apia/open_api/objects/parameters.rb

if child_arg.type.argument_set?
  schema = generate_schema_ref(child_arg)
else
  schema = generate_scalar_schema(child_arg)
end

The schema was updated like this as an example:

        "parameters": [
          {
            "name": "address_list[id]",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "The address list to return. All 'address_list[]' params are mutually exclusive, only one can be provided."
          },
          {
            "name": "address_list[annotation]",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/KeyValue"
            },
            "description": "The address list to return. All 'address_list[]' params are mutually exclusive, only one can be provided."
          }
        ],
        
        ...
        
     "KeyValue": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string"
          },
          "value": {
            "type": "string"
          }
        },
        "required": [
          "key"
        ]
      },

The Ruby client then allowed me to do this:

KatapultAPI.configure do |config|
  config.access_token = ENV['KATAPULT_ACCESS_TOKEN']
  config.host = 'http://katapult-api.localhost/'
  config.scheme = 'http'
end

api_instance = KatapultAPI::CoreApi.new
result = api_instance.get_address_list({ address_list_annotation: { key: 'test.io/something', value: 'abc' } })
puts result.inspect

In RapidAPI we can build a nested query string like this:

Screenshot 2024-08-21 at 08 24 37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant