Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package io.swagger.codegen.v3.utils;
import io.swagger.codegen.v3.CodegenConstants;
import io.swagger.codegen.v3.CodegenModel;
import io.swagger.codegen.v3.CodegenProperty;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.PathItem;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class ModelUtils {
/**
* Searches for the model by name in the map of models and returns it
*
* @param name Name of the model
* @param models Map of models
* @return model
*/
public static CodegenModel getModelByName(final String name, final Map models) {
final Object data = models.get(name);
if (data instanceof Map) {
final Map, ?> dataMap = (Map, ?>) data;
final Object dataModels = dataMap.get("models");
if (dataModels instanceof List) {
final List> dataModelsList = (List>) dataModels;
for (final Object entry : dataModelsList) {
if (entry instanceof Map) {
final Map, ?> entryMap = (Map, ?>) entry;
final Object model = entryMap.get("model");
if (model instanceof CodegenModel) {
return (CodegenModel) model;
}
}
}
}
}
return null;
}
public static Operation[] createOperationArray (PathItem pathItem) {
return Stream.of(
pathItem.getGet(),
pathItem.getPost(),
pathItem.getDelete(),
pathItem.getHead(),
pathItem.getPut(),
pathItem.getPatch(),
pathItem.getOptions()
)
.filter(Objects::nonNull)
.collect(Collectors.toSet())
.toArray(new Operation[]{});
}
public static void processCodegenModels(Map allModels) {
// Fix up all parent and interface CodegenModel references.
for (CodegenModel codegenModel : allModels.values()) {
if (codegenModel.getParent() != null) {
codegenModel.setParentModel(allModels.get(codegenModel.getParent()));
}
if (codegenModel.getInterfaces() == null || codegenModel.getInterfaces().isEmpty()) {
continue;
}
codegenModel.setInterfaceModels(new ArrayList(codegenModel.getInterfaces().size()));
for (String intf : codegenModel.getInterfaces()) {
CodegenModel intfModel = allModels.get(intf);
if (intfModel != null) {
codegenModel.getInterfaceModels().add(intfModel);
}
}
}
// Let parent know about all its children
for (String name : allModels.keySet()) {
CodegenModel codegenModel = allModels.get(name);
CodegenModel parent = allModels.get(codegenModel.getParent());
// if a discriminator exists on the parent, don't add this child to the inheritance heirarchy
// TODO Determine what to do if the parent discriminator name == the grandparent discriminator name
while (parent != null) {
if (parent.getChildren() == null) {
parent.setChildren(new ArrayList());
}
parent.getChildren().add(codegenModel);
if (parent.getDiscriminator() == null) {
parent = allModels.get(parent.parent);
} else {
parent = null;
}
}
}
}
public static void processModelEnums(Map objs) {
List