Skip to content

Commit

Permalink
[plugins/openapi-controllers] fix for inline parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangsa committed Dec 4, 2024
1 parent 11ef2e5 commit 6a0729d
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public List<TemplateOutput> generate(Map<String, Object> contextModel) {
}

var methodParameters = methodParameters(operation);
var serviceMethodParameter = serviceMethodParameter(method, zdlModel);

serviceOperations.add(Maps.of(
"operationId", operation.get("operationId"),
Expand All @@ -151,7 +152,7 @@ public List<TemplateOutput> generate(Map<String, Object> contextModel) {
"methodParameterInstances", methodParameterInstances(operation),
"methodParameterPlaceholders", methodParameterPlaceholders(operation),
"reqBodyVariableName", reqBodyVariableName(method, zdlModel),
"serviceMethodParameter", serviceMethodParameter(method, zdlModel),
"serviceMethodParameter", serviceMethodParameter,
"serviceMethodCall", serviceMethodCall(method, operation, zdlModel),
"mappedInputVariable", mappedInputVariable(method),
"inputType", inputType,
Expand All @@ -172,10 +173,10 @@ public List<TemplateOutput> generate(Map<String, Object> contextModel) {
var requestKey = format("%s_%s", requestDtoName, inputType);
Maps.getOrCreateDefault(mapperRequestDtoEntity, requestKey, new HashMap<>())
.putAll(Map.of("requestDto", requestDtoName, "inputType", inputType));
} else if (inputType != null && StringUtils.isNotBlank(methodParameters)) {
} else if (inputType != null && StringUtils.isNotBlank(serviceMethodParameter)) {
var requestKey = format("%s_%s", methodParameters, inputType);
Maps.getOrCreateDefault(mapperRequestDtoEntity, requestKey, new HashMap<>())
.putAll(Map.of("methodParameters", methodParameters, "inputType", inputType));
.putAll(Map.of("methodParameters", methodParameters, "inputType", serviceMethodParameter));
}
if (responseSchemaName != null && outputType != null) {
var responseKey = format("%s_%s_%s_%s", responseDtoName, outputType, isResponseArray, isResponsePaginated);
Expand Down Expand Up @@ -272,7 +273,22 @@ private String reqBodyVariableName(Map<String, Object> serviceMethod, Map zdl) {

private String serviceMethodParameter(Map<String, Object> method, Map<String, Object> zdlModel) {
if(method == null) { return "Entity"; }
return ZDLHttpUtils.getRequestBodyType(method, zdlModel);
var methodParameterType = (String) method.get("parameter");
var parameterEntity = JSONPath.get(zdlModel, "$.allEntitiesAndEnums." + methodParameterType);
if(parameterEntity == null) {
return null;
}
var isInline = JSONPath.get(parameterEntity, "$.options.inline", false);
if (isInline) {
var fields = JSONPath.get(parameterEntity, "$.fields", Map.<String, Map>of());
for (Map field : fields.values()) {
if (JSONPath.get(field, "$.isComplexType", false)) {
return JSONPath.get(field, "$.type");
}
}
return null;
}
return methodParameterType;
}

private String mappedInputVariable(Map<String, Object> method) {
Expand Down

0 comments on commit 6a0729d

Please sign in to comment.