mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 19:33:55 +00:00
Merge pull request #1305 from iushankin/issue-1304
Fixed #1304: Migrate tests from the Scala to the plain Java. Part 1
This commit is contained in:
commit
053af7a749
@ -0,0 +1,41 @@
|
||||
package io.swagger.codegen;
|
||||
|
||||
import io.swagger.models.auth.AuthorizationValue;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ClientAuthInputTest {
|
||||
|
||||
@Test(description = "read a file upload param from a 2.0 spec")
|
||||
public void clientAuthInputTest() {
|
||||
final ClientOptInput input = new ClientOptInput();
|
||||
|
||||
final String header = "api_key:special-key,api_key:hello,X-AUTHORIZATION:0e6c11d79a,Authorization:Basic 1jz0";
|
||||
input.setAuth(header);
|
||||
final List<AuthorizationValue> authValues = input.getAuthorizationValues();
|
||||
Assert.assertEquals(authValues.size(), 4);
|
||||
|
||||
final AuthorizationValue a1 = authValues.get(0);
|
||||
Assert.assertEquals(a1.getKeyName(), "api_key");
|
||||
Assert.assertEquals(a1.getValue(), "special-key");
|
||||
Assert.assertEquals(a1.getType(), "header");
|
||||
|
||||
final AuthorizationValue a2 = authValues.get(1);
|
||||
Assert.assertEquals(a2.getKeyName(), "api_key");
|
||||
Assert.assertEquals(a2.getValue(), "hello");
|
||||
Assert.assertEquals(a2.getType(), "header");
|
||||
|
||||
final AuthorizationValue a3 = authValues.get(2);
|
||||
Assert.assertEquals(a3.getKeyName(), "X-AUTHORIZATION");
|
||||
Assert.assertEquals(a3.getValue(), "0e6c11d79a");
|
||||
Assert.assertEquals(a3.getType(), "header");
|
||||
|
||||
final AuthorizationValue a4 = authValues.get(3);
|
||||
Assert.assertEquals(a4.getKeyName(), "Authorization");
|
||||
Assert.assertEquals(a4.getValue(), "Basic 1jz0");
|
||||
Assert.assertEquals(a4.getType(), "header");
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package io.swagger.codegen;
|
||||
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.parser.SwaggerParser;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class SwaggerMigratorTest {
|
||||
|
||||
@Test(description = "read a 1.2 spec")
|
||||
public void swaggerMigratorTest() {
|
||||
final SwaggerParser loader = new SwaggerParser();
|
||||
final Swagger swagger = loader.read("src/test/resources/1_2/petstore-1.2/api-docs");
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package io.swagger.codegen.java;
|
||||
|
||||
import io.swagger.codegen.CodegenModel;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.languages.JavaClientCodegen;
|
||||
import io.swagger.models.ComposedModel;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.ModelImpl;
|
||||
import io.swagger.models.RefModel;
|
||||
import io.swagger.models.properties.StringProperty;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class JavaInheritanceTest {
|
||||
|
||||
@Test(description = "convert a composed model")
|
||||
public void javaInheritanceTest() {
|
||||
final Model model = new ComposedModel().parent(new RefModel("Base"))
|
||||
.child(new ModelImpl().additionalProperties(new StringProperty()));
|
||||
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||
|
||||
Assert.assertEquals(cm.name, "sample");
|
||||
Assert.assertEquals(cm.classname, "Sample");
|
||||
Assert.assertEquals(cm.parent, "Base");
|
||||
Assert.assertEquals(cm.imports, Sets.newHashSet("Base"));
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package io.swagger.codegen.java;
|
||||
|
||||
import io.swagger.codegen.CodegenModel;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.languages.JavaClientCodegen;
|
||||
import io.swagger.models.ComposedModel;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.ModelImpl;
|
||||
import io.swagger.models.RefModel;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.properties.StringProperty;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class JavaModelEnumTest {
|
||||
|
||||
@Test(description = "convert a java model with an enum")
|
||||
public void converterTest() {
|
||||
final StringProperty enumProperty = new StringProperty();
|
||||
enumProperty.setEnum(Arrays.asList("VALUE1", "VALUE2", "VALUE3"));
|
||||
final ModelImpl model = new ModelImpl().property("name", enumProperty);
|
||||
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||
|
||||
Assert.assertEquals(cm.vars.size(), 1);
|
||||
|
||||
final CodegenProperty enumVar = cm.vars.get(0);
|
||||
Assert.assertEquals(enumVar.baseName, "name");
|
||||
Assert.assertEquals(enumVar.datatype, "String");
|
||||
Assert.assertEquals(enumVar.datatypeWithEnum, "NameEnum");
|
||||
Assert.assertEquals(enumVar.name, "name");
|
||||
Assert.assertEquals(enumVar.defaultValue, "null");
|
||||
Assert.assertEquals(enumVar.baseType, "String");
|
||||
Assert.assertTrue(enumVar.isEnum);
|
||||
}
|
||||
|
||||
@Test(description = "not override identical parent enums")
|
||||
public void overrideEnumTest() {
|
||||
final StringProperty identicalEnumProperty = new StringProperty();
|
||||
identicalEnumProperty.setEnum(Arrays.asList("VALUE1", "VALUE2", "VALUE3"));
|
||||
|
||||
final StringProperty subEnumProperty = new StringProperty();
|
||||
subEnumProperty.setEnum(Arrays.asList("SUB1", "SUB2", "SUB3"));
|
||||
|
||||
// Add one enum property to the parent
|
||||
final Map<String, Property> parentProperties = new HashMap<String, Property>();
|
||||
parentProperties.put("sharedThing", identicalEnumProperty);
|
||||
|
||||
// Add TWO enums to the subType model; one of which is identical to the one in parent class
|
||||
final Map<String, Property> subProperties = new HashMap<String, Property>();
|
||||
subProperties.put("sharedThing", identicalEnumProperty);
|
||||
subProperties.put("unsharedThing", identicalEnumProperty);
|
||||
|
||||
final ModelImpl parentModel = new ModelImpl();
|
||||
parentModel.setProperties(parentProperties);
|
||||
parentModel.name("parentModel");
|
||||
|
||||
final ModelImpl subModel = new ModelImpl();
|
||||
subModel.setProperties(subProperties);
|
||||
subModel.name("subModel");
|
||||
|
||||
final ComposedModel model = new ComposedModel()
|
||||
.parent(new RefModel(parentModel.getName()))
|
||||
.child(subModel)
|
||||
.interfaces(new ArrayList<RefModel>());
|
||||
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final Map<String, Model> allModels = new HashMap<String, Model>();
|
||||
allModels.put(codegen.toModelName(parentModel.getName()), parentModel);
|
||||
allModels.put(codegen.toModelName(subModel.getName()), subModel);
|
||||
|
||||
final CodegenModel cm = codegen.fromModel("sample", model, allModels);
|
||||
|
||||
Assert.assertEquals(cm.name, "sample");
|
||||
Assert.assertEquals(cm.classname, "Sample");
|
||||
Assert.assertEquals(cm.parent, "ParentModel");
|
||||
Assert.assertEquals(cm.imports, Collections.singletonList("ParentModel"));
|
||||
|
||||
// Assert that only the unshared/uninherited enum remains
|
||||
Assert.assertEquals(cm.vars.size(), 1);
|
||||
final CodegenProperty enumVar = cm.vars.get(0);
|
||||
Assert.assertEquals(enumVar.baseName, "unsharedThing");
|
||||
Assert.assertEquals(enumVar.datatype, "String");
|
||||
Assert.assertEquals(enumVar.datatypeWithEnum, "UnsharedThingEnum");
|
||||
Assert.assertTrue(enumVar.isEnum);
|
||||
}
|
||||
}
|
@ -0,0 +1,456 @@
|
||||
package io.swagger.codegen.java;
|
||||
|
||||
import io.swagger.codegen.CodegenModel;
|
||||
import io.swagger.codegen.CodegenParameter;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.languages.JavaClientCodegen;
|
||||
import io.swagger.models.ArrayModel;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.ModelImpl;
|
||||
import io.swagger.models.parameters.QueryParameter;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.ByteArrayProperty;
|
||||
import io.swagger.models.properties.DateTimeProperty;
|
||||
import io.swagger.models.properties.IntegerProperty;
|
||||
import io.swagger.models.properties.LongProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.RefProperty;
|
||||
import io.swagger.models.properties.StringProperty;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class JavaModelTest {
|
||||
|
||||
@Test(description = "convert a simple java model")
|
||||
public void simpleModelTest() {
|
||||
final Model model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("id", new LongProperty())
|
||||
.property("name", new StringProperty())
|
||||
.property("createdAt", new DateTimeProperty())
|
||||
.required("id")
|
||||
.required("name");
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||
|
||||
Assert.assertEquals(cm.name, "sample");
|
||||
Assert.assertEquals(cm.classname, "Sample");
|
||||
Assert.assertEquals(cm.description, "a sample model");
|
||||
Assert.assertEquals(cm.vars.size(), 3);
|
||||
|
||||
final List<CodegenProperty> vars = cm.vars;
|
||||
|
||||
final CodegenProperty property1 = vars.get(0);
|
||||
Assert.assertEquals(property1.baseName, "id");
|
||||
Assert.assertEquals(property1.getter, "getId");
|
||||
Assert.assertEquals(property1.setter, "setId");
|
||||
Assert.assertEquals(property1.datatype, "Long");
|
||||
Assert.assertEquals(property1.name, "id");
|
||||
Assert.assertEquals(property1.defaultValue, "null");
|
||||
Assert.assertEquals(property1.baseType, "Long");
|
||||
Assert.assertTrue(property1.hasMore);
|
||||
Assert.assertTrue(property1.required);
|
||||
Assert.assertTrue(property1.isNotContainer);
|
||||
|
||||
final CodegenProperty property2 = vars.get(1);
|
||||
Assert.assertEquals(property2.baseName, "name");
|
||||
Assert.assertEquals(property2.getter, "getName");
|
||||
Assert.assertEquals(property2.setter, "setName");
|
||||
Assert.assertEquals(property2.datatype, "String");
|
||||
Assert.assertEquals(property2.name, "name");
|
||||
Assert.assertEquals(property2.defaultValue, "null");
|
||||
Assert.assertEquals(property2.baseType, "String");
|
||||
Assert.assertTrue(property2.hasMore);
|
||||
Assert.assertTrue(property2.required);
|
||||
Assert.assertTrue(property2.isNotContainer);
|
||||
|
||||
final CodegenProperty property3 = vars.get(2);
|
||||
Assert.assertEquals(property3.baseName, "createdAt");
|
||||
Assert.assertEquals(property3.getter, "getCreatedAt");
|
||||
Assert.assertEquals(property3.setter, "setCreatedAt");
|
||||
Assert.assertEquals(property3.datatype, "Date");
|
||||
Assert.assertEquals(property3.name, "createdAt");
|
||||
Assert.assertEquals(property3.defaultValue, "null");
|
||||
Assert.assertEquals(property3.baseType, "Date");
|
||||
Assert.assertNull(property3.hasMore);
|
||||
Assert.assertNull(property3.required);
|
||||
Assert.assertTrue(property3.isNotContainer);
|
||||
}
|
||||
|
||||
@Test(description = "convert a model with list property")
|
||||
public void listPropertyTest() {
|
||||
final Model model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("id", new LongProperty())
|
||||
.property("urls", new ArrayProperty()
|
||||
.items(new StringProperty()))
|
||||
.required("id");
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||
|
||||
Assert.assertEquals(cm.name, "sample");
|
||||
Assert.assertEquals(cm.classname, "Sample");
|
||||
Assert.assertEquals(cm.description, "a sample model");
|
||||
Assert.assertEquals(cm.vars.size(), 2);
|
||||
|
||||
final CodegenProperty property = cm.vars.get(1);
|
||||
Assert.assertEquals(property.baseName, "urls");
|
||||
Assert.assertEquals(property.getter, "getUrls");
|
||||
Assert.assertEquals(property.setter, "setUrls");
|
||||
Assert.assertEquals(property.datatype, "List<String>");
|
||||
Assert.assertEquals(property.name, "urls");
|
||||
Assert.assertEquals(property.defaultValue, "new ArrayList<String>()");
|
||||
Assert.assertEquals(property.baseType, "List");
|
||||
Assert.assertEquals(property.containerType, "array");
|
||||
Assert.assertNull(property.required);
|
||||
Assert.assertTrue(property.isContainer);
|
||||
}
|
||||
|
||||
@Test(description = "convert a model with a map property")
|
||||
public void mapPropertyTest() {
|
||||
final Model model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("translations", new MapProperty()
|
||||
.additionalProperties(new StringProperty()))
|
||||
.required("id");
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||
|
||||
Assert.assertEquals(cm.name, "sample");
|
||||
Assert.assertEquals(cm.classname, "Sample");
|
||||
Assert.assertEquals(cm.description, "a sample model");
|
||||
Assert.assertEquals(cm.vars.size(), 1);
|
||||
|
||||
final CodegenProperty property = cm.vars.get(0);
|
||||
Assert.assertEquals(property.baseName, "translations");
|
||||
Assert.assertEquals(property.getter, "getTranslations");
|
||||
Assert.assertEquals(property.setter, "setTranslations");
|
||||
Assert.assertEquals(property.datatype, "Map<String, String>");
|
||||
Assert.assertEquals(property.name, "translations");
|
||||
Assert.assertEquals(property.defaultValue, "new HashMap<String, String>()");
|
||||
Assert.assertEquals(property.baseType, "Map");
|
||||
Assert.assertEquals(property.containerType, "map");
|
||||
Assert.assertNull(property.required);
|
||||
Assert.assertTrue(property.isContainer);
|
||||
}
|
||||
|
||||
@Test(description = "convert a model with a map with complex list property")
|
||||
public void mapWithListPropertyTest() {
|
||||
final Model model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("translations",
|
||||
new MapProperty().additionalProperties(new ArrayProperty().items(new RefProperty("Pet"))))
|
||||
.required("id");
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||
|
||||
Assert.assertEquals(cm.name, "sample");
|
||||
Assert.assertEquals(cm.classname, "Sample");
|
||||
Assert.assertEquals(cm.description, "a sample model");
|
||||
Assert.assertEquals(cm.vars.size(), 1);
|
||||
|
||||
final CodegenProperty property = cm.vars.get(0);
|
||||
Assert.assertEquals(property.baseName, "translations");
|
||||
Assert.assertEquals(property.getter, "getTranslations");
|
||||
Assert.assertEquals(property.setter, "setTranslations");
|
||||
Assert.assertEquals(property.datatype, "Map<String, List<Pet>>");
|
||||
Assert.assertEquals(property.name, "translations");
|
||||
Assert.assertEquals(property.defaultValue, "new HashMap<String, List<Pet>>()");
|
||||
Assert.assertEquals(property.baseType, "Map");
|
||||
Assert.assertEquals(property.containerType, "map");
|
||||
Assert.assertNull(property.required);
|
||||
Assert.assertTrue(property.isContainer);
|
||||
}
|
||||
|
||||
@Test(description = "convert a model with a 2D list property")
|
||||
public void list2DPropertyTest() {
|
||||
final Model model = new ModelImpl().name("sample").property("list2D", new ArrayProperty().items(
|
||||
new ArrayProperty().items(new RefProperty("Pet"))));
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||
|
||||
Assert.assertEquals(cm.vars.size(), 1);
|
||||
|
||||
final CodegenProperty property = cm.vars.get(0);
|
||||
Assert.assertEquals(property.baseName, "list2D");
|
||||
Assert.assertEquals(property.getter, "getList2D");
|
||||
Assert.assertEquals(property.setter, "setList2D");
|
||||
Assert.assertEquals(property.datatype, "List<List<Pet>>");
|
||||
Assert.assertEquals(property.name, "list2D");
|
||||
Assert.assertEquals(property.defaultValue, "new ArrayList<List<Pet>>()");
|
||||
Assert.assertEquals(property.baseType, "List");
|
||||
Assert.assertEquals(property.containerType, "array");
|
||||
Assert.assertNull(property.required);
|
||||
Assert.assertTrue(property.isContainer);
|
||||
}
|
||||
|
||||
@Test(description = "convert a model with complex properties")
|
||||
public void complexPropertiesTest() {
|
||||
final Model model = new ModelImpl().description("a sample model")
|
||||
.property("children", new RefProperty("#/definitions/Children"));
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||
|
||||
Assert.assertEquals(cm.name, "sample");
|
||||
Assert.assertEquals(cm.classname, "Sample");
|
||||
Assert.assertEquals(cm.description, "a sample model");
|
||||
Assert.assertEquals(cm.vars.size(), 1);
|
||||
|
||||
final CodegenProperty property = cm.vars.get(0);
|
||||
Assert.assertEquals(property.baseName, "children");
|
||||
Assert.assertEquals(property.getter, "getChildren");
|
||||
Assert.assertEquals(property.setter, "setChildren");
|
||||
Assert.assertEquals(property.datatype, "Children");
|
||||
Assert.assertEquals(property.name, "children");
|
||||
Assert.assertEquals(property.defaultValue, "null");
|
||||
Assert.assertEquals(property.baseType, "Children");
|
||||
Assert.assertNull(property.required);
|
||||
Assert.assertTrue(property.isNotContainer);
|
||||
}
|
||||
|
||||
@Test(description = "convert a model with complex list property")
|
||||
public void complexListPropertyTest() {
|
||||
final Model model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("children", new ArrayProperty().items(new RefProperty("#/definitions/Children")));
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||
|
||||
Assert.assertEquals(cm.name, "sample");
|
||||
Assert.assertEquals(cm.classname, "Sample");
|
||||
Assert.assertEquals(cm.description, "a sample model");
|
||||
Assert.assertEquals(cm.vars.size(), 1);
|
||||
|
||||
final CodegenProperty property = cm.vars.get(0);
|
||||
Assert.assertEquals(property.baseName, "children");
|
||||
Assert.assertEquals(property.complexType, "Children");
|
||||
Assert.assertEquals(property.getter, "getChildren");
|
||||
Assert.assertEquals(property.setter, "setChildren");
|
||||
Assert.assertEquals(property.datatype, "List<Children>");
|
||||
Assert.assertEquals(property.name, "children");
|
||||
Assert.assertEquals(property.defaultValue, "new ArrayList<Children>()");
|
||||
Assert.assertEquals(property.baseType, "List");
|
||||
Assert.assertEquals(property.containerType, "array");
|
||||
Assert.assertNull(property.required);
|
||||
Assert.assertTrue(property.isContainer);
|
||||
}
|
||||
|
||||
@Test(description = "convert a model with complex map property")
|
||||
public void complexMapPropertyTest() {
|
||||
final Model model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("children", new MapProperty().additionalProperties(new RefProperty("#/definitions/Children")));
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||
|
||||
Assert.assertEquals(cm.name, "sample");
|
||||
Assert.assertEquals(cm.classname, "Sample");
|
||||
Assert.assertEquals(cm.description, "a sample model");
|
||||
Assert.assertEquals(cm.vars.size(), 1);
|
||||
Assert.assertEquals(Sets.union(cm.imports, Sets.newHashSet("Map", "List", "Children")).size(), 3);
|
||||
|
||||
final CodegenProperty property = cm.vars.get(0);
|
||||
Assert.assertEquals(property.baseName, "children");
|
||||
Assert.assertEquals(property.complexType, "Children");
|
||||
Assert.assertEquals(property.getter, "getChildren");
|
||||
Assert.assertEquals(property.setter, "setChildren");
|
||||
Assert.assertEquals(property.datatype, "Map<String, Children>");
|
||||
Assert.assertEquals(property.name, "children");
|
||||
Assert.assertEquals(property.defaultValue, "new HashMap<String, Children>()");
|
||||
Assert.assertEquals(property.baseType, "Map");
|
||||
Assert.assertEquals(property.containerType, "map");
|
||||
Assert.assertNull(property.required);
|
||||
Assert.assertTrue(property.isContainer);
|
||||
Assert.assertNull(property.isNotContainer);
|
||||
|
||||
}
|
||||
|
||||
@Test(description = "convert an array model")
|
||||
public void arrayModelTest() {
|
||||
final Model model = new ArrayModel()
|
||||
.description("an array model")
|
||||
.items(new RefProperty("#/definitions/Children"));
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||
|
||||
Assert.assertEquals(cm.name, "sample");
|
||||
Assert.assertEquals(cm.classname, "Sample");
|
||||
Assert.assertEquals(cm.description, "an array model");
|
||||
Assert.assertEquals(cm.vars.size(), 0);
|
||||
Assert.assertEquals(cm.parent, "ArrayList<Children>");
|
||||
Assert.assertEquals(cm.imports.size(), 3);
|
||||
Assert.assertEquals(Sets.union(cm.imports, Sets.newHashSet("List", "ArrayList", "Children")).size(), 3);
|
||||
}
|
||||
|
||||
@Test(description = "convert an map model")
|
||||
public void mapModelTest() {
|
||||
final Model model = new ModelImpl()
|
||||
.description("an map model")
|
||||
.additionalProperties(new RefProperty("#/definitions/Children"));
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||
|
||||
Assert.assertEquals(cm.name, "sample");
|
||||
Assert.assertEquals(cm.classname, "Sample");
|
||||
Assert.assertEquals(cm.description, "an map model");
|
||||
Assert.assertEquals(cm.vars.size(), 0);
|
||||
Assert.assertEquals(cm.parent, "HashMap<String, Children>");
|
||||
Assert.assertEquals(cm.imports.size(), 3);
|
||||
Assert.assertEquals(Sets.union(cm.imports, Sets.newHashSet("Map", "HashMap", "Children")).size(), 3);
|
||||
}
|
||||
|
||||
@Test(description = "convert a model with upper-case property names")
|
||||
public void upperCaseNamesTest() {
|
||||
final Model model = new ModelImpl()
|
||||
.description("a model with upper-case property names")
|
||||
.property("NAME", new StringProperty())
|
||||
.required("NAME");
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||
|
||||
Assert.assertEquals(cm.name, "sample");
|
||||
Assert.assertEquals(cm.classname, "Sample");
|
||||
Assert.assertEquals(cm.vars.size(), 1);
|
||||
|
||||
final CodegenProperty property = cm.vars.get(0);
|
||||
Assert.assertEquals(property.baseName, "NAME");
|
||||
Assert.assertEquals(property.getter, "getNAME");
|
||||
Assert.assertEquals(property.setter, "setNAME");
|
||||
Assert.assertEquals(property.datatype, "String");
|
||||
Assert.assertEquals(property.name, "NAME");
|
||||
Assert.assertEquals(property.defaultValue, "null");
|
||||
Assert.assertEquals(property.baseType, "String");
|
||||
Assert.assertNull(property.hasMore);
|
||||
Assert.assertTrue(property.required);
|
||||
Assert.assertTrue(property.isNotContainer);
|
||||
}
|
||||
|
||||
@Test(description = "convert a model with a 2nd char upper-case property names")
|
||||
public void secondCharUpperCaseNamesTest() {
|
||||
final Model model = new ModelImpl()
|
||||
.description("a model with a 2nd char upper-case property names")
|
||||
.property("pId", new StringProperty())
|
||||
.required("pId");
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||
|
||||
Assert.assertEquals(cm.name, "sample");
|
||||
Assert.assertEquals(cm.classname, "Sample");
|
||||
Assert.assertEquals(cm.vars.size(), 1);
|
||||
|
||||
final CodegenProperty property = cm.vars.get(0);
|
||||
Assert.assertEquals(property.baseName, "pId");
|
||||
Assert.assertEquals(property.getter, "getPId");
|
||||
Assert.assertEquals(property.setter, "setPId");
|
||||
Assert.assertEquals(property.datatype, "String");
|
||||
Assert.assertEquals(property.name, "pId");
|
||||
Assert.assertEquals(property.defaultValue, "null");
|
||||
Assert.assertEquals(property.baseType, "String");
|
||||
Assert.assertNull(property.hasMore);
|
||||
Assert.assertTrue(property.required);
|
||||
Assert.assertTrue(property.isNotContainer);
|
||||
}
|
||||
|
||||
@Test(description = "convert hyphens per issue 503")
|
||||
public void hyphensTest() {
|
||||
final Model model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("created-at", new DateTimeProperty());
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||
|
||||
final CodegenProperty property = cm.vars.get(0);
|
||||
Assert.assertEquals(property.baseName, "created-at");
|
||||
Assert.assertEquals(property.getter, "getCreatedAt");
|
||||
Assert.assertEquals(property.setter, "setCreatedAt");
|
||||
Assert.assertEquals(property.name, "createdAt");
|
||||
}
|
||||
|
||||
@Test(description = "convert query[password] to queryPassword")
|
||||
public void squareBracketsTest() {
|
||||
final Model model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("query[password]", new StringProperty());
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||
|
||||
final CodegenProperty property = cm.vars.get(0);
|
||||
Assert.assertEquals(property.baseName, "query[password]");
|
||||
Assert.assertEquals(property.getter, "getQueryPassword");
|
||||
Assert.assertEquals(property.setter, "setQueryPassword");
|
||||
Assert.assertEquals(property.name, "queryPassword");
|
||||
}
|
||||
|
||||
@Test(description = "properly escape names per 567")
|
||||
public void escapeNamesTest() {
|
||||
final Model model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("created-at", new DateTimeProperty());
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenModel cm = codegen.fromModel("with.dots", model);
|
||||
|
||||
Assert.assertEquals(cm.classname, "WithDots");
|
||||
}
|
||||
|
||||
@Test(description = "convert a model with binary data")
|
||||
public void binaryDataTest() {
|
||||
final Model model = new ModelImpl()
|
||||
.description("model with binary")
|
||||
.property("inputBinaryData", new ByteArrayProperty());
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||
|
||||
final CodegenProperty property = cm.vars.get(0);
|
||||
Assert.assertEquals(property.baseName, "inputBinaryData");
|
||||
Assert.assertEquals(property.getter, "getInputBinaryData");
|
||||
Assert.assertEquals(property.setter, "setInputBinaryData");
|
||||
Assert.assertEquals(property.datatype, "byte[]");
|
||||
Assert.assertEquals(property.name, "inputBinaryData");
|
||||
Assert.assertEquals(property.defaultValue, "null");
|
||||
Assert.assertEquals(property.baseType, "byte[]");
|
||||
Assert.assertNull(property.hasMore);
|
||||
Assert.assertNull(property.required);
|
||||
Assert.assertTrue(property.isNotContainer);
|
||||
}
|
||||
|
||||
@Test(description = "translate an invalid param name")
|
||||
public void invalidParamNameTest() {
|
||||
final Model model = new ModelImpl()
|
||||
.description("a model with a 2nd char upper-case property names")
|
||||
.property("_", new StringProperty());
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||
|
||||
Assert.assertEquals(cm.name, "sample");
|
||||
Assert.assertEquals(cm.classname, "Sample");
|
||||
Assert.assertEquals(cm.vars.size(), 1);
|
||||
|
||||
final CodegenProperty property = cm.vars.get(0);
|
||||
Assert.assertEquals(property.baseName, "_");
|
||||
Assert.assertEquals(property.getter, "getU");
|
||||
Assert.assertEquals(property.setter, "setU");
|
||||
Assert.assertEquals(property.datatype, "String");
|
||||
Assert.assertEquals(property.name, "u");
|
||||
Assert.assertEquals(property.defaultValue, "null");
|
||||
Assert.assertEquals(property.baseType, "String");
|
||||
Assert.assertNull(property.hasMore);
|
||||
Assert.assertTrue(property.isNotContainer);
|
||||
}
|
||||
|
||||
@Test(description = "convert a parameter")
|
||||
public void convertParameterTest() {
|
||||
final QueryParameter parameter = new QueryParameter()
|
||||
.property(new IntegerProperty())
|
||||
.name("limit")
|
||||
.required(true);
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
final CodegenParameter cm = codegen.fromParameter(parameter, null);
|
||||
|
||||
Assert.assertNull(cm.allowableValues);
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
import io.swagger.codegen._
|
||||
import org.junit.runner.RunWith
|
||||
import org.scalatest.{FlatSpec, Matchers}
|
||||
import org.scalatest.junit.JUnitRunner
|
||||
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class ClientAuthInputTest extends FlatSpec with Matchers {
|
||||
behavior of "ClientAuthInput"
|
||||
|
||||
it should "read a file upload param from a 2.0 spec" in {
|
||||
val input = new ClientOptInput()
|
||||
|
||||
val header = "api_key:special-key,api_key:hello,X-AUTHORIZATION:0e6c11d79a,Authorization:Basic 1jz0"
|
||||
input.setAuth(header)
|
||||
val authValues = input.getAuthorizationValues()
|
||||
authValues.size() should be(4)
|
||||
|
||||
val a1 = authValues.get(0)
|
||||
a1.getKeyName should be("api_key")
|
||||
a1.getValue should be("special-key")
|
||||
a1.getType should be("header")
|
||||
|
||||
val a2 = authValues.get(1)
|
||||
a2.getKeyName should be("api_key")
|
||||
a2.getValue should be("hello")
|
||||
a2.getType should be("header")
|
||||
|
||||
val a3 = authValues.get(2)
|
||||
a3.getKeyName should be("X-AUTHORIZATION")
|
||||
a3.getValue should be("0e6c11d79a")
|
||||
a3.getType should be("header")
|
||||
|
||||
val a4 = authValues.get(3)
|
||||
a4.getKeyName should be("Authorization")
|
||||
a4.getValue should be("Basic 1jz0")
|
||||
a4.getType should be("header")
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package Java
|
||||
|
||||
import io.swagger.codegen.languages.JavaClientCodegen
|
||||
import io.swagger.models.{ComposedModel, ModelImpl, RefModel}
|
||||
import io.swagger.models.properties.StringProperty
|
||||
import org.junit.runner.RunWith
|
||||
import org.scalatest.{FlatSpec, Matchers}
|
||||
import org.scalatest.junit.JUnitRunner
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class JavaInheritanceTest extends FlatSpec with Matchers {
|
||||
it should "convert a composed model" in {
|
||||
val model = new ComposedModel().parent(new RefModel("Base")).child(new ModelImpl().additionalProperties(new StringProperty()))
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.parent should be("Base")
|
||||
cm.imports.asScala should be(Set("Base"))
|
||||
}
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
package Java
|
||||
|
||||
import io.swagger.codegen.languages.JavaClientCodegen
|
||||
import io.swagger.models._
|
||||
import io.swagger.models.properties._
|
||||
import org.junit.runner.RunWith
|
||||
import org.scalatest.junit.JUnitRunner
|
||||
import org.scalatest.{FlatSpec, Matchers}
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class JavaModelEnumTest extends FlatSpec with Matchers {
|
||||
|
||||
it should "convert a java model with an enum" in {
|
||||
val enumProperty = new StringProperty()
|
||||
enumProperty.setEnum(List("VALUE1", "VALUE2", "VALUE3").asJava)
|
||||
val model = new ModelImpl()
|
||||
.property("name", enumProperty)
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.vars.size should be(1)
|
||||
val enumVar = cm.vars.get(0)
|
||||
enumVar.baseName should be("name")
|
||||
enumVar.datatype should be("String")
|
||||
enumVar.datatypeWithEnum should be("NameEnum")
|
||||
enumVar.name should be("name")
|
||||
enumVar.defaultValue should be("null")
|
||||
enumVar.baseType should be("String")
|
||||
enumVar.isEnum should equal(true)
|
||||
}
|
||||
|
||||
it should "not override identical parent enums" in {
|
||||
|
||||
val identicalEnumProperty = new StringProperty()
|
||||
identicalEnumProperty.setEnum(List("VALUE1", "VALUE2", "VALUE3").asJava)
|
||||
|
||||
val subEnumProperty = new StringProperty()
|
||||
subEnumProperty.setEnum(List("SUB1", "SUB2", "SUB3").asJava)
|
||||
|
||||
// Add one enum ptoperty to the parent
|
||||
val parentProperties = new java.util.HashMap[String, Property]()
|
||||
parentProperties.put("sharedThing", identicalEnumProperty)
|
||||
|
||||
// Add TWO enums to the subType model; one of which is identical to the one in parent class
|
||||
val subProperties = new java.util.HashMap[String, Property]()
|
||||
subProperties.put("sharedThing", identicalEnumProperty)
|
||||
subProperties.put("unsharedThing", identicalEnumProperty)
|
||||
|
||||
val parentModel = new ModelImpl();
|
||||
parentModel.setProperties(parentProperties);
|
||||
parentModel.name("parentModel");
|
||||
|
||||
val subModel = new ModelImpl();
|
||||
subModel.setProperties(subProperties);
|
||||
subModel.name("subModel");
|
||||
|
||||
val model = new ComposedModel()
|
||||
.parent(new RefModel(parentModel.getName()))
|
||||
.child(subModel)
|
||||
.interfaces(new java.util.ArrayList[RefModel]())
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val allModels = new java.util.HashMap[String, Model]()
|
||||
allModels.put(codegen.toModelName(parentModel.getName()), parentModel)
|
||||
allModels.put(codegen.toModelName(subModel.getName()), subModel)
|
||||
|
||||
val cm = codegen.fromModel("sample", model, allModels)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.parent should be("ParentModel")
|
||||
cm.imports.asScala should be(Set("ParentModel"))
|
||||
|
||||
// Assert that only the unshared/uninherited enum remains
|
||||
cm.vars.size should be (1)
|
||||
val enumVar = cm.vars.get(0)
|
||||
enumVar.baseName should be("unsharedThing")
|
||||
enumVar.datatype should be("String")
|
||||
enumVar.datatypeWithEnum should be("UnsharedThingEnum")
|
||||
enumVar.isEnum should equal(true)
|
||||
}
|
||||
}
|
@ -1,445 +0,0 @@
|
||||
package Java
|
||||
|
||||
import io.swagger.codegen.languages.JavaClientCodegen
|
||||
import io.swagger.models._
|
||||
import io.swagger.models.parameters._
|
||||
import io.swagger.models.properties._
|
||||
import io.swagger.util.Json
|
||||
import org.junit.runner.RunWith
|
||||
import org.scalatest.{FlatSpec, Matchers}
|
||||
import org.scalatest.junit.JUnitRunner
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class JavaModelTest extends FlatSpec with Matchers {
|
||||
it should "convert a simple java model" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("id", new LongProperty())
|
||||
.property("name", new StringProperty())
|
||||
.property("createdAt", new DateTimeProperty())
|
||||
.required("id")
|
||||
.required("name")
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("a sample model")
|
||||
cm.vars.size should be(3)
|
||||
|
||||
val vars = cm.vars
|
||||
vars.get(0).baseName should be("id")
|
||||
vars.get(0).getter should be("getId")
|
||||
vars.get(0).setter should be("setId")
|
||||
vars.get(0).datatype should be("Long")
|
||||
vars.get(0).name should be("id")
|
||||
vars.get(0).defaultValue should be("null")
|
||||
vars.get(0).baseType should be("Long")
|
||||
vars.get(0).hasMore should equal(true)
|
||||
vars.get(0).required should equal(true)
|
||||
vars.get(0).isNotContainer should equal(true)
|
||||
|
||||
vars.get(1).baseName should be("name")
|
||||
vars.get(1).getter should be("getName")
|
||||
vars.get(1).setter should be("setName")
|
||||
vars.get(1).datatype should be("String")
|
||||
vars.get(1).name should be("name")
|
||||
vars.get(1).defaultValue should be("null")
|
||||
vars.get(1).baseType should be("String")
|
||||
vars.get(1).hasMore should equal(true)
|
||||
vars.get(1).required should equal(true)
|
||||
vars.get(1).isNotContainer should equal(true)
|
||||
|
||||
vars.get(2).baseName should be("createdAt")
|
||||
vars.get(2).getter should be("getCreatedAt")
|
||||
vars.get(2).setter should be("setCreatedAt")
|
||||
vars.get(2).datatype should be("Date")
|
||||
vars.get(2).name should be("createdAt")
|
||||
vars.get(2).defaultValue should be("null")
|
||||
vars.get(2).baseType should be("Date")
|
||||
vars.get(2).hasMore should equal(null)
|
||||
vars.get(2).required should equal(null)
|
||||
vars.get(2).isNotContainer should equal(true)
|
||||
}
|
||||
|
||||
it should "convert a model with list property" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("id", new LongProperty())
|
||||
.property("urls", new ArrayProperty()
|
||||
.items(new StringProperty()))
|
||||
.required("id")
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("a sample model")
|
||||
cm.vars.size should be(2)
|
||||
|
||||
val vars = cm.vars
|
||||
vars.get(1).baseName should be("urls")
|
||||
vars.get(1).getter should be("getUrls")
|
||||
vars.get(1).setter should be("setUrls")
|
||||
vars.get(1).datatype should be("List<String>")
|
||||
vars.get(1).name should be("urls")
|
||||
vars.get(1).defaultValue should be("new ArrayList<String>()")
|
||||
vars.get(1).baseType should be("List")
|
||||
vars.get(1).containerType should be("array")
|
||||
vars.get(1).required should equal(null)
|
||||
vars.get(1).isContainer should equal(true)
|
||||
}
|
||||
|
||||
it should "convert a model with a map property" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("translations", new MapProperty()
|
||||
.additionalProperties(new StringProperty()))
|
||||
.required("id")
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("a sample model")
|
||||
cm.vars.size should be(1)
|
||||
|
||||
val vars = cm.vars
|
||||
vars.get(0).baseName should be("translations")
|
||||
vars.get(0).getter should be("getTranslations")
|
||||
vars.get(0).setter should be("setTranslations")
|
||||
vars.get(0).datatype should be("Map<String, String>")
|
||||
vars.get(0).name should be("translations")
|
||||
vars.get(0).defaultValue should be("new HashMap<String, String>()")
|
||||
vars.get(0).baseType should be("Map")
|
||||
vars.get(0).containerType should be("map")
|
||||
vars.get(0).required should equal(null)
|
||||
vars.get(0).isContainer should equal(true)
|
||||
}
|
||||
|
||||
|
||||
it should "convert a model with a map with complex list property" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("translations", new MapProperty()
|
||||
.additionalProperties(
|
||||
new ArrayProperty().items(new RefProperty("Pet")))
|
||||
)
|
||||
.required("id")
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("a sample model")
|
||||
cm.vars.size should be(1)
|
||||
|
||||
val vars = cm.vars
|
||||
vars.get(0).baseName should be("translations")
|
||||
vars.get(0).getter should be("getTranslations")
|
||||
vars.get(0).setter should be("setTranslations")
|
||||
vars.get(0).datatype should be("Map<String, List<Pet>>")
|
||||
vars.get(0).name should be("translations")
|
||||
vars.get(0).defaultValue should be("new HashMap<String, List<Pet>>()")
|
||||
vars.get(0).baseType should be("Map")
|
||||
vars.get(0).containerType should be("map")
|
||||
vars.get(0).required should equal(null)
|
||||
vars.get(0).isContainer should equal(true)
|
||||
}
|
||||
|
||||
it should "convert a model with a 2D list property" in {
|
||||
val model = new ModelImpl().name("sample").property("list2D", new ArrayProperty().items(
|
||||
new ArrayProperty().items(new RefProperty("Pet"))))
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
val vars = cm.vars
|
||||
vars.size should be (1)
|
||||
val list = vars.get(0)
|
||||
list.baseName should be("list2D")
|
||||
list.getter should be("getList2D")
|
||||
list.setter should be("setList2D")
|
||||
list.datatype should be("List<List<Pet>>")
|
||||
list.name should be("list2D")
|
||||
list.defaultValue should be ("new ArrayList<List<Pet>>()")
|
||||
list.baseType should be("List")
|
||||
list.containerType should be("array")
|
||||
list.required should equal(null)
|
||||
list.isContainer should equal(true)
|
||||
}
|
||||
|
||||
it should "convert a model with complex properties" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("children", new RefProperty("#/definitions/Children"))
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("a sample model")
|
||||
cm.vars.size should be(1)
|
||||
|
||||
val vars = cm.vars
|
||||
vars.get(0).baseName should be("children")
|
||||
vars.get(0).getter should be("getChildren")
|
||||
vars.get(0).setter should be("setChildren")
|
||||
vars.get(0).datatype should be("Children")
|
||||
vars.get(0).name should be("children")
|
||||
vars.get(0).defaultValue should be("null")
|
||||
vars.get(0).baseType should be("Children")
|
||||
vars.get(0).required should equal(null)
|
||||
vars.get(0).isNotContainer should equal(true)
|
||||
}
|
||||
|
||||
it should "convert a model with complex list property" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("children", new ArrayProperty()
|
||||
.items(new RefProperty("#/definitions/Children")))
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("a sample model")
|
||||
cm.vars.size should be(1)
|
||||
|
||||
val vars = cm.vars
|
||||
vars.get(0).baseName should be("children")
|
||||
vars.get(0).complexType should be("Children")
|
||||
vars.get(0).getter should be("getChildren")
|
||||
vars.get(0).setter should be("setChildren")
|
||||
vars.get(0).datatype should be("List<Children>")
|
||||
vars.get(0).name should be("children")
|
||||
vars.get(0).defaultValue should be("new ArrayList<Children>()")
|
||||
vars.get(0).baseType should be("List")
|
||||
vars.get(0).containerType should be("array")
|
||||
vars.get(0).required should equal(null)
|
||||
vars.get(0).isContainer should equal(true)
|
||||
}
|
||||
|
||||
it should "convert a model with complex map property" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("children", new MapProperty()
|
||||
.additionalProperties(new RefProperty("#/definitions/Children")))
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("a sample model")
|
||||
cm.vars.size should be(1)
|
||||
(cm.imports.asScala.toSet & Set("Map", "List", "Children")).size should be(3)
|
||||
|
||||
val vars = cm.vars
|
||||
vars.get(0).baseName should be("children")
|
||||
vars.get(0).complexType should be("Children")
|
||||
vars.get(0).getter should be("getChildren")
|
||||
vars.get(0).setter should be("setChildren")
|
||||
vars.get(0).datatype should be("Map<String, Children>")
|
||||
vars.get(0).name should be("children")
|
||||
vars.get(0).defaultValue should be("new HashMap<String, Children>()")
|
||||
vars.get(0).baseType should be("Map")
|
||||
vars.get(0).containerType should be("map")
|
||||
vars.get(0).required should equal(null)
|
||||
vars.get(0).isContainer should equal(true)
|
||||
vars.get(0).isNotContainer should be(null)
|
||||
}
|
||||
|
||||
it should "convert an array model" in {
|
||||
val model = new ArrayModel()
|
||||
.description("an array model")
|
||||
.items(new RefProperty("#/definitions/Children"))
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("an array model")
|
||||
cm.vars.size should be(0)
|
||||
cm.parent should be("ArrayList<Children>")
|
||||
cm.imports.size should be(3)
|
||||
(cm.imports.asScala.toSet & Set("List", "ArrayList", "Children")).size should be(3)
|
||||
}
|
||||
|
||||
it should "convert an map model" in {
|
||||
val model = new ModelImpl()
|
||||
.description("an map model")
|
||||
.additionalProperties(new RefProperty("#/definitions/Children"))
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("an map model")
|
||||
cm.vars.size should be(0)
|
||||
cm.parent should be("HashMap<String, Children>")
|
||||
cm.imports.size should be(3)
|
||||
(cm.imports.asScala.toSet & Set("Map", "HashMap", "Children")).size should be(3)
|
||||
}
|
||||
|
||||
it should "convert a model with upper-case property names" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a model with upper-case property names")
|
||||
.property("NAME", new StringProperty())
|
||||
.required("NAME")
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.vars.size should be(1)
|
||||
|
||||
val vars = cm.vars
|
||||
vars.get(0).baseName should be("NAME")
|
||||
vars.get(0).getter should be("getNAME")
|
||||
vars.get(0).setter should be("setNAME")
|
||||
vars.get(0).datatype should be("String")
|
||||
vars.get(0).name should be("NAME")
|
||||
vars.get(0).defaultValue should be("null")
|
||||
vars.get(0).baseType should be("String")
|
||||
vars.get(0).hasMore should equal(null)
|
||||
vars.get(0).required should equal(true)
|
||||
vars.get(0).isNotContainer should equal(true)
|
||||
}
|
||||
|
||||
it should "convert a model with a 2nd char upper-case property names" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a model with a 2nd char upper-case property names")
|
||||
.property("pId", new StringProperty())
|
||||
.required("pId")
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.vars.size should be(1)
|
||||
|
||||
val vars = cm.vars
|
||||
vars.get(0).baseName should be("pId")
|
||||
vars.get(0).getter should be("getPId")
|
||||
vars.get(0).setter should be("setPId")
|
||||
vars.get(0).datatype should be("String")
|
||||
vars.get(0).name should be("pId")
|
||||
vars.get(0).defaultValue should be("null")
|
||||
vars.get(0).baseType should be("String")
|
||||
vars.get(0).hasMore should equal(null)
|
||||
vars.get(0).required should equal(true)
|
||||
vars.get(0).isNotContainer should equal(true)
|
||||
}
|
||||
|
||||
it should "convert hyphens per issue 503" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("created-at", new DateTimeProperty())
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
val vars = cm.vars
|
||||
vars.get(0).baseName should be("created-at")
|
||||
vars.get(0).getter should be("getCreatedAt")
|
||||
vars.get(0).setter should be("setCreatedAt")
|
||||
vars.get(0).name should be("createdAt")
|
||||
}
|
||||
|
||||
it should "convert query[password] to queryPassword" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("query[password]", new StringProperty())
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
val vars = cm.vars
|
||||
vars.get(0).baseName should be("query[password]")
|
||||
vars.get(0).getter should be("getQueryPassword")
|
||||
vars.get(0).setter should be("setQueryPassword")
|
||||
vars.get(0).name should be("queryPassword")
|
||||
}
|
||||
|
||||
it should "properly escape names per 567" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("created-at", new DateTimeProperty())
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("with.dots", model)
|
||||
val vars = cm.vars
|
||||
cm.classname should be("WithDots")
|
||||
}
|
||||
|
||||
it should "convert a modelwith binary data" in {
|
||||
val model = new ModelImpl()
|
||||
.description("model with binary")
|
||||
.property("inputBinaryData", new ByteArrayProperty());
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
val vars = cm.vars
|
||||
|
||||
vars.get(0).baseName should be ("inputBinaryData")
|
||||
vars.get(0).getter should be ("getInputBinaryData")
|
||||
vars.get(0).setter should be ("setInputBinaryData")
|
||||
vars.get(0).datatype should be ("byte[]")
|
||||
vars.get(0).name should be ("inputBinaryData")
|
||||
vars.get(0).defaultValue should be ("null")
|
||||
vars.get(0).baseType should be ("byte[]")
|
||||
vars.get(0).hasMore should equal (null)
|
||||
vars.get(0).required should equal (null)
|
||||
vars.get(0).isNotContainer should equal (true)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class JavaModelTest2 extends FlatSpec with Matchers {
|
||||
it should "translate an invalid param name" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a model with a 2nd char upper-case property names")
|
||||
.property("_", new StringProperty())
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.vars.size should be(1)
|
||||
|
||||
val vars = cm.vars
|
||||
vars.get(0).baseName should be("_")
|
||||
vars.get(0).getter should be("getU")
|
||||
vars.get(0).setter should be("setU")
|
||||
vars.get(0).datatype should be("String")
|
||||
vars.get(0).name should be("u")
|
||||
vars.get(0).defaultValue should be("null")
|
||||
vars.get(0).baseType should be("String")
|
||||
vars.get(0).hasMore should equal(null)
|
||||
vars.get(0).isNotContainer should equal(true)
|
||||
}
|
||||
|
||||
it should "convert a parameter" in {
|
||||
val parameter = new QueryParameter()
|
||||
.property(
|
||||
new IntegerProperty())
|
||||
.name("limit")
|
||||
.required(true)
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cp = codegen.fromParameter(parameter, null)
|
||||
|
||||
cp.allowableValues should be (null)
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
import io.swagger.parser._
|
||||
import org.junit.runner.RunWith
|
||||
import org.scalatest.{FlatSpec, Matchers}
|
||||
import org.scalatest.junit.JUnitRunner
|
||||
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class SwaggerMigratorTest extends FlatSpec with Matchers {
|
||||
behavior of "SwaggerMigrator"
|
||||
|
||||
it should "read a 1.2 spec" in {
|
||||
val loader = new SwaggerParser()
|
||||
val swagger = loader.read("src/test/resources/1_2/petstore-1.2/api-docs")
|
||||
}
|
||||
}
|
@ -35,44 +35,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>net.alchim31.maven</groupId>
|
||||
<artifactId>scala-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>scala-test-compile</id>
|
||||
<phase>process-test-resources</phase>
|
||||
<goals>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<configuration>
|
||||
<recompileMode>incremental</recompileMode>
|
||||
</configuration>
|
||||
<jvmArgs>
|
||||
<jvmArg>-Xmx384m</jvmArg>
|
||||
</jvmArgs>
|
||||
<args>
|
||||
<arg>-target:jvm-1.6</arg>
|
||||
<arg>-deprecation</arg>
|
||||
</args>
|
||||
<launchers>
|
||||
<launcher>
|
||||
<id>run-scalatest</id>
|
||||
<mainClass>org.scalatest.tools.Runner</mainClass>
|
||||
<args>
|
||||
<arg>-p</arg>
|
||||
<arg>${project.build.testOutputDirectory}</arg>
|
||||
</args>
|
||||
<jvmArgs>
|
||||
<jvmArg>-Xmx512m</jvmArg>
|
||||
</jvmArgs>
|
||||
</launcher>
|
||||
</launchers>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
@ -241,28 +203,8 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.scalatest</groupId>
|
||||
<artifactId>scalatest_2.11</artifactId>
|
||||
<version>${scala-test-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.scala-lang</groupId>
|
||||
<artifactId>scala-library</artifactId>
|
||||
<version>${scala-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.scala-lang</groupId>
|
||||
<artifactId>scala-compiler</artifactId>
|
||||
<version>${scala-version}</version>
|
||||
<scope>test</scope>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
|
@ -0,0 +1,14 @@
|
||||
package io.swagger.generator;
|
||||
|
||||
import io.swagger.generator.model.GeneratorInput;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class GeneratorInputTest {
|
||||
|
||||
@Test(description = "write an object")
|
||||
public void writeObjectTest() {
|
||||
final GeneratorInput generatorInput = new GeneratorInput();
|
||||
generatorInput.setSwaggerUrl("http://petstore.swagger.io/v2/swagger.json");
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
import io.swagger.generator.model._
|
||||
import org.junit.runner.RunWith
|
||||
import org.scalatest.{FlatSpec, Matchers}
|
||||
import org.scalatest.junit.JUnitRunner
|
||||
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class GeneratorInputTest extends FlatSpec with Matchers {
|
||||
it should "write an object" in {
|
||||
val obj = new GeneratorInput()
|
||||
obj.setSwaggerUrl("http://petstore.swagger.io/v2/swagger.json")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user