2015-05-15 11 views
12

chcę wdrożyć API, które jest o string.This zapytań jest APISwagger API, które jest o ciąg kwerendy

v1/products?q=circuit breaker&locale=en-GB&pageSize=8&pageNo=1&project=GLOBAL 

Oto jak jestem wykonawczych

"/v1/products?q={searchText}&locale={ctrCode}&pageSize={pageSize}&pageNo={pageNo}&project={project}&country={country}":{ 
     "get":{ 
      "tags":[ 
       "Search Text" 
      ], 
      "summary":"Get Products by searching text, countrycode, page number, pagesize, project and country(optional)", 
      "description":"Get Products by searching text, countrycode, page number, pagesize, project and country(optional)", 
      "operationId":"getProductName", 
      "produces":[ 
       "application/json", 
       "application/xml" 
      ], 
      "parameters":[ 
       { 
        "name":"searchText", 
        "in":"path", 
        "description":"The Product that needs to be fetched", 
        "required":true, 
        "type":"string" 
       }, 
       { 
        "name":"ctrCode", 
        "in":"path", 
        "description":"The Product locale needs to be fetched. Example=en-GB, fr-FR, etc.", 
        "required":true, 
        "type":"string" 
       }, 
       { 
        "name":"pageSize", 
        "in":"path", 
        "description":"The Product PageSize that needs to be fetched. Example=10, 20 etc.", 
        "required":true, 
        "type":"number" 
       }, 
       { 
        "name":"pageNo", 
        "in":"path", 
        "description":"The Product pageNo that needs to be fetched. Example=1,2 etc.", 
        "required":true, 
        "type":"number" 
       }, 
       { 
        "name":"project", 
        "in":"path", 
        "description":"The Project that needs to be fetched. Example=Mypact, DSL etc.", 
        "required":true, 
        "type":"string" 
       }, 
       { 
        "name":"country", 
        "in":"header", 
        "description":"The Country that needs to be fetched. Example=France, India etc.", 
        "required":false, 
        "type":"string" 
       } 
      ], 
      "responses":{ 
       "200":{ 
        "description":"successful operation", 
        "schema":{ 
        "$ref":"#/definitions/Products" 
        } 
       }, 
       "400":{ 
        "description":"Invalid Product_id supplied" 
       }, 
       "404":{ 
        "description":"Product not found" 
       } 
      } 
     } 
     } 

Kraj jest opcjonalny parametr w tym. Chcę, aby adres URL wyświetlał kraj tylko wtedy, gdy użytkownik wprowadzi jakąś wartość, w przeciwnym razie nie powinien być wyświetlany w adresie URL.

+0

sam problem ... Swagger jest głupi tutaj ... – gouchaoer

Odpowiedz

16

Nie można opisać parametrów zapytania jako części ścieżki w Swagger. Musisz jawnie zadeklarować te parametry jako parametry zapytania.

"/v1/products":{ 
     "get":{ 
      "tags":[ 
       "Search Text" 
      ], 
      "summary":"Get Products by searching text, countrycode, page number, pagesize, project and country(optional)", 
      "description":"Get Products by searching text, countrycode, page number, pagesize, project and country(optional)", 
      "operationId":"getProductName", 
      "produces":[ 
       "application/json", 
       "application/xml" 
      ], 
      "parameters":[ 
       { 
        "name":"searchText", 
        "in":"query", 
        "description":"The Product that needs to be fetched", 
        "required":true, 
        "type":"string" 
       }, 
       { 
        "name":"ctrCode", 
        "in":"query", 
        "description":"The Product locale needs to be fetched. Example=en-GB, fr-FR, etc.", 
        "required":true, 
        "type":"string" 
       }, 
       { 
        "name":"pageSize", 
        "in":"query", 
        "description":"The Product PageSize that needs to be fetched. Example=10, 20 etc.", 
        "required":true, 
        "type":"number" 
       }, 
       { 
        "name":"pageNo", 
        "in":"query", 
        "description":"The Product pageNo that needs to be fetched. Example=1,2 etc.", 
        "required":true, 
        "type":"number" 
       }, 
       { 
        "name":"project", 
        "in":"query", 
        "description":"The Project that needs to be fetched. Example=Mypact, DSL etc.", 
        "required":true, 
        "type":"string" 
       }, 
       { 
        "name":"country", 
        "in":"query", 
        "description":"The Country that needs to be fetched. Example=France, India etc.", 
        "required":false, 
        "type":"string" 
       } 
      ], 
      "responses":{ 
       "200":{ 
        "description":"successful operation", 
        "schema":{ 
        "$ref":"#/definitions/Products" 
        } 
       }, 
       "400":{ 
        "description":"Invalid Product_id supplied" 
       }, 
       "404":{ 
        "description":"Product not found" 
       } 
      } 
     } 
     } 
+0

, że nie jest mój problem, problem polega na tym, że jeśli użytkownik nic nie daje dla danego kraju (parametr), kraj = {kraj} nie powinien być wyświetlany w URL – schneider

+1

Masz rację, zapominam o pewnej poprawce. Edytowane w celu odzwierciedlenia tego. – Ron

3

Twój parametr IN musi być "query" nie "ścieżka"

To powinno działać:

{ 
    "name":"country", 
    "in":"query", 
    "description":"The Country that needs to be fetched. Example=France, India etc.", 
    "required":false, 
    "type":"string" 
} 
Powiązane problemy