### Example GET Requests for Parameter Options
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v2_0/describing-parameters.md
Demonstrates two ways to call the `/report` endpoint: one using a relative date and another using a start and end date. Use these examples to understand the input variations.
```sh
GET /report?rdate=Today
```
```sh
GET /report?start_date=2016-11-15&end_date=2016-11-20
```
--------------------------------
### Pagination Example with Cursors
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/links.md
This example demonstrates a GET request for items with a limit, followed by a response containing pagination metadata, and then a subsequent GET request using the 'next' cursor.
```yaml
GET /items?limit=100
```
```yaml
{
"metadata": {
"previous": null,
"next": "Q1MjAwNz",
"count": 10
},
...
}
```
```yaml
GET /items?cursor=Q1MjAwNz&limit=100
```
--------------------------------
### Example Request and Response
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/links.md
Illustrates a typical GET request with query parameters and its corresponding JSON response, including a custom header.
```yaml
GET /users?limit=2&total=true
Host: api.example.com
Accept: application/json
```
```yaml
HTTP/1.1 200 OK
Content-Type: application/json
X-Total-Count: 37
{
"prev_offset": 0,
"next_offset": 2,
"users": [
{"id": 1, "name": "Alice"},
{"id": 2, "name": "Bob"}
]
}
```
--------------------------------
### GET /users Example
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/links.md
An example of a GET request to retrieve users with query parameters for limit and total, and its corresponding successful response.
```APIDOC
## GET /users?limit=2&total=true
### Description
Retrieves a list of users with options to limit the number of results and include total count information.
### Method
GET
### Endpoint
/users
### Parameters
#### Query Parameters
- **limit** (integer) - Optional - The maximum number of users to return.
- **total** (boolean) - Optional - Whether to include the total count of users in the response headers.
### Request Example
```yaml
GET /users?limit=2&total=true
Host: api.example.com
Accept: application/json
```
### Response
#### Success Response (200)
- **prev_offset** (integer) - The offset for the previous page of results.
- **next_offset** (integer) - The offset for the next page of results.
- **users** (array) - An array of user objects.
- **id** (integer) - The unique identifier for the user.
- **name** (string) - The name of the user.
- **X-Total-Count** (integer) - The total number of users available (if `total` query parameter is true).
#### Response Example
```json
{
"prev_offset": 0,
"next_offset": 2,
"users": [
{"id": 1, "name": "Alice"},
{"id": 2, "name": "Bob"}
]
}
```
```
--------------------------------
### Add Multiple Examples to Parameter
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/adding-examples.md
Use the `examples` keyword to provide multiple named examples for a parameter. Each example can include an optional `summary` for a brief description.
```yaml
parameters:
- in: query
name: limit
schema:
type: integer
maximum: 50
examples: # Multiple examples
zero:
value: 0
summary: A sample limit value
max:
value: 50
summary: A sample limit value
```
--------------------------------
### Detailed Operation with Parameters and Schema
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v2_0/paths-and-operations.md
A comprehensive example of a GET operation for a user path, including summary, description, tags, parameters, response schema, and external documentation links.
```yaml
paths:
/users/{id}:
get:
summary: Gets a user by ID.
description: >
A detailed description of the operation.
GitHub Flavored Markdown can be used for rich text representation,
such as **bold**, *italic* and [links](https://swagger.io).
operationId: getUsers
tags:
- users
produces:
- application/json
- application/xml
parameters:
- name: id
in: path
description: User ID
type: integer
required: true
responses:
200:
description: OK
schema:
$ref: "#/definitions/User"
externalDocs:
url: http://api.example.com/docs/user-operations/
description: Learn more about User operations provided by this API.
definitions:
User:
type: object
properties:
id:
type: integer
name:
type: string
required:
- id
- name
```
--------------------------------
### Detailed Operation with Parameters and Response
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/paths-and-operations.md
An example of a GET operation including tags, summary, description, parameters, response schema, and external documentation.
```yaml
paths:
/users/{id}:
get:
tags:
- Users
summary: Gets a user by ID.
description: >
A detailed description of the operation.
Use markdown for rich text representation,
such as **bold**, *italic*, and [links](https://swagger.io).
operationId: getUserById
parameters:
- name: id
in: path
description: User ID
required: true
schema:
type: integer
format: int64
responses:
"200":
description: Successful operation
content:
application/json:
schema:
$ref: "#/components/schemas/User"
externalDocs:
description: Learn more about user operations provided by this API.
url: http://api.example.com/docs/user-operations/
components:
schemas:
User:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
required:
- id
- name
```
--------------------------------
### Example: GET /users/{userId}
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v2_0/describing-parameters.md
This example demonstrates how to define a path parameter for retrieving a user by their ID in OpenAPI 2.0.
```APIDOC
## GET /users/{userId}
### Description
Gets a user by ID.
### Method
GET
### Endpoint
/users/{userId}
### Parameters
#### Path Parameters
- **userId** (integer) - Required - Numeric ID of the user to get.
### Responses
#### Success Response (200)
- description: OK
```
--------------------------------
### Valid Base Path Examples
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v2_0/api-host-and-base-path.md
Illustrates correct formats for the API's URL prefix, which must start with a leading slash.
```sh
/v2
/api/v2
/
```
--------------------------------
### User Operations Example
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/paths-and-operations.md
This example demonstrates how to define GET, PATCH, and DELETE operations for a user resource, including path templating and detailed descriptions.
```APIDOC
## GET /users/{id}
### Description
Retrieves a specific user by their unique ID.
### Method
GET
### Endpoint
/users/{id}
### Parameters
#### Path Parameters
- **id** (integer) - Required - The unique identifier for the user.
### Response
#### Success Response (200)
- **id** (integer) - The user's unique identifier.
- **name** (string) - The name of the user.
### Response Example
```json
{
"id": 123,
"name": "John Doe"
}
```
```
```APIDOC
## PATCH /users/{id}
### Description
Updates an existing user's information.
### Method
PATCH
### Endpoint
/users/{id}
### Parameters
#### Path Parameters
- **id** (integer) - Required - The unique identifier for the user to update.
### Request Body
- **name** (string) - Optional - The new name for the user.
### Request Example
```json
{
"name": "Jane Doe"
}
```
### Response
#### Success Response (200)
- **id** (integer) - The user's unique identifier.
- **name** (string) - The updated name of the user.
### Response Example
```json
{
"id": 123,
"name": "Jane Doe"
}
```
```
```APIDOC
## DELETE /users/{id}
### Description
Deletes a user by their unique ID.
### Method
DELETE
### Endpoint
/users/{id}
### Parameters
#### Path Parameters
- **id** (integer) - Required - The unique identifier for the user to delete.
### Response
#### Success Response (200)
- **description** (string) - Indicates the operation was successful.
```
--------------------------------
### Install Dependencies
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/open-source-tools/Swagger UI/Development/setting-up.md
Install all the necessary project dependencies using npm.
```bash
npm install
```
--------------------------------
### Dictionary with Example Content
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/Data Models/dictionaries.md
Illustrates how to provide sample data for a dictionary. The `example` keyword shows expected key-value pairs.
```yaml
type: object
additionalProperties:
type: string
example:
en: Hello!
fr: Bonjour!
```
--------------------------------
### Add Multiple Examples to Request Body with $ref
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/adding-examples.md
Use the `examples` keyword under the media type to provide multiple named examples for a request body when using `$ref` for the schema.
```yaml
paths:
/users:
post:
summary: Adds a new user
requestBody:
content:
application/json: # Media type
schema: # Request body contents
$ref: "#/components/schemas/User" # Reference to an object
examples: # Child of media type
Jessica: # Example 1
value:
id: 10
name: Jessica Smith
Ron: # Example 2
value:
id: 11
name: Ron Stewart
responses:
"200":
description: OK
```
--------------------------------
### Start Swagger Generator Docker Image and Generate Client
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/open-source-tools/Swagger Codegen/Codegen v2/docker.md
This example demonstrates starting the official Swagger Generator Docker image in detached mode, retrieving its IP address, sending a POST request to generate a JavaScript client from a Swagger URL, downloading the resulting zip file, and then stopping and removing the container.
```bash
# Start container and save the container id
CID=$(docker run -d swaggerapi/swagger-generator)
# allow for startup
sleep 5
# Get the IP of the running container
GEN_IP=$(docker inspect --format '{{.NetworkSettings.IPAddress}}' $CID)
# Execute an HTTP request and store the download link
RESULT=$(curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
"swaggerUrl": "https://petstore.swagger.io/v2/swagger.json"
}' 'http://localhost:8188/api/gen/clients/javascript' | jq '.link' | tr -d '"')
# Download the generated zip and redirect to a file
curl $RESULT > result.zip
# Shutdown the swagger generator image
docker stop $CID && docker rm $CID
```
--------------------------------
### Add Single Example to Response Body with $ref
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/adding-examples.md
Provide a single example for a response body by placing the `example` keyword under the media type when the schema uses `$ref`.
```yaml
responses:
"200":
description: A user object.
content:
application/json:
schema:
$ref: "#/components/schemas/User" # Reference to an object
example:
# Properties of the referenced object
id: 10
name: Jessica Smith
```
--------------------------------
### Add Multiple Examples to Response Body with $ref
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/adding-examples.md
Use the `examples` keyword under the media type to define multiple named examples for a response body when the schema is referenced via `$ref`.
```yaml
responses:
"200":
description: A user object.
content:
application/json:
schema:
$ref: "#/components/schemas/User" # Reference to an object
examples:
Jessica:
value:
id: 10
name: Jessica Smith
Ron:
value:
id: 20
name: Ron Stewart
```
--------------------------------
### Specify JSON Response Example using JSON Syntax
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v2_0/adding-examples.md
Use standard JSON syntax to define a JSON response example within the `examples` object.
```json
examples:
application/json:
{
"id": 38,
"title": "T-shirt"
}
```
--------------------------------
### Link Example: getReport Operation
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/links.md
Illustrates a practical example of using links to call the `getReport` operation, passing a relative date from the response of a previous operation and setting empty values for start and end dates.
```APIDOC
## Link Example: getReport Operation
This example shows how to link from a `GET /date_ranges` operation to a `GET /report` operation.
```yaml
paths:
/date_ranges:
get:
summary: Get relative date ranges for the report.
responses:
'200':
description: OK
content:
application/json:
example: [Today, Yesterday, LastWeek, ThisMonth]
links:
ReportRelDate:
operationId: getReport
# Call "getReport" with the `rdate` parameter and with empty `start_date` and `end_date`
parameters:
rdate: '$response.body#/1'
start_date: ''
end_date: ''
# GET /report?rdate=...
# GET /report?start_date=...&end_date=...
/report:
get:
operationId: getReport
...
```
```
--------------------------------
### Object-Level Example in Schema
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/adding-examples.md
Provide an example for an entire object schema. This is useful for demonstrating a complete instance of the object with all its properties.
```yaml
components:
schemas:
User: # Schema name
type: object
properties:
id:
type: integer
name:
type: string
example: # Object-level example
id: 1
name: Jessica Smith
```
--------------------------------
### Specify Multiple Named Examples for an Array Parameter
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/describing-parameters.md
Use the 'examples' object to define multiple, named examples for a parameter. Each example can have a summary and a 'value'. This is useful for array parameters with different input scenarios.
```yaml
parameters:
- in: query
name: ids
description: One or more IDs
required: true
schema:
type: array
items:
type: integer
style: form
explode: false
examples:
oneId:
summary: Example of a single ID
value: [5] # ?ids=5
multipleIds:
summary: Example of multiple IDs
value: [1, 5, 7] # ?ids=1,5,7
```
--------------------------------
### Add Single Example to Parameter
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/adding-examples.md
Use the `example` keyword directly under the parameter's schema to provide a single example value. Ensure the example matches the parameter's data type.
```yaml
parameters:
- in: query
name: status
schema:
type: string
enum: [approved, pending, closed, new]
example: approved # Example of a parameter value
```
--------------------------------
### Multiple Request Body Examples
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/Describing Request Body/describing-request-body.md
Use the `examples` property for multiple request body examples. Supports inline values, external values, and references.
```yaml
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
examples:
dog: # <--- example name
summary: An example of a dog
value:
# vv Actual payload goes here vv
name: Fluffy
petType: dog
cat: # <--- example name
summary: An example of a cat
externalValue: http://api.example.com/examples/cat.json # cat.json contains {"name": "Tiger", "petType": "cat"}
hamster: # <--- example name
$ref: '#/components/examples/hamster'
components:
examples:
hamster: # <--- example name
summary: An example of a hamster
value:
# vv Actual payload goes here vv
name: Ginger
petType: hamster
```
--------------------------------
### Create User Operation Example
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/links.md
This example shows a POST request to create a user and its typical JSON response containing the user's ID.
```yaml
POST /users HTTP/1.1
Host: example.com
Content-Type: application/json
{
"name": "Alex",
"age": 27
}
```
```yaml
HTTP/1.1 201 Created
Content-Type: application/json
{
"id": 305
}
```
--------------------------------
### Inline Request Body Example
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/Describing Request Body/describing-request-body.md
Use the `example` property for a single, inline request body example. This overrides schema examples.
```yaml
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
example:
name: Fluffy
petType: dog
```
--------------------------------
### Install swagger-ui-dist Package
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/open-source-tools/Swagger UI/Usage/installation.md
Install the swagger-ui-dist package for server-side projects needing assets.
```sh
$ npm install swagger-ui-dist
```
--------------------------------
### Whole Schema Example
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v2_0/adding-examples.md
Define an example for an entire schema, including all its nested properties. The example must conform to the complete schema definition.
```yaml
definition:
CatalogItem:
type: object
properties:
id:
type: integer
name:
type: string
image:
type: object
properties:
url:
type: string
width:
type: integer
height:
type: integer
required:
- id
- name
example:
id: 38
name: T-shirt
image:
url: images/38.png
width: 100
height: 100
```
--------------------------------
### Array of Primitives Example
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v2_0/adding-examples.md
Illustrate an array of primitive types using the `example` key. The provided example must match the `items` type defined for the array.
```yaml
definitions:
ArrayOfStrings:
type: array
items:
type: string
example:
- foo
- bar
- baz
```
--------------------------------
### Docker Compose .env File Example
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/open-source-tools/Swagger UI/Usage/configuration.md
Example of how to define array variables in a .env file for Docker Compose.
```shell
SUPPORTED_SUBMIT_METHODS=['get', 'post']
URLS=[ { url: 'https://petstore.swagger.io/v2/swagger.json', name: 'Petstore' } ]
```
--------------------------------
### Example JSON Configuration for Java Client
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/open-source-tools/Swagger Codegen/Codegen v2/generators-configuration.md
An example JSON configuration file specifying package names and artifact details for a Java client.
```json
{
"apiPackage" : "petstore"
}
```
--------------------------------
### Valid Server URL Examples
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/api-host-and-base-path.md
Provides examples of valid server URLs, including absolute, relative, and WebSocket schemes.
```yaml
https://api.example.com
https://api.example.com:8443/v1/reports
http://localhost:3025/v1
http://10.0.81.36/v1
ws://api.example.com/v1
wss://api.example.com/v1
/v1/reports
/
//api.example.com
```
--------------------------------
### Array of Objects Example
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v2_0/adding-examples.md
Provide an example for an array where each item is an object. The example should contain objects conforming to the schema referenced by `items`.
```yaml
definitions:
ArrayOfCatalogItems:
type: array
items:
$ref: '#/definitions/CatalogItem'
example:
- id: 38
title: T-shirt
- id: 114
title: Phone
```
--------------------------------
### Generate Code with Swagger Generator Minimal Image
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/open-source-tools/Swagger Codegen/Codegen v3/docker.md
This example demonstrates how to use the Swagger Generator Minimal Docker image to generate code. It starts the container, waits for it to initialize, retrieves its IP address, sends a POST request to generate code, and then stops and removes the container.
```sh
# Start container and save the container id
CID=$(docker run -d swaggerapi/swagger-generator-v3-minimal)
# allow for startup
sleep 5
# Get the IP of the running container
GEN_IP=$(docker inspect --format '{{.NetworkSettings.IPAddress}}' $CID)
# Execute an HTTP request and store the download link
curl -X POST \
http://localhost:8080/api/generate \
-H 'content-type: application/json' \
-d '{
"specURL" : "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml",
"lang" : "jaxrs-jersey",
"type" : "SERVER",
"codegenVersion" : "V3"
}' > result.zip
# Shutdown the swagger generator image
docker stop $CID && docker rm $CID
```
--------------------------------
### External Examples using externalValue
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/adding-examples.md
Reference example values from external URLs using `externalValue`. This is suitable when examples are too large, non-conformant, or stored separately.
```yaml
content:
application/json:
schema:
$ref: "#/components/schemas/MyObject"
examples:
jsonObject:
summary: A sample object
externalValue: "http://example.com/examples/object-example.json"
application/pdf:
schema:
type: string
format: binary
examples:
sampleFile:
summary: A sample file
externalValue: "http://example.com/examples/example.pdf"
```
--------------------------------
### Install swagger-ui-react Package
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/open-source-tools/Swagger UI/Usage/installation.md
Install the swagger-ui-react package for projects using React.
```sh
$ npm install swagger-ui-react
```
--------------------------------
### Array of Objects Example
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/adding-examples.md
Provide a multi-item example for an array where each item is an object. This demonstrates a collection of structured data.
```yaml
components:
schemas:
ArrayOfUsers:
type: array
items:
type: object
properties:
id:
type: integer
name:
type: string
example:
- id: 10
name: Jessica Smith
- id: 20
name: Ron Stewart
```
--------------------------------
### Example POST /subscribe Request
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/callbacks.md
This is an example of a POST request to the /subscribe endpoint, including headers, a query parameter, and a JSON body with a callbackUrl.
```yaml
POST /subscribe?p1=query-param-value HTTP/1.1
Host: my.example.com
Content-Type: application/json
Content-Length: 187
{
"callbackUrl" : "http://my.client.com/callback"
}
201 Created
Location: http://my.example.com?id=123
```
--------------------------------
### Specify a Single Example for a Parameter
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/describing-parameters.md
Provide a single 'example' value that conforms to the parameter's schema. This is useful for demonstrating expected input.
```yaml
parameters:
- in: query
name: limit
schema:
type: integer
minimum: 1
example: 20
```
--------------------------------
### Complete OpenAPI 3.0 Links Example
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/links.md
A full OpenAPI 3.0 example demonstrating how to link the 'createUser' operation's response to the 'getUser' operation using a runtime expression for the userId parameter.
```yaml
openapi: 3.0.4
info:
version: 0.0.0
title: Links example
paths:
/users:
post:
summary: Creates a user and returns the user ID
operationId: createUser
requestBody:
required: true
description: A JSON object that contains the user name and age.
content:
application/json:
schema:
$ref: "#/components/schemas/User"
responses:
"201":
description: Created
content:
application/json:
schema:
type: object
properties:
id:
type: integer
format: int64
description: ID of the created user.
# -----------------------------------------------------
# Links
# -----------------------------------------------------
links:
GetUserByUserId: # <---- arbitrary name for the link
operationId: getUser
# or
# operationRef: '#/paths/~1users~1{userId}/get'
parameters:
userId: "$response.body#/id"
description: >
The `id` value returned in the response can be used as
the `userId` parameter in `GET /users/{userId}`.
# -----------------------------------------------------
/users/{userId}:
get:
summary: Gets a user by ID
operationId: getUser
parameters:
- in: path
name: userId
required: true
schema:
type: integer
format: int64
responses:
"200":
description: A User object
content:
application/json:
schema:
$ref: "#/components/schemas/User"
components:
schemas:
User:
type: object
properties:
id:
type: integer
format: int64
readOnly: true
name:
type: string
```
--------------------------------
### Add Single Example to Request Body with $ref
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/adding-examples.md
If the request body schema uses `$ref`, the `example` keyword should be a child of the media type, not the schema. This ensures the example is correctly associated.
```yaml
paths:
/users:
post:
summary: Adds a new user
requestBody:
content:
application/json: # Media type
schema: # Request body contents
$ref: "#/components/schemas/User" # Reference to an object
example: # Child of media type because we use $ref above
# Properties of a referenced object
id: 10
name: Jessica Smith
responses:
"200":
description: OK
```
--------------------------------
### Path Parameters Example
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v2_0/describing-parameters.md
This example illustrates defining a required path parameter for a specific resource in OpenAPI 2.0.
```APIDOC
## GET /users/{id}
### Description
Retrieves a specific user by their ID.
### Method
GET
### Endpoint
/users/{id}
### Parameters
#### Path Parameters
- **id** (integer) - Required - The user ID.
### Responses
#### Success Response (200)
- description: OK
```
--------------------------------
### Install swagger-ui Package
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/open-source-tools/Swagger UI/Usage/installation.md
Install the swagger-ui package for JavaScript web projects that use module bundlers.
```sh
$ npm install swagger-ui
```
--------------------------------
### Install Dependencies for Swagger Editor
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/open-source-tools/swagger-editor.md
Run this command to install project dependencies. It's recommended to use the latest Node.js and npm versions.
```shell
$ npm i --legacy-peer-deps
```
--------------------------------
### Install Project Dependencies
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/README.md
Install the necessary dependencies for the Swagger Open Source Docs project using npm or yarn.
```bash
npm install
# or
yarn install
```
--------------------------------
### Example Java Client Configuration JSON
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/open-source-tools/Swagger Codegen/Codegen v2/generators-configuration.md
A comprehensive JSON configuration example for a Java client, specifying group ID, artifact ID, version, and library.
```json
{
"groupId": "com.my.company",
"artifactId": "MyClient",
"artifactVersion": "1.2.0",
"library": "feign"
}
```
--------------------------------
### Basic Authentication Header Example
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v2_0/Authentication/basic-authentication.md
An example of the Authorization header for Basic Authentication, showing the base64-encoded username and password.
```yaml
Authorization: Basic ZGVtbzpwQDU1dzByZA==
```
--------------------------------
### Query Parameters Example
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v2_0/describing-parameters.md
This example shows how to define query parameters for filtering and pagination in OpenAPI 2.0.
```APIDOC
## GET /pets/findByStatus
### Description
Finds pets by status.
### Method
GET
### Endpoint
/pets/findByStatus
### Parameters
#### Query Parameters
- **status** (string) - Optional - The status to filter pets by.
## GET /notes
### Description
Retrieves notes with pagination.
### Method
GET
### Endpoint
/notes
### Parameters
#### Query Parameters
- **offset** (integer) - Optional - The number of items to skip before starting to collect the result set.
- **limit** (integer) - Optional - The number of items to return.
```
--------------------------------
### Examples of Valid Component Names
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/components.md
Provides examples of valid component names that adhere to the specified character set, including 'User', 'New_User', 'org.example.User', and '401-Unauthorized'.
```yaml
User
New_User
org.example.User
401-Unauthorized
```
--------------------------------
### Array-Level Example
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/adding-examples.md
Define an example for an entire array, including multiple items. This is useful for showing a collection of data that conforms to the array schema.
```yaml
components:
schemas:
ArrayOfInt:
type: array
items:
type: integer
format: int64
example: [1, 2, 3]
```
--------------------------------
### Start Development Server
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/open-source-tools/Swagger UI/Development/setting-up.md
Run the development server to enable hot module reloading and unminified stack traces.
```bash
npm run dev
```
--------------------------------
### Reusing Defined Examples
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/adding-examples.md
Define common examples in `components/examples` and reference them using `$ref` elsewhere in the specification. This promotes reusability and consistency.
```yaml
content:
application/json:
schema:
$ref: '#/components/schemas/MyObject'
examples:
objectExample:
$ref: '#/components/examples/objectExample'
...
components:
examples:
objectExample:
value:
id: 1
name: new object
summary: A sample object
```
--------------------------------
### Clone and Set Up Swagger Editor Repository
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/open-source-tools/swagger-editor-next.md
Steps to clone the repository, switch to the 'next' branch, initialize and update submodules, and install dependencies.
```shell
$ git clone https://github.com/swagger-api/swagger-editor.git
$ cd swagger-editor
$ git checkout next
$ git submodule init
$ git submodule update
$ npm i
$ npm start
```
--------------------------------
### Ping Operation Example
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/paths-and-operations.md
A minimal example of a GET operation for a ping endpoint.
```APIDOC
## GET /ping
### Description
Checks if the API is reachable.
### Method
GET
### Endpoint
/ping
### Response
#### Success Response (200)
- **description** (string) - Indicates the API is operational.
```
--------------------------------
### Add Single Example to Request Body Schema
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/adding-examples.md
When the request body schema is defined directly, use the `example` keyword as a child of the schema to provide a sample object.
```yaml
paths:
/users:
post:
summary: Adds a new user
requestBody:
content:
application/json:
schema: # Request body contents
type: object
properties:
id:
type: integer
name:
type: string
example: # Sample object
id: 10
name: Jessica Smith
responses:
"200":
description: OK
```
--------------------------------
### Example HTTP Request with Custom Header
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v2_0/describing-parameters.md
This is an example of an HTTP GET request that includes a custom `X-Request-ID` header.
```http
GET /ping HTTP/1.1
Host: example.com
X-Request-ID: 77e1c83b-7bb0-437b-bc50-a7a58e5660ac
```
--------------------------------
### Client Credentials Flow Example (Getty Images API)
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/Authentication/oauth2.md
Example of an OAuth2 security scheme using the Client Credentials flow, suitable for machine-to-machine authentication.
```yaml
components:
securitySchemes:
oAuth2ClientCredentials:
type: oauth2
description: See http://developers.gettyimages.com/api/docs/v3/oauth2.html
flows:
clientCredentials:
tokenUrl: https://api.gettyimages.com/oauth2/token/
scopes: {} # Getty Images does not use scopes
```
--------------------------------
### Array Item Example
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/adding-examples.md
Specify an example for an individual item within an array schema. This clarifies the expected structure and data for elements in the array.
```yaml
components:
schemas:
ArrayOfInt:
type: array
items:
type: integer
format: int64
example: 1
```
--------------------------------
### Define Response Examples for Multiple MIME Types
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v2_0/adding-examples.md
Specify examples for different content types directly within the response definition. Ensure MIME types are listed in the operation's `produces` array.
```yaml
produces:
- application/json
- text/csv
responses:
200:
description: OK
examples:
application/json: { "id": 38, "title": "T-shirt" }
text/csv: >
id,title
38,T-shirt
```
--------------------------------
### Path with Summary and Description
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/paths-and-operations.md
Example of a path with documentation elements like summary and multi-line description.
```yaml
paths:
/users/{id}:
summary: Represents a user
description: >
This resource represents an individual user in the system.
Each user is identified by a numeric `id`.
get: ...
patch: ...
delete: ...
```
--------------------------------
### Property-Level Example in Schema
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/adding-examples.md
Define an example for an individual property within a schema. This helps illustrate the expected data type and format for that specific field.
```yaml
components:
schemas:
User: # Schema name
type: object
properties:
id:
type: integer
format: int64
example: 1 # Property example
name:
type: string
example: New order # Property example
```
--------------------------------
### Examples for XML and HTML Data
Source: https://github.com/swagger-api/swagger.io-docs/blob/main/src/content/docs/specification/v3_0/adding-examples.md
Specify examples for non-JSON/YAML data types like XML and HTML by providing them as strings. This is useful for describing literal content.
```yaml
content:
application/xml:
schema:
$ref: "#/components/schemas/xml"
examples:
xml:
summary: A sample XML response
value: "