[dart] Improve types & imports (#9167)

* [dart] Improve types & imports

* don't use importMapping as it is intended for something different that is not possible in dart
* introduce imports map for dart specific features
* always import `dart:core`
* get rid of additionalReservedWords
* fix `--type-mappings` not working
* use required type mappings in samples
* no longer define additional reserved words  as it is impossible to list all anyways, they can now be configured via type-mapping parameter
* simplify dio imports

* Don't use guava for map instantiation

* Update docs
This commit is contained in:
Peter Leibiger 2021-04-06 18:33:35 +02:00 committed by GitHub
parent acedd1cfba
commit 065c0281fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
79 changed files with 241 additions and 222 deletions

View File

@ -2,5 +2,9 @@ generatorName: dart-dio-next
outputDir: samples/openapi3/client/petstore/dart-dio-next/petstore_client_lib_fake
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/dart/libraries/dio
typeMappings:
Client: "ModelClient"
File: "ModelFile"
EnumClass: "ModelEnumClass"
additionalProperties:
hideGenerationTimestamp: "true"

View File

@ -2,5 +2,9 @@ generatorName: dart-dio
outputDir: samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/dart-dio
typeMappings:
Client: "ModelClient"
File: "ModelFile"
EnumClass: "ModelEnumClass"
additionalProperties:
hideGenerationTimestamp: "true"

View File

@ -2,5 +2,8 @@ generatorName: dart
outputDir: samples/openapi3/client/petstore/dart2/petstore_client_lib_fake
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/dart2
typeMappings:
Client: "ModelClient"
File: "ModelFile"
additionalProperties:
hideGenerationTimestamp: "true"

View File

@ -2,6 +2,9 @@ generatorName: dart
outputDir: samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/dart2
typeMappings:
Client: "ModelClient"
File: "ModelFile"
additionalProperties:
hideGenerationTimestamp: "true"
serializationLibrary: json_serializable

View File

@ -44,7 +44,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>String</li>
<li>bool</li>
<li>double</li>
<li>dynamic</li>
<li>int</li>
<li>num</li>
</ul>

View File

@ -30,11 +30,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
| Type/Alias | Imports |
| ---------- | ------- |
|BuiltList|package:built_collection/built_collection.dart|
|BuiltMap|package:built_collection/built_collection.dart|
|BuiltSet|package:built_collection/built_collection.dart|
|JsonObject|package:built_value/json_object.dart|
|Uint8List|dart:typed_data|
## INSTANTIATION TYPES
@ -49,7 +44,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>String</li>
<li>bool</li>
<li>double</li>
<li>dynamic</li>
<li>int</li>
<li>num</li>
</ul>

View File

@ -44,7 +44,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>String</li>
<li>bool</li>
<li>double</li>
<li>dynamic</li>
<li>int</li>
<li>num</li>
</ul>

View File

@ -43,7 +43,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>String</li>
<li>bool</li>
<li>double</li>
<li>dynamic</li>
<li>int</li>
<li>num</li>
</ul>

View File

@ -1,6 +1,7 @@
package org.openapitools.codegen.languages;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.media.ArraySchema;
@ -51,9 +52,7 @@ public abstract class AbstractDartCodegen extends DefaultCodegen {
protected String apiTestPath = "test" + File.separator;
protected String modelTestPath = "test" + File.separator;
// Names that must not be used as model names because they clash with existing
// default imports (dart:io, dart:async, package:http etc.) but are not basic dataTypes.
protected Set<String> additionalReservedWords;
protected Map<String, String> imports = new HashMap<>();
public AbstractDartCodegen() {
super();
@ -112,13 +111,13 @@ public abstract class AbstractDartCodegen extends DefaultCodegen {
}
setReservedWordsLowerCase(reservedWordsList);
// These types return isPrimitive=true in templates
languageSpecificPrimitives = Sets.newHashSet(
"String",
"bool",
"int",
"num",
"double",
"dynamic"
"double"
);
typeMapping = new HashMap<>();
@ -149,29 +148,31 @@ public abstract class AbstractDartCodegen extends DefaultCodegen {
typeMapping.put("object", "Object");
typeMapping.put("AnyType", "Object");
// DataTypes of the above values which are automatically imported.
// They are also not allowed to be model names.
// Data types of the above values which are automatically imported
defaultIncludes = Sets.newHashSet(
"String",
"bool",
"int",
"num",
"double",
"dynamic",
"List",
"Set",
"Map",
"DateTime",
"Object",
"MultipartFile"
"Object"
);
additionalReservedWords = Sets.newHashSet(
"File",
"Client",
"Future",
"Response"
);
imports.put("String", "dart:core");
imports.put("bool", "dart:core");
imports.put("int", "dart:core");
imports.put("num", "dart:core");
imports.put("double", "dart:core");
imports.put("List", "dart:core");
imports.put("Set", "dart:core");
imports.put("Map", "dart:core");
imports.put("DateTime", "dart:core");
imports.put("Object", "dart:core");
imports.put("MultipartFile", "package:http/http.dart");
cliOptions.add(new CliOption(PUB_LIBRARY, "Library name in generated code"));
cliOptions.add(new CliOption(PUB_NAME, "Name in generated pubspec"));
@ -182,7 +183,6 @@ public abstract class AbstractDartCodegen extends DefaultCodegen {
cliOptions.add(new CliOption(PUB_HOMEPAGE, "Homepage 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
@ -279,13 +279,17 @@ public abstract class AbstractDartCodegen extends DefaultCodegen {
}
}
@Override
protected boolean needToImport(String type) {
// Import everything, unless it is from dart:core.
return StringUtils.isNotBlank(type) && (!imports.containsKey(type) || !imports.get(type).equals("dart:core"));
}
@Override
protected boolean isReservedWord(String word) {
// consider everything as reserved that is either a keyword,
// a default included type, or a type include through some library
return super.isReservedWord(word) ||
defaultIncludes().contains(word) ||
additionalReservedWords.contains(word);
return super.isReservedWord(word) || defaultIncludes().contains(word);
}
@Override
@ -367,20 +371,34 @@ public abstract class AbstractDartCodegen extends DefaultCodegen {
@Override
public String toModelName(final String name) {
String nameWithPrefixSuffix = sanitizeName(name);
String sanitizedName = sanitizeName(name);
if (!StringUtils.isEmpty(modelNamePrefix)) {
// add '_' so that model name can be camelized correctly
nameWithPrefixSuffix = modelNamePrefix + "_" + nameWithPrefixSuffix;
sanitizedName = modelNamePrefix + "_" + sanitizedName;
}
if (!StringUtils.isEmpty(modelNameSuffix)) {
// add '_' so that model name can be camelized correctly
nameWithPrefixSuffix = nameWithPrefixSuffix + "_" + modelNameSuffix;
sanitizedName = sanitizedName + "_" + modelNameSuffix;
}
// camelize the model name
// phone_number => PhoneNumber
final String camelizedName = camelize(nameWithPrefixSuffix);
final String camelizedName = camelize(sanitizedName);
// Check if there is a mapping that can be used
if (typeMapping().containsKey(camelizedName)) {
String typeName = typeMapping().get(camelizedName);
if (imports.containsKey(typeName)) {
// Anything with an import mapping is likely
// generator specific and can not be used as model name.
final String modelName = "Model" + camelizedName;
LOGGER.warn("{} (existing type) cannot be used as model name. Renamed to {}", camelizedName, modelName);
return modelName;
}
return typeName;
}
// model name cannot use reserved keyword, e.g. return
if (isReservedWord(camelizedName)) {
@ -473,11 +491,8 @@ public abstract class AbstractDartCodegen extends DefaultCodegen {
if (openAPIType == null) {
LOGGER.error("No Type defined for Schema {}", p);
}
if (typeMapping.containsKey(openAPIType)) {
return typeMapping.get(openAPIType);
}
if (languageSpecificPrimitives.contains(openAPIType)) {
return openAPIType;
if (typeMapping().containsKey(openAPIType)) {
return typeMapping().get(openAPIType);
}
return toModelName(openAPIType);
}
@ -607,8 +622,9 @@ public abstract class AbstractDartCodegen extends DefaultCodegen {
// operationId starts with a number
if (operationId.matches("^\\d.*")) {
LOGGER.warn("{} (starting with a number) cannot be used as method name. Renamed to {}", operationId, camelize("call_" + operationId), true);
operationId = camelize("call_" + operationId, true);
String newOperationId = camelize("call_" + operationId, true);
LOGGER.warn("{} (starting with a number) cannot be used as method name. Renamed to {}", operationId, newOperationId);
operationId = newOperationId;
}
return operationId;

View File

@ -37,20 +37,6 @@ public class DartClientCodegen extends AbstractDartCodegen {
public DartClientCodegen() {
super();
additionalReservedWords.addAll(
Sets.newHashSet(
"StreamedRequest",
"ApiClient",
"QueryParam",
"Authentication",
"HttpBasicAuth",
"HttpBearerAuth",
"ApiKeyAuth",
"OAuth"
)
);
final CliOption serializationLibrary = CliOption.newString(CodegenConstants.SERIALIZATION_LIBRARY,
"Specify serialization library");
serializationLibrary.setDefault(SERIALIZATION_LIBRARY_NATIVE);

View File

@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
import static org.openapitools.codegen.utils.StringUtils.underscore;
@ -77,22 +78,11 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
typeMapping.put("object", "JsonObject");
typeMapping.put("AnyType", "JsonObject");
additionalReservedWords.addAll(Sets.newHashSet(
"EnumClass",
// The following are reserved dataTypes but can not be added to defaultIncludes
// as this would prevent them from being added to the imports.
"BuiltList",
"BuiltSet",
"BuiltMap",
"Uint8List",
"JsonObject"
));
importMapping.put("BuiltList", "package:built_collection/built_collection.dart");
importMapping.put("BuiltSet", "package:built_collection/built_collection.dart");
importMapping.put("BuiltMap", "package:built_collection/built_collection.dart");
importMapping.put("JsonObject", "package:built_value/json_object.dart");
importMapping.put("Uint8List", "dart:typed_data");
imports.put("BuiltList", "package:built_collection/built_collection.dart");
imports.put("BuiltSet", "package:built_collection/built_collection.dart");
imports.put("BuiltMap", "package:built_collection/built_collection.dart");
imports.put("JsonObject", "package:built_value/json_object.dart");
imports.put("Uint8List", "dart:typed_data");
}
public String getDateLibrary() {
@ -210,9 +200,8 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
typeMapping.put("Date", "OffsetDate");
typeMapping.put("DateTime", "OffsetDateTime");
typeMapping.put("datetime", "OffsetDateTime");
additionalReservedWords.addAll(Sets.newHashSet("OffsetDate", "OffsetDateTime"));
importMapping.put("OffsetDate", "package:time_machine/time_machine.dart");
importMapping.put("OffsetDateTime", "package:time_machine/time_machine.dart");
imports.put("OffsetDate", "package:time_machine/time_machine.dart");
imports.put("OffsetDateTime", "package:time_machine/time_machine.dart");
supportingFiles.add(new SupportingFile("local_date_serializer.mustache", libFolder, "local_date_serializer.dart"));
}
}
@ -225,21 +214,9 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
for (Object _mo : models) {
Map<String, Object> mo = (Map<String, Object>) _mo;
Set<String> modelImports = new HashSet<>();
CodegenModel cm = (CodegenModel) mo.get("model");
for (String modelImport : cm.imports) {
if (needToImport(modelImport)) {
if (importMapping().containsKey(modelImport)) {
modelImports.add(importMapping().get(modelImport));
} else {
modelImports.add("package:" + pubName + "/model/" + underscore(modelImport) + ".dart");
}
}
}
cm.imports = modelImports;
boolean hasVars = cm.vars.size() > 0;
cm.vendorExtensions.put("x-has-vars", hasVars);
cm.imports = rewriteImports(cm.imports);
cm.vendorExtensions.put("x-has-vars", !cm.vars.isEmpty());
}
return objs;
}
@ -292,8 +269,7 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
Set<Map<String, Object>> serializers = new HashSet<>();
Set<String> modelImports = new HashSet<>();
Set<String> fullImports = new HashSet<>();
Set<String> resultImports = new HashSet<>();
for (CodegenOperation op : operationList) {
op.httpMethod = op.httpMethod.toLowerCase(Locale.ROOT);
@ -331,23 +307,11 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
op.vendorExtensions.put("x-is-form", isForm);
op.vendorExtensions.put("x-is-multipart", isMultipart);
resultImports.addAll(rewriteImports(op.imports));
if (op.getHasFormParams()) {
fullImports.add("package:" + pubName + "/api_util.dart");
resultImports.add("package:" + pubName + "/api_util.dart");
}
Set<String> imports = new HashSet<>();
for (String item : op.imports) {
if (needToImport(item)) {
if (importMapping().containsKey(item)) {
fullImports.add(importMapping().get(item));
} else {
imports.add(underscore(item));
}
}
}
modelImports.addAll(imports);
op.imports = imports;
if (op.returnContainer != null) {
final Map<String, Object> serializer = new HashMap<>();
serializer.put("isArray", Objects.equals("array", op.returnContainer) || Objects.equals("set", op.returnContainer));
@ -358,11 +322,21 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
}
}
objs.put("modelImports", modelImports);
objs.put("fullImports", fullImports);
objs.put("imports", resultImports.stream().sorted().collect(Collectors.toList()));
objs.put("serializers", serializers);
return objs;
}
private Set<String> rewriteImports(Set<String> originalImports) {
Set<String> resultImports = Sets.newHashSet();
for (String modelImport : originalImports) {
if (imports.containsKey(modelImport)) {
resultImports.add(imports.get(modelImport));
} else {
resultImports.add("package:" + pubName + "/model/" + underscore(modelImport) + ".dart");
}
}
return resultImports;
}
}

View File

@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
import static org.openapitools.codegen.utils.StringUtils.underscore;
@ -186,22 +187,11 @@ public class DartDioNextClientCodegen extends AbstractDartCodegen {
typeMapping.put("object", "JsonObject");
typeMapping.put("AnyType", "JsonObject");
additionalReservedWords.addAll(Sets.newHashSet(
"EnumClass",
// The following are reserved dataTypes but can not be added to defaultIncludes
// as this would prevent them from being added to the imports.
"BuiltList",
"BuiltSet",
"BuiltMap",
"Uint8List",
"JsonObject"
));
importMapping.put("BuiltList", "package:built_collection/built_collection.dart");
importMapping.put("BuiltSet", "package:built_collection/built_collection.dart");
importMapping.put("BuiltMap", "package:built_collection/built_collection.dart");
importMapping.put("JsonObject", "package:built_value/json_object.dart");
importMapping.put("Uint8List", "dart:typed_data");
imports.put("BuiltList", "package:built_collection/built_collection.dart");
imports.put("BuiltSet", "package:built_collection/built_collection.dart");
imports.put("BuiltMap", "package:built_collection/built_collection.dart");
imports.put("JsonObject", "package:built_value/json_object.dart");
imports.put("Uint8List", "dart:typed_data");
}
private void configureDateLibrary(String srcFolder) {
@ -212,9 +202,8 @@ public class DartDioNextClientCodegen extends AbstractDartCodegen {
typeMapping.put("Date", "OffsetDate");
typeMapping.put("DateTime", "OffsetDateTime");
typeMapping.put("datetime", "OffsetDateTime");
additionalReservedWords.addAll(Sets.newHashSet("OffsetDate", "OffsetDateTime"));
importMapping.put("OffsetDate", "package:time_machine/time_machine.dart");
importMapping.put("OffsetDateTime", "package:time_machine/time_machine.dart");
imports.put("OffsetDate", "package:time_machine/time_machine.dart");
imports.put("OffsetDateTime", "package:time_machine/time_machine.dart");
if (SERIALIZATION_LIBRARY_BUILT_VALUE.equals(library)) {
supportingFiles.add(new SupportingFile("serialization/built_value/local_date_serializer.mustache", srcFolder, "local_date_serializer.dart"));
}
@ -261,21 +250,9 @@ public class DartDioNextClientCodegen extends AbstractDartCodegen {
for (Object _mo : models) {
Map<String, Object> mo = (Map<String, Object>) _mo;
Set<String> modelImports = new HashSet<>();
CodegenModel cm = (CodegenModel) mo.get("model");
for (String modelImport : cm.imports) {
if (needToImport(modelImport)) {
if (importMapping().containsKey(modelImport)) {
modelImports.add(importMapping().get(modelImport));
} else {
modelImports.add("package:" + pubName + "/src/model/" + underscore(modelImport) + ".dart");
}
}
}
cm.imports = modelImports;
boolean hasVars = cm.vars.size() > 0;
cm.vendorExtensions.put("x-has-vars", hasVars);
cm.imports = rewriteImports(cm.imports);
cm.vendorExtensions.put("x-has-vars", !cm.vars.isEmpty());
}
return objs;
}
@ -319,6 +296,7 @@ public class DartDioNextClientCodegen extends AbstractDartCodegen {
sb.append(")]");
}
@Override
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
objs = super.postProcessOperationsWithModels(objs, allModels);
@ -326,8 +304,7 @@ public class DartDioNextClientCodegen extends AbstractDartCodegen {
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
Set<Map<String, Object>> serializers = new HashSet<>();
Set<String> modelImports = new HashSet<>();
Set<String> fullImports = new HashSet<>();
Set<String> resultImports = new HashSet<>();
for (CodegenOperation op : operationList) {
op.httpMethod = op.httpMethod.toLowerCase(Locale.ROOT);
@ -365,23 +342,11 @@ public class DartDioNextClientCodegen extends AbstractDartCodegen {
op.vendorExtensions.put("x-is-form", isForm);
op.vendorExtensions.put("x-is-multipart", isMultipart);
resultImports.addAll(rewriteImports(op.imports));
if (op.getHasFormParams()) {
fullImports.add("package:" + pubName + "/src/api_util.dart");
resultImports.add("package:" + pubName + "/src/api_util.dart");
}
Set<String> imports = new HashSet<>();
for (String item : op.imports) {
if (needToImport(item)) {
if (importMapping().containsKey(item)) {
fullImports.add(importMapping().get(item));
} else {
imports.add(underscore(item));
}
}
}
modelImports.addAll(imports);
op.imports = imports;
if (op.returnContainer != null) {
final Map<String, Object> serializer = new HashMap<>();
serializer.put("isArray", Objects.equals("array", op.returnContainer) || Objects.equals("set", op.returnContainer));
@ -392,11 +357,21 @@ public class DartDioNextClientCodegen extends AbstractDartCodegen {
}
}
objs.put("modelImports", modelImports);
objs.put("fullImports", fullImports);
objs.put("imports", resultImports.stream().sorted().collect(Collectors.toList()));
objs.put("serializers", serializers);
return objs;
}
private Set<String> rewriteImports(Set<String> originalImports) {
Set<String> resultImports = Sets.newHashSet();
for (String modelImport : originalImports) {
if (imports.containsKey(modelImport)) {
resultImports.add(imports.get(modelImport));
} else {
resultImports.add("package:" + pubName + "/src/model/" + underscore(modelImport) + ".dart");
}
}
return resultImports;
}
}

View File

@ -4,10 +4,8 @@ import 'package:dio/dio.dart';
import 'package:built_value/serializer.dart';
{{#operations}}
{{#modelImports}}import 'package:{{pubName}}/model/{{.}}.dart';
{{/modelImports}}
{{#fullImports}}import '{{.}}';
{{/fullImports}}
{{#imports}}import '{{.}}';
{{/imports}}
class {{classname}} {

View File

@ -5,10 +5,8 @@ import 'dart:async';
import 'package:dio/dio.dart';
{{#operations}}
{{#modelImports}}import 'package:{{pubName}}/src/model/{{.}}.dart';
{{/modelImports}}
{{#fullImports}}import '{{.}}';
{{/fullImports}}
{{#imports}}import '{{.}}';
{{/imports}}
class {{classname}} {

View File

@ -337,8 +337,8 @@ public class DartModelTest {
{"sample name", "SampleName"},
{"List", "ModelList"},
{"list", "ModelList"},
{"File", "ModelFile"},
{"Client", "ModelClient"},
{"File", "TestModelFile"},
{"Client", "TestModelClient"},
{"String", "ModelString"},
};
}
@ -349,6 +349,8 @@ public class DartModelTest {
final Schema model = new Schema();
final DefaultCodegen codegen = new DartClientCodegen();
codegen.setOpenAPI(openAPI);
codegen.typeMapping().put("File", "TestModelFile");
codegen.typeMapping().put("Client", "TestModelClient");
final CodegenModel cm = codegen.fromModel(name, model);
Assert.assertEquals(cm.name, name);

View File

@ -380,10 +380,8 @@ public class DartDioModelTest {
@DataProvider(name = "modelNames")
public static Object[][] modelNames() {
return new Object[][] {
{"EnumClass", "ModelEnumClass"},
{"JsonObject", "ModelJsonObject"},
// OffsetDate is valid without timemachine date library
{"OffsetDate", "OffsetDate"},
{"EnumClass", "TestModelEnumClass"},
{"JsonObject", "TestModelJsonObject"}
};
}
@ -393,6 +391,8 @@ public class DartDioModelTest {
final Schema model = new Schema();
final DartDioClientCodegen codegen = new DartDioClientCodegen();
codegen.setOpenAPI(openAPI);
codegen.typeMapping().put("EnumClass", "TestModelEnumClass");
codegen.typeMapping().put("JsonObject", "TestModelJsonObject");
final CodegenModel cm = codegen.fromModel(name, model);
Assert.assertEquals(cm.name, name);
@ -402,10 +402,9 @@ public class DartDioModelTest {
@DataProvider(name = "modelNamesTimemachine")
public static Object[][] modelNamesTimemachine() {
return new Object[][] {
{"EnumClass", "ModelEnumClass"},
{"JsonObject", "ModelJsonObject"},
// OffsetDate is not valid with timemachine date library
{"OffsetDate", "ModelOffsetDate"},
{"EnumClass", "TestModelEnumClass"},
{"JsonObject", "TestModelJsonObject"},
{"OffsetDate", "TestModelOffsetDate"},
};
}
@ -416,6 +415,9 @@ public class DartDioModelTest {
final DartDioClientCodegen codegen = new DartDioClientCodegen();
codegen.setDateLibrary("timemachine");
codegen.processOpts();
codegen.typeMapping().put("EnumClass", "TestModelEnumClass");
codegen.typeMapping().put("JsonObject", "TestModelJsonObject");
codegen.typeMapping().put("OffsetDate", "TestModelOffsetDate");
codegen.setOpenAPI(openAPI);
final CodegenModel cm = codegen.fromModel(name, model);

View File

@ -390,10 +390,8 @@ public class DartDioNextModelTest {
@DataProvider(name = "modelNames")
public static Object[][] modelNames() {
return new Object[][] {
{"EnumClass", "ModelEnumClass"},
{"JsonObject", "ModelJsonObject"},
// OffsetDate is valid without timemachine date library
{"OffsetDate", "OffsetDate"},
{"EnumClass", "TestModelEnumClass"},
{"JsonObject", "TestModelJsonObject"},
};
}
@ -405,7 +403,8 @@ public class DartDioNextModelTest {
final DefaultCodegen codegen = new DartDioNextClientCodegen();
codegen.additionalProperties().put(CodegenConstants.SERIALIZATION_LIBRARY, DartDioNextClientCodegen.SERIALIZATION_LIBRARY_BUILT_VALUE);
codegen.processOpts();
codegen.typeMapping().put("EnumClass", "TestModelEnumClass");
codegen.typeMapping().put("JsonObject", "TestModelJsonObject");
codegen.setOpenAPI(openAPI);
final CodegenModel cm = codegen.fromModel(name, model);
@ -417,10 +416,9 @@ public class DartDioNextModelTest {
@DataProvider(name = "modelNamesTimemachine")
public static Object[][] modelNamesTimemachine() {
return new Object[][] {
{"EnumClass", "ModelEnumClass"},
{"JsonObject", "ModelJsonObject"},
// OffsetDate is not valid with timemachine date library
{"OffsetDate", "ModelOffsetDate"},
{"EnumClass", "TestModelEnumClass"},
{"JsonObject", "TestModelJsonObject"},
{"OffsetDate", "TestModelOffsetDate"},
};
}
@ -431,7 +429,11 @@ public class DartDioNextModelTest {
final DartDioNextClientCodegen codegen = new DartDioNextClientCodegen();
codegen.additionalProperties().put(DartDioNextClientCodegen.DATE_LIBRARY, DartDioNextClientCodegen.DATE_LIBRARY_TIME_MACHINE);
codegen.processOpts();
codegen.typeMapping().put("EnumClass", "TestModelEnumClass");
codegen.typeMapping().put("JsonObject", "TestModelJsonObject");
codegen.typeMapping().put("OffsetDate", "TestModelOffsetDate");
codegen.setOpenAPI(openAPI);
final CodegenModel cm = codegen.fromModel(name, model);
Assert.assertEquals(cm.name, name);

View File

@ -7,16 +7,16 @@ import 'dart:async';
import 'package:built_value/serializer.dart';
import 'package:dio/dio.dart';
import 'package:openapi/src/model/file_schema_test_class.dart';
import 'package:openapi/src/model/outer_composite.dart';
import 'package:openapi/src/model/outer_object_with_enum_property.dart';
import 'package:openapi/src/model/user.dart';
import 'package:openapi/src/model/health_check_result.dart';
import 'package:openapi/src/model/pet.dart';
import 'package:openapi/src/model/model_client.dart';
import 'package:openapi/src/api_util.dart';
import 'dart:typed_data';
import 'package:built_collection/built_collection.dart';
import 'package:openapi/src/api_util.dart';
import 'package:openapi/src/model/file_schema_test_class.dart';
import 'package:openapi/src/model/health_check_result.dart';
import 'package:openapi/src/model/model_client.dart';
import 'package:openapi/src/model/outer_composite.dart';
import 'package:openapi/src/model/outer_object_with_enum_property.dart';
import 'package:openapi/src/model/pet.dart';
import 'package:openapi/src/model/user.dart';
class FakeApi {

View File

@ -7,11 +7,11 @@ import 'dart:async';
import 'package:built_value/serializer.dart';
import 'package:dio/dio.dart';
import 'package:openapi/src/model/pet.dart';
import 'package:openapi/src/model/api_response.dart';
import 'package:openapi/src/api_util.dart';
import 'dart:typed_data';
import 'package:built_collection/built_collection.dart';
import 'package:openapi/src/api_util.dart';
import 'package:openapi/src/model/api_response.dart';
import 'package:openapi/src/model/pet.dart';
class PetApi {

View File

@ -7,8 +7,8 @@ import 'dart:async';
import 'package:built_value/serializer.dart';
import 'package:dio/dio.dart';
import 'package:openapi/src/model/order.dart';
import 'package:built_collection/built_collection.dart';
import 'package:openapi/src/model/order.dart';
class StoreApi {

View File

@ -7,8 +7,8 @@ import 'dart:async';
import 'package:built_value/serializer.dart';
import 'package:dio/dio.dart';
import 'package:openapi/src/model/user.dart';
import 'package:built_collection/built_collection.dart';
import 'package:openapi/src/model/user.dart';
class UserApi {

View File

@ -16,5 +16,6 @@ void main() {
test('to test the property `mapOfMapProperty`', () async {
// TODO
});
});
}

View File

@ -16,5 +16,6 @@ void main() {
test('to test the property `color`', () async {
// TODO
});
});
}

View File

@ -1,6 +1,7 @@
import 'package:test/test.dart';
import 'package:openapi/openapi.dart';
/// tests for AnotherFakeApi
void main() {
final instance = Openapi().getAnotherFakeApi();
@ -14,5 +15,6 @@ void main() {
test('test call123testSpecialTags', () async {
// TODO
});
});
}

View File

@ -21,5 +21,6 @@ void main() {
test('to test the property `message`', () async {
// TODO
});
});
}

View File

@ -11,5 +11,6 @@ void main() {
test('to test the property `arrayArrayNumber`', () async {
// TODO
});
});
}

View File

@ -11,5 +11,6 @@ void main() {
test('to test the property `arrayNumber`', () async {
// TODO
});
});
}

View File

@ -21,5 +21,6 @@ void main() {
test('to test the property `arrayArrayOfModel`', () async {
// TODO
});
});
}

View File

@ -32,10 +32,11 @@ void main() {
// TODO
});
// Name of the pet
// Name of the pet
// String ATT_NAME
test('to test the property `ATT_NAME`', () async {
// TODO
});
});
}

View File

@ -11,5 +11,6 @@ void main() {
test('to test the property `declawed`', () async {
// TODO
});
});
}

View File

@ -21,5 +21,6 @@ void main() {
test('to test the property `declawed`', () async {
// TODO
});
});
}

View File

@ -16,5 +16,6 @@ void main() {
test('to test the property `name`', () async {
// TODO
});
});
}

View File

@ -11,5 +11,6 @@ void main() {
test('to test the property `class_`', () async {
// TODO
});
});
}

View File

@ -1,6 +1,7 @@
import 'package:test/test.dart';
import 'package:openapi/openapi.dart';
/// tests for DefaultApi
void main() {
final instance = Openapi().getDefaultApi();
@ -10,5 +11,6 @@ void main() {
test('test fooGet', () async {
// TODO
});
});
}

View File

@ -11,5 +11,6 @@ void main() {
test('to test the property `breed`', () async {
// TODO
});
});
}

View File

@ -21,5 +21,6 @@ void main() {
test('to test the property `breed`', () async {
// TODO
});
});
}

View File

@ -16,5 +16,6 @@ void main() {
test('to test the property `arrayEnum`', () async {
// TODO
});
});
}

View File

@ -46,5 +46,6 @@ void main() {
test('to test the property `outerEnumIntegerDefaultValue`', () async {
// TODO
});
});
}

View File

@ -1,6 +1,7 @@
import 'package:test/test.dart';
import 'package:openapi/openapi.dart';
/// tests for FakeApi
void main() {
final instance = Openapi().getFakeApi();
@ -76,9 +77,9 @@ void main() {
// TODO
});
// Fake endpoint for testing various parameters
// Fake endpoint for testing various parameters
//
// Fake endpoint for testing various parameters
// Fake endpoint for testing various parameters
//
//Future testEndpointParameters(num number, double double_, String patternWithoutDelimiter, String byte, { int integer, int int32, int int64, double float, String string, Uint8List binary, DateTime date, DateTime dateTime, String password, String callback }) async
test('test testEndpointParameters', () async {
@ -123,5 +124,6 @@ void main() {
test('test testQueryParameterCollectionFormat', () async {
// TODO
});
});
}

View File

@ -1,6 +1,7 @@
import 'package:test/test.dart';
import 'package:openapi/openapi.dart';
/// tests for FakeClassnameTags123Api
void main() {
final instance = Openapi().getFakeClassnameTags123Api();
@ -14,5 +15,6 @@ void main() {
test('test testClassname', () async {
// TODO
});
});
}

View File

@ -16,5 +16,6 @@ void main() {
test('to test the property `files`', () async {
// TODO
});
});
}

View File

@ -11,5 +11,6 @@ void main() {
test('to test the property `bar`', () async {
// TODO
});
});
}

View File

@ -88,5 +88,6 @@ void main() {
test('to test the property `patternWithDigitsAndDelimiter`', () async {
// TODO
});
});
}

