forked from springwolf/springwolf-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): group AsyncApi (springwolf#967)
* feat(core): group AsyncApi Co-authored-by: David Müller <[email protected]> * feat(core): integrate grouping into DefaultAsyncApiService Co-authored-by: Timon Back <[email protected]> * feat(core): extend config properties to support grouping Co-authored-by: Timon Back <[email protected]> * feat(core): use patterns in group Co-authored-by: David Müller <[email protected]> * feat(core): mark messages (wip) Co-authored-by: David Müller <[email protected]> * feat(core): refactor DefaultAsyncApiService and add tests * feat(core): filter messages * test(core): add grouping integration test * feat(core): include schemas in grouping * refactor(core): include schemas in grouping * test(core): integration test grouping * refactor(core): update AsyncApiService default impl * feat(core): expose group via controller (wip) * feat(ui): show group in ui settings * chore(core): cleanup Co-authored-by: Timon Back <[email protected]> --------- Co-authored-by: David Müller <[email protected]>
- Loading branch information
Showing
49 changed files
with
1,762 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...-core/src/main/java/io/github/springwolf/core/asyncapi/grouping/AsyncApiGroupService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.springwolf.core.asyncapi.grouping; | ||
|
||
import io.github.springwolf.asyncapi.v3.model.AsyncAPI; | ||
import io.github.springwolf.core.configuration.docket.AsyncApiGroup; | ||
import io.github.springwolf.core.configuration.properties.SpringwolfConfigProperties; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.util.StringUtils; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class AsyncApiGroupService { | ||
private final SpringwolfConfigProperties springwolfConfigProperties; | ||
private final GroupingService groupingService; | ||
|
||
public Map<String, AsyncAPI> group(AsyncAPI asyncAPI) { | ||
return getAsyncApiGroups() | ||
.map(group -> Map.entry(group.getGroupName(), groupingService.groupAPI(asyncAPI, group))) | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
} | ||
|
||
public Stream<AsyncApiGroup> getAsyncApiGroups() { | ||
return springwolfConfigProperties.getDocket().getGroupConfigs().stream() | ||
.map(AsyncApiGroupService::toGroupConfigAndValidate); | ||
} | ||
|
||
private static AsyncApiGroup toGroupConfigAndValidate(SpringwolfConfigProperties.ConfigDocket.Group group) { | ||
String groupName = group.getGroup(); | ||
List<Pattern> channelNameToMatch = | ||
group.getChannelNameToMatch().stream().map(Pattern::compile).toList(); | ||
List<Pattern> messageNameToMatch = | ||
group.getMessageNameToMatch().stream().map(Pattern::compile).toList(); | ||
|
||
if (!StringUtils.hasText(groupName)) { | ||
throw new IllegalArgumentException("AsyncApiGroup must have a name set in configuration"); | ||
} | ||
|
||
int allItemCount = group.getActionToMatch().size() | ||
+ group.getChannelNameToMatch().size() | ||
+ group.getMessageNameToMatch().size(); | ||
if (allItemCount != 0 | ||
&& group.getActionToMatch().size() != allItemCount | ||
&& channelNameToMatch.size() != allItemCount | ||
&& messageNameToMatch.size() != allItemCount) { | ||
throw new IllegalArgumentException( | ||
"AsyncApiGroup %s must specify at most one filter criteria".formatted(groupName)); | ||
} | ||
|
||
AsyncApiGroup asyncApiGroup = AsyncApiGroup.builder() | ||
.groupName(groupName) | ||
.operationActionsToKeep(group.getActionToMatch()) | ||
.channelNamesToKeep(channelNameToMatch) | ||
.messageNamesToKeep(messageNameToMatch) | ||
.build(); | ||
log.debug("Loaded AsyncApiGroup from configuration: {}", asyncApiGroup); | ||
return asyncApiGroup; | ||
} | ||
} |
Oops, something went wrong.