Skip to content

Commit e7d7553

Browse files
authored
Merge pull request #183 from anderslindho/master
Improve swagger documentation with operation annotations
2 parents bcc1b4d + dd5a088 commit e7d7553

File tree

7 files changed

+242
-249
lines changed

7 files changed

+242
-249
lines changed

src/main/java/org/phoebus/channelfinder/CFResourceDescriptors.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,12 @@ public class CFResourceDescriptors {
99
public static final String CHANNEL_RESOURCE_URI = CF_SERVICE + "/resources/channels";
1010
public static final String SCROLL_RESOURCE_URI = CF_SERVICE + "/resources/scroll";
1111
public static final String CHANNEL_PROCESSOR_RESOURCE_URI = CF_SERVICE + "/resources/processors";
12+
13+
public static final String SEARCH_PARAM_DESCRIPTION =
14+
"Search parameters. Examples:\n" +
15+
"- ~name: Filter by channel name (e.g., ~name=SR*)\n" +
16+
"- ~tag: Filter by tag name, use ! to negate (e.g., ~tag=active)\n" +
17+
"- ~size: Number of results (e.g., ~size=100)\n" +
18+
"- ~from: Starting index (e.g., ~from=0)\n" +
19+
"Use |,; as value separators";
1220
}

src/main/java/org/phoebus/channelfinder/ChannelManager.java

Lines changed: 66 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import io.swagger.v3.oas.annotations.media.Schema;
88
import io.swagger.v3.oas.annotations.responses.ApiResponse;
99
import io.swagger.v3.oas.annotations.responses.ApiResponses;
10+
import io.swagger.v3.oas.annotations.Operation;
11+
import io.swagger.v3.oas.annotations.Parameter;
1012
import org.phoebus.channelfinder.AuthorizationService.ROLES;
1113
import org.phoebus.channelfinder.entity.Channel;
1214
import org.phoebus.channelfinder.entity.Property;
@@ -41,6 +43,7 @@
4143
import java.util.stream.StreamSupport;
4244

4345
import static org.phoebus.channelfinder.CFResourceDescriptors.CHANNEL_RESOURCE_URI;
46+
import static org.phoebus.channelfinder.CFResourceDescriptors.SEARCH_PARAM_DESCRIPTION;
4447

