Comments (6)
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.
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.
That would be a nice feature if it was possible.
from connexion.
@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.
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.
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)
- Frozen application can't run
- Maintenance release with less restrictive dependencies HOT 1
- How to add Prometheus client /metrics endpoint to Connexion 3.x AsyncApp? HOT 3
- Validation error with multipart/form-data and object type property HOT 1
- allOf doesn't work with multipart/form-data
- Arrays are parsed incorrectly with multipart/form-data HOT 1
- Release 3.0.6? HOT 4
- Add request as an optional kwarg to auth flow HOT 2
- Stream large file to AsyncApp (application/octet-stream) HOT 7
- Execution Order Issue: before_request Executing After x-apikeyInfoFunc Authentication Method HOT 1
- RoutingMiddleware should sort paths HOT 1
- Migrating to Connexion 3: Issues with current_app and g for Authentication and Request Lifecycle HOT 4
- g object is not accessible in x-bearerInfoFunc HOT 1
- Import issues when using editable install HOT 1
- Treats trailing slashes differently for swagger and normal endpoints HOT 2
- Missing API documentation HOT 2
- Document that ConnexionMiddleware might require to specifiy routes explicitly HOT 2
- Question: Using `validate_responses=True` in connexion 3.* HOT 1
- All defaults from all OneOf schema options get propagated using the DefaultJSONValidator
- swagger-ui not resolving external references
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from connexion.