use of io.swagger.codegen.CodegenParameter in project carbon-apimgt by wso2.
the class DynamicHtmlGenTestCase method testFromParameter.
@Test
public void testFromParameter() throws Exception {
Parameter parameter = new QueryParameter();
parameter.setName("query");
final String description = "Sample parameter description";
parameter.setDescription(description);
DynamicHtmlGen htmlGen = new DynamicHtmlGen();
CodegenParameter modified = htmlGen.fromParameter(parameter, new HashSet<>());
Assert.assertEquals(modified.description, description);
}
use of io.swagger.codegen.CodegenParameter in project okta-sdk-java by okta.
the class AbstractOktaJavaClientCodegen method addOptionalExtension.
private void addOptionalExtension(CodegenOperation co, List<CodegenParameter> params) {
if (params.parallelStream().anyMatch(param -> !param.required)) {
co.vendorExtensions.put("hasOptional", true);
List<CodegenParameter> nonOptionalParams = params.stream().filter(param -> param.required).map(CodegenParameter::copy).collect(Collectors.toList());
if (!nonOptionalParams.isEmpty()) {
CodegenParameter param = nonOptionalParams.get(nonOptionalParams.size() - 1);
param.hasMore = false;
co.vendorExtensions.put("nonOptionalParams", nonOptionalParams);
}
// remove the noOptionalParams if we have trimmed down the list.
if (co.vendorExtensions.get("nonOptionalParams") != null && nonOptionalParams.isEmpty()) {
co.vendorExtensions.remove("nonOptionalParams");
}
// remove th body parameter if it was optional
if (co.bodyParam != null && !co.bodyParam.required) {
co.vendorExtensions.put("optionalBody", true);
}
}
}
use of io.swagger.codegen.CodegenParameter in project carbon-apimgt by wso2.
the class DynamicHtmlGen method fromParameter.
@Override
public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
CodegenParameter parameter = super.fromParameter(param, imports);
parameter.description = param.getDescription();
return parameter;
}
use of io.swagger.codegen.CodegenParameter in project carbon-apimgt by wso2.
the class DynamicHtmlGen method fromParameter.
@Override
public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
CodegenParameter parameter = super.fromParameter(param, imports);
parameter.description = param.getDescription();
return parameter;
}
use of io.swagger.codegen.CodegenParameter in project okta-sdk-java by okta.
the class AbstractOktaJavaClientCodegen method handleOktaLinkedOperations.
private void handleOktaLinkedOperations(Swagger swagger) {
// we want to move any operations defined by the 'x-okta-operations' or 'x-okta-crud' vendor extension to the model
Map<String, Model> modelMap = swagger.getDefinitions().entrySet().stream().filter(e -> e.getValue().getVendorExtensions().containsKey("x-okta-operations") || e.getValue().getVendorExtensions().containsKey("x-okta-crud")).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
modelMap.forEach((k, model) -> {
List<ObjectNode> linkNodes = new ArrayList<>();
addAllIfNotNull(linkNodes, (List<ObjectNode>) model.getVendorExtensions().get("x-okta-operations"));
addAllIfNotNull(linkNodes, (List<ObjectNode>) model.getVendorExtensions().get("x-okta-crud"));
Map<String, CodegenOperation> operationMap = new HashMap<>();
linkNodes.forEach(n -> {
String operationId = n.get("operationId").textValue();
// find the swagger path operation
swagger.getPaths().forEach((pathName, path) -> {
Optional<Map.Entry<HttpMethod, Operation>> operationEntry = path.getOperationMap().entrySet().stream().filter(e -> e.getValue().getOperationId().equals(operationId)).findFirst();
if (operationEntry.isPresent()) {
Operation operation = operationEntry.get().getValue();
CodegenOperation cgOperation = fromOperation(pathName, operationEntry.get().getKey().name().toLowerCase(), operation, swagger.getDefinitions(), swagger);
boolean canLinkMethod = true;
JsonNode aliasNode = n.get("alias");
if (aliasNode != null) {
String alias = aliasNode.textValue();
cgOperation.vendorExtensions.put("alias", alias);
if ("update".equals(alias)) {
model.getVendorExtensions().put("saveable", true);
} else if ("delete".equals(alias)) {
model.getVendorExtensions().put("deletable", true);
cgOperation.vendorExtensions.put("selfDelete", true);
} else if ("read".equals(alias) || "create".equals(alias)) {
canLinkMethod = false;
}
}
// we do NOT link read or create methods, those need to be on the parent object
if (canLinkMethod) {
// now any params that match the models we need to use the model value directly
// for example if the path contained {id} we would call getId() instead
Map<String, String> argMap = createArgMap(n);
List<CodegenParameter> cgOtherPathParamList = new ArrayList<>();
List<CodegenParameter> cgParamAllList = new ArrayList<>();
List<CodegenParameter> cgParamModelList = new ArrayList<>();
cgOperation.pathParams.forEach(param -> {
if (argMap.containsKey(param.paramName)) {
String paramName = argMap.get(param.paramName);
cgParamModelList.add(param);
if (model.getProperties() != null) {
CodegenProperty cgProperty = fromProperty(paramName, model.getProperties().get(paramName));
param.vendorExtensions.put("fromModel", cgProperty);
} else {
System.err.println("Model '" + model.getTitle() + "' has no properties");
}
} else {
cgOtherPathParamList.add(param);
}
});
// remove the body param if the body is the object itself
for (Iterator<CodegenParameter> iter = cgOperation.bodyParams.iterator(); iter.hasNext(); ) {
CodegenParameter bodyParam = iter.next();
if (argMap.containsKey(bodyParam.paramName)) {
cgOperation.vendorExtensions.put("bodyIsSelf", true);
iter.remove();
}
}
// do not add the parrent path params to the list (they will be parsed from the href)
SortedSet<String> pathParents = parentPathParams(n);
cgOtherPathParamList.forEach(param -> {
if (!pathParents.contains(param.paramName)) {
cgParamAllList.add(param);
}
});
if (!pathParents.isEmpty()) {
cgOperation.vendorExtensions.put("hasPathParents", true);
cgOperation.vendorExtensions.put("pathParents", pathParents);
}
cgParamAllList.addAll(cgOperation.queryParams);
cgParamAllList.addAll(cgOperation.bodyParams);
// set all params to have more
cgParamAllList.forEach(param -> param.hasMore = true);
// then grab the last one and mark it as the last
if (!cgParamAllList.isEmpty()) {
CodegenParameter param = cgParamAllList.get(cgParamAllList.size() - 1);
param.hasMore = false;
}
cgOperation.vendorExtensions.put("allParams", cgParamAllList);
cgOperation.vendorExtensions.put("fromModelPathParams", cgParamModelList);
addOptionalExtension(cgOperation, cgParamAllList);
operationMap.put(cgOperation.operationId, cgOperation);
// mark the operation as moved so we do NOT add it to the client
operation.getVendorExtensions().put("moved", true);
}
}
});
});
model.getVendorExtensions().put("operations", operationMap.values());
});
}
Aggregations