Skip to content

Commit

Permalink
Fixes path enum generation
Browse files Browse the repository at this point in the history
  • Loading branch information
spacether committed Jul 27, 2022
1 parent 17a3bcf commit 8033c34
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.PathItem;
import io.swagger.v3.oas.models.Paths;
import io.swagger.v3.oas.models.servers.Server;
import io.swagger.v3.oas.models.tags.Tag;

Expand Down Expand Up @@ -465,15 +466,13 @@ protected void generateEndpoints(OperationsMap objs) {
OperationMap operations = objs.getOperations();
List<CodegenOperation> codegenOperations = operations.getOperation();
HashMap<String, String> pathModuleToPath = new HashMap<>();
Map<String, Object> pathValToVar = new HashMap<>();
// one file per endpoint
for (CodegenOperation co: codegenOperations) {
String path = co.path;
String pathModuleName = toVarName(path);
if (!pathModuleToPath.containsKey(pathModuleName)) {
pathModuleToPath.put(pathModuleName, path);
}
pathValToVar.put(path, co.operationIdLowerCase);
co.nickname = pathModuleName;
Map<String, Object> operationMap = new HashMap<>();
operationMap.put("operation", co);
Expand All @@ -488,7 +487,18 @@ protected void generateEndpoints(OperationsMap objs) {
LOGGER.error("Error when writing template file {}", e.toString());
}
}
Paths paths = openAPI.getPaths();
if (paths == null) {
return;
}
// one file in the path directory
Map<String, Object> pathValToVar = new LinkedHashMap<>();
for (Map.Entry<String, PathItem> pathsEntry : paths.entrySet()) {
String path = pathsEntry.getKey();
if (!pathValToVar.containsKey(path)) {
pathValToVar.put(path, toEnumVarName(path, "str"));
}
}
Map<String, Object> initOperationMap = new HashMap<>();
initOperationMap.put("packageName", packageName);
initOperationMap.put("apiClassname", "Api");
Expand All @@ -507,6 +517,7 @@ protected void generateEndpoints(OperationsMap objs) {
LOGGER.error("Error when writing template file {}", e.toString());
}
// one file per path module, one per paths
// TODO have this write to the apis folder
for (Map.Entry<String, String> entry: pathModuleToPath.entrySet()) {
String pathModule = entry.getKey();
String path = entry.getValue();
Expand Down
Loading

0 comments on commit 8033c34

Please sign in to comment.