Skip to content

Commit e19d563

Browse files
authored
Simplify API response annotations in chapter04.adoc
Refactored API response annotations for clarity and updated a note about usage of @APIResponses with `extensions' meta data fields.
1 parent 55b4d14 commit e19d563

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

modules/ROOT/pages/chapter04/chapter04.adoc

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,17 @@ public class ProductResource {
138138
@GET
139139
@Produces(MediaType.APPLICATION_JSON)
140140
@Operation(summary = "List all products", description = "Retrieves a list of all available products")
141-
@APIResponses(value = {
142-
@APIResponse(
143-
responseCode = "200",
144-
description = "Successful, list of products found",
145-
content = @Content(mediaType = "application/json",
146-
schema = @Schema(implementation = Product.class))
147-
),
148-
@APIResponse(
149-
responseCode = "400",
150-
description = "Unsuccessful, no products found",
151-
content = @Content(mediaType = "application/json")
152-
)
153-
})
141+
@APIResponse(
142+
responseCode = "200",
143+
description = "Successful, list of products found",
144+
content = @Content(mediaType = "application/json",
145+
schema = @Schema(implementation = Product.class)
146+
),
147+
@APIResponse(
148+
responseCode = "400",
149+
description = "Unsuccessful, no products found",
150+
content = @Content(mediaType = "application/json")
151+
)
154152
public List<Product> getAllProducts() {
155153
// Method implementation
156154
}
@@ -161,11 +159,15 @@ The annotations provide the following documentation:
161159

162160
* `@Tag`: Groups related endpoints together in the documentation
163161
* `@Operation`: Describes what the endpoint does
164-
* `@APIResponses`: Documents possible HTTP responses from the operation
165162
* `@APIResponse`: Defines a specific response with status code and content
166163
* `@Content`: Specifies the response media type and structure
167164
* `@Schema`: References the data model returned (in this case, `Product.class`)
168165

166+
[NOTE]
167+
====
168+
The `@APIResponse` annotation is repeatable, which means you can apply it multiple times to document different response codes. You only need the `@APIResponses` wrapper annotation when using the `extensions` field to add vendor-specific metadata to all responses.
169+
====
170+
169171
These annotations enrich the `ProductResource` class with metadata necessary for generating comprehensive OpenAPI documentation automatically.
170172

171173
[NOTE]

0 commit comments

Comments
 (0)