View File

@ -16,5 +16,6 @@ void main() {
test('to test the property `foo`', () async {
// TODO
});
});
}

View File

@ -11,5 +11,6 @@ void main() {
test('to test the property `nullableMessage`', () async {
// TODO
});
});
}

View File

@ -11,5 +11,6 @@ void main() {
test('to test the property `string`', () async {
// TODO
});
});
}

View File

@ -26,5 +26,6 @@ void main() {
test('to test the property `indirectMap`', () async {
// TODO
});
});
}

View File

@ -21,5 +21,6 @@ void main() {
test('to test the property `map`', () async {
// TODO
});
});
}

View File

@ -16,5 +16,6 @@ void main() {
test('to test the property `class_`', () async {
// TODO
});
});
}

View File

@ -11,5 +11,6 @@ void main() {
test('to test the property `client`', () async {
// TODO
});
});
}

View File

@ -3,5 +3,7 @@ import 'package:openapi/openapi.dart';
// tests for ModelEnumClass
void main() {
group(ModelEnumClass, () {});
group(ModelEnumClass, () {
});
}

View File

@ -12,5 +12,6 @@ void main() {
test('to test the property `sourceURI`', () async {
// TODO
});
});
}

View File

@ -11,5 +11,6 @@ void main() {
test('to test the property `n123list`', () async {
// TODO
});
});
}

