最近我寫了RESTful API中有用SpringMVC和招搖的UI(V2)。今天,我只注意到按鈕導入的postman.And我點擊它,我在上面剛纔看到的評論 「導入郵差收集,環境,數據轉儲,curl命令,或腎錯構瘤/ WADL /揚鞭(V1/V2)/ Runscope文件。」 如何招搖的API導出到郵遞員
起初我gooled,但沒有答案滿足我的情況。
所以我的問題是如何創建郵遞員需要的文件。順便說一下,我不熟悉招搖。
最近我寫了RESTful API中有用SpringMVC和招搖的UI(V2)。今天,我只注意到按鈕導入的postman.And我點擊它,我在上面剛纔看到的評論 「導入郵差收集,環境,數據轉儲,curl命令,或腎錯構瘤/ WADL /揚鞭(V1/V2)/ Runscope文件。」 如何招搖的API導出到郵遞員
起初我gooled,但沒有答案滿足我的情況。
所以我的問題是如何創建郵遞員需要的文件。順便說一下,我不熟悉招搖。
我使用PHP並使用Swagger 2.0來記錄API。 Swagger文檔是即時創建的(至少這是我在PHP中使用的)。該文檔以JSON格式生成。
樣品文件
{
"swagger": "2.0",
"info": {
"title": "Company Admin Panel",
"description": "Converting the Magento code into core PHP and RESTful APIs for increasing the performance of the website.",
"contact": {
"email": "[email protected]"
},
"version": "1.0.0"
},
"host": "localhost/cv_admin/api",
"schemes": [
"http"
],
"paths": {
"/getCustomerByEmail.php": {
"post": {
"summary": "List the details of customer by the email.",
"consumes": [
"string",
"application/json",
"application/x-www-form-urlencoded"
],
"produces": [
"application/json"
],
"parameters": [
{
"name": "email",
"in": "body",
"description": "Customer email to ge the data",
"required": true,
"schema": {
"properties": {
"id": {
"properties": {
"abc": {
"properties": {
"inner_abc": {
"type": "number",
"default": 1,
"example": 123
}
},
"type": "object"
},
"xyz": {
"type": "string",
"default": "xyz default value",
"example": "xyz example value"
}
},
"type": "object"
}
}
}
}
],
"responses": {
"200": {
"description": "Details of the customer"
},
"400": {
"description": "Email required"
},
"404": {
"description": "Customer does not exist"
},
"default": {
"description": "an \"unexpected\" error"
}
}
}
},
"/getCustomerById.php": {
"get": {
"summary": "List the details of customer by the ID",
"parameters": [
{
"name": "id",
"in": "query",
"description": "Customer ID to get the data",
"required": true,
"type": "integer"
}
],
"responses": {
"200": {
"description": "Details of the customer"
},
"400": {
"description": "ID required"
},
"404": {
"description": "Customer does not exist"
},
"default": {
"description": "an \"unexpected\" error"
}
}
}
},
"/getShipmentById.php": {
"get": {
"summary": "List the details of shipment by the ID",
"parameters": [
{
"name": "id",
"in": "query",
"description": "Shipment ID to get the data",
"required": true,
"type": "integer"
}
],
"responses": {
"200": {
"description": "Details of the shipment"
},
"404": {
"description": "Shipment does not exist"
},
"400": {
"description": "ID required"
},
"default": {
"description": "an \"unexpected\" error"
}
}
}
}
},
"definitions": {
}
}
這可以導入到郵差如下。
您還可以使用 '導入來源鏈接'。這裏粘貼從Swagger或任何其他API文檔工具生成API的JSON格式的URL。
這是我的文檔(JSON)生成文件。它在PHP中。我不知道JAVA和Swagger。
<?php
require("vendor/autoload.php");
$swagger = \Swagger\scan('path_of_the_directory_to_scan');
header('Content-Type: application/json');
echo $swagger;
你也可以在線獲取一些示例swagger文件來驗證這一點(如果你在swagger doc中有錯誤)。
來顯示您在此答案中描述的郵遞員中導入的JSON我如何導出swagger.yaml?我在SpringMvc中使用swagger-ui。 –
你想從哪裏出口?你是否已經在使用Swagger來創作你的YAML? –
謝謝,但現在的問題是我怎麼能從swagger-ui中導出文件?而且鏈接是無用的。 –
@DemonColdmist我已經添加了代碼來生成API。基本上,它掃描整個目錄,檢查註釋並生成JSON/YAML輸出。對不起,但我沒有用JAVA的Swagger。 – JDpawar
謝謝,如果它可以在PHP中導出,那麼Java也是如此。我將把它翻譯成Java。 –