2017-03-03 42 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'] 

再見!