Swagger 服务器存根是什么意思?

what does Swagger server stub mean?

我是 Swagger 的新手,我 运行 了解术语 Server Stub,我不明白这是什么意思,如果有人能解释一下,我将不胜感激对我来说。

来自 swagger 教程:

With SwaggerHub, you can easily generate a server stub (an API implementation stub) for Node.js, ASP.NET, JAX-RS, and other servers and frameworks. The server stub is a good starting point for implementing your API – you can run and test it locally, implement the business logic for your API, and then deploy it to your server.

https://app.swaggerhub.com/help/apis/generating-code/server-stub

存根是:

method stub or simply stub in software development is a piece of code used to stand in for some other programming functionality. A stub may simulate the behavior of existing code (such as a procedure on a remote machine, such methods are often called mocks) or be a temporary substitute for yet-to-be-developed code. Stubs are therefore most useful in porting, distributed computing as well as general software development and testing.

https://en.wikipedia.org/wiki/Method_stub

Stub API 意思是:创建一个 mock 来服务 swagger 文件中描述的示例。 这个模拟可以用特定的语言/框架格式化

根据您计划用于 API 的后端平台和框架,服务器存根可能非常强大。

例如,您可以选择 Apache(常见于 Linux 环境)或 ASP.NET(常见于 IIS)。正在生成的服务器 "stubs" 通常是该特定平台的可部署库。您通常得到的是:

  • 路由到您的业务逻辑。该框架将处理 HTTP 规范,但实际上从 "controller" 映射到您的服务层是由代码生成器根据您的 API 规范处理的。
  • 模型的序列化和反序列化(适用于 Java/C# 等强类型语言)。
  • AuthN/AuthZ 可能会在某种程度上根据框架对您 API 所选择的身份验证方案的支持进行处理。

tl;dr:服务器存根旨在成为一个随时可以部署的应用程序,它将 HTTP 请求路由到后端的实际业务逻辑。