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

request header params ignored #850

Closed
adrpp opened this issue Jan 14, 2019 · 5 comments
Closed

request header params ignored #850

adrpp opened this issue Jan 14, 2019 · 5 comments
Labels

Comments

@adrpp
Copy link

adrpp commented Jan 14, 2019

Description

for openapi spec 3, it seems that the header arguments are completely ignored.
For example, openapi-generator-cli.jar generates related controller (method), where the header argument defined in the spec, is to be found as positional argument.

venv3/lib/python3.6/site-packages/connexion/operations/abstract.py -> get_arguments() does not care about header arguments at all and so, does not pass required positional argument (as generated), into the controller.

Expected behaviour

it is expected that header arguments will be passed into controller cls/method as any other arguments (query, path)

Actual behaviour

request header arguments are ignored = not passed into callable (controller method)

Steps to reproduce

openapi: 3.0.0
info:
  description: "dog service"
  version: "1.0.0"
  title: "dog service"
  contact:
    email: "apiteam@swagger.io"
  license:
    name: "Apache 2.0"
    url: "http://www.apache.org/licenses/LICENSE-2.0.html"
servers:
  - url: http://0.0.0.0:8080/v1
    description: "local"

tags:
- name: "Dogs"
  description: "Everything about Dogs"

paths:
  /dogs:
    get:
      tags:
      - "Dogs"
      summary: ""
      description: "Obtain Dogs"
      operationId: "getDogs"
      parameters:
      - $ref: "#/components/parameters/MyHeaderParam"
      responses:
        200:
          description: "successful operation"

components:
  parameters:
    MyHeaderParam:
      name: "myHeaderParam"
      in: "header"
      description: "my header param"
      required: true
      schema:
        type: "string"
        format: "uuid"

Invoking GET method on /dogs returns:

127.0.0.1 - - [14/Jan/2019 16:49:06] "GET /v1/ui/ HTTP/1.1" 200 -
127.0.0.1 - - [14/Jan/2019 16:49:06] "GET /v1/ui/swagger-ui-standalone-preset.js HTTP/1.1" 304 -
127.0.0.1 - - [14/Jan/2019 16:49:06] "GET /v1/ui/swagger-ui-bundle.js HTTP/1.1" 304 -
127.0.0.1 - - [14/Jan/2019 16:49:06] "GET /v1/ui/swagger-ui.css HTTP/1.1" 304 -
127.0.0.1 - - [14/Jan/2019 16:49:07] "GET /v1/openapi.json HTTP/1.1" 200 -
[2019-01-14 16:49:23,226] ERROR in app: Exception on /v1/dogs [GET]
Traceback (most recent call last):
File "venv3/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "venv3/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "venv3/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "venv3/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "venv3/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "venv3/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functionsrule.endpoint
File "venv3/lib/python3.6/site-packages/connexion/decorators/decorator.py", line 48, in wrapper
response = function(request)
File "venv3/lib/python3.6/site-packages/connexion/decorators/uri_parsing.py", line 143, in wrapper
response = function(request)
File "venv3/lib/python3.6/site-packages/connexion/decorators/validation.py", line 347, in wrapper
return function(request)
File "venv3/lib/python3.6/site-packages/connexion/decorators/parameter.py", line 133, in wrapper
return function(**kwargs)
TypeError: get_dogs() missing 1 required positional argument: 'my_header_param'
127.0.0.1 - - [14/Jan/2019 16:49:23] "GET /v1/dogs HTTP/1.1" 500 -

@dtkav
Copy link
Collaborator

dtkav commented Jan 15, 2019

The headers are accessible via the flask request object.

from flask import request

def my_handler(some_arg):
    headers = request.headers
    ...

There's discussion on #788 to pass the headers into the handler function, but for now you have to use the request object when using flask.

@dtkav dtkav added the question label Jan 15, 2019
@adrpp
Copy link
Author

adrpp commented Jan 15, 2019

@dtkav right, I mean, it's just not working out of box with pre-generated model & server code from openapi-generator-cli which assumes that all defined parameters in the spec file are passed into the contoller.

@dtkav
Copy link
Collaborator

dtkav commented Jan 25, 2019

hey @adrpp have you opened a ticket with that project?
It sounds like a bug in the code generator if it generates code that doesn't work with connexion.

That being said, it does sound like a nice feature to have. Feel free to join the discussion in #788 .

@doub1eYu
Copy link

check this
https://connexion.readthedocs.io/en/latest/request.html#header-parameters

Currently, header parameters are not passed to the handler functions as parameters.

@vishnuagbly
Copy link

Check this for a workaround, if anyone is looking for it.

#788 (comment)

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

5 participants