From 0e4f4499ae3f1d8d7a89a7c978f6dd780fcfb541 Mon Sep 17 00:00:00 2001 From: Peter Leibiger Date: Wed, 9 Dec 2020 14:32:40 +0100 Subject: [PATCH] [dart] Fix and improve enumVar naming/generation * use same handling for all 3 generators * allow `updateEnumVarsWithExtensions` to have access to the data type * improve `x-enum-values` handling and add supprt for other enum vendor extensions * remove duplicate and outdated tests from `DartDioModelTest` * add more tests to `DartModelTest` * no longer force lowercase enums for plain dart generator (breaking) * this change also removes the trailing underscore from plain dart generator (breaking) --- .../openapitools/codegen/DefaultCodegen.java | 6 +- .../codegen/languages/DartClientCodegen.java | 91 +++-------- .../languages/DartDioClientCodegen.java | 16 -- .../languages/PythonClientCodegen.java | 2 +- .../src/main/resources/dart2/enum.mustache | 6 +- .../main/resources/dart2/enum_inline.mustache | 6 +- .../codegen/DefaultCodegenTest.java | 2 +- .../codegen/dart/DartModelTest.java | 142 ++++++++++++++++-- .../codegen/dartdio/DartDioModelTest.java | 40 +---- .../petstore/test/pet_faked_client_test.dart | 75 ++++----- .../dart2/petstore/test/pet_test.dart | 8 +- .../petstore_client_lib/lib/model/order.dart | 18 +-- .../petstore_client_lib/lib/model/pet.dart | 18 +-- .../lib/model/enum_arrays.dart | 4 +- .../lib/model/enum_test.dart | 8 +- .../lib/model/inline_object2.dart | 6 +- .../lib/model/map_test.dart | 2 +- .../lib/model/model_enum_class.dart | 2 +- .../lib/model/special_model_name.dart | 2 +- .../petstore/test/pet_faked_client_test.dart | 75 ++++----- .../dart2/petstore/test/pet_test.dart | 8 +- .../petstore_client_lib/lib/model/order.dart | 18 +-- .../petstore_client_lib/lib/model/pet.dart | 18 +-- .../lib/model/enum_arrays.dart | 24 +-- .../lib/model/enum_class.dart | 18 +-- .../lib/model/enum_test.dart | 48 +++--- .../lib/model/inline_object2.dart | 30 ++-- .../lib/model/map_test.dart | 12 +- .../lib/model/order.dart | 18 +-- .../lib/model/outer_enum.dart | 18 +-- .../lib/model/outer_enum_default_value.dart | 18 +-- .../lib/model/outer_enum_integer.dart | 18 +-- .../outer_enum_integer_default_value.dart | 18 +-- .../lib/model/pet.dart | 18 +-- 34 files changed, 411 insertions(+), 402 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index eabdd934cef5..f2d5b050d32d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -628,7 +628,7 @@ public Map postProcessModelsEnum(Map objs) { List values = (List) allowableValues.get("values"); List> enumVars = buildEnumVars(values, cm.dataType); // if "x-enum-varnames" or "x-enum-descriptions" defined, update varnames - updateEnumVarsWithExtensions(enumVars, cm.getVendorExtensions()); + updateEnumVarsWithExtensions(enumVars, cm.getVendorExtensions(), cm.dataType); cm.allowableValues.put("enumVars", enumVars); } @@ -5441,7 +5441,7 @@ public void updateCodegenPropertyEnum(CodegenProperty var) { if (referencedSchema.isPresent()) { extensions = referencedSchema.get().getExtensions(); } - updateEnumVarsWithExtensions(enumVars, extensions); + updateEnumVarsWithExtensions(enumVars, extensions, dataType); allowableValues.put("enumVars", enumVars); // handle default value for enum, e.g. available => StatusEnum.AVAILABLE @@ -5494,7 +5494,7 @@ protected List> buildEnumVars(List values, String da return enumVars; } - protected void updateEnumVarsWithExtensions(List> enumVars, Map vendorExtensions) { + protected void updateEnumVarsWithExtensions(List> enumVars, Map vendorExtensions, String dataType) { if (vendorExtensions != null) { updateEnumVarsWithExtensions(enumVars, vendorExtensions, "x-enum-varnames", "name"); updateEnumVarsWithExtensions(enumVars, vendorExtensions, "x-enum-descriptions", "enumDescription"); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java index 14fc8facec9b..b5a9e61b448d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java @@ -35,8 +35,6 @@ import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.CliOption; 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; @@ -354,6 +352,10 @@ public String modelDocFileFolder() { @Override public String toVarName(String name) { + return toVarName(name, "n"); + } + + private String toVarName(String name, String numberPrefix) { // replace - with _ e.g. created-at => created_at name = name.replace("-", "_"); @@ -378,7 +380,7 @@ public String toVarName(String name) { name = camelize(name, true); if (name.matches("^\\d.*")) { - name = "n" + name; + name = numberPrefix + name; } if (isReservedWord(name) || importMapping().containsKey(name)) { @@ -505,65 +507,27 @@ public Map postProcessModels(Map objs) { } @Override - public Map postProcessModelsEnum(Map objs) { - List models = (List) objs.get("models"); - for (Object _mo : models) { - Map mo = (Map) _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 allowableValues = cm.allowableValues; - List values = (List) allowableValues.get("values"); - List> enumVars = buildEnumVars(values, cm.dataType); - 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> values = (List>) extension; - List> enumVars = new ArrayList<>(); - for (Map value : values) { - Map enumVar = new HashMap<>(); - 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()); + protected void updateEnumVarsWithExtensions(List> enumVars, Map vendorExtensions, String dataType) { + if (vendorExtensions != null && useEnumExtension && vendorExtensions.containsKey("x-enum-values")) { + // Use the x-enum-values extension for this enum + // Existing enumVars added by the default handling need to be removed first + enumVars.clear(); + + Object extension = vendorExtensions.get("x-enum-values"); + List> values = (List>) extension; + for (Map value : values) { + Map enumVar = new HashMap<>(); + enumVar.put("name", toEnumVarName((String) value.get("identifier"), dataType)); + enumVar.put("value", toEnumValue(value.get("numericValue").toString(), dataType)); + enumVar.put("isString", isDataTypeString(dataType)); + if (value.containsKey("description")) { + enumVar.put("description", value.get("description").toString()); + } + enumVars.add(enumVar); } - enumVars.add(enumVar); + } else { + super.updateEnumVarsWithExtensions(enumVars, vendorExtensions, dataType); } - cm.allowableValues.put("enumVars", enumVars); - return true; } @Override @@ -571,12 +535,7 @@ 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)); + return toVarName(value, "number"); } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java index 34dfd1c9cd88..9c2b13abf1bb 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java @@ -132,22 +132,6 @@ protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Sc addImport(codegenModel, codegenModel.additionalPropertiesType); } - @Override - public String toEnumVarName(String name, String datatype) { - if (name.length() == 0) { - return "empty"; - } - if ("number".equalsIgnoreCase(datatype) || "int".equalsIgnoreCase(datatype)) { - name = "Number" + name; - } - name = camelize(name, true); - // for reserved word or word starting with number, append _ - if (isReservedWord(name) || name.matches("^\\d.*")) { - name = escapeReservedWord(name); - } - return name; - } - @Override public void processOpts() { defaultProcessOpts(); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java index cf7a01d188ce..afc29d252789 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java @@ -450,7 +450,7 @@ public void updateCodegenPropertyEnum(CodegenProperty var) { if (referencedSchema != null) { extensions = referencedSchema.getExtensions(); } - updateEnumVarsWithExtensions(enumVars, extensions); + updateEnumVarsWithExtensions(enumVars, extensions, dataType); allowableValues.put("enumVars", enumVars); // overwriting defaultValue omitted from here } diff --git a/modules/openapi-generator/src/main/resources/dart2/enum.mustache b/modules/openapi-generator/src/main/resources/dart2/enum.mustache index 9d6dd3022fa5..efc0aca0a1bb 100644 --- a/modules/openapi-generator/src/main/resources/dart2/enum.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/enum.mustache @@ -26,7 +26,7 @@ class {{{classname}}} { {{#allowableValues}} {{#enumVars}} - static const {{#lambda.lowercase}}{{{name}}}{{/lambda.lowercase}} = {{{classname}}}._({{{value}}}); + static const {{{name}}} = {{{classname}}}._({{{value}}}); {{/enumVars}} {{/allowableValues}} @@ -34,7 +34,7 @@ class {{{classname}}} { static const values = <{{{classname}}}>[ {{#allowableValues}} {{#enumVars}} - {{#lambda.lowercase}}{{{name}}}{{/lambda.lowercase}}, + {{{name}}}, {{/enumVars}} {{/allowableValues}} ]; @@ -71,7 +71,7 @@ class {{{classname}}}TypeTransformer { switch (data) { {{#allowableValues}} {{#enumVars}} - case {{{value}}}: return {{{classname}}}.{{#lambda.lowercase}}{{{name}}}{{/lambda.lowercase}}; + case {{{value}}}: return {{{classname}}}.{{{name}}}; {{/enumVars}} {{/allowableValues}} default: diff --git a/modules/openapi-generator/src/main/resources/dart2/enum_inline.mustache b/modules/openapi-generator/src/main/resources/dart2/enum_inline.mustache index f77a0a371037..9a307abb5489 100644 --- a/modules/openapi-generator/src/main/resources/dart2/enum_inline.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/enum_inline.mustache @@ -26,7 +26,7 @@ class {{{classname}}}{{{enumName}}} { {{#allowableValues}} {{#enumVars}} - static const {{#lambda.lowercase}}{{{name}}}{{/lambda.lowercase}} = {{{classname}}}{{{enumName}}}._({{{value}}}); + static const {{{name}}} = {{{classname}}}{{{enumName}}}._({{{value}}}); {{/enumVars}} {{/allowableValues}} @@ -34,7 +34,7 @@ class {{{classname}}}{{{enumName}}} { static const values = <{{{classname}}}{{{enumName}}}>[ {{#allowableValues}} {{#enumVars}} - {{#lambda.lowercase}}{{{name}}}{{/lambda.lowercase}}, + {{{name}}}, {{/enumVars}} {{/allowableValues}} ]; @@ -71,7 +71,7 @@ class {{{classname}}}{{{enumName}}}TypeTransformer { switch (data) { {{#allowableValues}} {{#enumVars}} - case {{{value}}}: return {{{classname}}}{{{enumName}}}.{{#lambda.lowercase}}{{{name}}}{{/lambda.lowercase}}; + case {{{value}}}: return {{{classname}}}{{{enumName}}}.{{{name}}}; {{/enumVars}} {{/allowableValues}} default: diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java index cef1d10be352..9233174859a1 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java @@ -516,7 +516,7 @@ public void updateCodegenPropertyEnum() { } @Test - public void updateCodegenPropertyEnumWithExtention() { + public void updateCodegenPropertyEnumWithExtension() { { CodegenProperty enumProperty = codegenPropertyWithXEnumVarName(Arrays.asList("dog", "cat"), Arrays.asList("DOGVAR", "CATVAR")); (new DefaultCodegen()).updateCodegenPropertyEnum(enumProperty); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/DartModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/DartModelTest.java index 0e958c408dbd..375c7c00cd06 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/DartModelTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/DartModelTest.java @@ -26,6 +26,8 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import java.util.*; + @SuppressWarnings("static-method") public class DartModelTest { @@ -339,18 +341,38 @@ public void convertVarName(String name, String expectedName) { Assert.assertEquals(codegen.toVarName(name), expectedName); } - @Test(description = "test enum variable names") - public void testEnumVarNames() { + @DataProvider(name = "enumVarNames") + public static Object[][] enumVarNames() { + return new Object[][] { + {"", "empty"}, + {"Double", "double_"}, + {"double", "double_"}, + {"dynamic", "dynamic_"}, + {"String", "string"}, + {"string", "string"}, + {"hello", "hello"}, + {"FOO", "FOO"}, + {"FOO_BAR", "FOO_BAR"}, + {"FOO_BAR_BAZ_", "FOO_BAR_BAZ_"}, + {"123hello", "number123hello"}, + {"_hello", "hello"}, + {"_double", "double_"}, + {"_123hello", "number123hello"}, + {"_5FOO", "number5fOO"}, + {"_FOO", "FOO"}, + {"_$foo", "dollarFoo"}, + {"_$_foo_", "dollarFoo"}, + {"$special[property.name]", "dollarSpecialLeftSquareBracketPropertyPeriodNameRightSquareBracket"}, + {"$", "dollar"}, + {">=", "greaterThanEqual"}, + {"foo bar", "fooBar"}, + }; + } + + @Test(dataProvider = "enumVarNames", description = "test enum names are correctly escaped") + public void convertEnumVarNames(String name, String expectedName) { final DefaultCodegen codegen = new DartClientCodegen(); - // variable names are always lower case: Double -> double -> double_ - Assert.assertEquals(codegen.toEnumVarName("Double", null), "double_"); - Assert.assertEquals(codegen.toEnumVarName("double", null), "double_"); - Assert.assertEquals(codegen.toEnumVarName("dynamic", null), "dynamic_"); - - // should not escape non-reserved - // TODO these are wrong - Assert.assertEquals(codegen.toEnumVarName("IF", null), "iF_"); - Assert.assertEquals(codegen.toEnumVarName("hello", null), "hello_"); + Assert.assertEquals(codegen.toEnumVarName(name, null), expectedName); } @Test(description = "model names support `--model-name-prefix` and `--model-name-suffix`") @@ -362,6 +384,104 @@ public void modelPrefixSuffixTest() { Assert.assertEquals(codegen.toModelName("hello_test"), "ModelHelloTestType"); } + @Test(description = "support normal enum values") + public void testEnumValues() { + final Schema model = new Schema() + .description("a sample model") + .addProperties("testStringEnum", new StringSchema()._enum(Arrays.asList("foo", "bar"))) + .addProperties("testIntEnum", new IntegerSchema().addEnumItem(1).addEnumItem(2)); + final DefaultCodegen codegen = new DartClientCodegen(); + OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model); + codegen.setOpenAPI(openAPI); + final CodegenModel cm = codegen.fromModel("sample", model); + codegen.postProcessModels(Collections.singletonMap("models", Collections.singletonList(Collections.singletonMap("model", cm)))); + + final CodegenProperty property1 = cm.vars.get(0); + Assert.assertEquals(property1.baseName, "testStringEnum"); + Assert.assertEquals(property1.dataType, "String"); + Assert.assertEquals(property1.baseType, "String"); + Assert.assertEquals(property1.datatypeWithEnum, "TestStringEnumEnum"); + Assert.assertEquals(property1.name, "testStringEnum"); + Assert.assertTrue(property1.isEnum); + Assert.assertEquals(property1.allowableValues.size(), 2); + Assert.assertEquals(((List) property1.allowableValues.get("values")).size(), 2); + List> enumVars1 = (List>) property1.allowableValues.get("enumVars"); + Assert.assertEquals(enumVars1.size(), 2); + + Assert.assertEquals(enumVars1.get(0).get("name"), "foo"); + Assert.assertEquals(enumVars1.get(0).get("value"), "'foo'"); + Assert.assertEquals(enumVars1.get(0).get("isString"), true); + + Assert.assertEquals(enumVars1.get(1).get("name"), "bar"); + Assert.assertEquals(enumVars1.get(1).get("value"), "'bar'"); + Assert.assertEquals(enumVars1.get(1).get("isString"), true); + + final CodegenProperty property2 = cm.vars.get(1); + Assert.assertEquals(property2.baseName, "testIntEnum"); + Assert.assertEquals(property2.dataType, "int"); + Assert.assertEquals(property2.baseType, "int"); + Assert.assertEquals(property2.datatypeWithEnum, "TestIntEnumEnum"); + Assert.assertEquals(property2.name, "testIntEnum"); + Assert.assertTrue(property2.isEnum); + Assert.assertEquals(property2.allowableValues.size(), 2); + Assert.assertEquals(((List) property2.allowableValues.get("values")).size(), 2); + List> enumVars2 = (List>) property2.allowableValues.get("enumVars"); + Assert.assertEquals(enumVars2.size(), 2); + + Assert.assertEquals(enumVars2.get(0).get("name"), "number1"); + Assert.assertEquals(enumVars2.get(0).get("value"), "1"); + Assert.assertEquals(enumVars2.get(0).get("isString"), false); + + Assert.assertEquals(enumVars2.get(1).get("name"), "number2"); + Assert.assertEquals(enumVars2.get(1).get("value"), "2"); + Assert.assertEquals(enumVars2.get(1).get("isString"), false); + } + + @Test(description = "support for x-enum-values extension") + public void testXEnumValuesExtension() { + final Map enumValue1 = new HashMap<>(); + enumValue1.put("identifier", "foo"); + enumValue1.put("numericValue", 1); + enumValue1.put("description", "the foo"); + final Map enumValue2 = new HashMap<>(); + enumValue2.put("identifier", "bar"); + enumValue2.put("numericValue", 2); + enumValue2.put("description", "the bar"); + + final Schema model = new Schema() + .description("a sample model") + .addProperties("testIntEnum", new IntegerSchema().addEnumItem(1).addEnumItem(2) + .extensions(Collections.singletonMap("x-enum-values", Arrays.asList(enumValue1, enumValue2)))); + final DartClientCodegen codegen = new DartClientCodegen(); + codegen.setUseEnumExtension(true); + OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model); + codegen.setOpenAPI(openAPI); + final CodegenModel cm = codegen.fromModel("sample", model); + codegen.postProcessModels(Collections.singletonMap("models", Collections.singletonList(Collections.singletonMap("model", cm)))); + + final CodegenProperty property1 = cm.vars.get(0); + Assert.assertEquals(property1.baseName, "testIntEnum"); + Assert.assertEquals(property1.dataType, "int"); + Assert.assertEquals(property1.baseType, "int"); + Assert.assertEquals(property1.datatypeWithEnum, "TestIntEnumEnum"); + Assert.assertEquals(property1.name, "testIntEnum"); + Assert.assertTrue(property1.isEnum); + Assert.assertEquals(property1.allowableValues.size(), 2); + Assert.assertEquals(((List) property1.allowableValues.get("values")).size(), 2); + List> enumVars = (List>) property1.allowableValues.get("enumVars"); + Assert.assertEquals(enumVars.size(), 2); + + Assert.assertEquals(enumVars.get(0).get("name"), "foo"); + Assert.assertEquals(enumVars.get(0).get("value"), "1"); + Assert.assertEquals(enumVars.get(0).get("isString"), false); + Assert.assertEquals(enumVars.get(0).get("description"), "the foo"); + + Assert.assertEquals(enumVars.get(1).get("name"), "bar"); + Assert.assertEquals(enumVars.get(1).get("value"), "2"); + Assert.assertEquals(enumVars.get(1).get("isString"), false); + Assert.assertEquals(enumVars.get(1).get("description"), "the bar"); + } + // datetime (or primitive type) not yet supported in HTTP request body @Test(description = "returns DateTime when using `--model-name-prefix`") public void dateTest() { diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/dartdio/DartDioModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/dartdio/DartDioModelTest.java index e7ec5c5687b6..44bf10b3a92a 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/dartdio/DartDioModelTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/dartdio/DartDioModelTest.java @@ -328,7 +328,6 @@ public void arrayModelTest() { Assert.assertTrue(cm.isArray); Assert.assertEquals(cm.description, "an array model"); Assert.assertEquals(cm.vars.size(), 0); - // skip import test as import is not used by PHP codegen } @Test(description = "convert a map model") @@ -345,21 +344,12 @@ public void mapModelTest() { Assert.assertEquals(cm.classname, "Sample"); Assert.assertEquals(cm.description, "a map model"); Assert.assertEquals(cm.vars.size(), 0); - // {{imports}} is not used in template - //Assert.assertEquals(cm.imports.size(), 2); - //Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("Children")).size(), 1); } @DataProvider(name = "modelNames") - public static Object[][] primeNumbers() { + public static Object[][] modelNames() { return new Object[][] { - {"sample", "Sample"}, - {"sample_name", "SampleName"}, - {"sample__name", "SampleName"}, - {"/sample", "Sample"}, - {"\\sample", "Sample"}, - {"sample.name", "SampleName"}, - {"_sample", "Sample"}, + {"EnumClass", "ModelEnumClass"}, }; } @@ -374,30 +364,4 @@ public void modelNameTest(String name, String expectedName) { Assert.assertEquals(cm.name, name); Assert.assertEquals(cm.classname, expectedName); } - - @Test(description = "test enum variable names for reserved words") - public void testReservedWord() throws Exception { - final DefaultCodegen codegen = new DartDioClientCodegen(); - Assert.assertEquals(codegen.toEnumVarName("assert", null), "assert_"); - Assert.assertEquals(codegen.toEnumVarName("default", null), "default_"); - Assert.assertEquals(codegen.toEnumVarName("IF", null), "iF_"); - // should not escape non-reserved - Assert.assertEquals(codegen.toEnumVarName("hello", null), "hello"); - } - - // datetime (or primitive type) not yet supported in HTTP request body - @Test(description = "returns DateTime when using `--model-name-prefix`") - public void dateTest() { - final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/datePropertyTest.json"); - final DefaultCodegen codegen = new DartDioClientCodegen(); - codegen.setModelNamePrefix("foo"); - codegen.setOpenAPI(openAPI); - - final String path = "/tests/dateResponse"; - final Operation p = openAPI.getPaths().get(path).getPost(); - final CodegenOperation op = codegen.fromOperation(path, "post", p, null); - - Assert.assertEquals(op.returnType, "DateTime"); - Assert.assertEquals(op.bodyParam.dataType, "DateTime"); - } } diff --git a/samples/client/petstore/dart2/petstore/test/pet_faked_client_test.dart b/samples/client/petstore/dart2/petstore/test/pet_faked_client_test.dart index ada6c5fd444a..0b80d597c6c8 100644 --- a/samples/client/petstore/dart2/petstore/test/pet_faked_client_test.dart +++ b/samples/client/petstore/dart2/petstore/test/pet_faked_client_test.dart @@ -1,5 +1,4 @@ import 'dart:io'; -import 'dart:math'; import 'package:http/http.dart'; import 'package:openapi/api.dart'; @@ -39,11 +38,10 @@ void main() { /// Setup the fake client then call [petApi.addPet] Future addPet(Pet pet) { petApi.apiClient.client = FakeClient( - expectedUrl: 'http://petstore.swagger.io/v2/pet', - expectedPostRequestBody: petApi.apiClient.serialize(pet), - postResponseBody: '', - expectedHeaders: { 'Content-Type': 'application/json' } - ); + expectedUrl: 'http://petstore.swagger.io/v2/pet', + expectedPostRequestBody: petApi.apiClient.serialize(pet), + postResponseBody: '', + expectedHeaders: {'Content-Type': 'application/json'}); return petApi.addPet(pet); } @@ -54,11 +52,10 @@ void main() { // use the pet api to add a pet petApi.apiClient.client = FakeClient( - expectedUrl: 'http://petstore.swagger.io/v2/pet', - expectedPostRequestBody: petApi.apiClient.serialize(newPet), - postResponseBody: '', - expectedHeaders: { 'Content-Type': 'application/json' } - ); + expectedUrl: 'http://petstore.swagger.io/v2/pet', + expectedPostRequestBody: petApi.apiClient.serialize(newPet), + postResponseBody: '', + expectedHeaders: {'Content-Type': 'application/json'}); await petApi.addPet(newPet); // retrieve the same pet by id @@ -88,19 +85,16 @@ void main() { // add a new pet petApi.apiClient.client = FakeClient( - expectedUrl: 'http://petstore.swagger.io/v2/pet', - expectedPostRequestBody: petApi.apiClient.serialize(newPet), - postResponseBody: '', - expectedHeaders: { 'Content-Type': 'application/json' } - ); + expectedUrl: 'http://petstore.swagger.io/v2/pet', + expectedPostRequestBody: petApi.apiClient.serialize(newPet), + postResponseBody: '', + expectedHeaders: {'Content-Type': 'application/json'}); await petApi.addPet(newPet); // delete the pet petApi.apiClient.client = FakeClient( expectedUrl: 'http://petstore.swagger.io/v2/pet/$id', - expectedHeaders: { - 'api_key': 'special-key' - }, + expectedHeaders: {'api_key': 'special-key'}, deleteResponseBody: '', ); await petApi.deletePet(id, apiKey: 'special-key'); @@ -120,11 +114,10 @@ void main() { // add a new pet petApi.apiClient.client = FakeClient( - expectedUrl: 'http://petstore.swagger.io/v2/pet', - expectedPostRequestBody: petApi.apiClient.serialize(newPet), - postResponseBody: '', - expectedHeaders: { 'Content-Type': 'application/json' } - ); + expectedUrl: 'http://petstore.swagger.io/v2/pet', + expectedPostRequestBody: petApi.apiClient.serialize(newPet), + postResponseBody: '', + expectedHeaders: {'Content-Type': 'application/json'}); await petApi.addPet(newPet); final multipartRequest = MultipartRequest(null, null); @@ -160,20 +153,18 @@ void main() { // add a new pet petApi.apiClient.client = FakeClient( - expectedUrl: 'http://petstore.swagger.io/v2/pet', - expectedPostRequestBody: petApi.apiClient.serialize(newPet), - postResponseBody: '', - expectedHeaders: { 'Content-Type': 'application/json' } - ); + expectedUrl: 'http://petstore.swagger.io/v2/pet', + expectedPostRequestBody: petApi.apiClient.serialize(newPet), + postResponseBody: '', + expectedHeaders: {'Content-Type': 'application/json'}); await petApi.addPet(newPet); // update the same pet petApi.apiClient.client = FakeClient( - expectedUrl: 'http://petstore.swagger.io/v2/pet', - expectedPutRequestBody: petApi.apiClient.serialize(updatePet), - putResponseBody: '', - expectedHeaders: { 'Content-Type': 'application/json' } - ); + expectedUrl: 'http://petstore.swagger.io/v2/pet', + expectedPutRequestBody: petApi.apiClient.serialize(updatePet), + putResponseBody: '', + expectedHeaders: {'Content-Type': 'application/json'}); await petApi.updatePet(updatePet); // check update worked @@ -189,10 +180,10 @@ void main() { final id1 = newId(); final id2 = newId(); final id3 = newId(); - final status = PetStatusEnum.available_.value; + final status = PetStatusEnum.available.value; final pet1 = makePet(id: id1, status: status); final pet2 = makePet(id: id2, status: status); - final pet3 = makePet(id: id3, status: PetStatusEnum.sold_.value); + final pet3 = makePet(id: id3, status: PetStatusEnum.sold.value); return Future.wait([addPet(pet1), addPet(pet2), addPet(pet3)]) .then((_) async { @@ -205,7 +196,8 @@ void main() { final pets = await petApi.findPetsByStatus([status]); // tests serialisation and deserialisation of enum - final petsByStatus = pets.where((p) => p.status == PetStatusEnum.available_); + final petsByStatus = + pets.where((p) => p.status == PetStatusEnum.available); expect(petsByStatus.length, equals(2)); final petIds = pets.map((pet) => pet.id).toList(); expect(petIds, contains(id1)); @@ -223,11 +215,10 @@ void main() { // add a new pet petApi.apiClient.client = FakeClient( - expectedUrl: 'http://petstore.swagger.io/v2/pet', - expectedPostRequestBody: petApi.apiClient.serialize(newPet), - postResponseBody: '', - expectedHeaders: { 'Content-Type': 'application/json' } - ); + expectedUrl: 'http://petstore.swagger.io/v2/pet', + expectedPostRequestBody: petApi.apiClient.serialize(newPet), + postResponseBody: '', + expectedHeaders: {'Content-Type': 'application/json'}); await petApi.addPet(newPet); petApi.apiClient.client = FakeClient( diff --git a/samples/client/petstore/dart2/petstore/test/pet_test.dart b/samples/client/petstore/dart2/petstore/test/pet_test.dart index 10a71acd9a09..e480ec7baa08 100644 --- a/samples/client/petstore/dart2/petstore/test/pet_test.dart +++ b/samples/client/petstore/dart2/petstore/test/pet_test.dart @@ -27,12 +27,12 @@ void main() { ]; return Pet( - id : id, + id: id, category: category, name: name, //required field tags: tags, photoUrls: ['https://petstore.com/sample/photo1.jpg'] //required field - ) + ) ..status = PetStatusEnum.fromJson(status) ..photoUrls = ['https://petstore.com/sample/photo1.jpg']; } @@ -81,12 +81,12 @@ void main() { var id1 = newId(); var id2 = newId(); var id3 = newId(); - var status = PetStatusEnum.available_.value; + var status = PetStatusEnum.available.value; return Future.wait([ petApi.addPet(makePet(id: id1, status: status)), petApi.addPet(makePet(id: id2, status: status)), - petApi.addPet(makePet(id: id3, status: PetStatusEnum.sold_.value)) + petApi.addPet(makePet(id: id3, status: PetStatusEnum.sold.value)) ]).then((_) async { var pets = await petApi.findPetsByStatus([status]); var petIds = pets.map((pet) => pet.id).toList(); diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/model/order.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/model/order.dart index 4ba9c2ea96d9..e6660d5a08a5 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/model/order.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/model/order.dart @@ -143,15 +143,15 @@ class OrderStatusEnum { String toJson() => value; - static const placed_ = OrderStatusEnum._('placed'); - static const approved_ = OrderStatusEnum._('approved'); - static const delivered_ = OrderStatusEnum._('delivered'); + static const placed = OrderStatusEnum._('placed'); + static const approved = OrderStatusEnum._('approved'); + static const delivered = OrderStatusEnum._('delivered'); /// List of all possible values in this [enum][OrderStatusEnum]. static const values = [ - placed_, - approved_, - delivered_, + placed, + approved, + delivered, ]; static OrderStatusEnum fromJson(dynamic value) => @@ -184,9 +184,9 @@ class OrderStatusEnumTypeTransformer { /// and users are still using an old app with the old code. OrderStatusEnum decode(dynamic data, {bool allowNull}) { switch (data) { - case 'placed': return OrderStatusEnum.placed_; - case 'approved': return OrderStatusEnum.approved_; - case 'delivered': return OrderStatusEnum.delivered_; + case 'placed': return OrderStatusEnum.placed; + case 'approved': return OrderStatusEnum.approved; + case 'delivered': return OrderStatusEnum.delivered; default: if (allowNull == false) { throw ArgumentError('Unknown enum value to decode: $data'); diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart index 1fb0d7b04057..76ca801b9f4d 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart @@ -143,15 +143,15 @@ class PetStatusEnum { String toJson() => value; - static const available_ = PetStatusEnum._('available'); - static const pending_ = PetStatusEnum._('pending'); - static const sold_ = PetStatusEnum._('sold'); + static const available = PetStatusEnum._('available'); + static const pending = PetStatusEnum._('pending'); + static const sold = PetStatusEnum._('sold'); /// List of all possible values in this [enum][PetStatusEnum]. static const values = [ - available_, - pending_, - sold_, + available, + pending, + sold, ]; static PetStatusEnum fromJson(dynamic value) => @@ -184,9 +184,9 @@ class PetStatusEnumTypeTransformer { /// and users are still using an old app with the old code. PetStatusEnum decode(dynamic data, {bool allowNull}) { switch (data) { - case 'available': return PetStatusEnum.available_; - case 'pending': return PetStatusEnum.pending_; - case 'sold': return PetStatusEnum.sold_; + case 'available': return PetStatusEnum.available; + case 'pending': return PetStatusEnum.pending; + case 'sold': return PetStatusEnum.sold; default: if (allowNull == false) { throw ArgumentError('Unknown enum value to decode: $data'); diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/enum_arrays.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/enum_arrays.dart index 48064167ea82..7c1007142a1f 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/enum_arrays.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/enum_arrays.dart @@ -27,9 +27,9 @@ abstract class EnumArrays implements Built { class EnumArraysJustSymbol extends EnumClass { @BuiltValueEnumConst(wireName: '>=') - static const EnumArraysJustSymbol >= = _$enumArraysJustSymbol_>=; + static const EnumArraysJustSymbol greaterThanEqual = _$enumArraysJustSymbol_greaterThanEqual; @BuiltValueEnumConst(wireName: '$') - static const EnumArraysJustSymbol $ = _$enumArraysJustSymbol_$; + static const EnumArraysJustSymbol dollar = _$enumArraysJustSymbol_dollar; static Serializer get serializer => _$enumArraysJustSymbolSerializer; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/enum_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/enum_test.dart index 0788d1778b6e..a9ce7fc6c602 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/enum_test.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/enum_test.dart @@ -61,7 +61,7 @@ abstract class EnumTest implements Built { class EnumTestEnumString extends EnumClass { @BuiltValueEnumConst(wireName: 'UPPER') - static const EnumTestEnumString uPPER = _$enumTestEnumString_uPPER; + static const EnumTestEnumString UPPER = _$enumTestEnumString_UPPER; @BuiltValueEnumConst(wireName: 'lower') static const EnumTestEnumString lower = _$enumTestEnumString_lower; @BuiltValueEnumConst(wireName: '') @@ -79,7 +79,7 @@ class EnumTestEnumString extends EnumClass { class EnumTestEnumStringRequired extends EnumClass { @BuiltValueEnumConst(wireName: 'UPPER') - static const EnumTestEnumStringRequired uPPER = _$enumTestEnumStringRequired_uPPER; + static const EnumTestEnumStringRequired UPPER = _$enumTestEnumStringRequired_UPPER; @BuiltValueEnumConst(wireName: 'lower') static const EnumTestEnumStringRequired lower = _$enumTestEnumStringRequired_lower; @BuiltValueEnumConst(wireName: '') @@ -113,9 +113,9 @@ class EnumTestEnumInteger extends EnumClass { class EnumTestEnumNumber extends EnumClass { @BuiltValueEnumConst(wireName: '1.1') - static const EnumTestEnumNumber 11_ = _$enumTestEnumNumber_11_; + static const EnumTestEnumNumber number1period1 = _$enumTestEnumNumber_number1period1; @BuiltValueEnumConst(wireName: '-1.2') - static const EnumTestEnumNumber 12_ = _$enumTestEnumNumber_12_; + static const EnumTestEnumNumber number1period2 = _$enumTestEnumNumber_number1period2; static Serializer get serializer => _$enumTestEnumNumberSerializer; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/inline_object2.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/inline_object2.dart index 936eed83abd4..37b93d3c3e68 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/inline_object2.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/inline_object2.dart @@ -28,10 +28,10 @@ class InlineObject2EnumFormStringArray extends EnumClass { /// Form parameter enum test (string array) @BuiltValueEnumConst(wireName: '>') - static const InlineObject2EnumFormStringArray > = _$inlineObject2EnumFormStringArray_>; + static const InlineObject2EnumFormStringArray greaterThan = _$inlineObject2EnumFormStringArray_greaterThan; /// Form parameter enum test (string array) @BuiltValueEnumConst(wireName: '$') - static const InlineObject2EnumFormStringArray $ = _$inlineObject2EnumFormStringArray_$; + static const InlineObject2EnumFormStringArray dollar = _$inlineObject2EnumFormStringArray_dollar; static Serializer get serializer => _$inlineObject2EnumFormStringArraySerializer; @@ -52,7 +52,7 @@ class InlineObject2EnumFormString extends EnumClass { static const InlineObject2EnumFormString efg = _$inlineObject2EnumFormString_efg; /// Form parameter enum test (string) @BuiltValueEnumConst(wireName: '(xyz)') - static const InlineObject2EnumFormString (xyz) = _$inlineObject2EnumFormString_(xyz); + static const InlineObject2EnumFormString leftParenthesisXyzRightParenthesis = _$inlineObject2EnumFormString_leftParenthesisXyzRightParenthesis; static Serializer get serializer => _$inlineObject2EnumFormStringSerializer; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/map_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/map_test.dart index 3dd4226e2d67..79e10af233d0 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/map_test.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/map_test.dart @@ -34,7 +34,7 @@ abstract class MapTest implements Built { class MapTestMapOfEnumString extends EnumClass { @BuiltValueEnumConst(wireName: 'UPPER') - static const MapTestMapOfEnumString uPPER = _$mapTestMapOfEnumString_uPPER; + static const MapTestMapOfEnumString UPPER = _$mapTestMapOfEnumString_UPPER; @BuiltValueEnumConst(wireName: 'lower') static const MapTestMapOfEnumString lower = _$mapTestMapOfEnumString_lower; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/model_enum_class.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/model_enum_class.dart index a43af990446d..3b7c5386a1dc 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/model_enum_class.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/model_enum_class.dart @@ -11,7 +11,7 @@ class ModelEnumClass extends EnumClass { @BuiltValueEnumConst(wireName: '-efg') static const ModelEnumClass efg = _$efg; @BuiltValueEnumConst(wireName: '(xyz)') - static const ModelEnumClass (xyz) = _$(xyz); + static const ModelEnumClass leftParenthesisXyzRightParenthesis = _$leftParenthesisXyzRightParenthesis; static Serializer get serializer => _$modelEnumClassSerializer; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/special_model_name.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/special_model_name.dart index 1ec09cacc3d4..583d07d9b1b2 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/special_model_name.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/model/special_model_name.dart @@ -14,6 +14,6 @@ abstract class SpecialModelName implements Built get serializer => _$specialModelPeriodNameSerializer; + static Serializer get serializer => _$specialModelNameSerializer; } diff --git a/samples/openapi3/client/petstore/dart2/petstore/test/pet_faked_client_test.dart b/samples/openapi3/client/petstore/dart2/petstore/test/pet_faked_client_test.dart index 41f66951484d..70f1b0d6bebe 100644 --- a/samples/openapi3/client/petstore/dart2/petstore/test/pet_faked_client_test.dart +++ b/samples/openapi3/client/petstore/dart2/petstore/test/pet_faked_client_test.dart @@ -1,5 +1,4 @@ import 'dart:io'; -import 'dart:math'; import 'package:http/http.dart'; import 'package:openapi/api.dart'; @@ -39,11 +38,10 @@ void main() { /// Setup the fake client then call [petApi.addPet] Future addPet(Pet pet) { petApi.apiClient.client = FakeClient( - expectedUrl: 'http://petstore.swagger.io/v2/pet', - expectedPostRequestBody: petApi.apiClient.serialize(pet), - postResponseBody: petApi.apiClient.serialize(pet), - expectedHeaders: { 'Content-Type': 'application/json' } - ); + expectedUrl: 'http://petstore.swagger.io/v2/pet', + expectedPostRequestBody: petApi.apiClient.serialize(pet), + postResponseBody: petApi.apiClient.serialize(pet), + expectedHeaders: {'Content-Type': 'application/json'}); return petApi.addPet(pet); } @@ -54,11 +52,10 @@ void main() { // use the pet api to add a pet petApi.apiClient.client = FakeClient( - expectedUrl: 'http://petstore.swagger.io/v2/pet', - expectedPostRequestBody: petApi.apiClient.serialize(newPet), - postResponseBody: petApi.apiClient.serialize(newPet), - expectedHeaders: { 'Content-Type': 'application/json' } - ); + expectedUrl: 'http://petstore.swagger.io/v2/pet', + expectedPostRequestBody: petApi.apiClient.serialize(newPet), + postResponseBody: petApi.apiClient.serialize(newPet), + expectedHeaders: {'Content-Type': 'application/json'}); await petApi.addPet(newPet); // retrieve the same pet by id @@ -88,19 +85,16 @@ void main() { // add a new pet petApi.apiClient.client = FakeClient( - expectedUrl: 'http://petstore.swagger.io/v2/pet', - expectedPostRequestBody: petApi.apiClient.serialize(newPet), - postResponseBody: petApi.apiClient.serialize(newPet), - expectedHeaders: { 'Content-Type': 'application/json' } - ); + expectedUrl: 'http://petstore.swagger.io/v2/pet', + expectedPostRequestBody: petApi.apiClient.serialize(newPet), + postResponseBody: petApi.apiClient.serialize(newPet), + expectedHeaders: {'Content-Type': 'application/json'}); await petApi.addPet(newPet); // delete the pet petApi.apiClient.client = FakeClient( expectedUrl: 'http://petstore.swagger.io/v2/pet/$id', - expectedHeaders: { - 'api_key': 'special-key' - }, + expectedHeaders: {'api_key': 'special-key'}, deleteResponseBody: '', ); await petApi.deletePet(id, apiKey: 'special-key'); @@ -120,11 +114,10 @@ void main() { // add a new pet petApi.apiClient.client = FakeClient( - expectedUrl: 'http://petstore.swagger.io/v2/pet', - expectedPostRequestBody: petApi.apiClient.serialize(newPet), - postResponseBody: petApi.apiClient.serialize(newPet), - expectedHeaders: { 'Content-Type': 'application/json' } - ); + expectedUrl: 'http://petstore.swagger.io/v2/pet', + expectedPostRequestBody: petApi.apiClient.serialize(newPet), + postResponseBody: petApi.apiClient.serialize(newPet), + expectedHeaders: {'Content-Type': 'application/json'}); await petApi.addPet(newPet); final multipartRequest = MultipartRequest(null, null); @@ -160,20 +153,18 @@ void main() { // add a new pet petApi.apiClient.client = FakeClient( - expectedUrl: 'http://petstore.swagger.io/v2/pet', - expectedPostRequestBody: petApi.apiClient.serialize(newPet), - postResponseBody: petApi.apiClient.serialize(newPet), - expectedHeaders: { 'Content-Type': 'application/json' } - ); + expectedUrl: 'http://petstore.swagger.io/v2/pet', + expectedPostRequestBody: petApi.apiClient.serialize(newPet), + postResponseBody: petApi.apiClient.serialize(newPet), + expectedHeaders: {'Content-Type': 'application/json'}); await petApi.addPet(newPet); // update the same pet petApi.apiClient.client = FakeClient( - expectedUrl: 'http://petstore.swagger.io/v2/pet', - expectedPutRequestBody: petApi.apiClient.serialize(updatePet), - putResponseBody: petApi.apiClient.serialize(updatePet), - expectedHeaders: { 'Content-Type': 'application/json' } - ); + expectedUrl: 'http://petstore.swagger.io/v2/pet', + expectedPutRequestBody: petApi.apiClient.serialize(updatePet), + putResponseBody: petApi.apiClient.serialize(updatePet), + expectedHeaders: {'Content-Type': 'application/json'}); await petApi.updatePet(updatePet); // check update worked @@ -189,10 +180,10 @@ void main() { final id1 = newId(); final id2 = newId(); final id3 = newId(); - final status = PetStatusEnum.available_.value; + final status = PetStatusEnum.available.value; final pet1 = makePet(id: id1, status: status); final pet2 = makePet(id: id2, status: status); - final pet3 = makePet(id: id3, status: PetStatusEnum.sold_.value); + final pet3 = makePet(id: id3, status: PetStatusEnum.sold.value); return Future.wait([addPet(pet1), addPet(pet2), addPet(pet3)]) .then((_) async { @@ -205,7 +196,8 @@ void main() { final pets = await petApi.findPetsByStatus([status]); // tests serialisation and deserialisation of enum - final petsByStatus = pets.where((p) => p.status == PetStatusEnum.available_); + final petsByStatus = + pets.where((p) => p.status == PetStatusEnum.available); expect(petsByStatus.length, equals(2)); final petIds = pets.map((pet) => pet.id).toList(); expect(petIds, contains(id1)); @@ -223,11 +215,10 @@ void main() { // add a new pet petApi.apiClient.client = FakeClient( - expectedUrl: 'http://petstore.swagger.io/v2/pet', - expectedPostRequestBody: petApi.apiClient.serialize(newPet), - postResponseBody: petApi.apiClient.serialize(newPet), - expectedHeaders: { 'Content-Type': 'application/json' } - ); + expectedUrl: 'http://petstore.swagger.io/v2/pet', + expectedPostRequestBody: petApi.apiClient.serialize(newPet), + postResponseBody: petApi.apiClient.serialize(newPet), + expectedHeaders: {'Content-Type': 'application/json'}); await petApi.addPet(newPet); petApi.apiClient.client = FakeClient( diff --git a/samples/openapi3/client/petstore/dart2/petstore/test/pet_test.dart b/samples/openapi3/client/petstore/dart2/petstore/test/pet_test.dart index 10a71acd9a09..e480ec7baa08 100644 --- a/samples/openapi3/client/petstore/dart2/petstore/test/pet_test.dart +++ b/samples/openapi3/client/petstore/dart2/petstore/test/pet_test.dart @@ -27,12 +27,12 @@ void main() { ]; return Pet( - id : id, + id: id, category: category, name: name, //required field tags: tags, photoUrls: ['https://petstore.com/sample/photo1.jpg'] //required field - ) + ) ..status = PetStatusEnum.fromJson(status) ..photoUrls = ['https://petstore.com/sample/photo1.jpg']; } @@ -81,12 +81,12 @@ void main() { var id1 = newId(); var id2 = newId(); var id3 = newId(); - var status = PetStatusEnum.available_.value; + var status = PetStatusEnum.available.value; return Future.wait([ petApi.addPet(makePet(id: id1, status: status)), petApi.addPet(makePet(id: id2, status: status)), - petApi.addPet(makePet(id: id3, status: PetStatusEnum.sold_.value)) + petApi.addPet(makePet(id: id3, status: PetStatusEnum.sold.value)) ]).then((_) async { var pets = await petApi.findPetsByStatus([status]); var petIds = pets.map((pet) => pet.id).toList(); diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/order.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/order.dart index 4ba9c2ea96d9..e6660d5a08a5 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/order.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/order.dart @@ -143,15 +143,15 @@ class OrderStatusEnum { String toJson() => value; - static const placed_ = OrderStatusEnum._('placed'); - static const approved_ = OrderStatusEnum._('approved'); - static const delivered_ = OrderStatusEnum._('delivered'); + static const placed = OrderStatusEnum._('placed'); + static const approved = OrderStatusEnum._('approved'); + static const delivered = OrderStatusEnum._('delivered'); /// List of all possible values in this [enum][OrderStatusEnum]. static const values = [ - placed_, - approved_, - delivered_, + placed, + approved, + delivered, ]; static OrderStatusEnum fromJson(dynamic value) => @@ -184,9 +184,9 @@ class OrderStatusEnumTypeTransformer { /// and users are still using an old app with the old code. OrderStatusEnum decode(dynamic data, {bool allowNull}) { switch (data) { - case 'placed': return OrderStatusEnum.placed_; - case 'approved': return OrderStatusEnum.approved_; - case 'delivered': return OrderStatusEnum.delivered_; + case 'placed': return OrderStatusEnum.placed; + case 'approved': return OrderStatusEnum.approved; + case 'delivered': return OrderStatusEnum.delivered; default: if (allowNull == false) { throw ArgumentError('Unknown enum value to decode: $data'); diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart index 1fb0d7b04057..76ca801b9f4d 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart @@ -143,15 +143,15 @@ class PetStatusEnum { String toJson() => value; - static const available_ = PetStatusEnum._('available'); - static const pending_ = PetStatusEnum._('pending'); - static const sold_ = PetStatusEnum._('sold'); + static const available = PetStatusEnum._('available'); + static const pending = PetStatusEnum._('pending'); + static const sold = PetStatusEnum._('sold'); /// List of all possible values in this [enum][PetStatusEnum]. static const values = [ - available_, - pending_, - sold_, + available, + pending, + sold, ]; static PetStatusEnum fromJson(dynamic value) => @@ -184,9 +184,9 @@ class PetStatusEnumTypeTransformer { /// and users are still using an old app with the old code. PetStatusEnum decode(dynamic data, {bool allowNull}) { switch (data) { - case 'available': return PetStatusEnum.available_; - case 'pending': return PetStatusEnum.pending_; - case 'sold': return PetStatusEnum.sold_; + case 'available': return PetStatusEnum.available; + case 'pending': return PetStatusEnum.pending; + case 'sold': return PetStatusEnum.sold; default: if (allowNull == false) { throw ArgumentError('Unknown enum value to decode: $data'); diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_arrays.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_arrays.dart index 2e902906c4a1..e8a3626b6797 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_arrays.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_arrays.dart @@ -101,13 +101,13 @@ class EnumArraysJustSymbolEnum { String toJson() => value; - static const _ = EnumArraysJustSymbolEnum._('>='); - static const _ = EnumArraysJustSymbolEnum._('$'); + static const greaterThanEqual = EnumArraysJustSymbolEnum._('>='); + static const dollar = EnumArraysJustSymbolEnum._('$'); /// List of all possible values in this [enum][EnumArraysJustSymbolEnum]. static const values = [ - _, - _, + greaterThanEqual, + dollar, ]; static EnumArraysJustSymbolEnum fromJson(dynamic value) => @@ -140,8 +140,8 @@ class EnumArraysJustSymbolEnumTypeTransformer { /// and users are still using an old app with the old code. EnumArraysJustSymbolEnum decode(dynamic data, {bool allowNull}) { switch (data) { - case '>=': return EnumArraysJustSymbolEnum._; - case '$': return EnumArraysJustSymbolEnum._; + case '>=': return EnumArraysJustSymbolEnum.greaterThanEqual; + case '$': return EnumArraysJustSymbolEnum.dollar; default: if (allowNull == false) { throw ArgumentError('Unknown enum value to decode: $data'); @@ -175,13 +175,13 @@ class EnumArraysArrayEnumEnum { String toJson() => value; - static const fish_ = EnumArraysArrayEnumEnum._('fish'); - static const crab_ = EnumArraysArrayEnumEnum._('crab'); + static const fish = EnumArraysArrayEnumEnum._('fish'); + static const crab = EnumArraysArrayEnumEnum._('crab'); /// List of all possible values in this [enum][EnumArraysArrayEnumEnum]. static const values = [ - fish_, - crab_, + fish, + crab, ]; static EnumArraysArrayEnumEnum fromJson(dynamic value) => @@ -214,8 +214,8 @@ class EnumArraysArrayEnumEnumTypeTransformer { /// and users are still using an old app with the old code. EnumArraysArrayEnumEnum decode(dynamic data, {bool allowNull}) { switch (data) { - case 'fish': return EnumArraysArrayEnumEnum.fish_; - case 'crab': return EnumArraysArrayEnumEnum.crab_; + case 'fish': return EnumArraysArrayEnumEnum.fish; + case 'crab': return EnumArraysArrayEnumEnum.crab; default: if (allowNull == false) { throw ArgumentError('Unknown enum value to decode: $data'); diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_class.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_class.dart index 3959cdf31aeb..d8bc602471e6 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_class.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_class.dart @@ -30,15 +30,15 @@ class EnumClass { String toJson() => value; - static const abc_ = EnumClass._('_abc'); - static const efg_ = EnumClass._('-efg'); - static const xyz_ = EnumClass._('(xyz)'); + static const abc = EnumClass._('_abc'); + static const efg = EnumClass._('-efg'); + static const leftParenthesisXyzRightParenthesis = EnumClass._('(xyz)'); /// List of all possible values in this [enum][EnumClass]. static const values = [ - abc_, - efg_, - xyz_, + abc, + efg, + leftParenthesisXyzRightParenthesis, ]; static EnumClass fromJson(dynamic value) => @@ -71,9 +71,9 @@ class EnumClassTypeTransformer { /// and users are still using an old app with the old code. EnumClass decode(dynamic data, {bool allowNull}) { switch (data) { - case '_abc': return EnumClass.abc_; - case '-efg': return EnumClass.efg_; - case '(xyz)': return EnumClass.xyz_; + case '_abc': return EnumClass.abc; + case '-efg': return EnumClass.efg; + case '(xyz)': return EnumClass.leftParenthesisXyzRightParenthesis; default: if (allowNull == false) { throw ArgumentError('Unknown enum value to decode: $data'); diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_test.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_test.dart index b6e9ef26bf88..957c02778717 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_test.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_test.dart @@ -161,14 +161,14 @@ class EnumTestEnumStringEnum { String toJson() => value; - static const upper_ = EnumTestEnumStringEnum._('UPPER'); - static const lower_ = EnumTestEnumStringEnum._('lower'); + static const UPPER = EnumTestEnumStringEnum._('UPPER'); + static const lower = EnumTestEnumStringEnum._('lower'); static const empty = EnumTestEnumStringEnum._(''); /// List of all possible values in this [enum][EnumTestEnumStringEnum]. static const values = [ - upper_, - lower_, + UPPER, + lower, empty, ]; @@ -202,8 +202,8 @@ class EnumTestEnumStringEnumTypeTransformer { /// and users are still using an old app with the old code. EnumTestEnumStringEnum decode(dynamic data, {bool allowNull}) { switch (data) { - case 'UPPER': return EnumTestEnumStringEnum.upper_; - case 'lower': return EnumTestEnumStringEnum.lower_; + case 'UPPER': return EnumTestEnumStringEnum.UPPER; + case 'lower': return EnumTestEnumStringEnum.lower; case '': return EnumTestEnumStringEnum.empty; default: if (allowNull == false) { @@ -238,14 +238,14 @@ class EnumTestEnumStringRequiredEnum { String toJson() => value; - static const upper_ = EnumTestEnumStringRequiredEnum._('UPPER'); - static const lower_ = EnumTestEnumStringRequiredEnum._('lower'); + static const UPPER = EnumTestEnumStringRequiredEnum._('UPPER'); + static const lower = EnumTestEnumStringRequiredEnum._('lower'); static const empty = EnumTestEnumStringRequiredEnum._(''); /// List of all possible values in this [enum][EnumTestEnumStringRequiredEnum]. static const values = [ - upper_, - lower_, + UPPER, + lower, empty, ]; @@ -279,8 +279,8 @@ class EnumTestEnumStringRequiredEnumTypeTransformer { /// and users are still using an old app with the old code. EnumTestEnumStringRequiredEnum decode(dynamic data, {bool allowNull}) { switch (data) { - case 'UPPER': return EnumTestEnumStringRequiredEnum.upper_; - case 'lower': return EnumTestEnumStringRequiredEnum.lower_; + case 'UPPER': return EnumTestEnumStringRequiredEnum.UPPER; + case 'lower': return EnumTestEnumStringRequiredEnum.lower; case '': return EnumTestEnumStringRequiredEnum.empty; default: if (allowNull == false) { @@ -315,13 +315,13 @@ class EnumTestEnumIntegerEnum { String toJson() => value; - static const number1_ = EnumTestEnumIntegerEnum._(1); - static const number1_ = EnumTestEnumIntegerEnum._(-1); + static const number1 = EnumTestEnumIntegerEnum._(1); + static const number1 = EnumTestEnumIntegerEnum._(-1); /// List of all possible values in this [enum][EnumTestEnumIntegerEnum]. static const values = [ - number1_, - number1_, + number1, + number1, ]; static EnumTestEnumIntegerEnum fromJson(dynamic value) => @@ -354,8 +354,8 @@ class EnumTestEnumIntegerEnumTypeTransformer { /// and users are still using an old app with the old code. EnumTestEnumIntegerEnum decode(dynamic data, {bool allowNull}) { switch (data) { - case 1: return EnumTestEnumIntegerEnum.number1_; - case -1: return EnumTestEnumIntegerEnum.number1_; + case 1: return EnumTestEnumIntegerEnum.number1; + case -1: return EnumTestEnumIntegerEnum.number1; default: if (allowNull == false) { throw ArgumentError('Unknown enum value to decode: $data'); @@ -389,13 +389,13 @@ class EnumTestEnumNumberEnum { String toJson() => value; - static const 11_ = EnumTestEnumNumberEnum._('1.1'); - static const 12_ = EnumTestEnumNumberEnum._('-1.2'); + static const number1period1 = EnumTestEnumNumberEnum._('1.1'); + static const number1period2 = EnumTestEnumNumberEnum._('-1.2'); /// List of all possible values in this [enum][EnumTestEnumNumberEnum]. static const values = [ - 11_, - 12_, + number1period1, + number1period2, ]; static EnumTestEnumNumberEnum fromJson(dynamic value) => @@ -428,8 +428,8 @@ class EnumTestEnumNumberEnumTypeTransformer { /// and users are still using an old app with the old code. EnumTestEnumNumberEnum decode(dynamic data, {bool allowNull}) { switch (data) { - case '1.1': return EnumTestEnumNumberEnum.11_; - case '-1.2': return EnumTestEnumNumberEnum.12_; + case '1.1': return EnumTestEnumNumberEnum.number1period1; + case '-1.2': return EnumTestEnumNumberEnum.number1period2; default: if (allowNull == false) { throw ArgumentError('Unknown enum value to decode: $data'); diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/inline_object2.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/inline_object2.dart index f82f4ba81d3e..86c73284068a 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/inline_object2.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/inline_object2.dart @@ -101,13 +101,13 @@ class InlineObject2EnumFormStringArrayEnum { String toJson() => value; - static const _ = InlineObject2EnumFormStringArrayEnum._('>'); - static const _ = InlineObject2EnumFormStringArrayEnum._('$'); + static const greaterThan = InlineObject2EnumFormStringArrayEnum._('>'); + static const dollar = InlineObject2EnumFormStringArrayEnum._('$'); /// List of all possible values in this [enum][InlineObject2EnumFormStringArrayEnum]. static const values = [ - _, - _, + greaterThan, + dollar, ]; static InlineObject2EnumFormStringArrayEnum fromJson(dynamic value) => @@ -140,8 +140,8 @@ class InlineObject2EnumFormStringArrayEnumTypeTransformer { /// and users are still using an old app with the old code. InlineObject2EnumFormStringArrayEnum decode(dynamic data, {bool allowNull}) { switch (data) { - case '>': return InlineObject2EnumFormStringArrayEnum._; - case '$': return InlineObject2EnumFormStringArrayEnum._; + case '>': return InlineObject2EnumFormStringArrayEnum.greaterThan; + case '$': return InlineObject2EnumFormStringArrayEnum.dollar; default: if (allowNull == false) { throw ArgumentError('Unknown enum value to decode: $data'); @@ -175,15 +175,15 @@ class InlineObject2EnumFormStringEnum { String toJson() => value; - static const abc_ = InlineObject2EnumFormStringEnum._('_abc'); - static const efg_ = InlineObject2EnumFormStringEnum._('-efg'); - static const xyz_ = InlineObject2EnumFormStringEnum._('(xyz)'); + static const abc = InlineObject2EnumFormStringEnum._('_abc'); + static const efg = InlineObject2EnumFormStringEnum._('-efg'); + static const leftParenthesisXyzRightParenthesis = InlineObject2EnumFormStringEnum._('(xyz)'); /// List of all possible values in this [enum][InlineObject2EnumFormStringEnum]. static const values = [ - abc_, - efg_, - xyz_, + abc, + efg, + leftParenthesisXyzRightParenthesis, ]; static InlineObject2EnumFormStringEnum fromJson(dynamic value) => @@ -216,9 +216,9 @@ class InlineObject2EnumFormStringEnumTypeTransformer { /// and users are still using an old app with the old code. InlineObject2EnumFormStringEnum decode(dynamic data, {bool allowNull}) { switch (data) { - case '_abc': return InlineObject2EnumFormStringEnum.abc_; - case '-efg': return InlineObject2EnumFormStringEnum.efg_; - case '(xyz)': return InlineObject2EnumFormStringEnum.xyz_; + case '_abc': return InlineObject2EnumFormStringEnum.abc; + case '-efg': return InlineObject2EnumFormStringEnum.efg; + case '(xyz)': return InlineObject2EnumFormStringEnum.leftParenthesisXyzRightParenthesis; default: if (allowNull == false) { throw ArgumentError('Unknown enum value to decode: $data'); diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/map_test.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/map_test.dart index ad46cde3fedb..7c930a530ff0 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/map_test.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/map_test.dart @@ -129,13 +129,13 @@ class MapTestMapOfEnumStringEnum { String toJson() => value; - static const upper_ = MapTestMapOfEnumStringEnum._('UPPER'); - static const lower_ = MapTestMapOfEnumStringEnum._('lower'); + static const UPPER = MapTestMapOfEnumStringEnum._('UPPER'); + static const lower = MapTestMapOfEnumStringEnum._('lower'); /// List of all possible values in this [enum][MapTestMapOfEnumStringEnum]. static const values = [ - upper_, - lower_, + UPPER, + lower, ]; static MapTestMapOfEnumStringEnum fromJson(dynamic value) => @@ -168,8 +168,8 @@ class MapTestMapOfEnumStringEnumTypeTransformer { /// and users are still using an old app with the old code. MapTestMapOfEnumStringEnum decode(dynamic data, {bool allowNull}) { switch (data) { - case 'UPPER': return MapTestMapOfEnumStringEnum.upper_; - case 'lower': return MapTestMapOfEnumStringEnum.lower_; + case 'UPPER': return MapTestMapOfEnumStringEnum.UPPER; + case 'lower': return MapTestMapOfEnumStringEnum.lower; default: if (allowNull == false) { throw ArgumentError('Unknown enum value to decode: $data'); diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/order.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/order.dart index 4ba9c2ea96d9..e6660d5a08a5 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/order.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/order.dart @@ -143,15 +143,15 @@ class OrderStatusEnum { String toJson() => value; - static const placed_ = OrderStatusEnum._('placed'); - static const approved_ = OrderStatusEnum._('approved'); - static const delivered_ = OrderStatusEnum._('delivered'); + static const placed = OrderStatusEnum._('placed'); + static const approved = OrderStatusEnum._('approved'); + static const delivered = OrderStatusEnum._('delivered'); /// List of all possible values in this [enum][OrderStatusEnum]. static const values = [ - placed_, - approved_, - delivered_, + placed, + approved, + delivered, ]; static OrderStatusEnum fromJson(dynamic value) => @@ -184,9 +184,9 @@ class OrderStatusEnumTypeTransformer { /// and users are still using an old app with the old code. OrderStatusEnum decode(dynamic data, {bool allowNull}) { switch (data) { - case 'placed': return OrderStatusEnum.placed_; - case 'approved': return OrderStatusEnum.approved_; - case 'delivered': return OrderStatusEnum.delivered_; + case 'placed': return OrderStatusEnum.placed; + case 'approved': return OrderStatusEnum.approved; + case 'delivered': return OrderStatusEnum.delivered; default: if (allowNull == false) { throw ArgumentError('Unknown enum value to decode: $data'); diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum.dart index 5edeca38ef2f..90b78ad1d77e 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum.dart @@ -30,15 +30,15 @@ class OuterEnum { String toJson() => value; - static const placed_ = OuterEnum._('placed'); - static const approved_ = OuterEnum._('approved'); - static const delivered_ = OuterEnum._('delivered'); + static const placed = OuterEnum._('placed'); + static const approved = OuterEnum._('approved'); + static const delivered = OuterEnum._('delivered'); /// List of all possible values in this [enum][OuterEnum]. static const values = [ - placed_, - approved_, - delivered_, + placed, + approved, + delivered, ]; static OuterEnum fromJson(dynamic value) => @@ -71,9 +71,9 @@ class OuterEnumTypeTransformer { /// and users are still using an old app with the old code. OuterEnum decode(dynamic data, {bool allowNull}) { switch (data) { - case 'placed': return OuterEnum.placed_; - case 'approved': return OuterEnum.approved_; - case 'delivered': return OuterEnum.delivered_; + case 'placed': return OuterEnum.placed; + case 'approved': return OuterEnum.approved; + case 'delivered': return OuterEnum.delivered; default: if (allowNull == false) { throw ArgumentError('Unknown enum value to decode: $data'); diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_default_value.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_default_value.dart index a046a153dbb0..954bb4e528c4 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_default_value.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_default_value.dart @@ -30,15 +30,15 @@ class OuterEnumDefaultValue { String toJson() => value; - static const placed_ = OuterEnumDefaultValue._('placed'); - static const approved_ = OuterEnumDefaultValue._('approved'); - static const delivered_ = OuterEnumDefaultValue._('delivered'); + static const placed = OuterEnumDefaultValue._('placed'); + static const approved = OuterEnumDefaultValue._('approved'); + static const delivered = OuterEnumDefaultValue._('delivered'); /// List of all possible values in this [enum][OuterEnumDefaultValue]. static const values = [ - placed_, - approved_, - delivered_, + placed, + approved, + delivered, ]; static OuterEnumDefaultValue fromJson(dynamic value) => @@ -71,9 +71,9 @@ class OuterEnumDefaultValueTypeTransformer { /// and users are still using an old app with the old code. OuterEnumDefaultValue decode(dynamic data, {bool allowNull}) { switch (data) { - case 'placed': return OuterEnumDefaultValue.placed_; - case 'approved': return OuterEnumDefaultValue.approved_; - case 'delivered': return OuterEnumDefaultValue.delivered_; + case 'placed': return OuterEnumDefaultValue.placed; + case 'approved': return OuterEnumDefaultValue.approved; + case 'delivered': return OuterEnumDefaultValue.delivered; default: if (allowNull == false) { throw ArgumentError('Unknown enum value to decode: $data'); diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_integer.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_integer.dart index 0bb65d3251e4..dd0d8111bb6d 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_integer.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_integer.dart @@ -30,15 +30,15 @@ class OuterEnumInteger { String toJson() => value; - static const number0_ = OuterEnumInteger._(0); - static const number1_ = OuterEnumInteger._(1); - static const number2_ = OuterEnumInteger._(2); + static const number0 = OuterEnumInteger._(0); + static const number1 = OuterEnumInteger._(1); + static const number2 = OuterEnumInteger._(2); /// List of all possible values in this [enum][OuterEnumInteger]. static const values = [ - number0_, - number1_, - number2_, + number0, + number1, + number2, ]; static OuterEnumInteger fromJson(dynamic value) => @@ -71,9 +71,9 @@ class OuterEnumIntegerTypeTransformer { /// and users are still using an old app with the old code. OuterEnumInteger decode(dynamic data, {bool allowNull}) { switch (data) { - case 0: return OuterEnumInteger.number0_; - case 1: return OuterEnumInteger.number1_; - case 2: return OuterEnumInteger.number2_; + case 0: return OuterEnumInteger.number0; + case 1: return OuterEnumInteger.number1; + case 2: return OuterEnumInteger.number2; default: if (allowNull == false) { throw ArgumentError('Unknown enum value to decode: $data'); diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_integer_default_value.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_integer_default_value.dart index 506ab94c4af4..eb1eaae1c2db 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_integer_default_value.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_integer_default_value.dart @@ -30,15 +30,15 @@ class OuterEnumIntegerDefaultValue { String toJson() => value; - static const number0_ = OuterEnumIntegerDefaultValue._(0); - static const number1_ = OuterEnumIntegerDefaultValue._(1); - static const number2_ = OuterEnumIntegerDefaultValue._(2); + static const number0 = OuterEnumIntegerDefaultValue._(0); + static const number1 = OuterEnumIntegerDefaultValue._(1); + static const number2 = OuterEnumIntegerDefaultValue._(2); /// List of all possible values in this [enum][OuterEnumIntegerDefaultValue]. static const values = [ - number0_, - number1_, - number2_, + number0, + number1, + number2, ]; static OuterEnumIntegerDefaultValue fromJson(dynamic value) => @@ -71,9 +71,9 @@ class OuterEnumIntegerDefaultValueTypeTransformer { /// and users are still using an old app with the old code. OuterEnumIntegerDefaultValue decode(dynamic data, {bool allowNull}) { switch (data) { - case 0: return OuterEnumIntegerDefaultValue.number0_; - case 1: return OuterEnumIntegerDefaultValue.number1_; - case 2: return OuterEnumIntegerDefaultValue.number2_; + case 0: return OuterEnumIntegerDefaultValue.number0; + case 1: return OuterEnumIntegerDefaultValue.number1; + case 2: return OuterEnumIntegerDefaultValue.number2; default: if (allowNull == false) { throw ArgumentError('Unknown enum value to decode: $data'); diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/pet.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/pet.dart index 1fb0d7b04057..76ca801b9f4d 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/pet.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/pet.dart @@ -143,15 +143,15 @@ class PetStatusEnum { String toJson() => value; - static const available_ = PetStatusEnum._('available'); - static const pending_ = PetStatusEnum._('pending'); - static const sold_ = PetStatusEnum._('sold'); + static const available = PetStatusEnum._('available'); + static const pending = PetStatusEnum._('pending'); + static const sold = PetStatusEnum._('sold'); /// List of all possible values in this [enum][PetStatusEnum]. static const values = [ - available_, - pending_, - sold_, + available, + pending, + sold, ]; static PetStatusEnum fromJson(dynamic value) => @@ -184,9 +184,9 @@ class PetStatusEnumTypeTransformer { /// and users are still using an old app with the old code. PetStatusEnum decode(dynamic data, {bool allowNull}) { switch (data) { - case 'available': return PetStatusEnum.available_; - case 'pending': return PetStatusEnum.pending_; - case 'sold': return PetStatusEnum.sold_; + case 'available': return PetStatusEnum.available; + case 'pending': return PetStatusEnum.pending; + case 'sold': return PetStatusEnum.sold; default: if (allowNull == false) { throw ArgumentError('Unknown enum value to decode: $data');