what does Swagger server stub mean?
Asked Answered
W

4

30

What does the term Server Stub mean in the context of the Swagger ecosystem? How is it used?

Worsen answered 2/8, 2018 at 15:3 Comment(1)
What does stubbing mean in programming?Panama
A
22

From a swagger tutorial:

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

and a stub is:

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

Arabel answered 2/8, 2018 at 15:12 Comment(0)
C
7

Stub the API means : create à mock to serve examples described in swagger file. This mock can be formatted in specific languages/ framework

Chisel answered 31/1, 2019 at 17:22 Comment(0)
L
3

Server stubbing can be quite powerful depending on the backend platform and framework you plan to use for your API.

For example, you may choose Apache (common in Linux environments) or ASP.NET (common for IIS). The server "stubs" being generated will typically be a deployable library to that specific platform. What you typically get is:

  • Routing to your business logic. The framework will handle the HTTP specification, but actually mapping from a "controller" to your service layer is being handled by the code generator, based on your API specification.
  • Serialization and Deserialization of your models (applies to strongly-typed languages like Java/C#).
  • AuthN/AuthZ may be handled, to some degree, based on the framework's support for your API's chosen auth scheme.

tl;dr: A server stub is intended to be a ready-to-deploy application that routes HTTP requests to your actual business logic on the backend.

Locative answered 15/2, 2019 at 5:6 Comment(1)
How does one customise the generated server-side code? Can someone explain or point to a explanation. Can the API be changed and auto-generated again without losing customisations?Proselyte
S
0

From my experience and peers, I found stub to be a mock function or a placeholder function where you can fill in the proper implementation later.

Socinian answered 21/9, 2022 at 18:10 Comment(1)
You are correct regarding the meaning of a "stub" as a general definition, but the question was specifically about the meaning of a "Server Stub" in the context of the Swagger ecosystem.Brelje

© 2022 - 2024 — McMap. All rights reserved.