forked from loafle/openapi-generator-original
add Dart generator
This commit is contained in:
parent
852b5b02bd
commit
19c16fd572
@ -0,0 +1,475 @@
|
|||||||
|
package org.openapitools.codegen.languages;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.CliOption;
|
||||||
|
import org.openapitools.codegen.CodegenConfig;
|
||||||
|
import org.openapitools.codegen.CodegenConstants;
|
||||||
|
import org.openapitools.codegen.CodegenModel;
|
||||||
|
import org.openapitools.codegen.CodegenProperty;
|
||||||
|
import org.openapitools.codegen.CodegenType;
|
||||||
|
import org.openapitools.codegen.DefaultCodegen;
|
||||||
|
import org.openapitools.codegen.SupportingFile;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
|
import io.swagger.v3.oas.models.Operation;
|
||||||
|
import io.swagger.v3.oas.models.media.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
|
public static final String BROWSER_CLIENT = "browserClient";
|
||||||
|
public static final String PUB_NAME = "pubName";
|
||||||
|
public static final String PUB_VERSION = "pubVersion";
|
||||||
|
public static final String PUB_DESCRIPTION = "pubDescription";
|
||||||
|
public static final String USE_ENUM_EXTENSION = "useEnumExtension";
|
||||||
|
protected boolean browserClient = true;
|
||||||
|
protected String pubName = "swagger";
|
||||||
|
protected String pubVersion = "1.0.0";
|
||||||
|
protected String pubDescription = "Swagger API client";
|
||||||
|
protected boolean useEnumExtension = false;
|
||||||
|
protected String sourceFolder = "";
|
||||||
|
protected String apiDocPath = "docs/";
|
||||||
|
protected String modelDocPath = "docs/";
|
||||||
|
|
||||||
|
public DartClientCodegen() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
// clear import mapping (from default generator) as dart does not use it
|
||||||
|
// at the moment
|
||||||
|
importMapping.clear();
|
||||||
|
|
||||||
|
outputFolder = "generated-code/dart";
|
||||||
|
modelTemplateFiles.put("model.mustache", ".dart");
|
||||||
|
apiTemplateFiles.put("api.mustache", ".dart");
|
||||||
|
embeddedTemplateDir = templateDir = "dart";
|
||||||
|
apiPackage = "lib.api";
|
||||||
|
modelPackage = "lib.model";
|
||||||
|
modelDocTemplateFiles.put("object_doc.mustache", ".md");
|
||||||
|
apiDocTemplateFiles.put("api_doc.mustache", ".md");
|
||||||
|
|
||||||
|
setReservedWordsLowerCase(
|
||||||
|
Arrays.asList(
|
||||||
|
"abstract", "as", "assert", "async", "async*", "await",
|
||||||
|
"break", "case", "catch", "class", "const", "continue",
|
||||||
|
"default", "deferred", "do", "dynamic", "else", "enum",
|
||||||
|
"export", "external", "extends", "factory", "false", "final",
|
||||||
|
"finally", "for", "get", "if", "implements", "import", "in",
|
||||||
|
"is", "library", "new", "null", "operator", "part", "rethrow",
|
||||||
|
"return", "set", "static", "super", "switch", "sync*", "this",
|
||||||
|
"throw", "true", "try", "typedef", "var", "void", "while",
|
||||||
|
"with", "yield", "yield*" )
|
||||||
|
);
|
||||||
|
|
||||||
|
languageSpecificPrimitives = new HashSet<String>(
|
||||||
|
Arrays.asList(
|
||||||
|
"String",
|
||||||
|
"bool",
|
||||||
|
"int",
|
||||||
|
"num",
|
||||||
|
"double")
|
||||||
|
);
|
||||||
|
instantiationTypes.put("array", "List");
|
||||||
|
instantiationTypes.put("map", "Map");
|
||||||
|
|
||||||
|
typeMapping = new HashMap<String, String>();
|
||||||
|
typeMapping.put("Array", "List");
|
||||||
|
typeMapping.put("array", "List");
|
||||||
|
typeMapping.put("List", "List");
|
||||||
|
typeMapping.put("boolean", "bool");
|
||||||
|
typeMapping.put("string", "String");
|
||||||
|
typeMapping.put("char", "String");
|
||||||
|
typeMapping.put("int", "int");
|
||||||
|
typeMapping.put("long", "int");
|
||||||
|
typeMapping.put("short", "int");
|
||||||
|
typeMapping.put("number", "num");
|
||||||
|
typeMapping.put("float", "double");
|
||||||
|
typeMapping.put("double", "double");
|
||||||
|
typeMapping.put("object", "Object");
|
||||||
|
typeMapping.put("integer", "int");
|
||||||
|
typeMapping.put("Date", "DateTime");
|
||||||
|
typeMapping.put("date", "DateTime");
|
||||||
|
typeMapping.put("File", "MultipartFile");
|
||||||
|
typeMapping.put("UUID", "String");
|
||||||
|
//TODO binary should be mapped to byte array
|
||||||
|
// mapped to String as a workaround
|
||||||
|
typeMapping.put("binary", "String");
|
||||||
|
|
||||||
|
cliOptions.add(new CliOption(BROWSER_CLIENT, "Is the client browser based"));
|
||||||
|
cliOptions.add(new CliOption(PUB_NAME, "Name in generated pubspec"));
|
||||||
|
cliOptions.add(new CliOption(PUB_VERSION, "Version in generated pubspec"));
|
||||||
|
cliOptions.add(new CliOption(PUB_DESCRIPTION, "Description in generated pubspec"));
|
||||||
|
cliOptions.add(new CliOption(USE_ENUM_EXTENSION, "Allow the 'x-enum-values' extension for enums"));
|
||||||
|
cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, "source folder for generated code"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CodegenType getTag() {
|
||||||
|
return CodegenType.CLIENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "dart";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelp() {
|
||||||
|
return "Generates a Dart client library.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processOpts() {
|
||||||
|
super.processOpts();
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(BROWSER_CLIENT)) {
|
||||||
|
this.setBrowserClient(convertPropertyToBooleanAndWriteBack(BROWSER_CLIENT));
|
||||||
|
} else {
|
||||||
|
//not set, use to be passed to template
|
||||||
|
additionalProperties.put(BROWSER_CLIENT, browserClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(PUB_NAME)) {
|
||||||
|
this.setPubName((String) additionalProperties.get(PUB_NAME));
|
||||||
|
} else {
|
||||||
|
//not set, use to be passed to template
|
||||||
|
additionalProperties.put(PUB_NAME, pubName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(PUB_VERSION)) {
|
||||||
|
this.setPubVersion((String) additionalProperties.get(PUB_VERSION));
|
||||||
|
} else {
|
||||||
|
//not set, use to be passed to template
|
||||||
|
additionalProperties.put(PUB_VERSION, pubVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(PUB_DESCRIPTION)) {
|
||||||
|
this.setPubDescription((String) additionalProperties.get(PUB_DESCRIPTION));
|
||||||
|
} else {
|
||||||
|
//not set, use to be passed to template
|
||||||
|
additionalProperties.put(PUB_DESCRIPTION, pubDescription);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(USE_ENUM_EXTENSION)) {
|
||||||
|
this.setUseEnumExtension(convertPropertyToBooleanAndWriteBack(USE_ENUM_EXTENSION));
|
||||||
|
} else {
|
||||||
|
// Not set, use to be passed to template.
|
||||||
|
additionalProperties.put(USE_ENUM_EXTENSION, useEnumExtension);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(CodegenConstants.SOURCE_FOLDER)) {
|
||||||
|
this.setSourceFolder((String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER));
|
||||||
|
}
|
||||||
|
|
||||||
|
// default HIDE_GENERATION_TIMESTAMP to true
|
||||||
|
if (!additionalProperties.containsKey(CodegenConstants.HIDE_GENERATION_TIMESTAMP)) {
|
||||||
|
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, Boolean.TRUE.toString());
|
||||||
|
} else {
|
||||||
|
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP,
|
||||||
|
Boolean.valueOf(additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// make api and model doc path available in mustache template
|
||||||
|
additionalProperties.put("apiDocPath", apiDocPath);
|
||||||
|
additionalProperties.put("modelDocPath", modelDocPath);
|
||||||
|
|
||||||
|
final String libFolder = sourceFolder + File.separator + "lib";
|
||||||
|
supportingFiles.add(new SupportingFile("pubspec.mustache", "", "pubspec.yaml"));
|
||||||
|
supportingFiles.add(new SupportingFile("analysis_options.mustache", "", ".analysis_options"));
|
||||||
|
supportingFiles.add(new SupportingFile("api_client.mustache", libFolder, "api_client.dart"));
|
||||||
|
supportingFiles.add(new SupportingFile("api_exception.mustache", libFolder, "api_exception.dart"));
|
||||||
|
supportingFiles.add(new SupportingFile("api_helper.mustache", libFolder, "api_helper.dart"));
|
||||||
|
supportingFiles.add(new SupportingFile("apilib.mustache", libFolder, "api.dart"));
|
||||||
|
|
||||||
|
final String authFolder = sourceFolder + File.separator + "lib" + File.separator + "auth";
|
||||||
|
supportingFiles.add(new SupportingFile("auth/authentication.mustache", authFolder, "authentication.dart"));
|
||||||
|
supportingFiles.add(new SupportingFile("auth/http_basic_auth.mustache", authFolder, "http_basic_auth.dart"));
|
||||||
|
supportingFiles.add(new SupportingFile("auth/api_key_auth.mustache", authFolder, "api_key_auth.dart"));
|
||||||
|
supportingFiles.add(new SupportingFile("auth/oauth.mustache", authFolder, "oauth.dart"));
|
||||||
|
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||||
|
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
|
||||||
|
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String escapeReservedWord(String name) {
|
||||||
|
return name + "_";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String apiFileFolder() {
|
||||||
|
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String modelFileFolder() {
|
||||||
|
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String apiDocFileFolder() {
|
||||||
|
return (outputFolder + "/" + apiDocPath).replace('/', File.separatorChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String modelDocFileFolder() {
|
||||||
|
return (outputFolder + "/" + modelDocPath).replace('/', File.separatorChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toVarName(String name) {
|
||||||
|
// replace - with _ e.g. created-at => created_at
|
||||||
|
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||||
|
|
||||||
|
// if it's all uppper case, do nothing
|
||||||
|
if (name.matches("^[A-Z_]*$")) {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// camelize (lower first character) the variable name
|
||||||
|
// pet_id => petId
|
||||||
|
name = camelize(name, true);
|
||||||
|
|
||||||
|
if (name.matches("^\\d.*")) {
|
||||||
|
name = "n" + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isReservedWord(name)) {
|
||||||
|
name = escapeReservedWord(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toParamName(String name) {
|
||||||
|
// should be the same as variable name
|
||||||
|
return toVarName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toModelName(String name) {
|
||||||
|
// model name cannot use reserved keyword, e.g. return
|
||||||
|
if (isReservedWord(name)) {
|
||||||
|
LOGGER.warn(name + " (reserved word) cannot be used as model filename. Renamed to " + camelize("model_" + name));
|
||||||
|
name = "model_" + name; // e.g. return => ModelReturn (after camelize)
|
||||||
|
}
|
||||||
|
|
||||||
|
// camelize the model name
|
||||||
|
// phone_number => PhoneNumber
|
||||||
|
return camelize(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toModelFilename(String name) {
|
||||||
|
return underscore(toModelName(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toApiFilename(String name) {
|
||||||
|
return underscore(toApiName(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toDefaultValue(Schema p) {
|
||||||
|
if (p instanceof MapSchema) {
|
||||||
|
return "{}";
|
||||||
|
} else if (p instanceof ArraySchema) {
|
||||||
|
return "[]";
|
||||||
|
}
|
||||||
|
return super.toDefaultValue(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTypeDeclaration(Schema p) {
|
||||||
|
if (p instanceof ArraySchema) {
|
||||||
|
ArraySchema ap = (ArraySchema) p;
|
||||||
|
Schema inner = ap.getItems();
|
||||||
|
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
|
} else if (p instanceof MapSchema) {
|
||||||
|
MapSchema mp = (MapSchema) p;
|
||||||
|
Schema inner = (Schema) mp.getAdditionalProperties();
|
||||||
|
|
||||||
|
return getSchemaType(p) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||||
|
}
|
||||||
|
return super.getTypeDeclaration(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSchemaType(Schema p) {
|
||||||
|
String openAPIType = super.getSchemaType(p);
|
||||||
|
String type = null;
|
||||||
|
if (typeMapping.containsKey(openAPIType)) {
|
||||||
|
type = typeMapping.get(openAPIType);
|
||||||
|
if (languageSpecificPrimitives.contains(type)) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
type = openAPIType;
|
||||||
|
}
|
||||||
|
return toModelName(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||||
|
return postProcessModelsEnum(objs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
|
||||||
|
List<Object> models = (List<Object>) objs.get("models");
|
||||||
|
for (Object _mo : models) {
|
||||||
|
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||||
|
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||||
|
boolean succes = buildEnumFromVendorExtension(cm) ||
|
||||||
|
buildEnumFromValues(cm);
|
||||||
|
for (CodegenProperty var : cm.vars) {
|
||||||
|
updateCodegenPropertyEnum(var);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return objs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the set of enum members from their declared value.
|
||||||
|
*
|
||||||
|
* @return {@code true} if the enum was built
|
||||||
|
*/
|
||||||
|
private boolean buildEnumFromValues(CodegenModel cm) {
|
||||||
|
if (!cm.isEnum || cm.allowableValues == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Map<String, Object> allowableValues = cm.allowableValues;
|
||||||
|
List<Object> values = (List<Object>) allowableValues.get("values");
|
||||||
|
List<Map<String, String>> enumVars =
|
||||||
|
new ArrayList<Map<String, String>>();
|
||||||
|
String commonPrefix = findCommonPrefixOfVars(values);
|
||||||
|
int truncateIdx = commonPrefix.length();
|
||||||
|
for (Object value : values) {
|
||||||
|
Map<String, String> enumVar = new HashMap<String, String>();
|
||||||
|
String enumName;
|
||||||
|
if (truncateIdx == 0) {
|
||||||
|
enumName = value.toString();
|
||||||
|
} else {
|
||||||
|
enumName = value.toString().substring(truncateIdx);
|
||||||
|
if ("".equals(enumName)) {
|
||||||
|
enumName = value.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
enumVar.put("name", toEnumVarName(enumName, cm.dataType));
|
||||||
|
enumVar.put("value", toEnumValue(value.toString(), cm.dataType));
|
||||||
|
enumVars.add(enumVar);
|
||||||
|
}
|
||||||
|
cm.allowableValues.put("enumVars", enumVars);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the set of enum members from a vendor extension.
|
||||||
|
*
|
||||||
|
* @return {@code true} if the enum was built
|
||||||
|
*/
|
||||||
|
private boolean buildEnumFromVendorExtension(CodegenModel cm) {
|
||||||
|
if (!cm.isEnum || cm.allowableValues == null ||
|
||||||
|
!useEnumExtension ||
|
||||||
|
!cm.vendorExtensions.containsKey("x-enum-values")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Object extension = cm.vendorExtensions.get("x-enum-values");
|
||||||
|
List<Map<String, Object>> values =
|
||||||
|
(List<Map<String, Object>>) extension;
|
||||||
|
List<Map<String, String>> enumVars =
|
||||||
|
new ArrayList<Map<String, String>>();
|
||||||
|
for (Map<String, Object> value : values) {
|
||||||
|
Map<String, String> enumVar = new HashMap<String, String>();
|
||||||
|
String name = camelize((String) value.get("identifier"), true);
|
||||||
|
if (isReservedWord(name)) {
|
||||||
|
name = escapeReservedWord(name);
|
||||||
|
}
|
||||||
|
enumVar.put("name", name);
|
||||||
|
enumVar.put("value", toEnumValue(
|
||||||
|
value.get("numericValue").toString(), cm.dataType));
|
||||||
|
if (value.containsKey("description")) {
|
||||||
|
enumVar.put("description", value.get("description").toString());
|
||||||
|
}
|
||||||
|
enumVars.add(enumVar);
|
||||||
|
}
|
||||||
|
cm.allowableValues.put("enumVars", enumVars);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toEnumVarName(String value, String datatype) {
|
||||||
|
if (value.length() == 0) {
|
||||||
|
return "empty";
|
||||||
|
}
|
||||||
|
String var = value.replaceAll("\\W+", "_");
|
||||||
|
if ("number".equalsIgnoreCase(datatype) ||
|
||||||
|
"int".equalsIgnoreCase(datatype)) {
|
||||||
|
var = "Number" + var;
|
||||||
|
}
|
||||||
|
return escapeReservedWord(camelize(var, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toEnumValue(String value, String datatype) {
|
||||||
|
if ("number".equalsIgnoreCase(datatype) ||
|
||||||
|
"int".equalsIgnoreCase(datatype)) {
|
||||||
|
return value;
|
||||||
|
} else {
|
||||||
|
return "\"" + escapeText(value) + "\"";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toOperationId(String operationId) {
|
||||||
|
// method name cannot use reserved keyword, e.g. return
|
||||||
|
if (isReservedWord(operationId)) {
|
||||||
|
String newOperationId = camelize("call_" + operationId, true);
|
||||||
|
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
|
||||||
|
return newOperationId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return camelize(operationId, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBrowserClient(boolean browserClient) {
|
||||||
|
this.browserClient = browserClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPubName(String pubName) {
|
||||||
|
this.pubName = pubName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPubVersion(String pubVersion) {
|
||||||
|
this.pubVersion = pubVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPubDescription(String pubDescription) {
|
||||||
|
this.pubDescription = pubDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUseEnumExtension(boolean useEnumExtension) {
|
||||||
|
this.useEnumExtension = useEnumExtension;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSourceFolder(String sourceFolder) {
|
||||||
|
this.sourceFolder = sourceFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String escapeQuotationMark(String input) {
|
||||||
|
// remove " to avoid code injection
|
||||||
|
return input.replace("\"", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String escapeUnsafeCharacters(String input) {
|
||||||
|
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
org.openapitools.codegen.languages.BashClientCodegen
|
org.openapitools.codegen.languages.BashClientCodegen
|
||||||
|
org.openapitools.codegen.languages.DartClientCodegen
|
||||||
org.openapitools.codegen.languages.HaskellServantCodegen
|
org.openapitools.codegen.languages.HaskellServantCodegen
|
||||||
org.openapitools.codegen.languages.LumenServerCodegen
|
org.openapitools.codegen.languages.LumenServerCodegen
|
||||||
org.openapitools.codegen.languages.ObjcClientCodegen
|
org.openapitools.codegen.languages.ObjcClientCodegen
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
package org.openapitools.codegen.dart;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.AbstractOptionsTest;
|
||||||
|
import org.openapitools.codegen.CodegenConfig;
|
||||||
|
import org.openapitools.codegen.languages.DartClientCodegen;
|
||||||
|
import org.openapitools.codegen.options.DartClientOptionsProvider;
|
||||||
|
|
||||||
|
import mockit.Expectations;
|
||||||
|
import mockit.Tested;
|
||||||
|
|
||||||
|
public class DartClientOptionsTest extends AbstractOptionsTest {
|
||||||
|
|
||||||
|
@Tested
|
||||||
|
private DartClientCodegen clientCodegen;
|
||||||
|
|
||||||
|
public DartClientOptionsTest() {
|
||||||
|
super(new DartClientOptionsProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CodegenConfig getCodegenConfig() {
|
||||||
|
return clientCodegen;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
@Override
|
||||||
|
protected void setExpectations() {
|
||||||
|
new Expectations(clientCodegen) {{
|
||||||
|
clientCodegen.setSortParamsByRequiredFlag(Boolean.valueOf(DartClientOptionsProvider.SORT_PARAMS_VALUE));
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setBrowserClient(Boolean.valueOf(DartClientOptionsProvider.BROWSER_CLIENT_VALUE));
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setPubName(DartClientOptionsProvider.PUB_NAME_VALUE);
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setPubVersion(DartClientOptionsProvider.PUB_VERSION_VALUE);
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setPubDescription(DartClientOptionsProvider.PUB_DESCRIPTION_VALUE);
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setSourceFolder(DartClientOptionsProvider.SOURCE_FOLDER_VALUE);
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setUseEnumExtension(Boolean.valueOf(DartClientOptionsProvider.USE_ENUM_EXTENSION));
|
||||||
|
times = 1;
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package org.openapitools.codegen.options;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.CodegenConstants;
|
||||||
|
import org.openapitools.codegen.languages.DartClientCodegen;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class DartClientOptionsProvider implements OptionsProvider {
|
||||||
|
public static final String SORT_PARAMS_VALUE = "true";
|
||||||
|
public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true";
|
||||||
|
public static final String BROWSER_CLIENT_VALUE = "true";
|
||||||
|
public static final String PUB_NAME_VALUE = "swagger";
|
||||||
|
public static final String PUB_VERSION_VALUE = "1.0.0-SNAPSHOT";
|
||||||
|
public static final String PUB_DESCRIPTION_VALUE = "Swagger API client dart";
|
||||||
|
public static final String SOURCE_FOLDER_VALUE = "src";
|
||||||
|
public static final String USE_ENUM_EXTENSION = "true";
|
||||||
|
public static final String ALLOW_UNICODE_IDENTIFIERS_VALUE = "false";
|
||||||
|
public static final String PREPEND_FORM_OR_BODY_PARAMETERS_VALUE = "true";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLanguage() {
|
||||||
|
return "dart";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> createOptions() {
|
||||||
|
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
|
||||||
|
return builder.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE)
|
||||||
|
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE)
|
||||||
|
.put(DartClientCodegen.BROWSER_CLIENT, BROWSER_CLIENT_VALUE)
|
||||||
|
.put(DartClientCodegen.PUB_NAME, PUB_NAME_VALUE)
|
||||||
|
.put(DartClientCodegen.PUB_VERSION, PUB_VERSION_VALUE)
|
||||||
|
.put(DartClientCodegen.PUB_DESCRIPTION, PUB_DESCRIPTION_VALUE)
|
||||||
|
.put(CodegenConstants.SOURCE_FOLDER, SOURCE_FOLDER_VALUE)
|
||||||
|
.put(DartClientCodegen.USE_ENUM_EXTENSION, USE_ENUM_EXTENSION)
|
||||||
|
.put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE)
|
||||||
|
.put(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS, PREPEND_FORM_OR_BODY_PARAMETERS_VALUE)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isServer() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user