2013-02-28 3 views
0

source2swagger генерирует спецификацию swagger со всем apis в одном json-файле. Может ли swagger-ui использовать это? Когда я исследую сгенерированный json-файл с swagger-ui, он пытается прочитать описания api из своих путей в spec, вместо того, чтобы использовать описания/операции прямо в одном файле json.Статические документы API с source2swagger

ответ

0

Swagger-UI будет обрабатывать все json в одном файле. Я еще не уверен, если может быть несколько списков ресурсов верхнего уровня.

Вот рабочий пример:

{"basePath":"http://localhost:3001/", "resourcePath":"/", "swaggerVersion":"1.1", "apiVersion":"1.0", "apis":[ 
    { 
     "path":"/pay", 
     "format":"json", 
     "description":"Create a transaction with the given amount and token.", 
     "operations":[ 
      { 
       "httpMethod":"GET", 
       "tags":["production"], 
       "nickname":"pay", 
       "deprecated":false, 
       "summary":"Create a transaction with the given amount and token.", 
       "parameters":[ 
        { 
         "name":"token", 
         "description":"The token representing the pay card", 
         "dataType":"string", 
         "allowMultiple":false, 
         "required":true, 
         "paramType":"query" 
        }, 
        { 
         "name":"amount", 
         "description":"The amount to pay", 
         "dataType":"string", 
         "allowMultiple":false, 
         "required":true, 
         "paramType":"query" 
        } 
       ] 
      } 
     ] 
    }, 
    { 
     "path":"/customer", 
     "format":"json", 
     "description":"Create an HTML form for adding a customer.", 
     "operations":[ 
      { 
       "httpMethod":"GET", 
       "tags":["production"], 
       "nickname":"createCustomerForm", 
       "deprecated":false, 
       "summary":"Create an HTML form for adding a customer.", 
       "parameters":[ 
        { 
         "name":"customerId", 
         "description":"Your customer id", 
         "dataType":"string", 
         "allowMultiple":false, 
         "required":true, 
         "paramType":"query" 
        } 
       ] 
      } 
     ] 
    }, 
    { 
     "path":"/customer/{customerId}", 
     "format":"json", 
     "description":"Delete the customer info for given id.", 
     "operations":[ 
      { 
       "httpMethod":"DELETE", 
       "tags":["production"], 
       "nickname":"deleteCustomer", 
       "deprecated":false, 
       "summary":"Delete the customer info for given id.", 
       "parameters":[ 
        { 
         "name":"customerId", 
         "description":"the customer id to delete", 
         "dataType":"string", 
         "allowMultiple":false, 
         "required":true, 
         "paramType":"path" 
        } 
       ] 
      } 
     ] 
    }, 
    { 
     "path":"/card", 
     "format":"json", 
     "description":"Create an HTML form for adding a credit card.", 
     "operations":[ 
      { 
       "httpMethod":"GET", 
       "tags":["production"], 
       "nickname":"createCardForm", 
       "deprecated":false, 
       "summary":"Create an HTML form for the given customer to add a credit card.", 
       "parameters":[ 
        { 
         "name":"customerId", 
         "description":"Your customer id", 
         "dataType":"string", 
         "allowMultiple":false, 
         "required":true, 
         "paramType":"query" 
        } 
       ] 
      } 
     ] 
    }, 
    { 
     "path":"/card/{token}", 
     "format":"json", 
     "description":"Delete a card record by token.", 
     "operations":[ 
      { 
       "httpMethod":"DELETE", 
       "tags":["production"], 
       "nickname":"deleteCard", 
       "deprecated":false, 
       "summary":"Delete the card info for given token.", 
       "parameters":[ 
        { 
         "name":"token", 
         "description":"the token to delete", 
         "dataType":"string", 
         "allowMultiple":false, 
         "required":true, 
         "paramType":"path" 
        } 
       ] 
      } 
     ] 
    } 
]}