mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-04 14:40:53 +00:00
codegen should honor path level parameters
This commit is contained in:
parent
e78844cb54
commit
0a8fb1e532
@ -13,6 +13,7 @@ import io.swagger.models.Path;
|
|||||||
import io.swagger.models.Swagger;
|
import io.swagger.models.Swagger;
|
||||||
import io.swagger.models.auth.OAuth2Definition;
|
import io.swagger.models.auth.OAuth2Definition;
|
||||||
import io.swagger.models.auth.SecuritySchemeDefinition;
|
import io.swagger.models.auth.SecuritySchemeDefinition;
|
||||||
|
import io.swagger.models.parameters.Parameter;
|
||||||
import io.swagger.util.Json;
|
import io.swagger.util.Json;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
@ -383,12 +384,12 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
|||||||
|
|
||||||
for (String resourcePath : paths.keySet()) {
|
for (String resourcePath : paths.keySet()) {
|
||||||
Path path = paths.get(resourcePath);
|
Path path = paths.get(resourcePath);
|
||||||
processOperation(resourcePath, "get", path.getGet(), ops);
|
processOperation(resourcePath, "get", path.getGet(), ops, path);
|
||||||
processOperation(resourcePath, "put", path.getPut(), ops);
|
processOperation(resourcePath, "put", path.getPut(), ops, path);
|
||||||
processOperation(resourcePath, "post", path.getPost(), ops);
|
processOperation(resourcePath, "post", path.getPost(), ops, path);
|
||||||
processOperation(resourcePath, "delete", path.getDelete(), ops);
|
processOperation(resourcePath, "delete", path.getDelete(), ops, path);
|
||||||
processOperation(resourcePath, "patch", path.getPatch(), ops);
|
processOperation(resourcePath, "patch", path.getPatch(), ops, path);
|
||||||
processOperation(resourcePath, "options", path.getOptions(), ops);
|
processOperation(resourcePath, "options", path.getOptions(), ops, path);
|
||||||
}
|
}
|
||||||
return ops;
|
return ops;
|
||||||
}
|
}
|
||||||
@ -401,8 +402,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
|||||||
return map.get(name);
|
return map.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void processOperation(String resourcePath, String httpMethod, Operation operation, Map<String, List<CodegenOperation>> operations, Path path) {
|
||||||
public void processOperation(String resourcePath, String httpMethod, Operation operation, Map<String, List<CodegenOperation>> operations) {
|
|
||||||
if (operation != null) {
|
if (operation != null) {
|
||||||
List<String> tags = operation.getTags();
|
List<String> tags = operation.getTags();
|
||||||
if (tags == null) {
|
if (tags == null) {
|
||||||
@ -410,6 +410,26 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
|||||||
tags.add("default");
|
tags.add("default");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
build up a set of parameter "ids" defined at the operation level
|
||||||
|
per the swagger 2.0 spec "A unique parameter is defined by a combination of a name and location"
|
||||||
|
i'm assuming "location" == "in"
|
||||||
|
*/
|
||||||
|
Set<String> operationParameters = new HashSet<String>();
|
||||||
|
if (operation.getParameters() != null) {
|
||||||
|
for (Parameter parameter : operation.getParameters()) {
|
||||||
|
operationParameters.add(generateParameterId(parameter));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//need to propagate path level down to the operation
|
||||||
|
for (Parameter parameter : path.getParameters()) {
|
||||||
|
//skip propagation if a parameter with the same name is already defined at the operation level
|
||||||
|
if (!operationParameters.contains(generateParameterId(parameter))) {
|
||||||
|
operation.addParameter(parameter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (String tag : tags) {
|
for (String tag : tags) {
|
||||||
CodegenOperation co = config.fromOperation(resourcePath, httpMethod, operation, swagger.getDefinitions());
|
CodegenOperation co = config.fromOperation(resourcePath, httpMethod, operation, swagger.getDefinitions());
|
||||||
co.tags = new ArrayList<String>();
|
co.tags = new ArrayList<String>();
|
||||||
@ -454,6 +474,10 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String generateParameterId(Parameter parameter) {
|
||||||
|
return parameter.getName() + ":" + parameter.getIn();
|
||||||
|
}
|
||||||
|
|
||||||
protected String sanitizeTag(String tag) {
|
protected String sanitizeTag(String tag) {
|
||||||
// remove spaces and make strong case
|
// remove spaces and make strong case
|
||||||
String[] parts = tag.split(" ");
|
String[] parts = tag.split(" ");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user