Code Monkey home page Code Monkey logo

Comments (6)

hjacobs avatar hjacobs commented on May 15, 2024

There is no special trick here: you can simply access the Flask headers via "flask.request.headers", see http://flask.pocoo.org/docs/0.10/api/#flask.Request.headers

from connexion.

valgog avatar valgog commented on May 15, 2024

This way one can say, that all parameters are accessible with this "trick".

Headers are 1st class citizens in Swagger and are typed as well. So it seems that they should be pushed into the method as a parameter and typing should be checked and probably values converted, just like for the normal parameters.

from connexion.

danballance avatar danballance commented on May 15, 2024

That would be a nice feature if it was possible.

from connexion.

hjacobs avatar hjacobs commented on May 15, 2024

@valgog ok, I agree. I would define most headers not in the Swagger file (as they are usually technical metadata), but I see that there are valid use cases for using headers as first class citizens as defined in Swagger spec.

from connexion.

danballance avatar danballance commented on May 15, 2024

I agree with @hjacobs here - in that we wouldn't want to define every header. Rather just have the option to define one or more important headers in the spec. If a header is specified, then validating it would be great. Ideally this would work in both directions - request and response headers.

I had an example recently where in my spec I want to specify that a Location header is returned for a POST operation. We have the functionality now to return that extra header from the view. It would be great if we could verify the header is returned and possibly validate the format too. I didn't think about this when I made my pull request unfortunately.

I could try and take a look at this if people wanted this feature?

from connexion.

kleijnweb avatar kleijnweb commented on May 15, 2024

I don't really see a use case for passing to controllers. Headers are to be picked up by the infrastructure (gateways and the framework), usually. I realize you can specify in: header according to the docs, but that doesn't necessarily mean they should be passed to controllers. They should be validated and type casted though.

The Swagger spec is IMO a bit vague on header params. I mean this (from the spec):

name: token
in: header
description: token to be passed as a header
required: true
type: array
items:
  type: integer
  format: int64
collectionFormat: csv

Is fine, except for the name. Are we not using the "X-" extension prefix for HTTP header names? Dash-separated-upper-case-first? Or are we leaving out a transformation from header name to parameter name? In the latter case the interface would be incomplete so we have to assume the former. So we're talking:

name: X-Token
in: header
description: token to be passed as a header
required: true
type: array
items:
  type: integer
  format: int64
collectionFormat: csv

So we could strip X-, convert the rest to snake-case and pass it to the function. But what you probably want is to have it picked up by some middleware (eg Flask decorators), instead.

To summarize: yes to validate and cast, but using the result in a decorator would most likely be much more useful than as an argument.

from connexion.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.