Skip to content

Commit

Permalink
Properly encode filterBy parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierapivideo committed Jul 29, 2024
1 parent fc01675 commit e749875
Show file tree
Hide file tree
Showing 21 changed files with 434 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,17 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
@Override
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
Map<String, Object> res = super.postProcessModels(objs);
List<Map> models = (List<Map>) res.get("models");
ArrayList<HashMap<String, CodegenModel>> models = (ArrayList<HashMap<String, CodegenModel>>) res.get("models");

models.forEach(model -> {
((CodegenModel)model.get("model")).vars.forEach(var -> {
models.forEach(map -> {
CodegenModel model = map.get("model");
if(model.isMap) {
model.vendorExtensions.put("x-implements", Collections.singletonList("DeepObject"));
}
model.vars.forEach(var -> {
if(var.name.equals("_AccessToken")) var.name = "AccessToken";
if (var.defaultValue != null) {
((CodegenModel)model.get("model")).vendorExtensions.put("x-has-defaults", true);
model.vendorExtensions.put("x-has-defaults", true);
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
operation.allParams.stream().filter(p -> p.baseName.equals(queryParam.baseName)).forEach(p -> p.dataType = "time.Time");
queryParam.dataType = "time.Time";
}
if(queryParam.vendorExtensions.containsKey("x-is-deep-object")) additionalImports.add("fmt");
//if(queryParam.vendorExtensions.containsKey("x-is-deep-object")) additionalImports.add("fmt");
});

// overwrite operationId & nickname values of the operation with the x-client-action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ private void handlePagination(List<Object> allModels, CodegenOperation operation
@Override
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
Map<String, Object> stringObjectMap = super.postProcessModels(objs);
ArrayList<HashMap<String, CodegenModel>> models = (ArrayList<HashMap<String, CodegenModel>>) stringObjectMap.get("models");
models.stream().forEach((map) -> {
CodegenModel model = map.get("model");
if(model.isMap) {
((List<String>)model.vendorExtensions.get("x-implements") ).add("DeepObject");
}
});

((ArrayList) stringObjectMap.get("imports")).removeIf((v) -> ((Map) v).values().contains("org.openapitools.jackson.nullable.JsonNullable"));
return stringObjectMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,16 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
}

applyToAllParams(operation, (params) -> params.forEach(pp -> {
if("deepObject".equals(pp.style)) pp.collectionFormat = "deepObject";
if(pp.vendorExtensions != null && pp.vendorExtensions.containsKey("x-is-deep-object")) {
if(!pp.getHasVars()) {
pp.vendorExtensions.remove("x-is-deep-object");
} else {
if("deepObject".equals(pp.style)) {
pp.collectionFormat = "deepObject";
}
}
}

}));
applyToAllParams(operation, (params) -> params.removeIf(pp -> getVendorExtensionBooleanValue(pp, VENDOR_X_CLIENT_IGNORE)) );

Expand All @@ -80,6 +89,7 @@ private void applyToAllParams(CodegenOperation operation, Consumer<List<CodegenP
consumer.accept(operation.formParams);
consumer.accept(operation.cookieParams);
consumer.accept(operation.allParams);
consumer.accept(operation.queryParams);
}
}

Expand All @@ -100,14 +110,19 @@ public void processOpts() {

}


@Override
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
Map<String, Object> stringObjectMap = super.postProcessModels(objs);

List<Map<String, Object>> models = (List)objs.get("models");
models.forEach(map -> {
CodegenModel model = ((CodegenModel)map.get("model"));
if(model.vendorExtensions != null && model.vendorExtensions.containsKey("x-is-deep-object")) {
model.allVars.forEach(var -> {
String nameWithoutEndDigits = model.name.replaceAll("_\\d+$", "");
var.vendorExtensions.put("x-model-name", nameWithoutEndDigits);
});
}
model.vars.forEach(var -> {
if(var.vendorExtensions.containsKey("x-optional-nullable") && var.dataType.equals("String")) {
var.dataType = "NullableString";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,20 @@ protected String getParameterDataType(Parameter parameter, Schema p) {
} else if (ModelUtils.isMapSchema(p)) {
inner = (Schema) p.getAdditionalProperties();
return "{ [key: string]: " + this.getParameterDataType(parameter, inner) + "; }";
} else if (ModelUtils.isStringSchema(p)) {
} else if (p != null &&
parameter.getName() != null &&
parameter.getIn().equalsIgnoreCase("query") &&
parameter.getExplode() &&
parameter.getExtensions() != null &&
parameter.get$ref() != null &&
parameter.getExtensions().containsKey("x-is-deep-object")) {
String refName = parameter.get$ref().substring(parameter.get$ref().lastIndexOf("/") + 1);
refName = refName.replace("_", "");
refName = refName.substring(0, 1).toUpperCase() + refName.substring(1);

return refName;
}
else if (ModelUtils.isStringSchema(p)) {
// Handle string enums
if (p.getEnum() != null) {
return enumValuesToEnumTypeUnion(p.getEnum(), "string");
Expand Down
Loading

0 comments on commit e749875

Please sign in to comment.