View File

@ -11,5 +11,6 @@ void main() {
test('to test the property `return_`', () async {
// TODO
});
});
}

View File

@ -26,5 +26,6 @@ void main() {
test('to test the property `n123number`', () async {
// TODO
});
});
}

View File

@ -66,5 +66,6 @@ void main() {
test('to test the property `objectItemsNullable`', () async {
// TODO
});
});
}

View File

@ -11,5 +11,6 @@ void main() {
test('to test the property `justNumber`', () async {
// TODO
});
});
}

View File

@ -37,5 +37,6 @@ void main() {
test('to test the property `complete`', () async {
// TODO
});
});
}

View File

@ -21,5 +21,6 @@ void main() {
test('to test the property `myBoolean`', () async {
// TODO
});
});
}

View File

@ -3,5 +3,7 @@ import 'package:openapi/openapi.dart';
// tests for OuterEnumDefaultValue
void main() {
group(OuterEnumDefaultValue, () {});
group(OuterEnumDefaultValue, () {
});
}

View File

@ -3,5 +3,7 @@ import 'package:openapi/openapi.dart';
// tests for OuterEnumIntegerDefaultValue
void main() {
group(OuterEnumIntegerDefaultValue, () {});
group(OuterEnumIntegerDefaultValue, () {
});
}

