今天介紹一個 好用的網站,有時候 web api 寫好了,需要先把文件分享出去但是實際上這份文件只是先給對方預覽
你也還沒有再對外公開機器上面,雖然你說架好 swagger 就可以了,但是就是還沒對外,或是你只是要敘述你系統要怎麼呼叫
不可能因為他架設一個 sample 網站,今天找到一個不錯的 網站 https://editor.swagger.io/

1.首先,當然你要會將你的 web api 放入 swagger 方法請參考
https://docs.microsoft.com/zh-tw/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-6.0&tabs=visual-studio
2.架設起來後你在這裡可以找到 swagger.json 內容大概如下,把這內容複製起來

3. 之後到 https://editor.swagger.io/ 這網站,貼上swagger.json 的內容
範例內容:
{
"x-generator": "NSwag v13.15.5.0 (NJsonSchema v10.6.6.0 (Newtonsoft.Json v13.0.0.0))",
"swagger": "2.0",
"info": {
"title": "TATAKOSAN Dev API",
"version": "1.0.0"
},
"host": "localhost:44388",
"schemes": [
"https"
],
"produces": [
"text/plain",
"application/json",
"text/json"
],
"paths": {
"/api/Op": {
"get": {
"tags": [
"Op"
],
"operationId": "Op_Get",
"responses": {
"200": {
"x-nullable": false,
"description": "",
"schema": {
"type": "string"
}
}
}
}
},
"/api/Op/ClearPool": {
"get": {
"tags": [
"Op"
],
"operationId": "Op_GetClear",
"parameters": [
{
"type": "string",
"name": "token",
"in": "query",
"x-nullable": true
}
],
"responses": {
"200": {
"x-nullable": false,
"description": "",
"schema": {
"type": "string"
}
}
}
}
},
"/api/Op/Update": {
"post": {
"tags": [
"Op"
],
"operationId": "Op_CreateDataPublic",
"consumes": [
"application/json",
"text/json",
"application/*+json"
],
"parameters": [
{
"name": "src",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/RequestUpdateData"
},
"x-nullable": false
}
],
"responses": {
"200": {
"x-nullable": false,
"description": "",
"schema": {
"$ref": "#/definitions/ResponseBodyBasicOfString"
}
}
}
}
},
"/api/Op/Delete": {
"post": {
"tags": [
"Op"
],
"operationId": "Op_DeleteData",
"consumes": [
"application/json",
"text/json",
"application/*+json"
],
"parameters": [
{
"name": "src",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/RequestDeleteData"
},
"x-nullable": false
}
],
"responses": {
"200": {
"x-nullable": false,
"description": "",
"schema": {
"$ref": "#/definitions/ResponseBodyBasicOfString"
}
}
}
}
},
"/api/Op/CreateTable": {
"post": {
"tags": [
"Op"
],
"operationId": "Op_CreateTable",
"consumes": [
"application/json",
"text/json",
"application/*+json"
],
"parameters": [
{
"name": "src",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/RequestCreateTable"
},
"x-nullable": false
}
],
"responses": {
"200": {
"x-nullable": false,
"description": "",
"schema": {
"$ref": "#/definitions/ResponseBodyBasicOfString"
}
}
}
}
},
"/api/Qu": {
"get": {
"tags": [
"Query"
],
"operationId": "Query_Get",
"responses": {
"200": {
"x-nullable": false,
"description": "",
"schema": {
"type": "string"
}
}
}
}
},
"/api/Qu/IsTableExisted": {
"post": {
"tags": [
"Query"
],
"operationId": "Query_IsTableExisted",
"consumes": [
"application/json",
"text/json",
"application/*+json"
],
"parameters": [
{
"name": "src",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/RequestIsTableExist"
},
"x-nullable": false
}
],
"responses": {
"200": {
"x-nullable": false,
"description": "",
"schema": {
"$ref": "#/definitions/ResponseBodyBasicOfBoolean"
}
}
}
}
},
"/api/Qu/GetFullData": {
"post": {
"tags": [
"Query"
],
"operationId": "Query_GetFullData",
"consumes": [
"application/json",
"text/json",
"application/*+json"
],
"parameters": [
{
"name": "src",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/RequestQueryDataFull"
},
"x-nullable": false
}
],
"responses": {
"200": {
"x-nullable": false,
"description": "",
"schema": {
"$ref": "#/definitions/ResponseBodyBasicOfResponseDataInfo"
}
}
}
}
},
"/api/Qu/IsDataExist": {
"post": {
"tags": [
"Query"
],
"operationId": "Query_IsDataExist",
"consumes": [
"application/json",
"text/json",
"application/*+json"
],
"parameters": [
{
"name": "src",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/RequestIsDataExist"
},
"x-nullable": false
}
],
"responses": {
"200": {
"x-nullable": false,
"description": "",
"schema": {
"$ref": "#/definitions/ResponseBodyBasicOfResponseDataExist"
}
}
}
}
}
},
"definitions": {
"ResponseBodyBasicOfString": {
"allOf": [
{
"$ref": "#/definitions/ResponseBody"
},
{
"type": "object",
"properties": {
"Content": {
"type": "string"
},
"Sign": {
"type": "string"
}
}
}
]
},
"ResponseBody": {
"type": "object",
"properties": {
"Status": {
"type": "string"
},
"Code": {
"type": "string"
},
"Message": {
"type": "string"
},
"TimeStamp": {
"type": "string"
}
}
},
"RequestUpdateData": {
"type": "object",
"properties": {
"Id": {
"type": "string"
},
"Data": {
"type": "string"
},
"Ext1": {
"type": "string"
},
"Ext2": {
"type": "string"
},
"Ext3": {
"type": "string"
},
"Group": {
"type": "string"
},
"Table": {
"type": "string"
},
"Sign": {
"type": "string"
}
}
},
"RequestDeleteData": {
"type": "object",
"properties": {
"Table": {
"type": "string"
},
"Group": {
"type": "string"
},
"Id": {
"type": "string"
},
"Sign": {
"type": "string"
}
}
},
"RequestCreateTable": {
"type": "object",
"properties": {
"Table": {
"type": "string"
},
"Sign": {
"type": "string"
}
}
},
"ResponseBodyBasicOfBoolean": {
"allOf": [
{
"$ref": "#/definitions/ResponseBody"
},
{
"type": "object",
"required": [
"Content"
],
"properties": {
"Content": {
"type": "boolean"
},
"Sign": {
"type": "string"
}
}
}
]
},
"RequestIsTableExist": {
"type": "object",
"properties": {
"Table": {
"type": "string"
},
"Sign": {
"type": "string"
}
}
},
"ResponseBodyBasicOfResponseDataInfo": {
"allOf": [
{
"$ref": "#/definitions/ResponseBody"
},
{
"type": "object",
"properties": {
"Content": {
"$ref": "#/definitions/ResponseDataInfo"
},
"Sign": {
"type": "string"
}
}
}
]
},
"ResponseDataInfo": {
"type": "object",
"properties": {
"Id": {
"type": "string"
},
"Data": {
"type": "string"
},
"Ext1": {
"type": "string"
},
"Ext2": {
"type": "string"
},
"Ext3": {
"type": "string"
},
"Group": {
"type": "string"
}
}
},
"RequestQueryDataFull": {
"type": "object",
"properties": {
"Table": {
"type": "string"
},
"Group": {
"type": "string"
},
"Id": {
"type": "string"
},
"Sign": {
"type": "string"
}
}
},
"ResponseBodyBasicOfResponseDataExist": {
"allOf": [
{
"$ref": "#/definitions/ResponseBody"
},
{
"type": "object",
"properties": {
"Content": {
"$ref": "#/definitions/ResponseDataExist"
},
"Sign": {
"type": "string"
}
}
}
]
},
"ResponseDataExist": {
"type": "object",
"required": [
"IsInCache",
"IsInStorage"
],
"properties": {
"IsInCache": {
"type": "boolean"
},
"IsInStorage": {
"type": "boolean"
}
}
},
"RequestIsDataExist": {
"type": "object",
"properties": {
"Table": {
"type": "string"
},
"Group": {
"type": "string"
},
"Id": {
"type": "string"
},
"Sign": {
"type": "string"
}
}
}
}
}
4. 選取 Generate List 中的 html2 就可以得到一包 zip ,你就可以打開,看到一份簡單的文件,當然沒有 server 不能測試
但是基本上就可以看出怎麼呼叫,而且還有個語言的範例程式碼

5. 當然功能不只這個,他還可以產生 C# 的呼叫範例程式,我覺得很方便推薦給大家。