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 cd.connect.openapi;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.media.Schema;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.CodegenProperty;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.languages.DartClientCodegen;
import org.openapitools.codegen.utils.ModelUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class DartV3ApiGenerator extends DartClientCodegen implements CodegenConfig {
private static final Logger log = LoggerFactory.getLogger(DartV3ApiGenerator.class);
private static final String LIBRARY_NAME = "dart2-api";
private static final String DART2_TEMPLATE_FOLDER = "dart2-v3template";
public DartV3ApiGenerator() {
super();
library = LIBRARY_NAME;
supportedLibraries.clear();
supportedLibraries.put(LIBRARY_NAME, LIBRARY_NAME);
}
public String getName() {
return LIBRARY_NAME;
}
public String getHelp() {
return "dart2 api generator. generates all classes and interfaces with jax-rs annotations with jersey2 extensions as necessary";
}
@Override
public void processOpts() {
additionalProperties.put(SUPPORT_DART2, Boolean.TRUE);
super.processOpts();
// replace Object with dynamic
this.typeMapping.put("object", "dynamic");
// override the location
embeddedTemplateDir = templateDir = DART2_TEMPLATE_FOLDER;
String libFolder = this.sourceFolder + File.separator + "lib";
this.supportingFiles.clear();
// none of these are useful.
this.apiTestTemplateFiles.clear();
this.apiDocTemplateFiles.clear();
this.modelTestTemplateFiles.clear();
this.modelDocTemplateFiles.clear();
this.supportingFiles.add(new SupportingFile("pubspec.mustache", "", "pubspec.yaml"));
this.supportingFiles.add(new SupportingFile("api_client.mustache", libFolder, "api_client.dart"));
this.supportingFiles.add(new SupportingFile("apilib.mustache", libFolder, "api.dart"));
}
/**
* People because they are able to include custom mappings, may need to include 3rd party libraries in their pubspec.
*/
private void processPubspecMappings() {
deps("pubspec-dependencies", "x-dart-deps");
deps("pubspec-dev-dependencies", "x-dart-devdeps");
}
private void deps(String addnPropertiesTag, String vendorPrefix) {
String depsKey = (String)additionalProperties.get(addnPropertiesTag);
List deps = new ArrayList<>();
additionalProperties.put(vendorPrefix, deps);
if (depsKey != null) {
Arrays.stream(depsKey.split(",")).map(String::trim).filter(s -> !s.isEmpty()).forEach(deps::add);
}
}
/**
* Because Dart is generating a library, some of the files may be included in the Maven project to be local libs and
* thus need to have a "part" reference. Others will need to be imported.
*/
private void processImportMappings() {
List partImports = new ArrayList<>(); // if they have included them locally, no "package" names
List dartImports = new ArrayList<>();
additionalProperties.put("x-dart-imports", dartImports);
additionalProperties.put("x-dart-parts", partImports);
importMapping.forEach((key, value) -> {
if (!value.startsWith("package:")) {
partImports.add(value);
} else {
dartImports.add(value);
}
});
}
// don't just add stuff to the end of the name willy nilly, check it is a reserved word first
@Override
public String escapeReservedWord(String name) {
return (isReservedWord(name)) ? name + "_" : name;
}
@Override
public String toVarName(String name) {
if (reservedWordsMappings.containsKey(name)) {
return reservedWordsMappings().get(name);
}
name = name.replaceAll("-", "_")
.replaceAll("\\$", "__")
.replaceAll("\\^", "__")
.replaceAll("\\=", "__");
if (name.matches("^[A-Z_]*$")) {
return name;
} else {
name = org.openapitools.codegen.utils.StringUtils.camelize(name, true);
if (name.matches("^\\d.*")) {
name = "n" + name;
}
if (this.isReservedWord(name)) {
name = this.escapeReservedWord(name);
}
return name;
}
}
@Override
public String toModelFilename(String name) {
if (name.contains(".")) {
int lastIndex = name.lastIndexOf(".");
String path = name.substring(0, lastIndex).replace(".", File.separator).replace('-', '_');
String modelName = name.substring(lastIndex+1);
return path + File.separator + org.openapitools.codegen.utils.StringUtils.underscore(this.toModelName(modelName));
} else {
return org.openapitools.codegen.utils.StringUtils.underscore(this.toModelName(name));
}
}
// for debugging inevitable weirdness in the model generated
@Override
public Map updateAllModels(Map objs) {
Map allModels = new HashMap<>();
objs.values().forEach(o -> {
Map modelData = (Map)o;
List