View File

@ -3,5 +3,7 @@ import 'package:openapi/openapi.dart';
// tests for OuterEnumInteger
void main() {
group(OuterEnumInteger, () {});
group(OuterEnumInteger, () {
});
}

View File

@ -3,5 +3,7 @@ import 'package:openapi/openapi.dart';
// tests for OuterEnum
void main() {
group(OuterEnum, () {});
group(OuterEnum, () {
});
}

View File

@ -11,5 +11,6 @@ void main() {
test('to test the property `value`', () async {
// TODO
});
});
}

View File

@ -1,6 +1,7 @@
import 'package:test/test.dart';
import 'package:openapi/openapi.dart';
/// tests for PetApi
void main() {
final instance = Openapi().getPetApi();
@ -74,5 +75,6 @@ void main() {
test('test uploadFileWithRequiredFile', () async {
// TODO
});
});
}

View File

@ -37,5 +37,6 @@ void main() {
test('to test the property `status`', () async {
// TODO
});
});
}

View File

@ -16,5 +16,6 @@ void main() {
test('to test the property `baz`', () async {
// TODO
});
});
}

View File

@ -8,10 +8,9 @@ void main() {
group(SpecialModelName, () {
// int dollarSpecialLeftSquareBracketPropertyPeriodNameRightSquareBracket
test(
'to test the property `dollarSpecialLeftSquareBracketPropertyPeriodNameRightSquareBracket`',
() async {
test('to test the property `dollarSpecialLeftSquareBracketPropertyPeriodNameRightSquareBracket`', () async {
// TODO
});
});
}

View File

@ -1,6 +1,7 @@
import 'package:test/test.dart';
import 'package:openapi/openapi.dart';
/// tests for StoreApi
void main() {
final instance = Openapi().getStoreApi();
@ -39,5 +40,6 @@ void main() {
test('test placeOrder', () async {
// TODO
});
});
}

View File

@ -16,5 +16,6 @@ void main() {
test('to test the property `name`', () async {
// TODO
});
});
}

