concept definition in category swagger

appears as: definition, definition, definitions, definitions, The definition, The definition
Designing APIs with Swagger and OpenAPI

This is an excerpt from Manning's book Designing APIs with Swagger and OpenAPI.

OpenAPI is a description of HTTP-based APIs which are typically, RESTful APIs. It comes in the form of a YAML file or definition, that describes the inputs and outputs of an API. It can also include information such as where the API is hosted, what authorization is required to access it, and other details needed for consumers and producers (such as web-developers).

Definitions can be written by hand, by tools, or even generated from code. Once an API has been written down we say it has been described. Once API has been described into a definition, it becomes a platform for tools and humans to make use of. A typical example of making use of API definitions is to generate human readable documentation from it.

Figure 3.1. Mental model of OpenApi/Swagger, showing where definitions fit in.
mental model swagger api definitions

So far we’ve only been describing the bare essentials of the API, such as what operations exist and how to use them. This is the meat of the definition but we’re lacking a softness that comes from explaining the API from one person to another. In addition we’re also lacking some critical information that consumers require. Critical information such as the license of the API (are they allowed to consume it?) and contact information if they need to reach out. We’ll be adding this metadata to the definition under the info section.

We’ll be adding this to the info (and externalDocs) section of the definition. We have already created this section, as it was required for very basic metadata such as title and version. Without which it would be very difficult to identify the API at all! Extending it should be straightforward. We can smash those out pretty quickly. In later sections we’re going to flesh out the description field to include a host of rich text elements, but for now, we’ll just add a single line of text.

Listing 8.1. Info section fleshed out
openapi: 3.0.0
info:
  version: v1
  title: FarmStall API
  description: |- 
   #1
    An API for writing reviews about your favourite (or worst) farm stalls. 
   #2
  contact:
    name: Josh Ponelat 
   #3
    email: jponelat+daso@gmail.com 
   #4
    url: https://ponelat.com/contact 
   #5
  license:
    url: https://www.apache.org/licenses/LICENSE-2.0.html 
   #6
    name: Apache 2.0 
   #7
# ...end of the `info` section
externalDocs: 
   #8
  url: https://app.swaggerhub.com/apis/designing-apis/part-one 
   #9
  description: SwaggerHub 
   #10
#  ...rest of the definition...