4548
@CrossOrigin
4649
@RestController
@@ -69,14 +72,12 @@ public class ChannelManager {
6972
@Autowired
7073
ChannelProcessorService channelProcessorService;
7174

72-
/**
73-
* GET method for querying a collection of Channel instances, based on a
74-
* multi-parameter query specifying patterns for tags, property values, and
75-
* channel names to match against.
76-
*
77-
* @param allRequestParams query parameters
78-
* @return list of all channels
79-
*/
75+
@Operation(
76+
summary = "Query channels",
77+
description = "Query a collection of Channel instances based on tags, property values, and channel names.",
78+
operationId = "queryChannels",
79+
tags = {"Channel"}
80+
)
8081
@ApiResponses(
8182
value = {
8283
@ApiResponse(
@@ -94,18 +95,18 @@ public class ChannelManager {
9495
content = @Content(schema = @Schema(implementation = ResponseStatusException.class)))
9596
})
9697
@GetMapping
97-
public List<Channel> query(@RequestParam MultiValueMap<String, String> allRequestParams) {
98+
public List<Channel> query(
99+
@Parameter(description = SEARCH_PARAM_DESCRIPTION)
100+
@RequestParam MultiValueMap<String, String> allRequestParams) {
98101
return channelRepository.search(allRequestParams).channels();
99102
}
100103

101-
/**
102-
* GET method for querying for a collection of Channel instances, based on a
103-
* multi-parameter query specifying patterns for tags, property values, and
104-
* channel names to match against.
105-
*
106-
* @param allRequestParams query parameters
107-
* @return SearchResult a count to the total number of matches and the first 10k hits
108-
*/
104+
@Operation(
105+
summary = "Combined query for channels",
106+
description = "Query for a collection of Channel instances and get a count and the first 10k hits.",
107+
operationId = "combinedQueryChannels",
108+
tags = {"Channel"}
109+
)
109110
@ApiResponses(
110111
value = {
111112
@ApiResponse(
@@ -123,17 +124,18 @@ public List<Channel> query(@RequestParam MultiValueMap<String, String> allReques
123124
content = @Content(schema = @Schema(implementation = ResponseStatusException.class)))
124125
})
125126
@GetMapping("/combined")
126-
public SearchResult combinedQuery(@RequestParam MultiValueMap<String, String> allRequestParams) {
127+
public SearchResult combinedQuery(
128+
@Parameter(description = SEARCH_PARAM_DESCRIPTION)
129+
@RequestParam MultiValueMap<String, String> allRequestParams) {
127130
return channelRepository.search(allRequestParams);
128131
}
129132

130-
/**
131-
* GET method for querying the number of matches to a multi-parameter query specifying patterns for tags, property values, and
132-
* channel names to match against.
133-
*
134-
* @param allRequestParams query parameters
135-
* @return a total number of channels that match the query parameters
136-
*/
133+
@Operation(
134+
summary = "Count channels matching query",
135+
description = "Get the number of channels matching the given query parameters.",
136+
operationId = "countChannels",
137+
tags = {"Channel"}
138+
)
137139
@ApiResponses(
138140
value = {
139141
@ApiResponse(
@@ -146,17 +148,18 @@ public SearchResult combinedQuery(@RequestParam MultiValueMap<String, String> al
146148
content = @Content(schema = @Schema(implementation = ResponseStatusException.class)))
147149
})
148150
@GetMapping("/count")
149-
public long queryCount(@RequestParam MultiValueMap<String, String> allRequestParams) {
151+
public long queryCount(
152+
@Parameter(description = SEARCH_PARAM_DESCRIPTION)
153+
@RequestParam MultiValueMap<String, String> allRequestParams) {
150154
return channelRepository.count(allRequestParams);
151155
}
152156

153-
/**
154-
* GET method for retrieving an instance of Channel identified by
155-
* <code>channelName</code>.
156-
*
157-
* @param channelName - channel name to search for
158-
* @return found channel
159-
*/
157+
@Operation(
158+
summary = "Get channel by name",
159+
description = "Retrieve a Channel instance by its name.",
160+
operationId = "getChannelByName",
161+
tags = {"Channel"}
162+
)
160163
@ApiResponses(
161164
value = {
162165
@ApiResponse(
@@ -182,15 +185,12 @@ public Channel read(@PathVariable("channelName") String channelName) {
182185
}
183186
}
184187

185-
/**
186-
* PUT method for creating/replacing a channel instance identified by the
187-
* payload. The <b>complete</b> set of properties for the channel must be
188-
* supplied, which will replace the existing set of properties.
189-
*
190-
* @param channelName - name of channel to be created
191-
* @param channel - new data (properties/tags) for channel <code>chan</code>
192-
* @return the created channel
193-
*/
188+
@Operation(
189+
summary = "Create or replace a channel",
190+
description = "Create or replace a channel instance identified by the payload.",
191+
operationId = "createOrReplaceChannel",
192+
tags = {"Channel"}
193+
)
194194
@ApiResponses(
195195
value = {
196196
@ApiResponse(
@@ -248,12 +248,12 @@ public Channel create(@PathVariable("channelName") String channelName, @RequestB
248248
}
249249
}
250250

251-
/**
252-
* PUT method for creating multiple channels.
253-
*
254-
* @param channels - XmlChannels to be created
255-
* @return the list of channels created
256-
*/
251+
@Operation(
252+
summary = "Create or replace multiple channels",
253+
description = "Create or replace multiple channel instances.",
254+
operationId = "createOrReplaceChannels",
255+
tags = {"Channel"}
256+
)
257257
@ApiResponses(
258258
value = {
259259
@ApiResponse(
@@ -347,14 +347,12 @@ private void resetOwnersToExisting(Iterable<Channel> channels) {
347347
}
348348
}
349349

350-
/**
351-
* POST method for merging properties and tags of the channel identified by the
352-
* payload into an existing channel.
353-
*
354-
* @param channelName - name of channel to add
355-
* @param channel - new Channel data (properties/tags) to be merged into channel <code>channelName</code>
356-
* @return the updated channel
357-
*/
350+
@Operation(
351+
summary = "Update a channel",
352+
description = "Merge properties and tags of the channel identified by the payload into an existing channel.",
353+
operationId = "updateChannel",
354+
tags = {"Channel"}
355+
)
358356
@ApiResponses(
359357
value = {
360358
@ApiResponse(
@@ -427,13 +425,12 @@ public Channel update(@PathVariable("channelName") String channelName, @RequestB
427425
}
428426
}
429427

430-
/**
431-
* POST method for merging properties and tags of the Channels identified by the
432-
* payload into existing channels.
433-
*
434-
* @param channels - XmlChannels to be updated
435-
* @return the updated channels
436-
*/
428+
@Operation(
429+
summary = "Update multiple channels",
430+
description = "Merge properties and tags of the channels identified by the payload into existing channels.",
431+
operationId = "updateChannels",
432+
tags = {"Channel"}
433+
)
437434
@ApiResponses(
438435
value = {
439436
@ApiResponse(
@@ -497,12 +494,12 @@ public Iterable<Channel> update(@RequestBody Iterable<Channel> channels) {
497494
}
498495
}
499496

500-
/**
501-
* DELETE method for deleting a channel instance identified by path parameter
502-
* <code>channelName</code>.
503-
*
504-
* @param channelName - name of channel to remove
505-
*/
497+
@Operation(
498+
summary = "Delete a channel",
499+
description = "Delete a channel instance identified by its name.",
500+
operationId = "deleteChannel",
501+
tags = {"Channel"}
502+
)
506503
@ApiResponses(
507504
value = {
508505
@ApiResponse(

src/main/java/org/phoebus/channelfinder/ChannelScroll.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import io.swagger.v3.oas.annotations.media.Schema;
77
import io.swagger.v3.oas.annotations.responses.ApiResponse;
88
import io.swagger.v3.oas.annotations.responses.ApiResponses;
9+
import io.swagger.v3.oas.annotations.Operation;
10+
import io.swagger.v3.oas.annotations.Parameter;
911
import java.text.MessageFormat;
1012
import java.util.Comparator;
1113
import java.util.List;
@@ -54,14 +56,12 @@ public class ChannelScroll {
5456
@Qualifier("indexClient")
5557
ElasticsearchClient client;
5658

57-
/**
58-
* GET method for retrieving a collection of Channel instances, based on a
59-
* multi-parameter query specifying patterns for tags, property values, and
60-
* channel names to match against.
61-
*
62-
* @param allRequestParams search parameters
63-
* @return list of all channels
64-
*/
59+
@Operation(
60+
summary = "Scroll query for channels",
61+
description = "Retrieve a collection of Channel instances based on multi-parameter search.",
62+
operationId = "scrollQueryChannels",
63+
tags = {"ChannelScroll"}
64+
)
6565
@ApiResponses(
6666
value = {
6767
@ApiResponse(
@@ -74,18 +74,18 @@ public class ChannelScroll {
7474
content = @Content(schema = @Schema(implementation = ResponseStatusException.class)))
7575
})
7676
@GetMapping
77-
public Scroll query(@RequestParam MultiValueMap<String, String> allRequestParams) {
77+
public Scroll query(
78+
@Parameter(description = CFResourceDescriptors.SEARCH_PARAM_DESCRIPTION)
79+
@RequestParam MultiValueMap<String, String> allRequestParams) {
7880
return search(null, allRequestParams);
7981
}
8082

81-
/**
82-
* GET method for retrieving a collection of Channel instances, based on a
83-
* multi-parameter query specifying patterns for tags, property values, and
84-
* channel names to match against.
85-
*
86-
* @param scrollId scroll Id
87-
* @return list of all channels
88-
*/
83+
@Operation(
84+
summary = "Scroll query by scrollId",
85+
description = "Retrieve a collection of Channel instances using a scrollId and search parameters.",
86+
operationId = "scrollQueryById",
87+
tags = {"ChannelScroll"}
88+
)
8989
@ApiResponses(
9090
value = {
9191
@ApiResponse(
@@ -98,7 +98,10 @@ public Scroll query(@RequestParam MultiValueMap<String, String> allRequestParams
9898
content = @Content(schema = @Schema(implementation = ResponseStatusException.class)))
9999
})
100100
@GetMapping("/{scrollId}")
101-
public Scroll query(@PathVariable("scrollId") String scrollId, @RequestParam MultiValueMap<String, String> searchParameters) {
101+
public Scroll query(
102+
@Parameter(description = "Scroll ID from previous query") @PathVariable("scrollId") String scrollId,
103+
@Parameter(description = CFResourceDescriptors.SEARCH_PARAM_DESCRIPTION)
104+
@RequestParam MultiValueMap<String, String> searchParameters) {
102105
return search(scrollId, searchParameters);
103106
}
104107

src/main/java/org/phoebus/channelfinder/InfoManager.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.swagger.v3.oas.annotations.media.Schema;
77
import io.swagger.v3.oas.annotations.responses.ApiResponse;
88
import io.swagger.v3.oas.annotations.responses.ApiResponses;
9+
import io.swagger.v3.oas.annotations.Operation;
910
import java.io.IOException;
1011
import java.util.LinkedHashMap;
1112
import java.util.Map;
@@ -41,10 +42,12 @@ public class InfoManager {
4142

4243
private static final ObjectMapper objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
4344

44-
/**
45-
*
46-
* @return Information about the ChannelFinder service
47-
*/
45+
@Operation(
46+
summary = "Get ChannelFinder service info",
47+
description = "Returns information about the ChannelFinder service and its Elasticsearch backend.",
48+
operationId = "getServiceInfo",
49+
tags = {"Info"}
50+
)
4851
@ApiResponses(
4952
value = {
5053
@ApiResponse(

0 commit comments

Comments
 (0)