View File

@ -1,6 +1,7 @@
import 'package:test/test.dart';
import 'package:openapi/openapi.dart';
/// tests for UserApi
void main() {
final instance = Openapi().getUserApi();
@ -67,5 +68,6 @@ void main() {
test('test updateUser', () async {
// TODO
});
});
}

View File

@ -47,5 +47,6 @@ void main() {
test('to test the property `userStatus`', () async {
// TODO
});
});
}

View File

@ -9,11 +9,11 @@ import 'dart:async';
import 'package:dio/dio.dart';
import 'package:built_value/serializer.dart';
import 'package:openapi/model/pet.dart';
import 'package:openapi/model/api_response.dart';
import 'dart:typed_data';
import 'package:built_collection/built_collection.dart';
import 'package:openapi/api_util.dart';
import 'package:openapi/model/api_response.dart';
import 'package:openapi/model/pet.dart';
class PetApi {

View File

@ -9,8 +9,8 @@ import 'dart:async';
import 'package:dio/dio.dart';
import 'package:built_value/serializer.dart';
import 'package:openapi/model/order.dart';
import 'package:built_collection/built_collection.dart';
import 'package:openapi/model/order.dart';
class StoreApi {

View File

@ -9,8 +9,8 @@ import 'dart:async';
import 'package:dio/dio.dart';
import 'package:built_value/serializer.dart';
import 'package:openapi/model/user.dart';
import 'package:built_collection/built_collection.dart';
import 'package:openapi/model/user.dart';
class UserApi {

View File

@ -9,16 +9,16 @@ import 'dart:async';
import 'package:dio/dio.dart';
import 'package:built_value/serializer.dart';
import 'package:openapi/model/file_schema_test_class.dart';
import 'package:openapi/model/outer_composite.dart';
import 'package:openapi/model/outer_object_with_enum_property.dart';
import 'package:openapi/model/user.dart';
import 'package:openapi/model/health_check_result.dart';
import 'package:openapi/model/pet.dart';
import 'package:openapi/model/model_client.dart';
import 'dart:typed_data';
import 'package:built_collection/built_collection.dart';
import 'package:openapi/api_util.dart';
import 'package:openapi/model/file_schema_test_class.dart';
import 'package:openapi/model/health_check_result.dart';
import 'package:openapi/model/model_client.dart';
import 'package:openapi/model/outer_composite.dart';
import 'package:openapi/model/outer_object_with_enum_property.dart';
import 'package:openapi/model/pet.dart';
import 'package:openapi/model/user.dart';
class FakeApi {

View File

@ -9,11 +9,11 @@ import 'dart:async';
import 'package:dio/dio.dart';
import 'package:built_value/serializer.dart';
import 'package:openapi/model/pet.dart';
import 'package:openapi/model/api_response.dart';
import 'dart:typed_data';
import 'package:built_collection/built_collection.dart';
import 'package:openapi/api_util.dart';
import 'package:openapi/model/api_response.dart';
import 'package:openapi/model/pet.dart';
class PetApi {

View File

@ -9,8 +9,8 @@ import 'dart:async';
import 'package:dio/dio.dart';
import 'package:built_value/serializer.dart';
import 'package:openapi/model/order.dart';
import 'package:built_collection/built_collection.dart';
import 'package:openapi/model/order.dart';
class StoreApi {

View File

@ -9,8 +9,8 @@ import 'dart:async';
import 'package:dio/dio.dart';
import 'package:built_value/serializer.dart';
import 'package:openapi/model/user.dart';
import 'package:built_collection/built_collection.dart';
import 'package:openapi/model/user.dart';
class UserApi {