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

Unexpected value passed to handler when calling endpoint and not specifying the value for an array query parameter #166

Open
spinenkoia opened this issue Aug 12, 2022 · 0 comments
Labels

Comments

@spinenkoia
Copy link

spinenkoia commented Aug 12, 2022

Calling an endpoint and not specifying the value for an array query parameter results in handler receiving ['']

For example , when requesting curl -i -X GET "http://127.0.0.1:8080/test?ids=" in the handler, instead of [] I get ["]

Steps to reproduce
swagger.yaml

openapi: 2.0.0
info:
  version: 1.0
paths:
  /test:
    get:
      operationId: test_handler
      parameters:
        - name: ids
          required: false
          in: query
          type: array
          collectionFormat: csv
          items:
            type: string
            format: uuid
      responses:
        "200"

main.py

from typing import List

from aiohttp.web import Application, run_app
from aiohttp.web import Request, Response
from aiohttp_apiset import SwaggerRouter
from aiohttp_apiset.middlewares import jsonify
from aiohttp_apiset.swagger.operations import OperationIdMapping


async def test_handler(request: Request, ids: List[str]) -> Response:
    print(f"Received list: {ids}")

    return Response()


def main():
    router = SwaggerRouter(
        swagger_ui='/swagger/',
        search_dirs=['./'],
    )

    app = Application(router=router, middlewares=[jsonify])

    opmap = OperationIdMapping(test_handler=test_handler)

    router.include(spec='swagger.yaml', operationId_mapping=opmap)

    run_app(app)


if __name__ == "__main__":
    main()

Python version: 3.10.2
aiohttp_apiset vesion: 0.9.15

@aamalev aamalev added the bug label Aug 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants