{"id":10008055,"date":"2023-07-07T14:59:36","date_gmt":"2023-07-07T06:59:36","guid":{"rendered":"https:\/\/ityet.com\/?p=10008055"},"modified":"2023-07-07T14:59:36","modified_gmt":"2023-07-07T06:59:36","slug":"%e4%bd%bf%e7%94%a8-openapi-%e6%9e%84%e5%bb%ba-restful-api-%e6%96%87%e6%a1%a3","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10008055","title":{"rendered":"\u4f7f\u7528 OpenAPI \u6784\u5efa RESTful API \u6587\u6863"},"content":{"rendered":"<p>\u4f5c\u4e3a\u4e00\u540d\u5f00\u53d1\u8005\uff0c\u5f80\u5f80\u9700\u8981\u7f16\u5199\u7a0b\u5e8f\u7684 API \u6587\u6863\uff0c\u5c24\u5176\u662f Web \u540e\u7aef\u5f00\u53d1\u8005\uff0c\u5728\u8ddf\u524d\u7aef\u5bf9\u63a5 HTTP \u63a5\u53e3\u7684\u65f6\u5019\uff0c\u4e00\u4e2a\u597d\u7684 API \u6587\u6863\u80fd\u591f\u5927\u5927\u63d0\u9ad8\u534f\u4f5c\u6548\u7387\uff0c\u964d\u4f4e\u6c9f\u901a\u6210\u672c\uff0c\u672c\u6587\u5c31\u6765\u804a\u804a\u5982\u4f55\u4f7f\u7528 OpenAPI \u6784\u5efa HTTP \u63a5\u53e3\u6587\u6863\u3002<\/p>\n<h2><strong>OpenAPI<\/strong><\/h2>\n<h2><strong>\u4ec0\u4e48\u662fOpenAPI<\/strong><\/h2>\n<p>OpenAPI \u662f\u89c4\u8303\u5316\u63cf\u8ff0 API \u9886\u57df\u5e94\u7528\u6700\u5e7f\u6cdb\u7684\u884c\u4e1a\u6807\u51c6\uff0c\u7531 OpenAPI Initiative \u7ec4\u7ec7\u5b9a\u4e49\u5e76\u7ef4\u62a4\uff0c\u540c\u65f6\u4e5f\u662f Linux \u57fa\u91d1\u4f1a\u4e0b\u7684\u4e00\u4e2a\u5f00\u6e90\u9879\u76ee\u3002\u5b83\u4f7f\u7528\u89c4\u5b9a\u7684\u683c\u5f0f\u6765\u63cf\u8ff0 HTTP RESTful API \u7684\u5b9a\u4e49\uff0c\u4ee5\u6b64\u6765\u89c4\u8303 RESTful \u670d\u52a1\u5f00\u53d1\u8fc7\u7a0b\u3002\u4f7f\u7528 JSON \u6216 YAML \u6765\u63cf\u8ff0\u4e00\u4e2a\u6807\u51c6\u7684\u3001\u4e0e\u7f16\u7a0b\u8bed\u8a00\u65e0\u5173\u7684 HTTP API \u63a5\u53e3\u3002<\/p>\n<p>\u7b80\u5355\u6765\u8bf4\uff0cOpenAPI \u5c31\u662f\u7528\u6765\u5b9a\u4e49 HTTP \u63a5\u53e3\u6587\u6863\u7684\u4e00\u79cd\u89c4\u8303\uff0c\u5927\u5bb6\u90fd\u6309\u7167\u540c\u4e00\u5957\u89c4\u8303\u6765\u7f16\u5199\u63a5\u53e3\u6587\u6863\uff0c\u80fd\u591f\u6781\u5927\u5730\u51cf\u5c11\u6c9f\u901a\u6210\u672c\u3002<\/p>\n<h3><strong>OpenAPI\u89c4\u8303<\/strong><\/h3>\n<p>OpenAPI \u6587\u6863\u7f16\u5199\u5728\u4e00\u4e2a .json \u6216 .yaml \u4e2d\uff0c\u63a8\u8350\u5c06\u5176\u547d\u540d\u4e3a openapi.json \u6216 openapi.yaml\uff0cOpenAPI \u6587\u6863\u5176\u5b9e\u5c31\u662f\u4e00\u4e2a\u5355\u4e00\u7684 JSON \u5bf9\u8c61\uff0c\u5176\u4e2d\u5305\u542b\u7b26\u5408 OpenAPI \u89c4\u8303\u4e2d\u5b9a\u4e49\u7684\u7ed3\u6784\u5b57\u6bb5\u3002  <br \/>OpenAPI \u89c4\u8303\u57fa\u672c\u4fe1\u606f\u5982\u4e0b\uff1a<img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043982064\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\">OpenAPI \u89c4\u8303\u5185\u5bb9\u5305\u542b\u975e\u5e38\u591a\u7684\u7ec6\u8282\uff0c\u672c\u6587\u65e0\u6cd5\u4e00\u4e00\u8bb2\u89e3\uff0c\u8fd9\u91cc\u4ec5\u4ecb\u7ecd\u5e38\u89c1\u7684\u57fa\u672c\u4fe1\u606f\uff0c\u4ee5 YAML \u4e3a\u4f8b\u8fdb\u884c\u8bf4\u660e\u3002<\/p>\n<p>\u4e00\u4e2a YAML \u683c\u5f0f\u7684 OpenAPI \u6587\u6863\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre><code>openapi: 3.1.0info:  title: Tic Tac Toe  description: |    This API allows writing down marks on a Tic Tac Toe board    and requesting the state of the board or of individual squares.  version: 1.0.0 # \u6b64\u4e3a API \u63a5\u53e3\u6587\u6863\u7248\u672c\uff0c\u4e0e openapi \u7248\u672c\u65e0\u5173tags:  - name: Gameplaypaths:  # Whole board operations  \/board:    get:      summary: Get the whole board      description: Retrieves the current state of the board and the winner.      tags:        - Gameplay      operationId: get-board      responses:        &quot;200&quot;:          description: &quot;OK&quot;          content:            application\/json:              schema:                $ref: &quot;#\/components\/schemas\/status&quot;  # Single square operations  \/board\/{row}\/{column}:    parameters:      - $ref: &quot;#\/components\/parameters\/rowParam&quot;      - $ref: &quot;#\/components\/parameters\/columnParam&quot;    get:      summary: Get a single board square      description: Retrieves the requested square.      tags:        - Gameplay      operationId: get-square      responses:        &quot;200&quot;:          description: &quot;OK&quot;          content:            application\/json:              schema:                $ref: &quot;#\/components\/schemas\/mark&quot;        &quot;400&quot;:          description: The provided parameters are incorrect          content:            text\/html:              schema:                $ref: &quot;#\/components\/schemas\/errorMessage&quot;              example: &quot;Illegal coordinates&quot;...<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u5f00\u53d1\u8fc7 API \u63a5\u53e3\uff0c\u76f8\u4fe1\u80fd\u770b\u61c2\u6587\u6863\u5927\u90e8\u5206\u5185\u5bb9\u6240\u4ee3\u8868\u7684\u542b\u4e49\u3002\u4e0d\u5fc5\u5b8c\u5168\u638c\u63e1\u5176\u8bed\u6cd5\uff0c\u8fd9\u5e76\u4e0d\u4f1a\u5bf9\u9605\u8bfb\u672c\u6587\u63a5\u4e0b\u6765\u7684\u5185\u5bb9\u9020\u6210\u56f0\u6270\uff0c\u56e0\u4e3a\u7a0d\u540e\u6211\u4f1a\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7\u4ee3\u7801\u6ce8\u91ca\u7684\u65b9\u5f0f\u81ea\u52a8\u751f\u6210\u6b64\u6587\u6863\u3002\u5982\u679c\u4f60\u60f3\u624b\u52a8\u7f16\u5199 OpenAPI \u6587\u6863\uff0c\u90a3\u6211\u8fd8\u662f\u63a8\u8350\u4f60\u9605\u8bfb\u4e0b OpenAPI \u89c4\u8303\u3002\u9605\u8bfb\u89c4\u8303\u662f\u4e00\u4e2a\u6bd4\u8f83\u67af\u71e5\u7684\u8fc7\u7a0b\uff0c\u5982\u679c\u4f60\u6ca1\u6709\u8010\u5fc3\u8bfb\u5b8c\uff0c\u5f3a\u70c8\u5efa\u8bae\u9605\u8bfb OpenAPI \u89c4\u8303\u5165\u95e8\uff08<a href=\"https:\/\/link.segmentfault.com\/?enc=mutvBcB7Y4eT9%2FX7gZrz9A%3D%3D.UDwz%2Bp7OuGkTrNuUK0QQdcPEsIgyNiNmDopnTQpIpX4ZLwa6QQlDLevQUqsDwr1z\" rel=\"nofollow\">https:\/\/oai.github.io\/Documentation\/<\/a>\uff09\uff0c<br \/>\u76f8\u8f83\u4e8e\u5b8c\u6574\u7248\u7684\u89c4\u8303\u8981\u7cbe\u7b80\u5f97\u591a\uff0c\u5e76\u4e14\u8bb2\u89e3\u66f4\u52a0\u6613\u4e8e\u7406\u89e3\u3002<\/p>\n<p>\u53e6\u5916\u8fd8\u63a8\u8350\u8bbf\u95ee\u00a0OpenAPI Map\u00a0\u7f51\u7ad9\u6765\u638c\u63e1 OpenAPI \u89c4\u8303\uff0c\u8be5\u7f51\u7ad9\u4ee5\u601d\u7ef4\u5bfc\u56fe\u7684\u5f62\u5f0f\u5c55\u73b0\u89c4\u8303\u7684\u683c\u5f0f\u4ee5\u53ca\u8bf4\u660e\u3002<img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043982065\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<h3><strong>OpenAPI.Tools<\/strong><\/h3>\n<p>\u73b0\u5728\u6211\u4eec\u77e5\u9053\u4e86 OpenAPI \u89c4\u8303\uff0c\u63a5\u4e0b\u6765\u8981\u505a\u4ec0\u4e48\uff1f\u5f53\u7136\u662f\u4e86\u89e3 OpenAPI \u5f00\u653e\u4e86\u54ea\u4e9b\u80fd\u529b\u3002  <br \/>\u6709\u4e00\u4e2a\u53eb\u00a0OpenAPI.Tools\u00a0\u7684\u7f51\u7ad9\uff0c\u5206\u7c7b\u6574\u7406\u5e76\u8bb0\u5f55\u4e86\u793e\u533a\u56f4\u7ed5 OpenAPI \u89c4\u8303\u5f00\u53d1\u7684\u6d41\u884c\u5de5\u5177\u3002<img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043982066\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\">\u53ef\u4ee5\u770b\u5230\u5217\u8868\u4e2d\u6709\u5f88\u591a\u5206\u7c7b\uff0c\u5728\u6211\u4eec\u65e5\u5e38\u5f00\u53d1\u4e2d\uff0c\u6700\u7ecf\u5e38\u4f7f\u7528\u7684\u6709\u4e09\u7c7b\uff1a<\/p>\n<h4><strong>\u6587\u6863\u7f16\u8f91\u5668<\/strong><\/h4>\n<p>\u6587\u6863\u7f16\u8f91\u5668\u65b9\u4fbf\u6211\u4eec\u7528\u6765\u7f16\u5199\u7b26\u5408 OpenAPI \u89c4\u8303\u7684\u6587\u6863\uff0c\u6709\u52a9\u4e8e\u63d0\u9ad8\u7f16\u5199\u6587\u6863\u7684\u6548\u7387\uff0c\u5c31\u50cf VS Code \u80fd\u591f\u65b9\u4fbf\u6211\u4eec\u7f16\u5199\u4ee3\u7801\u4e00\u6837\u3002<\/p>\n<p>\u6587\u6863\u7f16\u8f91\u5668\u6709\u4e24\u79cd\uff1a\u6587\u672c\u7f16\u8f91\u5668\u4ee5\u53ca\u56fe\u5f62\u7f16\u8f91\u5668\u3002<\/p>\n<p>\u6587\u672c\u7f16\u8f91\u5668\u63a8\u8350\u4f7f\u7528\u5728\u7ebf\u7684\u00a0Swagger Editor\uff0c\u80fd\u591f\u5b9e\u73b0\u683c\u5f0f\u6821\u9a8c\u548c\u5b9e\u65f6\u9884\u89c8 Swagger \u4ea4\u4e92\u5f0f API \u6587\u6863\u529f\u80fd\uff0c\u6548\u679c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043982067\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\">\u5982\u679c\u4f60\u4e60\u60ef\u4f7f\u7528 VS Code\uff0c\u4e5f\u6709\u76f8\u5e94\u63d2\u4ef6\u53ef\u4f9b\u4f7f\u7528\u3002\u56fe\u5f62\u7f16\u8f91\u5668\u7684\u597d\u5904\u662f\u80fd\u591f\u4ee5\u53ef\u89c6\u5316\u7684\u5f62\u5f0f\u7f16\u8f91\u5185\u5bb9\uff0c\u4e0d\u4e86\u89e3 OpenAPI \u89c4\u8303\u8bed\u6cd5\u4e5f\u80fd\u7f16\u8f91\u3002\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u559c\u597d\u6765\u8fdb\u884c\u9009\u62e9\uff0c\u5982 Stoplight Studio\u3001APIGit \u7b49\u3002<\/p>\n<h4><strong>Mock \u670d\u52a1\u5668<\/strong><\/h4>\n<p>\u5f53\u6211\u4eec\u4f7f\u7528 OpenAPI \u89c4\u8303\u6765\u8fdb\u884c\u63a5\u53e3\u5f00\u53d1\u65f6\uff0c\u5f80\u5f80\u91c7\u7528\u6587\u6863\u5148\u884c\u7684\u7b56\u7565\uff0c\u4e5f\u5c31\u662f\u524d\u540e\u7aef\u5728\u5f00\u53d1\u4ee3\u7801\u524d\uff0c\u5148\u5b9a\u4e49\u597d\u63a5\u53e3\u6587\u6863\uff0c\u518d\u8fdb\u884c\u4ee3\u7801\u7684\u7f16\u5199\u3002\u6b64\u65f6\u524d\u7aef\u5982\u679c\u60f3\u6d4b\u8bd5\u63a5\u53e3\u53ef\u7528\u6027\uff0c\u800c\u540e\u7aef\u4ee3\u7801\u8fd8\u6ca1\u6709\u7f16\u5199\u5b8c\u6210\uff0cMock \u670d\u52a1\u5668\u5c31\u6d3e\u4e0a\u7528\u573a\u4e86\u3002Mock \u670d\u52a1\u5668\u80fd\u591f\u6839\u636e\u6240\u63d0\u4f9b\u7684 OpenAPI \u63a5\u53e3\u6587\u6863\uff0c\u81ea\u52a8\u751f\u6210\u4e00\u4e2a\u6a21\u62df\u7684 Web Server\u3002\u4f7f\u7528 Mock \u670d\u52a1\u5668\u80fd\u591f\u8f7b\u677e\u6a21\u62df\u771f\u5b9e\u7684\u540e\u7aef\u63a5\u53e3\uff0c\u65b9\u4fbf\u524d\u7aef\u540c\u5b66\u8fdb\u884c\u63a5\u53e3\u8c03\u8bd5\u3002<\/p>\n<p>\u4e0a\u9762\u63d0\u5230\u7684 APIGit \u4e5f\u540c\u65f6\u5177\u5907\u6b64\u529f\u80fd\u3002<\/p>\n<h4><strong>\u4ee3\u7801\u751f\u6210\u5668<\/strong><\/h4>\n<p>\u8fd8\u6709\u4e00\u79cd\u5f88\u5b9e\u7528\u7684\u5de5\u5177\u662f\u4ee3\u7801\u751f\u6210\u5668\uff0c\u4ee3\u7801\u751f\u6210\u5668\u6709\u4e24\u79cd\u7c7b\u578b\uff1a\u4e00\u79cd\u662f\u4ece\u4ee3\u7801\/\u6ce8\u91ca\u751f\u6210 OpenAPI \u6587\u6863\uff0c\u53e6\u4e00\u79cd\u662f\u4ece OpenAPI \u6587\u6863\u751f\u6210\u4ee3\u7801\u3002<\/p>\n<p>\u8fd9\u7c7b\u5de5\u5177\u540c\u6837\u975e\u5e38\u591a\uff0c\u4e14\u66f4\u4e3a\u5b9e\u7528\u3002\u6bd4\u5982\u6211\u4eec\u6709\u4e00\u4efd\u5199\u597d\u4e86\u7684 Go Web Server \u4ee3\u7801\uff0c\u60f3\u8981\u81ea\u52a8\u751f\u6210\u4e00\u4efd OpenAPI \u6587\u6863\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528 go-swagger \u8fd9\u4e2a\u5de5\u5177\u6765\u751f\u6210\u4e00\u4efd openapi.yaml \u6587\u6863\u3002<\/p>\n<p>\u800c\u5982\u679c\u6211\u4eec\u6709\u4e00\u4efd openapi.yaml \u6587\u6863\uff0c\u5c31\u53ef\u4ee5\u5229\u7528 go-swagger \u751f\u6210\u4e00\u4efd Go SDK \u4ee3\u7801\uff0c\u751a\u81f3\u5b83\u8fd8\u80fd\u6839\u636e\u8fd9\u4efd OpenAPI \u6587\u6863\u751f\u6210 Go Web Server \u7684\u6846\u67b6\u4ee3\u7801\uff0c\u6211\u4eec\u53ea\u9700\u8981\u5728\u5bf9\u5e94\u7684\u63a5\u53e3\u91cc\u9762\u5b9e\u73b0\u5177\u4f53\u7684\u4e1a\u52a1\u903b\u8f91\u5373\u53ef\u3002<\/p>\n<h2><strong>Swagger<\/strong><\/h2>\n<h3><strong>Swagger\u662f\u4ec0\u4e48<\/strong><\/h3>\n<p>Swagger \u662f\u4e00\u5957\u56f4\u7ed5 OpenAPI \u89c4\u8303\u6240\u6784\u5efa\u7684\u5f00\u6e90\u5de5\u5177\u96c6\uff0c\u63d0\u4f9b\u4e86\u5f3a\u5927\u548c\u6613\u4e8e\u4f7f\u7528\u7684\u5de5\u5177\u6765\u5145\u5206\u5229\u7528 OpenAPI \u89c4\u8303\uff0cSwagger \u5de5\u5177\u96c6\u7531\u6700\u521d\u7684 Swagger \u89c4\u8303\u80cc\u540e\u7684\u56e2\u961f\u6240\u5f00\u53d1\u3002Swagger \u5de5\u5177\u96c6\u63d0\u4f9b\u4e86 API \u8bbe\u8ba1\u3001\u5f00\u53d1\u3001\u6d4b\u8bd5\u3001\u6cbb\u7406\u548c\u76d1\u63a7\u7b49\u80fd\u529b\uff0c\u5176\u4e2d\u6700\u4e3b\u8981\u7684\u5de5\u5177\u5305\u542b\u5982\u4e0b\u4e09\u4e2a\uff1a<\/p>\n<ul>\n<li>Swagger Codegen\uff1a\u6839\u636e OpenAPI \u89c4\u8303\u5b9a\u4e49\u751f\u6210\u670d\u52a1\u5668\u5b58\u6839\u548c\u5ba2\u6237\u7aef SDK\u3002<\/li>\n<li>Swagger Editor\uff1a\u57fa\u4e8e\u6d4f\u89c8\u5668\u7684\u5728\u7ebf OpenAPI \u89c4\u8303\u7f16\u8f91\u5668\u3002<\/li>\n<li>Swagger UI\uff1a\u4ee5 UI \u754c\u9762\u7684\u65b9\u5f0f\u53ef\u89c6\u5316\u5c55\u793a OpenAPI \u89c4\u8303\u5b9a\u4e49\uff0c\u5e76\u4e14\u80fd\u591f\u5728\u6d4f\u89c8\u5668\u4e2d\u8fdb\u884c\u4ea4\u4e92\u3002<\/li>\n<\/ul>\n<p>\u5f53\u7136 Swagger \u4e5f\u6709\u4e3a\u4f01\u4e1a\u7528\u6237\u63d0\u4f9b\u7684\u6536\u8d39\u7248\u672c\u5de5\u5177 SwaggerHub Enterprise\uff0c\u611f\u5174\u8da3\u7684\u540c\u5b66\u53ef\u4ee5\u81ea\u884c\u4e86\u89e3\u3002<\/p>\n<h3><strong>Swagger\u548cOpenAPI\u7684\u5173\u7cfb<\/strong><\/h3>\n<p>\u8bb2\u5230\u4e86 Swagger\uff0c\u5c31\u4e0d\u5f97\u4e0d\u63d0\u53ca Swagger \u548c OpenAPI \u7684\u8054\u7cfb\u4e0e\u533a\u522b\uff0c\u56e0\u4e3a\u8fd9\u4e8c\u8005\u7ecf\u5e38\u5728\u4e00\u8d77\u51fa\u73b0\u3002 <\/p>\n<p>\u5728 OpenAPI \u5c1a\u672a\u51fa\u73b0\u4e4b\u524d\uff0cSwagger \u4ee3\u8868\u4e86 Swagger \u89c4\u8303\u4ee5\u53ca\u4e00\u7cfb\u5217\u56f4\u7ed5 Swagger \u89c4\u8303\u7684\u5f00\u6e90\u5de5\u5177\u96c6\u3002Swagger \u89c4\u8303\u6700\u540e\u4e00\u4e2a\u7248\u672c\u662f 2.0\uff0c\u4e4b\u540e\u5c31\u6350\u8d60\u7ed9\u4e86 OAI \u5e76\u88ab\u91cd\u65b0\u547d\u540d\u4e3a OpenAPI \u89c4\u8303\uff0c\u6240\u4ee5 OpenAPI \u89c4\u8303\u7b2c\u4e00\u4e2a\u7248\u672c\u662f 2.0\uff0c\u4e5f\u5c31\u662f Swagger \u89c4\u8303 2.0\uff0c\u800c\u7531 OAI \u8fd9\u4e2a\u7ec4\u7ec7\u53d1\u5e03\u7684\u7b2c\u4e00\u4e2a OpenAPI \u89c4\u8303\u6b63\u5f0f\u7248\u672c\u662f3.0.0\u3002<\/p>\n<p>\u73b0\u5728\uff0cSwagger \u89c4\u8303\u5df2\u88ab OpenAPI \u89c4\u8303\u5b8c\u5168\u63a5\u7ba1\u5e76\u53d6\u4ee3\u3002OpenAPI \u4ee3\u8868\u4e86 OpenAPI \u89c4\u8303\u4ee5\u53ca\u4e00\u7cfb\u5217\u751f\u6001\uff0c\u800c Swagger \u5219\u662f\u8fd9\u4e2a\u751f\u6001\u4e2d\u7684\u4e00\u90e8\u5206\uff0c\u662f Swagger \u56e2\u961f\u56f4\u7ed5 OpenAPI \u89c4\u8303\u6240\u5f00\u53d1\u7684\u4e00\u7cfb\u5217\u5de5\u5177\u96c6\u3002<\/p>\n<p>Swagger \u662f OpenAPI \u751f\u6001\u4e2d\u975e\u5e38\u91cd\u8981\u7684\u7ec4\u6210\u90e8\u5206\uff0c\u56e0\u4e3a\u5b83\u7ed9\u51fa\u4e86\u4e00\u6574\u5957\u65b9\u6848\uff0c\u4e14\u975e\u5e38\u6d41\u884c\u3002<\/p>\n<h2><strong>OpenAPI \u5728\u5b9e\u9645\u5f00\u53d1\u7684\u5e94\u7528<\/strong><\/h2>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u804a\u804a\u4ee5 Go \u8bed\u8a00\u4e3a\u4f8b\u8bb2\u89e3 OpenAPI \u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u7684\u5e94\u7528\u3002\u524d\u6587\u4ecb\u7ecd\u4e86\u7f16\u5199 OpenAPI \u6587\u6863\u7684\u4e24\u79cd\u7f16\u8f91\u5668\uff1a\u6587\u672c\u7f16\u8f91\u5668\u4ee5\u53ca\u56fe\u5f62\u7f16\u8f91\u5668\u3002\u5728\u65e5\u5e38\u5f00\u53d1\u4e2d\uff0c\u540e\u7aef\u53ef\u4ee5\u5148\u4f7f\u7528\u8fd9\u7c7b\u7f16\u8f91\u5668\u5982 Swagger Editor \u7f16\u5199\u51fa OpenAPI \u6587\u6863\uff0c\u7136\u540e\u5c06\u8fd9\u4efd\u6587\u6863\u4ea4\u7ed9\u524d\u7aef\uff0c\u524d\u7aef\u62ff\u5230 OpenAPI \u6587\u6863\u540e\u5c06\u5176\u5bfc\u5165\u5230 Swagger Editor\uff0c\u5c31\u53ef\u4ee5\u5728\u7ebf\u9605\u8bfb\u63a5\u53e3\u6587\u6863\u5e76\u4e0e\u4e4b\u8fdb\u884c\u4ea4\u4e92\uff0c\u4e4b\u540e\u524d\u540e\u7aef\u5c31\u53ef\u4ee5\u5e76\u884c\u5f00\u53d1\u4e86\u3002<\/p>\n<p>\u8fd9\u6837\u7684\u5de5\u4f5c\u6d41\u770b\u8d77\u6765\u4f3c\u4e4e\u6ca1\u4ec0\u4e48\u95ee\u9898\uff0c\u4e0d\u8fc7\u7f16\u5199 OpenAPI \u6587\u6863\u6bd5\u7adf\u662f\u4e2a\u82e6\u529b\u6d3b\uff0c\u4e0d\u4ec5\u6709\u5927\u91cf\u7684\u91cd\u590d\u5de5\u4f5c\uff0c\u8fd8\u8981\u6c42\u5f00\u53d1\u8005\u719f\u7ec3\u638c\u63e1 OpenAPI \u89c4\u8303\u8bed\u6cd5\u3002\u8fd9\u5bf9\u4e8e\u201c\u7231\u5077\u61d2\u201d\u7684\u5f00\u53d1\u8005\u663e\u7136\u662f\u65e0\u6cd5\u63a5\u53d7\u7684\uff0c\u5c31\u50cf\u6bb5\u5b50\u91cc\u8bf4\u7684\uff0c\u7a0b\u5e8f\u5458\u6700\u8ba8\u538c\u4e24\u4ef6\u4e8b\uff1a1. \u5199\u6587\u6863\uff0c2. \u522b\u4eba\u4e0d\u5199\u6587\u6863\u3002\u800c\u8fd9\u4e2a\u95ee\u9898\u7684\u89e3\u6cd5\uff0c\u5f53\u7136\u5c31\u662f\u524d\u6587\u63d0\u5230\u7684\u4ee3\u7801\u751f\u6210\u5668\u3002<\/p>\n<h3><strong>\u7528Swag\u751f\u6210Swagger\u6587\u6863<\/strong><\/h3>\n<p>\u5728 Go\u00a0\u8bed\u8a00\u751f\u6001\u91cc\uff0c\u76ee\u524d\u6709\u4e24\u4e2a\u6bd4\u8f83\u6d41\u884c\u7684\u5f00\u6e90\u5de5\u5177\u53ef\u4ee5\u751f\u6210 Swagger \u6587\u6863\uff0c\u5206\u522b\u662f go-swagger \u548c swag\u3002\u5b83\u4eec\u90fd\u80fd\u6839\u636e\u4ee3\u7801\u4e2d\u7684\u6ce8\u91ca\u751f\u6210 Swagger \u6587\u6863\uff0cgo-swagger \u4f5c\u4e3a\u4e00\u6b3e OpenAPI.Tools \u63a8\u8350\u7684\u5de5\u5177\uff0c\u5176\u529f\u80fd\u6bd4 swag \u66f4\u52a0\u5f3a\u5927\u4e14 Github Star \u6570\u91cf\u4e5f\u66f4\u9ad8\u3002\u4e0d\u8fc7\u672c\u6587\u5c06\u9009\u62e9 swag \u6765\u8fdb\u884c\u4ecb\u7ecd\uff0c\u4e00\u662f\u56e0\u4e3a swag \u6bd4\u8f83\u8f7b\u91cf\uff0c\u66f4\u9002\u5408\u5fae\u670d\u52a1\u5f00\u53d1\uff1b\u4e8c\u662f\u5982\u679c\u4f7f\u7528 swag\uff0c\u90a3\u4e48\u6ce8\u91ca\u4ee3\u7801\u4f1a\u79bb\u63a5\u53e3\u4ee3\u7801\u66f4\u8fd1\uff0c\u5347\u7ea7\u65f6\u65b9\u4fbf\u7ef4\u62a4\u3002\u5982\u679c\u4f60\u6709\u66f4\u9ad8\u7ea7\u7684\u9700\u6c42\uff0c\u5982\u6839\u636e Swagger \u6587\u6863\u751f\u6210\u5ba2\u6237\u7aef SDK\uff0c\u670d\u52a1\u7aef\u5b58\u6839\u7b49\uff0c\u5219\u63a8\u8350\u4f7f\u7528 go-swagger\u3002<\/p>\n<blockquote><p>\u6ce8\u610f\uff1a\u5728\u8fd9\u91cc\u6211\u4e00\u76f4\u63d0\u5230\u7684\u90fd\u662f\u751f\u6210 Swagger \u6587\u6863\uff0c\u800c\u6ca1\u6709\u8bf4\u662f OpenAPI \u6587\u6863\u3002\u56e0\u4e3a\u65e0\u8bba\u662f swag \u8fd8\u662f\u529f\u80fd\u66f4\u5f3a\u5927\u7684 go-swagger\uff0c\u5b83\u4eec\u76ee\u524d\u90fd\u4ec5\u652f\u6301\u751f\u6210 OpenAPI 2.0 \u6587\u6863\uff0c\u5e76\u4e0d\u652f\u6301\u751f\u6210 OpenAPI 3.0+ \u6587\u6863\uff0c\u800c OpenAPI 2.0 \u7248\u672c\u6211\u4eec\u66f4\u4e60\u60ef\u79f0\u5176\u4e3a Swagger \u6587\u6863\u3002<\/p><\/blockquote>\n<h3><strong>\u5b89\u88c5 Swag<\/strong><\/h3>\n<p>\u4f7f\u7528 go install \u547d\u4ee4\u5373\u53ef\u5b89\u88c5\u3002<\/p>\n<pre><code class=\"js\">$ go install github.com\/swaggo\/swag\/cmd\/swag@latest # \u5b89\u88c5\n$ swag --version # \u67e5\u770b\u7248\u672c\nswag version v1.8.10<\/code><\/pre>\n<h3><strong>Swag \u547d\u4ee4\u884c\u5de5\u5177<\/strong><\/h3>\n<p>swag \u975e\u5e38\u7b80\u6d01\uff0c\u4ec5\u63d0\u4f9b\u4e86\u4e24\u4e2a\u4e3b\u8981\u547d\u4ee4 init \u548c fmt\u3002<\/p>\n<ul>\n<li>\u5728\u5305\u542b main.go \u6587\u4ef6\uff08\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff09\u7684\u9879\u76ee\u6839\u76ee\u5f55\u8fd0\u884c swag init \u547d\u4ee4\uff0c\u5c06\u4f1a\u89e3\u6790 swag \u6ce8\u91ca\u5e76\u751f\u6210 docs\/ \u76ee\u5f55\u4ee5\u53ca \/docs\/docs.go\u3001docs\/swagger.json\u3001docs\/swagger.yaml \u4e09\u4e2a\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<pre><code>$ swag init -h # \u67e5\u770b init \u5b50\u547d\u4ee4\u4f7f\u7528\u65b9\u6cd5NAME:   swag init - Create docs.goUSAGE:   swag init [command options] [arguments...]OPTIONS:   --quiet, -q                            \u4e0d\u5728\u63a7\u5236\u53f0\u8f93\u51fa\u65e5\u5fd7 (default: false)   --generalInfo value, -g value          API \u901a\u7528\u4fe1\u606f\u6240\u5728\u7684 Go \u6e90\u6587\u4ef6\u8def\u5f84\uff0c\u5982\u679c\u662f\u76f8\u5bf9\u8def\u5f84\u5219\u57fa\u4e8e API \u89e3\u6790\u76ee\u5f55 (default: &quot;main.go&quot;)   --dir value, -d value                  API \u89e3\u6790\u76ee\u5f55\uff0c\u591a\u4e2a\u76ee\u5f55\u53ef\u7528\u9017\u53f7\u5206\u9694 (default: &quot;.\/&quot;)   --exclude value                        \u89e3\u6790\u626b\u63cf\u65f6\u6392\u9664\u7684\u76ee\u5f55\uff0c\u591a\u4e2a\u76ee\u5f55\u53ef\u7528\u9017\u53f7\u5206\u9694   --propertyStrategy value, -p value     \u7ed3\u6784\u4f53\u5b57\u6bb5\u547d\u540d\u89c4\u5219\uff0c\u4e09\u79cd\uff1asnake_case\uff0ccamelCase\uff0cPascalCase (default: &quot;camelCase&quot;)   --output value, -o value               \u6240\u6709\u751f\u6210\u6587\u4ef6\u7684\u8f93\u51fa\u76ee\u5f55\uff08swagger.json, swagger.yaml and docs.go\uff09(default:&quot;.\/docs&quot;)   --outputTypes value, --ot value        \u751f\u6210\u6587\u4ef6\u7684\u8f93\u51fa\u7c7b\u578b\uff08docs.go, swagger.json, swagger.yaml\uff09\u4e09\u79cd\uff1ago,json,yaml (default: &quot;go,json,yaml&quot;)   --parseDependency, --pd                \u89e3\u6790\u4f9d\u8d56\u76ee\u5f55\u4e2d\u7684 Go \u6587\u4ef6 (default: false)   --markdownFiles value, --md value      \u6307\u5b9a API \u7684\u63cf\u8ff0\u4fe1\u606f\u6240\u4f7f\u7528\u7684 Markdown \u6587\u4ef6\u6240\u5728\u7684\u76ee\u5f55\uff0c\u9ed8\u8ba4\u7981\u7528   --parseInternal                        \u89e3\u6790 internal \u5305\u4e2d\u7684 Go \u6587\u4ef6 (default: false)   --generatedTime                        \u8f93\u51fa\u65f6\u95f4\u6233\u5230\u8f93\u51fa\u6587\u4ef6 `docs.go` \u9876\u90e8 (default: false)   --parseDepth value                     \u4f9d\u8d56\u9879\u89e3\u6790\u6df1\u5ea6 (default: 100)   --requiredByDefault                    \u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u4e3a\u6240\u6709\u5b57\u6bb5\u8bbe\u7f6e `required` \u9a8c\u8bc1 (default: false)   --instanceName value                   \u8bbe\u7f6e\u6587\u6863\u5b9e\u4f8b\u540d (default: &quot;swagger&quot;)   --parseGoList                          \u901a\u8fc7 'go list' \u89e3\u6790\u4f9d\u8d56\u5173\u7cfb (default: true)   --tags value, -t value                 \u9017\u53f7\u5206\u9694\u7684\u6807\u7b7e\u5217\u8868\uff0c\u7528\u4e8e\u8fc7\u6ee4\u6307\u5b9a\u6807\u7b7e\u751f\u6210 API \u6587\u6863\u3002\u7279\u6b8a\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u6807\u7b7e\u524d\u7f00\u662f '!' \u5b57\u7b26\uff0c\u90a3\u4e48\u5e26\u6709\u8be5\u6807\u8bb0\u7684 API \u5c06\u88ab\u6392\u9664   --help, -h                             \u663e\u793a\u5e2e\u52a9\u4fe1\u606f (default: false)<\/code><\/pre>\n<blockquote><p>\u6ce8\u610f\uff1a\u4ee5\u4e0a swag init \u547d\u4ee4\u53ef\u9009\u53c2\u6570\u4ecb\u7ecd\u7565\u6709\u5220\u51cf\uff0c\u53ea\u5217\u51fa\u4e86\u5e38\u7528\u9009\u9879\uff0c\u66f4\u5b8c\u6574\u7684\u6587\u6863\u8bf7\u53c2\u8003\u5b98\u65b9 GitHub \u4ed3\u5e93\u3002<\/p><\/blockquote>\n<ul>\n<li>\n<p>swag fmt \u547d\u4ee4\u53ef\u4ee5\u683c\u5f0f\u5316 swag \u6ce8\u91ca\u3002<\/p>\n<pre><code class=\"js\">$ swag fmt -h # \u67e5\u770b fmt \u5b50\u547d\u4ee4\u4f7f\u7528\u65b9\u6cd5\nNAME:\nswag fmt - format swag comments \n\nUSAGE:  \nswag fmt [command options] [arguments...] \n\nOPTIONS:\n--dir value, -d value           API \u89e3\u6790\u76ee\u5f55\uff0c\u591a\u4e2a\u76ee\u5f55\u53ef\u7528\u9017\u53f7\u5206\u9694 (default: &quot;.\/&quot;) \n--exclude value                 \u89e3\u6790\u626b\u63cf\u65f6\u6392\u9664\u7684\u76ee\u5f55\uff0c\u591a\u4e2a\u76ee\u5f55\u53ef\u7528\u9017\u53f7\u5206\u9694 \ngeneralInfo value, -g value     API \u901a\u7528\u4fe1\u606f\u6240\u5728\u7684 Go \u6e90\u6587\u4ef6\u8def\u5f84\uff0c\u5982\u679c\u662f\u76f8\u5bf9\u8def\u5f84\u5219\u57fa\u4e8e API \u89e3\u6790\u76ee\u5f55 (default: &quot;main.go&quot;)\n--help, -h                      \u663e\u793a\u5e2e\u52a9\u4fe1\u606f (default: false) <\/code><\/pre>\n<h3><strong>\u5728 Gin \u4e2d\u4f7f\u7528 Swag<\/strong><\/h3>\n<\/li>\n<\/ul>\n<p>\u5728 gin \u6846\u67b6\u80fd\u591f\u5f88\u65b9\u4fbf\u7684\u4f7f\u7528 swag\uff0c\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\n<p>\u51c6\u5907\u9879\u76ee\u76ee\u5f55\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"js\">.\n\u251c\u2500\u2500 go.mod\n\u251c\u2500\u2500 go.sum\n\u2514\u2500\u2500 main.go<\/code><\/pre>\n<\/li>\n<li>\n<p>\u521d\u59cb\u5316\u9879\u76ee<\/p>\n<pre><code class=\"js\">$ go mod init gin-swag<\/code><\/pre>\n<\/li>\n<li>\u7f16\u5199 main.go \u4ee3\u7801\u5982\u4e0b\uff1a<\/li>\n<\/ol>\n<pre><code class=\"js\">package main\n\nimport (\n    &quot;net\/http&quot; \n    \n    &quot;github.com\/gin-gonic\/gin&quot;\n)\n\/\/ @title             Swagger Example API\n\/\/ @version           1.0\n\/\/ @schemes           http\n\/\/ @host              localhost:8080\n\/\/ @BasePath          \/api\/v1\n\/\/ @tag.name          example\n\/\/ @tag.description   \u793a\u4f8b\u63a5\u53e3\n\/\/ Helloworld godoc\n\/\/\n\/\/ @Summary           \u8be5\u64cd\u4f5c\u7684\u7b80\u77ed\u6458\u8981\n\/\/ @Description       \u64cd\u4f5c\u884c\u4e3a\u7684\u8be6\u7ec6\u8bf4\u660e\n\/\/ @Tags              example\n\/\/ @Accept            json\n\/\/ @Produce           json\n\/\/ @Success           200 {string} string &quot;Hello World!&quot;\n\/\/ @Router            \/example\/helloworld [get]\n\nfunc Helloworld(g *gin.Context) {\n    g.JSON(http.StatusOK, &quot;Hello World!&quot;)\n}\nfunc main() {\n    r := gin.Default()\n    v1 := r.Group(&quot;\/api\/v1&quot;)\n    {\n        eg := v1.Group(&quot;\/example&quot;)\n        {\n            eg.GET(&quot;\/helloworld&quot;, Helloworld)\n         }\n     } \n    if err := r.Run(&quot;:8080&quot;); err != nil {\n        panic(err)\n        }\n }<\/code><\/pre>\n<p>\u4ee3\u7801\u4e2d\u7684\u6ce8\u91ca\u90e8\u5206\u5373\u4e3a swag \u7684\u6ce8\u91ca\u8bed\u6cd5\uff0c\u7a0d\u540e\u901a\u8fc7\u8fd9\u4e9b\u6ce8\u91ca\u751f\u6210 Swagger \u6587\u6863\u3002<\/p>\n<p>\u5176\u4e2d\u901a\u7528 API \u4fe1\u606f\u90e8\u5206\u6ce8\u91ca\u542b\u4e49\u5982\u4e0b\uff1a<img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043982068\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\">\u8fd8\u6709\u4e00\u90e8\u5206\u6ce8\u91ca\u4ee3\u8868\u4e86 API \u64cd\u4f5c\uff0c\u5176\u542b\u4e49\u5982\u4e0b\uff1a<img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043982069\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\">\u4ee5\u4e0a\u8fd9\u4e9b\u6ce8\u91ca\u6700\u7ec8\u90fd\u4f1a\u5bf9\u5e94\u5230 OpenAPI 2.0 \u89c4\u8303\u7684\u67d0\u4e2a\u5b57\u6bb5\u4e0a\u3002<\/p>\n<ol start=\"4\">\n<li>\u4f7f\u7528 swag \u6839\u636e\u6ce8\u91ca\u751f\u6210 Swagger \u6587\u6863\uff0c\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\uff08.\uff09\u6267\u884c swag init\uff0c\u5c06\u5f97\u5230\u65b0\u7684\u76ee\u5f55\u7ed3\u6784\uff1a<\/li>\n<\/ol>\n<pre><code class=\"js\">.\n\u251c\u2500\u2500 docs\n\u2502 \u251c\u2500\u2500 docs.go\n\u2502 \u251c\u2500\u2500 swagger.json\n\u2502 \u2514\u2500\u2500 swagger.yaml\n\u251c\u2500\u2500 go.mod\n\u251c\u2500\u2500 go.sum\n\u2514\u2500\u2500 main.go<\/code><\/pre>\n<p>\u53ef\u4ee5\u53d1\u73b0 swag init \u751f\u6210\u7684\u4e09\u4e2a\u6587\u4ef6 docs.go\u3001swagger.json\u3001swagger.yaml \u9ed8\u8ba4\u90fd\u5728 docs\/ \u76ee\u5f55\u4e0b\u3002<\/p>\n<p>\u5176\u4e2d swagger.json\u3001swagger.yaml \u6b63\u662f\u7b26\u5408 OpenAPI 2.0 \u89c4\u8303\u7684 JSON \u548c YAML \u63a5\u53e3\u6587\u6863\uff0c\u4f8b\u5982 swagger.yaml \u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"js\">basePath: \/api\/v1\nhost: localhost:8080\ninfo:\n    contact: {} \n    title: Swagger Example API \n    version: &quot;1.0&quot; \n  paths: \n    \/example\/helloworld: \n      get: \n        consumes: \n        - application\/json \n        description: \u64cd\u4f5c\u884c\u4e3a\u7684\u8be6\u7ec6\u8bf4\u660e \n        produces: \n        - application\/json \n        responses: \n          &quot;200&quot;: \n            description: Hello World! \n            schema: \n              type: string \n        summary: \u8be5\u64cd\u4f5c\u7684\u7b80\u77ed\u6458\u8981 \n        tags: \n        - example \n schemes:\n - http\n swagger: &quot;2.0&quot;\n tags:\n - description: \u793a\u4f8b\u63a5\u53e3\n   name: example <\/code><\/pre>\n<p>\u5bf9\u6bd4\u4e0a\u9762\u4ee3\u7801\u4e2d\u7684\u6ce8\u91ca\uff0c\u5f88\u5bb9\u6613\u5c06\u5176\u5bf9\u5e94\u8d77\u6765\uff0c\u76f8\u6bd4\u4e8e\u76f4\u63a5\u7f16\u5199 YAML \u683c\u5f0f\u6587\u6863\uff0c\u663e\u7136\u5728\u4ee3\u7801\u4e2d\u7f16\u5199\u6ce8\u91ca\u66f4\u4e3a\u7b80\u5355\u3002<\/p>\n<p>\u5c06\u5176\u590d\u5236\u5230 Swagger Editor \u7f16\u8f91\u5668\u4e2d\u5373\u53ef\u67e5\u770b Swagger UI \u9884\u89c8\u3002<br \/><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043982070\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<h3><strong>\u5c06 Gin \u4f5c\u4e3a Swagger UI \u670d\u52a1\u5668<\/strong><\/h3>\n<p>\u4e0a\u9762\u6211\u4eec\u901a\u8fc7 Swag \u751f\u6210\u4e86 Swagger \u6587\u6863\uff0c\u5e76\u624b\u52a8\u5c06\u751f\u6210\u7684 swagger.yaml \u590d\u5236\u5230 Swagger Editor \u7f16\u8f91\u5668\u8fdb\u884c Swagger UI \u9884\u89c8\u3002\u4e0d\u8fc7\u8fd9\u4e48\u505a\u663e\u7136\u6709\u70b9\u9ebb\u70e6\uff0c\u597d\u5728 swag \u4f5c\u8005\u4e5f\u8003\u8651\u5230\u4e86\u8fd9\u4e00\u70b9\uff0c\u6240\u4ee5\u4ed6\u53c8\u63d0\u4f9b\u4e86\u53e6\u5916\u4e24\u4e2a\u9879\u76ee gin-swagger \u548c files\uff0c\u80fd\u591f\u76f4\u63a5\u5c06 gin \u4f5c\u4e3a Swagger UI \u670d\u52a1\u5668\uff0c\u8fd9\u6837\u5c31\u4e0d\u7528\u6bcf\u6b21\u90fd\u5c06 swagger.yaml \u624b\u52a8\u590d\u5236\u5230 Swagger Editor \u7f16\u8f91\u5668\u624d\u80fd\u5b9e\u73b0 Swagger UI \u9884\u89c8\u3002<\/p>\n<p>\u4f7f\u7528\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u4e0b\u8f7d gin-swagger\u3001files<\/li>\n<\/ol>\n<pre><code>$ go get -u github.com\/swaggo\/gin-swagger\n$ go get -u github.com\/swaggo\/files<\/code><\/pre>\n<ol start=\"2\">\n<li>\u5728\u4ee3\u7801\u4e2d\u5bfc\u5165 gin-swagger\u3001files<\/li>\n<\/ol>\n<pre><code>import &quot;github.com\/swaggo\/gin-swagger&quot; \/\/ gin-swagger middleware\nimport &quot;github.com\/swaggo\/files&quot; \/\/ swagger embed files<\/code><\/pre>\n<ol start=\"3\">\n<li>\u6ce8\u518c Swagger \u6587\u6863\u8def\u7531\u5730\u5740<\/li>\n<\/ol>\n<pre><code>r.GET(&quot;\/swagger\/*any&quot;, ginSwagger.WrapHandler(swaggerFiles.Handler))<\/code><\/pre>\n<p>\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code>package mainimport (  &quot;net\/http&quot;  &quot;github.com\/gin-gonic\/gin&quot;  swaggerFiles &quot;github.com\/swaggo\/files&quot;  ginSwagger &quot;github.com\/swaggo\/gin-swagger&quot;  &quot;gin-swag\/docs&quot; \/\/ \u5f53\u524d\u5305\u540d\u4e3a gin-swag)\/\/ @title           Swagger Example API\/\/ @version         1.0\/\/ @schemes         http\/\/ @host            localhost:8080\/\/ @BasePath        \/api\/v1\/\/ @tag.name        example\/\/ @tag.description \u793a\u4f8b\u63a5\u53e3\/\/ Helloworld godoc\/\/\/\/ @Summary     \u8be5\u64cd\u4f5c\u7684\u7b80\u77ed\u6458\u8981\/\/ @Description \u64cd\u4f5c\u884c\u4e3a\u7684\u8be6\u7ec6\u8bf4\u660e\/\/ @Tags        example\/\/ @Accept      json\/\/ @Produce     json\/\/ @Success     200 {string} string &quot;Hello World!&quot;\/\/ @Router      \/example\/helloworld [get]func Helloworld(g *gin.Context) {  g.JSON(http.StatusOK, &quot;Hello World!&quot;)}func main() {  \/\/ \u4f1a\u8986\u76d6\u4e0a\u9762\u6ce8\u91ca\u90e8\u5206 title \u5c5e\u6027\u7684\u8bbe\u7f6e  docs.SwaggerInfo.Title = &quot;Swag Example API&quot;  r := gin.Default()  v1 := r.Group(&quot;\/api\/v1&quot;)  {    eg := v1.Group(&quot;\/example&quot;)    {      eg.GET(&quot;\/helloworld&quot;, Helloworld)    }  }  \/\/ Swagger \u6587\u6863\u63a5\u53e3\u5730\u5740  r.GET(&quot;\/swagger\/*any&quot;, ginSwagger.WrapHandler(swaggerFiles.Handler))  if err := r.Run(&quot;:8080&quot;); err != nil {    panic(err)  }}<\/code><\/pre>\n<ol start=\"4\">\n<li>\u6267\u884c go run main.go \u542f\u52a8\u670d\u52a1\uff0c\u8bbf\u95ee\u00a0<a href=\"https:\/\/link.segmentfault.com\/?enc=o%2FnNT%2BTVrdGCJjMGUoPfIA%3D%3D.dp9x4SPtL5jO3Sh8GJN0hgTbbaWO%2FbaWC%2BC7v60mO3n9Gf4lUVxaMfK8QWHYt3Fh\" rel=\"nofollow\">http:\/\/localhost:8080\/swagger\/index.html<\/a>\u00a0\u5373\u53ef\u67e5\u770b Swagger UI \u4ea4\u4e92\u5f0f\u6587\u6863\u754c\u9762\u3002<img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043982071\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/li>\n<\/ol>\n<p>\u8fd9\u4e2a\u672c\u5730\u7684 Swagger UI \u670d\u52a1\u5668\u540c\u6837\u652f\u6301\u4ea4\u4e92\u5f0f\u64cd\u4f5c\u3002<\/p>\n<p>\u4e0e\u524d\u7aef\u5bf9\u63a5\u65f6\uff0c\u6211\u4eec\u53ea\u9700\u8981\u5c06\u63a5\u53e3\u6587\u6863\u5730\u5740\u7ed9\u5230\u524d\u7aef\uff0c\u524d\u7aef\u5c31\u53ef\u4ee5\u6839\u636e\u8fd9\u4e2a Swagger UI \u754c\u9762\u8fdb\u884c\u63a5\u53e3\u67e5\u9605\u548c\u8c03\u8bd5\u4e86\uff0c\u975e\u5e38\u65b9\u4fbf\u3002<\/p>\n<h3><strong>\u8ba9 Swag \u652f\u6301\u591a\u7248\u672c API \u6587\u6863<\/strong><\/h3>\n<p>\u5b9e\u9645\u5de5\u4f5c\u4e2d\uff0c\u6211\u4eec\u7684\u9879\u76ee\u4f1a\u6bd4\u8fd9\u4e2a\u53ea\u6709\u4e00\u4e2a\u63a5\u53e3\u7684 demo \u590d\u6742\u5f97\u591a\uff0c\u540c\u65f6 API \u4e5f\u53ef\u80fd\u4f1a\u652f\u6301\u591a\u7248\u672c\uff0c\u6bd4\u5982 \/api\/v1\u3001\/api\/v2\uff0c\u9488\u5bf9\u8fd9\u4e9b\u573a\u666f\uff0c\u6211\u5b9e\u73b0\u4e86\u4e00\u4e2a\u4f7f\u7528\u793a\u4f8b\u00a0<a href=\"https:\/\/link.segmentfault.com\/?enc=LAHs9Xi7E15lMleZ0xL1JQ%3D%3D.VbUF0HeZGLQ0vdYKq7hy%2Bs17U3N5kK2aLGq3MaF8%2FL2%2Fa6mMd58bJDAZ0HCbfYhQ\" rel=\"nofollow\">https:\/\/github.com\/jianghushinian\/swag-example<\/a>\u00a0\u4f9b\u4f60\u53c2\u8003\u3002<\/p>\n<p>\u4e3a\u4e86\u66f4\u52a0\u65b9\u4fbf\u5730\u4f7f\u7528 swag \u547d\u4ee4\uff0c\u5728 swag-example \u9879\u76ee\u4e2d\uff0c\u6211\u628a swag fmt \u548c swag init \u547d\u4ee4\u90fd\u5199\u5728 Makefile \u6587\u4ef6\u4e2d\uff0c\u6700\u91cd\u8981\u7684\u5c31\u662f\u4ee5\u4e0b\u4e24\u6761\u547d\u4ee4\uff1a<\/p>\n<pre><code>swag init -g internal\/api\/controller\/v1\/docs.go --exclude internal\/api\/controller\/v2 --instanceName v1\nswag init -g internal\/api\/controller\/v2\/docs.go --exclude internal\/api\/controller\/v1 --instanceName v2<\/code><\/pre>\n<p>\u8fd9\u4e24\u6761\u547d\u4ee4\u5206\u522b\u751f\u6210 v1\u3001v2 \u4e24\u4e2a\u7248\u672c\u7684 API \u6587\u6863\uff0c\u8fd9\u6837\u53ef\u4ee5\u5c06\u4e0d\u540c\u7248\u672c\u7684\u63a5\u53e3\u5206\u5f00\u5c55\u793a\uff0c\u66f4\u52a0\u6e05\u6670\u3002<\/p>\n<p>\u5176\u4e2d -g \u53c2\u6570\u6307\u660e API \u901a\u7528\u6ce8\u91ca\u4fe1\u606f\u6240\u5728\u7684 Go \u6e90\u6587\u4ef6\u8def\u5f84\uff0c\u5927\u578b\u9879\u76ee\u4e2d\u4e3a\u4e86\u4fdd\u6301\u4ee3\u7801\u67b6\u6784\u6574\u6d01\uff0c\u8fd9\u4e9b\u6ce8\u91ca\u5e94\u8be5\u72ec\u7acb\u4e8e\u4e00\u4e2a\u6587\u4ef6\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u5199\u5728 main.go \u4e2d\u3002<\/p>\n<p>&#8211;exclude \u53c2\u6570\u6307\u660e\u751f\u6210 Swagger \u6587\u6863\u65f6\uff0c\u9700\u8981\u6392\u9664\u7684\u76ee\u5f55\u3002\u53ef\u4ee5\u53d1\u73b0\uff0c\u5728\u751f\u6210 v1 \u7248\u672c\u63a5\u53e3\u6587\u6863\u65f6\uff0c\u6211\u6392\u9664\u4e86 v2 \u63a5\u53e3\u76ee\u5f55\uff0c\u5728\u751f\u6210 v2 \u7248\u672c\u63a5\u53e3\u6587\u6863\u65f6\uff0c\u6392\u9664\u4e86 v1 \u63a5\u53e3\u76ee\u5f55\uff0c\u8fd9\u6837\u5c31\u5b9e\u73b0\u4e86\u591a\u7248\u672c\u63a5\u53e3\u5206\u79bb\u3002<\/p>\n<p>\u5173\u4e8e\u8fd9\u4e2a\u9879\u76ee\u7684\u66f4\u591a\u7ec6\u8282\u5c31\u7559\u7ed9\u4f60\u81ea\u5df1\u53bb\u63a2\u7d22\u4e86\uff0c\u76f8\u4fe1\u4f60\u9605\u8bfb\u5b8c\u4ee3\u7801\u540e\u4f1a\u6709\u6240\u6536\u83b7\u3002<\/p>\n<h3><strong>Swag \u4f7f\u7528\u5efa\u8bae<\/strong><\/h3>\n<p>\u5728\u524d\u6587\u4ecb\u7ecd\u7684 swag \u4f7f\u7528\u6d41\u7a0b\u4e2d\uff0c\u4e0d\u77e5\u9053\u4f60\u6709\u6ca1\u6709\u6ce8\u610f\u5230\uff0c\u6211\u4eec\u662f\u5148\u7f16\u5199\u7684\u4ee3\u7801\uff0c\u7136\u540e\u518d\u751f\u6210\u7684 Swagger \u6587\u6863\uff0c\u6700\u540e\u5c06\u8fd9\u4efd\u6587\u6863\u4ea4\u7ed9\u524d\u7aef\u4f7f\u7528\u3002<\/p>\n<p>\u8fd9\u663e\u7136\u8fdd\u80cc\u4e86\u300c\u6587\u6863\u5148\u884c\u300d\u7684\u601d\u60f3\uff0c\u5b9e\u9645\u5de5\u4f5c\u4e2d\uff0c\u6211\u4eec\u66f4\u591a\u7684\u65f6\u5019\u662f\u5148\u8ddf\u524d\u7aef\u7ea6\u5b9a\u597d\u63a5\u53e3\uff0c\u7136\u540e\u540e\u7aef\u63d0\u4f9b Swagger \u6587\u6863\u4f9b\u524d\u7aef\u4f7f\u7528\uff0c\u6700\u540e\u624d\u662f\u524d\u540e\u7aef\u7f16\u7801\u9636\u6bb5\u3002<\/p>\n<p>\u8981\u60f3\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6700\u76f4\u63a5\u7684\u89e3\u51b3\u65b9\u6848\u662f\u4e0d\u4f7f\u7528 swag \u5de5\u5177\uff0c\u800c\u662f\u76f4\u63a5\u4f7f\u7528 Swagger Editor \u8fd9\u79cd\u7f16\u8f91\u5668\u624b\u5199 Swagger \u6587\u6863\uff0c\u8fd9\u6837\u5c31\u80fd\u5b9e\u73b0\u6587\u6863\u5148\u884c\u4e86\u3002<\/p>\n<p>\u4f46\u8fd9\u53c8\u8fdd\u80cc\u4e86 OpenAPI \u7ed9\u51fa\u7684\u300c\u6700\u4f73\u5b9e\u8df5\u300d\uff0c\u63a8\u8350\u81ea\u52a8\u751f\u6210 Swagger \u6587\u6863\uff0c\u800c\u975e\u624b\u52a8\u7f16\u5199\u3002<\/p>\n<p>\u6211\u81ea\u5df1\u7684\u89e3\u51b3\u65b9\u6848\u662f\uff0c\u4f9d\u65e7\u9009\u62e9\u4f7f\u7528 swag \u5de5\u5177\uff0c\u4e0d\u8fc7\u5728\u7f16\u5199\u4ee3\u7801\u65f6\uff0c\u5148\u5199\u63a5\u53e3\u7684\u6846\u67b6\u4ee3\u7801\uff0c\u800c\u4e0d\u5199\u5177\u4f53\u7684\u4e1a\u52a1\u903b\u8f91\uff0c\u8fd9\u6837\u5c31\u80fd\u591f\u5148\u901a\u8fc7\u63a5\u53e3\u6ce8\u91ca\u751f\u6210 Swagger \u6587\u6863\uff0c\u4f9b\u524d\u7aef\u4f7f\u7528\uff0c\u7136\u540e\u518d\u7f16\u5199\u4e1a\u52a1\u4ee3\u7801\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u8f83\u4e3a\u9057\u61be\u7684\u662f\uff0c\u76ee\u524d swag \u751f\u6210\u7684\u6587\u6863\u662f OpenAPI 2.0 \u7248\u672c\uff0c\u5e76\u4e0d\u80fd\u76f4\u63a5\u751f\u6210 OpenAPI 3.0 \u7248\u672c\uff0c\u5982\u679c\u4f60\u60f3\u4f7f\u7528 OpenAPI 3.0 \u7248\u672c\u7684\u6587\u6863\uff0c\u4e00\u4e2a\u53d8\u901a\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u5de5\u5177\u5c06 OpenAPI 2.0 \u6587\u6863\u8f6c\u6362\u6210 OpenAPI 3.0\uff0c\u5982\u524d\u6587\u63d0\u5230\u7684 Swagger Editor \u5c31\u652f\u6301\u6b64\u64cd\u4f5c\u3002<\/p>\n<h2><strong>\u4f7f\u7528ReDoc\u98ce\u683c\u7684API\u6587\u6863<\/strong><\/h2>\n<p>\u4e5f\u8bb8\u76f8\u8f83\u4e8e Swagger UI \u591a\u5e74\u4e0d\u53d8\u7684\u754c\u9762\u98ce\u683c\uff0c\u4f60\u66f4\u559c\u6b22 ReDoc \u98ce\u683c\u7684 UI\uff0c\u90a3\u4e48 go-redoc \u662f\u4e00\u4e2a\u6bd4\u8f83\u4e0d\u9519\u7684\u9009\u62e9\u3002  <\/p>\n<p>\u5728 gin \u4e2d\u4f7f\u7528 go-redoc \u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u5c06\u5982\u4e0b\u5957\u8def\u4ee3\u7801\u52a0\u5165\u5230\u6211\u4eec\u7684 main.go \u6587\u4ef6\u4e2d\u5373\u53ef\u3002<\/p>\n<pre><code class=\"js\">import (\n    &quot;github.com\/gin-gonic\/gin&quot; \n    &quot;github.com\/mvrilo\/go-redoc&quot; \n    ginRedoc &quot;github.com\/mvrilo\/go-redoc\/gin&quot; \n)\n    \n...\ndoc := redoc.Redoc{\n    Title:       &quot;Example API&quot;, \n    Description: &quot;Example API Description&quot;, \n    SpecFile: &quot;.\/openapi.json&quot;, \/\/ &quot;.\/openapi.yaml&quot; \n    SpecPath: &quot;\/openapi.json&quot;, \/\/ &quot;\/openapi.yaml&quot; \n    DocsPath: &quot;\/docs&quot;, \n}\nr := gin.New()\nr.Use(ginRedoc.New(doc))<\/code><\/pre>\n<p>\u6267\u884c go run main.go \u542f\u52a8\u670d\u52a1\uff0c\u8bbf\u95ee <a href=\"https:\/\/link.segmentfault.com\/?enc=nwcc0LE%2B93dIIuO%2FJFzyJQ%3D%3D.vqZaXPP9%2Bt3VtPcS9ZgbxRY6%2BPiYcvKUkQpT7HiCzMg%3D\" rel=\"nofollow\">http:\/\/localhost:8080\/redoc<\/a> \u5373\u53ef\u67e5\u770b Redoc UI\u3002<img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043982072\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\">\u4e0d\u8fc7\uff0c\u76f8\u8f83\u4e8e Swagger UI\uff0cRedoc UI \u6709\u4e2a\u5f0a\u7aef\u662f\u4e0d\u80fd\u5b9e\u73b0\u4ea4\u4e92\u5f0f\u64cd\u4f5c\uff0c\u5982\u679c\u4ec5\u4ee5\u6b64\u4f5c\u4e3a\u6587\u6863\u67e5\u9605\u5de5\u5177\uff0c\u6ca1\u6709\u4ea4\u4e92\u5f0f\u64cd\u4f5c\u7684\u9700\u6c42\uff0c\u90a3\u4e48\u8fd8\u662f\u6bd4\u8f83\u63a8\u8350\u4f7f\u7528\u7684\u3002<\/p>\n<h2><strong>\u66f4\u5148\u8fdb\u7684API\u5de5\u5177\u63a8\u8350<\/strong><\/h2>\n<p>\u9664\u4e86 OpenAPI.Tools \u63a8\u8350\u7684\u5f00\u6e90\u5de5\u5177\uff0c\u793e\u533a\u4e2d\u5176\u5b9e\u8fd8\u6709\u5f88\u591a\u5176\u4ed6\u4f18\u79c0\u5de5\u5177\u503c\u5f97\u5c1d\u8bd5\u4f7f\u7528\uff0c\u6bd4\u5982\u6211\u8fd9\u91cc\u8981\u63a8\u8350\u7684\u4e00\u6b3e\u56fd\u4ea7\u5de5\u5177 Apifox\uff0c\u5b98\u65b9\u5c06\u5176\u5b9a\u4e49\u4e3a Apifox = Postman + Swagger + Mock + JMeter\uff0c\u96c6 API \u8bbe\u8ba1\/\u5f00\u53d1\/\u6d4b\u8bd5 \u4e8e\u4e00\u8eab\u3002  <br \/>Apifox \u53ef\u8c13\u4e00\u7ad9\u5f0f\u56fe\u5f62\u5316\u5de5\u5177\uff0c\u5176\u529f\u80fd\u975e\u5e38\u5f3a\u5927\uff0c\u5c31\u50cf\u524d\u6587\u63d0\u5230\u7684 APIGit \u540c\u65f6\u5177\u5907\u4e86\u7f16\u8f91\u5668\u548c Mock \u670d\u52a1\u5668\u7684\u529f\u80fd\uff0cApifox \u6709\u8fc7\u4e4b\u800c\u65e0\u4e0d\u53ca\u3002<img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043982073\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\">\u56fe\u5f62\u5316\u5de5\u5177\u4e0a\u624b\u96be\u5ea6\u4e0d\u5927\uff0c\u52a0\u4e0a Apifox \u672c\u8eab\u7531\u56fd\u5185\u5f00\u53d1\uff0c\u975e\u5e38\u5bb9\u6613\u4e0a\u624b\uff0c\u6240\u4ee5\u672c\u6587\u4e5f\u5c31\u4e0d\u6df1\u5165\u4ecb\u7ecd\u4e86\uff0c\u4f60\u53ef\u4ee5\u89c2\u770b\u5b98\u65b9\u6559\u7a0b\u00a021 \u5206\u949f\u5b66\u4f1a Apifox\u00a0\u6765\u5b66\u4e60\u4f7f\u7528\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9~<\/p>\n<p><strong>\u53c2\u8003<\/strong><\/p>\n<blockquote>\n<p>OpenAPI \u5b98\u7f51\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=FTnK658Qgu8WWC3JKSoPDA%3D%3D.33xLsaPiDgihY0k8%2FUxYKyosbg%2FUEGNJM6nWX9XSWBg%3D\" rel=\"nofollow\">https:\/\/www.openapis.org\/<\/a><\/p>\n<p>OpenAPI\u5165\u95e8\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=IlGLMmqSY1qrC5NKT7prPQ%3D%3D.2SuVM5qyNgKLItGBBFqi10ELKuiZVB4YY35PxzhJZe5IFdGiiLdHIflTheJQpJbt\" rel=\"nofollow\">https:\/\/oai.github.io\/Documentation\/<\/a><\/p>\n<p>OpenAPI\u89c4\u8303\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=PaYbagEzVNTxuGb99z6whA%3D%3D.rclEdPM%2BoGdcRBCn2oXU7kUH52lmu7Uq8%2FWshtp08r7Ah7bF2NkIkDRRg%2FTKqG47\" rel=\"nofollow\">https:\/\/spec.openapis.org\/oas\/latest.html<\/a><\/p>\n<p>OpenAPI\u89c4\u8303\u4e2d\u6587\u7248\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=3SqWHnA2Kx0ZOtS0rmW7iQ%3D%3D.3DoRL3ypd1x0%2FoREpdOvBSi79pdWUM2C2BwSe%2FMxwJU%3D\" rel=\"nofollow\">https:\/\/openapi.apifox.cn\/<\/a><\/p>\n<p>OpenAPI\u89c4\u8303\u601d\u7ef4\u5bfc\u56fe\u7248\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=f85GAWkzvbKdr4JtZI7hVw%3D%3D.G5qp3ArbxXI79WrIyEpPBrUk%2BGfQAj480eTHTqaf18VVCJZHX350762OirSzQaCM\" rel=\"nofollow\">https:\/\/openapi-map.apihandyman.io\/<\/a><\/p>\n<p>OpenAPI.Tools\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=o6D%2FHNTKkfPPbI8rNe3LuQ%3D%3D.1U26EpsRpBBWNcmjaIzZNnRJvZaEFjJIdi6%2BZ0Fala4%3D\" rel=\"nofollow\">https:\/\/openapi.tools\/<\/a><\/p>\n<p>Swagger\u5b98\u7f51\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=kb%2BYxMG%2BCPTT9EMf68wseA%3D%3D.i73EqYaInbIKbDB%2F0xckAd812FIBcE%2FbzheUeVv52Xg%3D\" rel=\"nofollow\">https:\/\/swagger.io\/<\/a><\/p>\n<p>swag\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=dgOwCwBsf%2FmvV2p0LNZVpQ%3D%3D.ZIk%2BsyS%2Bg9sl38pTW61q6%2FhzovpzZEx%2FhGFzNjjxcKc%3D\" rel=\"nofollow\">https:\/\/github.com\/swaggo\/swag<\/a><\/p>\n<p>swag-example\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=ENNabWDvwLBQWSbmPHPt1g%3D%3D.c%2Fbx4fM9j1CleGeOhxeXnJAuilY3ZRba2AL7h3wLT10No%2BvO0RP6BRYnc8w1II9e\" rel=\"nofollow\">https:\/\/github.com\/jianghushinian\/swag-example<\/a><\/p>\n<p>go-redoc\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=H6IhB999ck1B2vGj8URu6g%3D%3D.rsdCMe8H3p3%2Fv5eDdRwVcJKW%2Bs%2FLxMwFzf0SFdzJ0GT2MPbahsSPJ5jxyvxs3Hre\" rel=\"nofollow\">https:\/\/github.com\/mvrilo\/go-redoc<\/a><\/p>\n<p>Apifox\u5b98\u7f51\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=x%2Br850geGbxJKNFUol0Tkg%3D%3D.QffKRSXLOxSy4OXM2qzDPlz7tbgW0YWqMQMgffy7GsQ%3D\" rel=\"nofollow\">https:\/\/www.apifox.com\/<\/a><\/p>\n<\/blockquote>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000043982062\">https:\/\/segmentfault.com\/a\/1190000043982062<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u4e3a\u4e00\u540d\u5f00\u53d1\u8005\uff0c\u5f80\u5f80\u9700\u8981\u7f16\u5199\u7a0b\u5e8f\u7684 API \u6587\u6863\uff0c\u5c24\u5176\u662f Web \u540e\u7aef\u5f00\u53d1\u8005\uff0c\u5728\u8ddf\u524d\u7aef\u5bf9\u63a5 HTTP \u63a5\u53e3\u7684\u65f6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10008055","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008055","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10008055"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008055\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10008055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10008055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10008055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}