use of io.swagger.codegen.v3.CodegenOperation in project hippo by NHS-digital-website.
the class ApiSpecificationStaticHtml2Codegen method sortedAccordingToCustomOrder.
private List<CodegenOperation> sortedAccordingToCustomOrder(List<CodegenOperation> operations, String groupName) {
final Predicate matchesGroupName = operationOrderEntry -> Optional.ofNullable(((LinkedHashMap<?, ?>) operationOrderEntry).get("group")).map(String.class::cast).map(this::toApiVarName).orElse("default").equals(groupName);
LinkedHashMap<String, Object> operationOrderGroup = (LinkedHashMap<String, Object>) Optional.ofNullable(openAPI.getExtensions()).map(extensions -> extensions.get("x-spec-publication")).map(LinkedHashMap.class::cast).map(xSpecPublication -> xSpecPublication.get("operation-order")).map(List.class::cast).orElse(emptyList()).stream().map(LinkedHashMap.class::cast).filter(matchesGroupName).findFirst().orElse(new LinkedHashMap<>());
if (operationOrderGroup.isEmpty()) {
return operations;
}
List<LinkedHashMap> ops = (List<LinkedHashMap>) Optional.ofNullable(operationOrderGroup.get("operations")).orElse(new ArrayList<>());
Function<CodegenOperation, Integer> getReferenceIndexOf = op -> {
LinkedHashMap<?, ?> matchingReference = ops.stream().filter(opReference -> ((String) opReference.get("method")).equalsIgnoreCase(op.getHttpMethod()) && opReference.get("path").equals(op.getPath())).findFirst().orElse(new LinkedHashMap());
return ops.indexOf(matchingReference);
};
operations.sort(Comparator.comparingInt(getReferenceIndexOf::apply));
return operations;
}
use of io.swagger.codegen.v3.CodegenOperation in project flow by vaadin.
the class CodeGenerator method setShouldShowTsDoc.
private void setShouldShowTsDoc(List<CodegenOperation> operations) {
for (CodegenOperation coop : operations) {
boolean hasDescription = GeneratorUtils.isNotBlank(coop.getNotes());
boolean hasParameter = hasParameterDescription(coop);
boolean hasResponseDescription = hasResponseDescription(coop);
if (hasDescription || hasParameter || hasResponseDescription) {
coop.getVendorExtensions().put(EXTENSION_VAADIN_CONNECT_SHOW_TSDOC, true);
}
}
}
use of io.swagger.codegen.v3.CodegenOperation in project flow by vaadin.
the class CodeGenerator method postProcessOperations.
@Override
@SuppressWarnings("unchecked")
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
String classname = (String) operations.get("classname");
for (Tag tag : tags) {
if (tag.getName().equals(classname)) {
objs.put(VAADIN_CONNECT_CLASS_DESCRIPTION, tag.getDescription());
setVaadinFilePath(objs, tag);
break;
}
}
if (objs.get(VAADIN_CONNECT_CLASS_DESCRIPTION) == null) {
logger.debug("The class '{}' doesn't have JavaDoc or it is invalid. This results in no TsDoc for the generated module '{}'.", classname, classname);
}
if ((operations.get(OPERATION) instanceof List)) {
List<CodegenOperation> codegenOperations = (List<CodegenOperation>) operations.get(OPERATION);
setShouldShowTsDoc(codegenOperations);
}
Map<String, Object> postProcessOperations = super.postProcessOperations(objs);
List<Map<String, Object>> imports = (List<Map<String, Object>>) objs.get("imports");
adjustImportInformationForEndpoints(imports);
printDebugMessage(postProcessOperations, "=== All operations data ===");
return postProcessOperations;
}
use of io.swagger.codegen.v3.CodegenOperation in project hippo by NHS-digital-website.
the class CodegenOperationSorter method getOperationsToAdd.
private List<CodegenOperation> getOperationsToAdd(List<CodegenOperation> flattenedOpList, List<Map<String, String>> operations) {
final List<CodegenOperation> operationsToAdd = new ArrayList<>();
for (Map<String, String> opReference : operations) {
String path = opReference.get("path");
String httpMethod = opReference.get("method");
CodegenOperation operation = flattenedOpList.stream().filter(op -> op.getPath().equals(path) && op.getHttpMethod().equals(httpMethod)).findAny().orElse(null);
if (operation == null) {
throw new RuntimeException("Could not find operation that matches reference: " + httpMethod + " " + path);
}
operationsToAdd.add(operation);
}
return operationsToAdd;
}
use of io.swagger.codegen.v3.CodegenOperation in project hippo by NHS-digital-website.
the class CodegenOperationSorterTest method operationWithPathAndMethod.
private static CodegenOperation operationWithPathAndMethod(String path, String httpMethod) {
CodegenOperation op = new CodegenOperation();
op.path = path;
op.httpMethod = httpMethod;
return op;
}
Aggregations