Swagger YAML Generator

API Definition

The title shown at the top of Swagger UI.

e.g., v1, v2, 1.0.0

A description of the API that appears below the title.

Network & Security

The primary domain serving the API.

- HTTP or HTTPS.

Scaffolding

- Generate a boilerplate /products endpoint to get started.
swagger.yaml
1openapi: 3.0.3
2info:
3 title: Acme Corp API
4 version: v1
5 description: API documentation generated for Swagger UI.
6 contact:
7 name: API Support
8 email: support@example.com
9 license:
10 name: MIT
11 url: https://opensource.org/licenses/MIT
12servers:
13 - url: https://api.example.com/v1
14 description: Production Server
15components:
16 schemas:
17 Product:
18 type: object
19 required:
20 - id
21 - name
22 - price
23 properties:
24 id:
25 type: string
26 format: uuid
27 description: Unique product identifier
28 name:
29 type: string
30 minLength: 1
31 maxLength: 255
32 description: Product name
33 description:
34 type: string
35 description: Product description
36 price:
37 type: number
38 format: double
39 minimum: 0
40 description: Product price
41 category:
42 type: string
43 description: Product category
44 inStock:
45 type: boolean
46 default: true
47 description: Whether the product is in stock
48 createdAt:
49 type: string
50 format: date-time
51 example:
52 id: prod-123e4567-e89b-12d3-a456-426614174000
53 name: Wireless Keyboard
54 description: Ergonomic wireless keyboard with backlight
55 price: 79.99
56 category: Electronics
57 inStock: true
58 createdAt: '2024-01-15T10:30:00Z'
59 Error:
60 type: object
61 required:
62 - code
63 - message
64 properties:
65 code:
66 type: string
67 description: Machine-readable error code
68 message:
69 type: string
70 description: Human-readable error message
71 details:
72 type: array
73 items:
74 type: object
75 properties:
76 field:
77 type: string
78 message:
79 type: string
80 example:
81 code: NOT_FOUND
82 message: The requested product was not found.
83 securitySchemes:
84 ApiKeyAuth:
85 type: apiKey
86 in: header
87 name: X-API-Key
88 description: API Key authentication via the X-API-Key header
89security:
90 - ApiKeyAuth: []
91paths:
92 /products:
93 get:
94 summary: List all products
95 description: Returns a paginated list of products. Supports filtering by category and sorting by price.
96 operationId: listProducts
97 tags:
98 - Products
99 parameters:
100 - name: page
101 in: query
102 description: Page number
103 schema:
104 type: integer
105 default: 1
106 - name: limit
107 in: query
108 description: Items per page
109 schema:
110 type: integer
111 default: 20
112 maximum: 100
113 - name: category
114 in: query
115 description: Filter by category
116 schema:
117 type: string
118 responses:
119 '200':
120 description: A paginated list of products
121 content:
122 application/json:
123 schema:
124 type: object
125 properties:
126 data:
127 type: array
128 items:
129 $ref: '#/components/schemas/Product'
130 meta:
131 type: object
132 properties:
133 total:
134 type: integer
135 page:
136 type: integer
137 limit:
138 type: integer
139 '500':
140 description: Internal server error
141 post:
142 summary: Create a new product
143 description: Creates a new product with the provided data.
144 operationId: createProduct
145 tags:
146 - Products
147 parameters:
148 - in: header
149 name: Content-Type
150 required: true
151 schema:
152 type: string
153 enum:
154 - application/json
155 - in: body
156 name: body
157 required: true
158 schema:
159 $ref: '#/definitions/Product'
160 requestBody:
161 required: true
162 content:
163 application/json:
164 schema:
165 $ref: '#/components/schemas/Product'
166 responses:
167 '201':
168 description: Product created successfully
169 '400':
170 description: Bad request - Invalid input
171 '422':
172 description: Validation failed
173 '500':
174 description: Internal server error
175 /products/{id}:
176 get:
177 summary: Get a product by ID
178 description: Returns a single product by its unique identifier.
179 operationId: getProduct
180 tags:
181 - Products
182 parameters:
183 - name: id
184 in: path
185 required: true
186 description: Product unique identifier
187 schema:
188 type: string
189 format: uuid
190 responses:
191 '200':
192 description: Product found
193 content:
194 application/json:
195 schema:
196 $ref: '#/components/schemas/Product'
197 '404':
198 description: Product not found
199 '500':
200 description: Internal server error
201 put:
202 summary: Replace a product
203 description: Replaces all fields of an existing product.
204 operationId: replaceProduct
205 tags:
206 - Products
207 parameters:
208 - name: id
209 in: path
210 required: true
211 schema:
212 type: string
213 format: uuid
214 requestBody:
215 required: true
216 content:
217 application/json:
218 schema:
219 $ref: '#/components/schemas/Product'
220 responses:
221 '200':
222 description: Product replaced
223 '404':
224 description: Not found
225 '422':
226 description: Validation failed
227 '500':
228 description: Internal server error
229 delete:
230 summary: Delete a product
231 description: Permanently deletes a product.
232 operationId: deleteProduct
233 tags:
234 - Products
235 parameters:
236 - name: id
237 in: path
238 required: true
239 schema:
240 type: string
241 format: uuid
242 responses:
243 '204':
244 description: Product deleted
245 '404':
246 description: Not found
247 '500':
248 description: Internal server error

