Skip to content

Commit

Permalink
handle shorthand argv
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Sep 5, 2024
1 parent f5668d9 commit 6c82f19
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,39 @@ public List<String> getEffectiveParams() {

Queue<Rule> ruleQueue = new ArrayDeque<>(endpointRuleSet.getRules());
Queue<Condition> conditionQueue = new ArrayDeque<>();
Queue<ObjectNode> argQueue = new ArrayDeque<>();
Queue<Node> argQueue = new ArrayDeque<>();

while (!ruleQueue.isEmpty() || !conditionQueue.isEmpty() || !argQueue.isEmpty()) {
while (!argQueue.isEmpty()) {
ObjectNode arg = argQueue.poll();
Optional<Node> ref = arg.getMember("ref");
if (ref.isPresent()) {
String refName = ref.get().expectStringNode().getValue();
if (initialParams.contains(refName)) {
effectiveParams.add(refName);
Node arg = argQueue.poll();
if (arg.isObjectNode()) {
Optional<Node> ref = arg.expectObjectNode().getMember("ref");
if (ref.isPresent()) {
String refName = ref.get().expectStringNode().getValue();
if (initialParams.contains(refName)) {
effectiveParams.add(refName);
}
}
}
Optional<Node> argv = arg.getMember("argv");
if (argv.isPresent()) {
ArrayNode nestedArgv = argv.get().expectArrayNode();
for (Node nestedArg : nestedArgv) {
if (nestedArg.isObjectNode()) {
argQueue.add(nestedArg.expectObjectNode());
Optional<Node> argv = arg.expectObjectNode().getMember("argv");
if (argv.isPresent()) {
ArrayNode nestedArgv = argv.get().expectArrayNode();
for (Node nestedArg : nestedArgv) {
if (nestedArg.isObjectNode()) {
argQueue.add(nestedArg.expectObjectNode());
}
}
}
} else if (arg.isStringNode()) {
String argString = arg.expectStringNode().getValue();
URL_PARAMETERS
.matcher(argString)
.results().forEach(matchResult -> {
if (matchResult.groupCount() >= 1) {
if (initialParams.contains(matchResult.group(1))) {
effectiveParams.add(matchResult.group(1));
}
}
});
}
}

Expand All @@ -113,9 +126,7 @@ public List<String> getEffectiveParams() {
.expectObjectNode()
.expectArrayMember("argv");
for (Node arg : argv) {
if (arg.isObjectNode()) {
argQueue.add(arg.expectObjectNode());
}
argQueue.add(arg);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class RuleSetParameterFinderTest {
"required": false,
"documentation": "...",
"type": "String"
},
"ShorthandParameter": {
"required": true,
"documentation": "...",
"type": "String"
}
},
"rules": [
Expand Down Expand Up @@ -83,6 +88,13 @@ class RuleSetParameterFinderTest {
},
true
]
},
{
"fn": "stringEquals",
"argv": [
"literal",
"{ShorthandParameter}"
]
}
],
"endpoint": {
Expand All @@ -109,6 +121,6 @@ void getEffectiveParams(@Mock ServiceShape serviceShape, @Mock EndpointRuleSetTr

List<String> effectiveParams = subject.getEffectiveParams();

assertEquals(List.of("BasicParameter", "NestedParameter", "UrlOnlyParameter"), effectiveParams);
assertEquals(List.of("BasicParameter", "NestedParameter", "ShorthandParameter", "UrlOnlyParameter"), effectiveParams);
}
}

0 comments on commit 6c82f19

Please sign in to comment.