You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/asciidoc/modules/openapi.adoc
+187-4Lines changed: 187 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
This module helps automating the generation of API documentation using Jooby projects. jooby-openapi works by examining an application at *build* time to infer API semantics based on byte code and optional annotations.
4
4
5
-
Automatically generates documentation in JSON/YAML format APIs. This documentation can be completed by comments using swagger-api annotations.
5
+
Automatically generates documentation in JSON/YAML format APIs. This documentation can be completed by javadoc comments or using swagger-api annotations.
6
6
7
7
This library supports:
8
8
@@ -148,12 +148,20 @@ The OpenAPI generator works exactly the same for MVC routes (a.k.a Controller):
148
148
{
149
149
install(new OpenAPIModule());
150
150
151
-
mvc(new Pets());
151
+
mvc(new Pets_());
152
152
}
153
153
154
+
/**
155
+
* Pet Library.
156
+
*/
154
157
@Path("/pets")
155
158
public class Pets {
156
159
160
+
/**
161
+
* List pets.
162
+
*
163
+
* @return All pets.
164
+
*/
157
165
@GET
158
166
public List<Pet> list() {
159
167
...
@@ -168,7 +176,7 @@ public class Pets {
168
176
{
169
177
install(OpenAPIModule())
170
178
171
-
mvc(new MyController())
179
+
mvc(Pets_())
172
180
}
173
181
174
182
@Path("/pets")
@@ -185,9 +193,184 @@ class Pets {
185
193
The Maven plugin and Gradle task provide two filter properties `includes` and `excludes`. These
186
194
properties filter routes by their path pattern. The filter is a regular expression.
187
195
196
+
=== JavaDoc comments
197
+
198
+
Parsing of JavaDoc comment is supported on Java MVC/Controller.
199
+
200
+
.Java
201
+
[source,java]
202
+
----
203
+
204
+
/**
205
+
* My Library.
206
+
* @version 5.4.1
207
+
* @tag Books. All about books.
208
+
* @server.url https://books.api.com
209
+
* @server.description Production
210
+
* @x-logo https://my.api.com/logo.png
211
+
*/
212
+
public class App {
213
+
{
214
+
mvc(new Books_());
215
+
install(new OpenAPIModule());
216
+
}
217
+
}
218
+
/**
219
+
* Books operations.
220
+
* @tag Books
221
+
*/
222
+
@Path("/api/books")
223
+
public class Books {
224
+
/**
225
+
* Query and filter books.
226
+
*
227
+
* @param query Book filter.
228
+
* @return List of matching books.
229
+
*/
230
+
public List<Book> query(@QueryParam BookQuery query) {
231
+
....
232
+
}
233
+
/**
234
+
* Find a book by ISBN.
235
+
*
236
+
* @param isbn ISBN code.
237
+
* @return A book.
238
+
* @throws BookNotFoundException When a book doesn't exist. <code>404</code>
239
+
*/
240
+
public Book bookByIsbn(@PathParam String isbn) {
241
+
242
+
}
243
+
}
244
+
245
+
/**
246
+
* Book query.
247
+
*
248
+
* @type Book type.
249
+
* @aga Book age.
250
+
*/
251
+
public record BookQuery(BookType type, int age) {}
252
+
253
+
/**
254
+
* Books can be broadly categorized into fiction and non-fiction
255
+
*/
256
+
public enum BookType {
257
+
/**
258
+
* Fiction includes genres like fantasy, science fiction, romance, and mystery.
259
+
*/
260
+
Fiction,
261
+
/**
262
+
* Non-fiction encompasses genres like history, biography, and self-help.
263
+
*/
264
+
NonFiction
265
+
}
266
+
----
267
+
268
+
A JavaDoc comment is split into:
269
+
270
+
- summary: Everything before the first `.` or `<p>` paragraph
271
+
- description: Everything after the first `.` or `<p>` paragraph
272
+
273
+
Whitespaces (including new lines) are ignored. To introduce a new line, you must use a `<p>`.
274
+
275
+
==== Supported OpenAPI tags
276
+
277
+
[cols="3,1,1,1,4"]
278
+
|===
279
+
| Tag | Main | Controller | Method | Description
280
+
281
+
|@version 4.0.4
282
+
| [x]
283
+
|
284
+
|
285
+
|
286
+
287
+
|@contact.name
288
+
|[x]
289
+
|
290
+
|
291
+
|
292
+
293
+
|@contact.url
294
+
|[x]
295
+
|
296
+
|
297
+
|
298
+
299
+
|@contact.email
300
+
|[x]
301
+
|
302
+
|
303
+
|
304
+
305
+
|@license.name
306
+
|[x]
307
+
|
308
+
|
309
+
|
310
+
311
+
|@license.url
312
+
|[x]
313
+
|
314
+
|
315
+
|
316
+
317
+
|@server.description
318
+
|[x]
319
+
|
320
+
|
321
+
|
322
+
323
+
|@x-
324
+
|[x]
325
+
|[x]
326
+
|[x]
327
+
|Tag starting with `x-` is considered an extension
328
+
329
+
|@tag.name
330
+
|[x]
331
+
|[x]
332
+
|[x]
333
+
|Tag name
334
+
335
+
|@tag.description
336
+
|[x]
337
+
|[x]
338
+
|[x]
339
+
|Tag Description
340
+
341
+
|@tag
342
+
|[x]
343
+
|[x]
344
+
|[x]
345
+
|Shortcut for previous `@tag.name` and `@tag.description`. The tag name is everything before `.`
346
+
347
+
|@param <name>
348
+
|
349
+
|
350
+
|[x]
351
+
|Operation parameter
352
+
353
+
|@return
354
+
|
355
+
|
356
+
|[x]
357
+
|Operation default response
358
+
359
+
|@throws
360
+
|
361
+
|
362
+
|[x]
363
+
|Additional non-success responses types. The HTTP response code is taken from `<code>{number}</code>`, or set to `500` error.
364
+
365
+
|===
366
+
367
+
This feature is only available for Java MVC/controller routes. There are plans to support lambda
368
+
routes on Java. Kotlin source code is not supported.
369
+
370
+
188
371
=== Annotations
189
372
190
-
To produces a better documentation this plugin depends on some OpenAPI annotations. To use them, you
373
+
To produce a better documentation, this plugin depends on some OpenAPI annotations. To use them, you
0 commit comments