Overview

Swagger YAML Documentation Generator

The Swagger YAML Generator allows developers to quickly scaffold API documentation specifically optimized for rendering beautifully in Swagger UI.

While standard OpenAPI JSON files work for machine reading, clean YAML is the industry standard for human-readable API documentation. This tool ensures proper indentation, correct security definitions, valid Markdown descriptions, and generates both the YAML spec and comprehensive Swagger UI setup instructions.

Best Practices

  • Use OpenAPI 3.0 specification over legacy Swagger 2.0 whenever possible, as it provides far better support for oneOf/anyOf schemas and complex authentication flows.
  • Embed standard GitHub-flavored Markdown in your `description` fields to render rich text, tables, and links directly inside Swagger UI.
  • Always group endpoints using the `tags` array to create clean, categorized navigation menus in the sidebar.

Common Mistakes

  • Mixing up Swagger 2.0 syntax (`securityDefinitions`, `host`, `basePath`) with OpenAPI 3.0 syntax (`components.securitySchemes`, `servers`).
  • Using tabs instead of spaces in your YAML file, which causes immediate parse errors in most Swagger readers.
  • Leaking internal-only administrative endpoints into public-facing Swagger documentation by forgetting to maintain separate YAML files.

Security Recommendations

  • Review your Swagger documentation before making it public to ensure internal administrative routes and internal server URLs are not exposed.
  • Use placeholder values (e.g., YOUR_API_KEY_HERE) in example headers and request bodies instead of real credentials.
  • Configure authentication in Swagger UI correctly so the 'Authorize' button works with your actual auth system.

Frequently Asked Questions

What is the difference between Swagger and OpenAPI?
Swagger originally referred to the API specification format, but it was donated to the Linux Foundation and renamed to OpenAPI (currently v3+). Today, 'Swagger' typically refers to the tooling ecosystem (like Swagger UI or Swagger Editor), while 'OpenAPI' refers to the specification format itself.
How do I set up Swagger UI with authentication?
Click the 'Authorize' button at the top of Swagger UI. For API Key auth, enter your key in the ApiKeyAuth field. For Bearer JWT, enter the token (without 'Bearer ' prefix) in the bearerAuth field. Click 'Authorize' to apply the credentials to all requests.
Can I use this YAML with Redoc instead of Swagger UI?
Yes. The generated YAML follows the OpenAPI specification and is compatible with both Swagger UI and Redoc. Redoc provides a clean, three-panel documentation layout that many developers prefer for API reference documentation.

Related Generators