2017-03-03 41 views
0

我使用招摇编辑器(版本2.10.5),以生成使用自定义页眉的烧瓶中的API,并开始下面的行添加到每个路径:招摇自动生成的烧瓶服务器头

parameters: 
    - $ref: '#/parameters/X-Forwarded-Host' 

的相对的定义:

X-Forwarded-Host: 
    name: 'X-Forwarded-Host' 
    in: header 
    description: Forwarded host header 
    required: true 
    type: string 

然后运行的自动生成的烧瓶服务器

$ python3 -m swagger_server 

创建一些PR oblems:

  • 使卷曲请求时,标头不正确的评估:

    $ curl -X GET --header 'Accept: application/json' --header 'X-Forwarded-Host: example.com' http://localhost:8080 
    

    返回

    health_get() missing required positional argument: 'X_Forwarded_Host' 
    
  • 自动生成的测试是无用太:

    headers = [('X_Forwarded_Host', 'X_Forwarded_Host_example'), ... 
    

我在做什么错?为什么swagger-editor(或codegen)将“ - ”全部设置为“_”?

在此先感谢

回答

0

好吧,我想通了..

的问题是不招摇编辑器本身,而是它是如何产生的瓶(联接)代码。

联接请求处理文档(url)表示:。

“目前,报头参数不传递给处理程序函数作为参数但通过底层connexion.request.headers对象它们可被访问,其别名flask.request.headers对象。“

的解决方案是从自动产生的控制器中删除所有函数的属性(与头)和从请求对象接他们,因此:

来自:

def health_get(X_Forwarded_Host): 
    ... 

到:

def health_get(): 
    forwarded_host = connexion.request.headers['X-Forwarded-Host'] 

再见!