Skip to content

Commit

Permalink
fix: Add support for multiple paths (#2122)
Browse files Browse the repository at this point in the history
* Add support for multiple paths

* Add tests for multiple paths

* Collect distinct paths

Co-authored-by: Michael Edgar <[email protected]>

* Improve semantics of null path segment

---------

Co-authored-by: Michael Edgar <[email protected]>
  • Loading branch information
geniegeist and MikeEdgar authored Jan 7, 2025
1 parent 1f49df8 commit 189b019
Show file tree
Hide file tree
Showing 21 changed files with 1,197 additions and 381 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.eclipse.microprofile.openapi.models.media.Content;
import org.eclipse.microprofile.openapi.models.media.Schema;
Expand Down Expand Up @@ -50,10 +51,10 @@ public static Comparator<Parameter> parameterComparator(List<Parameter> preferre

static final Pattern TEMPLATE_PARAM_PATTERN = Pattern.compile("\\{(\\w[\\w\\.-]*)\\}");

private String pathItemPath;
private List<String> pathItemPaths;
private List<Parameter> pathItemParameters;

private String operationPath;
private List<String> operationPaths;
private List<Parameter> operationParameters;

private Content formBodyContent;
Expand All @@ -62,12 +63,14 @@ public List<Parameter> getPathItemParameters() {
return pathItemParameters;
}

public String getOperationPath() {
return operationPath;
public List<String> getOperationPaths() {
return operationPaths;
}

public String getFullOperationPath() {
return pathItemPath + operationPath;
public List<String> getFullOperationPaths() {
return pathItemPaths.stream()
.flatMap(pathItemPath -> operationPaths.stream().map(operationPath -> pathItemPath + operationPath))
.collect(Collectors.toList());
}

public List<Parameter> getOperationParameters() {
Expand Down Expand Up @@ -107,16 +110,16 @@ public List<Parameter> getAllParameters() {
return all;
}

public void setPathItemPath(String pathItemPath) {
this.pathItemPath = pathItemPath;
public void setPathItemPaths(List<String> pathItemPaths) {
this.pathItemPaths = pathItemPaths;
}

public void setPathItemParameters(List<Parameter> pathItemParameters) {
this.pathItemParameters = pathItemParameters;
}

public void setOperationPath(String operationPath) {
this.operationPath = operationPath;
public void setOperationPaths(List<String> operationPaths) {
this.operationPaths = operationPaths;
}

public void setOperationParameters(List<Parameter> operationParameters) {
Expand All @@ -139,7 +142,11 @@ public void sort(List<Parameter> preferredOrder) {
}

public List<String> getPathParameterTemplateNames() {
return getPathParameterTemplateName(this.pathItemPath, this.operationPath);
return pathItemPaths.stream()
.flatMap(pathItemPath -> operationPaths.stream()
.flatMap(operationPath -> getPathParameterTemplateName(pathItemPath, operationPath).stream()))
.distinct()
.collect(Collectors.toList());
}

private static List<String> getPathParameterTemplateName(String... paths) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import java.math.BigInteger;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.eclipse.microprofile.openapi.models.Extensible;
import org.jboss.jandex.DotName;
Expand Down Expand Up @@ -63,6 +65,12 @@ public void setContextRoot(String path) {
this.contextRoot = path;
}

protected List<String> makePaths(List<String> operationPaths) {
return operationPaths.stream()
.map(operationPath -> createPathFromSegments(this.contextRoot, this.currentAppPath, operationPath))
.collect(Collectors.toList());
}

protected String makePath(String operationPath) {
return createPathFromSegments(this.contextRoot, this.currentAppPath, operationPath);
}
Expand Down
Loading

0 comments on commit 189b019

Please sign in to comment.