Merge remote-tracking branch 'upstream/master' into fix-cli-options

Conflicts:
	modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JaxRSServerCodegen.java
	modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JaxRSServerOptionsProvider.java
This commit is contained in:
evigeant
2016-01-28 12:11:14 -05:00
142 changed files with 5810 additions and 540 deletions

View File

@@ -0,0 +1,99 @@
package io.swagger.codegen.csharp;
import io.swagger.codegen.CodegenModel;
import io.swagger.codegen.CodegenProperty;
import io.swagger.codegen.DefaultCodegen;
import io.swagger.codegen.languages.CSharpClientCodegen;
import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.LongProperty;
import io.swagger.models.properties.StringProperty;
import org.testng.Assert;
import org.testng.annotations.Test;
@SuppressWarnings("static-method")
public class CSharpModelTest {
@Test(description = "convert a model with array property to default List<T>")
public void arrayPropertyTest() {
final Model model = getArrayTestModel();
final DefaultCodegen codegen = new CSharpClientCodegen();
final CodegenModel generated = codegen.fromModel("sample", model);
Assert.assertEquals(generated.name, "sample");
Assert.assertEquals(generated.classname, "Sample");
Assert.assertEquals(generated.description, "a sample model");
Assert.assertEquals(generated.vars.size(), 2);
final CodegenProperty property = generated.vars.get(1);
Assert.assertEquals(property.baseName, "examples");
Assert.assertEquals(property.getter, "getExamples");
Assert.assertEquals(property.setter, "setExamples");
Assert.assertEquals(property.datatype, "List<string>");
Assert.assertEquals(property.name, "Examples");
Assert.assertEquals(property.defaultValue, null);
Assert.assertEquals(property.baseType, "List");
Assert.assertEquals(property.containerType, "array");
Assert.assertNull(property.required);
Assert.assertTrue(property.isContainer);
}
@Test(description = "convert a model with array property to Collection<T>")
public void arrayPropertyCollectionOptionTest() {
final Model model = getArrayTestModel();
final CSharpClientCodegen codegen = new CSharpClientCodegen();
codegen.setUseCollection(true);
final CodegenModel generated = codegen.fromModel("sample", model);
Assert.assertEquals(generated.name, "sample");
Assert.assertEquals(generated.vars.size(), 2);
final CodegenProperty property = generated.vars.get(1);
Assert.assertEquals(property.baseName, "examples");
Assert.assertEquals(property.name, "Examples");
Assert.assertEquals(property.defaultValue, null);
Assert.assertEquals(property.datatype, "Collection<string>");
Assert.assertEquals(property.baseType, "Collection");
Assert.assertEquals(property.containerType, "array");
Assert.assertNull(property.required);
Assert.assertTrue(property.isContainer);
}
@Test(description = "convert a model with array property to Collection<T>")
public void arrayPropertyICollectionOptionTest() {
final Model model = getArrayTestModel();
final CSharpClientCodegen codegen = new CSharpClientCodegen();
codegen.setUseCollection(true);
codegen.setReturnICollection(true);
final CodegenModel generated = codegen.fromModel("sample", model);
Assert.assertEquals(generated.name, "sample");
Assert.assertEquals(generated.vars.size(), 2);
final CodegenProperty property = generated.vars.get(1);
Assert.assertEquals(property.baseName, "examples");
Assert.assertEquals(property.name, "Examples");
Assert.assertEquals(property.datatype, "Collection<string>",
"returnICollection option should not modify property datatype");
Assert.assertEquals(property.defaultValue, null);
Assert.assertEquals(property.baseType, "Collection",
"returnICollection option should not modify property baseType");
Assert.assertEquals(property.containerType, "array");
Assert.assertNull(property.required);
Assert.assertTrue(property.isContainer);
}
private Model getArrayTestModel() {
return new ModelImpl()
.description("a sample model")
.property("id", new LongProperty())
.property("examples", new ArrayProperty().items(new StringProperty()))
.required("id");
}
}

View File

@@ -45,7 +45,7 @@ public class JavaInflectorServerOptionsTest extends JavaClientOptionsTest {
times = 1;
clientCodegen.setSerializableModel(Boolean.valueOf(JavaInflectorServerOptionsProvider.SERIALIZABLE_MODEL_VALUE));
times = 1;
clientCodegen.setLibrary(JavaInflectorServerOptionsProvider.LIBRARY_VALUE);
clientCodegen.setLibrary(JavaInflectorServerOptionsProvider.DEFAULT_LIBRARY_VALUE);
times = 1;
clientCodegen.setFullJavaUtil(Boolean.valueOf(JavaInflectorServerOptionsProvider.FULL_JAVA_UTIL_VALUE));
times = 1;

View File

@@ -51,7 +51,7 @@ public class JavaClientOptionsTest extends AbstractOptionsTest {
times = 1;
clientCodegen.setSerializableModel(Boolean.valueOf(JavaOptionsProvider.SERIALIZABLE_MODEL_VALUE));
times = 1;
clientCodegen.setLibrary(JavaOptionsProvider.LIBRARY_VALUE);
clientCodegen.setLibrary(JavaOptionsProvider.DEFAULT_LIBRARY_VALUE);
times = 1;
clientCodegen.setFullJavaUtil(Boolean.valueOf(JavaOptionsProvider.FULL_JAVA_UTIL_VALUE));
times = 1;

View File

@@ -2,7 +2,7 @@ package io.swagger.codegen.jaxrs;
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.java.JavaClientOptionsTest;
import io.swagger.codegen.languages.JaxRSServerCodegen;
import io.swagger.codegen.languages.JavaJerseyServerCodegen;
import io.swagger.codegen.options.JaxRSServerOptionsProvider;
import mockit.Expectations;
@@ -11,7 +11,7 @@ import mockit.Tested;
public class JaxRSServerOptionsTest extends JavaClientOptionsTest {
@Tested
private JaxRSServerCodegen clientCodegen;
private JavaJerseyServerCodegen clientCodegen;
public JaxRSServerOptionsTest() {
super(new JaxRSServerOptionsProvider());
@@ -46,7 +46,7 @@ public class JaxRSServerOptionsTest extends JavaClientOptionsTest {
times = 1;
clientCodegen.setSerializableModel(Boolean.valueOf(JaxRSServerOptionsProvider.SERIALIZABLE_MODEL_VALUE));
times = 1;
clientCodegen.setLibrary(JaxRSServerOptionsProvider.LIBRARY_VALUE);
clientCodegen.setLibrary(JaxRSServerOptionsProvider.DEFAULT_LIBRARY_VALUE);
times = 1;
clientCodegen.setFullJavaUtil(Boolean.valueOf(JaxRSServerOptionsProvider.FULL_JAVA_UTIL_VALUE));
times = 1;

View File

@@ -2,7 +2,7 @@ package io.swagger.codegen.jaxrs;
import io.swagger.codegen.CodegenModel;
import io.swagger.codegen.languages.JaxRSServerCodegen;
import io.swagger.codegen.languages.JavaJerseyServerCodegen;
import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
import io.swagger.models.properties.DateProperty;
@@ -26,7 +26,7 @@ public class JaxrsJava8ModelTest {
.required("id")
.required("name");
final JaxRSServerCodegen codegen = new JaxRSServerCodegen();
final JavaJerseyServerCodegen codegen = new JavaJerseyServerCodegen();
codegen.setDateLibrary("java8");
codegen.processOpts();
final CodegenModel cm = codegen.fromModel("sample", model);

View File

@@ -1,7 +1,7 @@
package io.swagger.codegen.jaxrs;
import io.swagger.codegen.CodegenModel;
import io.swagger.codegen.languages.JaxRSServerCodegen;
import io.swagger.codegen.languages.JavaJerseyServerCodegen;
import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
import io.swagger.models.properties.DateProperty;
@@ -25,7 +25,7 @@ public class JaxrsJodaModelTest {
.required("id")
.required("name");
final JaxRSServerCodegen codegen = new JaxRSServerCodegen();
final JavaJerseyServerCodegen codegen = new JavaJerseyServerCodegen();
codegen.setDateLibrary("joda");
codegen.processOpts();
final CodegenModel cm = codegen.fromModel("sample", model);

View File

@@ -1,5 +1,6 @@
package io.swagger.codegen.options;
import io.swagger.codegen.Codegen;
import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.languages.JavaClientCodegen;
@@ -17,15 +18,19 @@ public class JavaOptionsProvider implements OptionsProvider {
public static final String ARTIFACT_VERSION_VALUE = "1.0.0-SNAPSHOT";
public static final String SOURCE_FOLDER_VALUE = "src/main/java/test";
public static final String LOCAL_PREFIX_VALUE = "tst";
public static final String LIBRARY_VALUE = "jersey2";
public static final String DEFAULT_LIBRARY_VALUE = "jersey2";
public static final String SERIALIZABLE_MODEL_VALUE = "false";
public static final String FULL_JAVA_UTIL_VALUE = "true";
public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true";
@Override
public Map<String, String> createOptions() {
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
return builder.put(CodegenConstants.MODEL_PACKAGE, MODEL_PACKAGE_VALUE)
private ImmutableMap<String, String> options;
/**
* Create an options provider with the default options.
*/
public JavaOptionsProvider() {
options = new ImmutableMap.Builder<String, String>()
.put(CodegenConstants.MODEL_PACKAGE, MODEL_PACKAGE_VALUE)
.put(CodegenConstants.API_PACKAGE, API_PACKAGE_VALUE)
.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE)
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE)
@@ -37,12 +42,28 @@ public class JavaOptionsProvider implements OptionsProvider {
.put(CodegenConstants.LOCAL_VARIABLE_PREFIX, LOCAL_PREFIX_VALUE)
.put(CodegenConstants.SERIALIZABLE_MODEL, SERIALIZABLE_MODEL_VALUE)
.put(JavaClientCodegen.FULL_JAVA_UTIL, FULL_JAVA_UTIL_VALUE)
.put(CodegenConstants.LIBRARY, LIBRARY_VALUE)
.put(CodegenConstants.LIBRARY, DEFAULT_LIBRARY_VALUE)
.put(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING, "true")
.put(JavaClientCodegen.USE_RX_JAVA, "false")
.put(JavaClientCodegen.DATE_LIBRARY, "joda")
.build();
}
/**
* Use the default options, but override the ones found in additionalOptions.
*/
public JavaOptionsProvider(Map<String, String> additionalOptions) {
options = new ImmutableMap.Builder<String, String>()
.putAll(options)
.putAll(additionalOptions)
.build();
}
@Override
public Map<String, String> createOptions() {
return options;
}
@Override
public boolean isServer() {
return false;

View File

@@ -26,6 +26,7 @@ public class JaxRSServerOptionsProvider extends JavaOptionsProvider {
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
builder.putAll(options)
.put(CodegenConstants.IMPL_FOLDER, IMPL_FOLDER_VALUE)
//.put(JavaJaxRSJersey1ServerCodegen.DATE_LIBRARY, "joda") //java.lang.IllegalArgumentException: Multiple entries with same key: dateLibrary=joda and dateLibrary=joda
.put("title", "Test title");
return builder.build();

View File

@@ -9,6 +9,7 @@ import java.util.Map;
public class TypeScriptAngularClientOptionsProvider implements OptionsProvider {
public static final String SORT_PARAMS_VALUE = "false";
public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true";
public static final String MODEL_PROPERTY_NAMING_VALUE = "camelCase";
@Override
public String getLanguage() {
@@ -20,6 +21,7 @@ public class TypeScriptAngularClientOptionsProvider implements OptionsProvider {
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
return builder.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE)
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE)
.put(CodegenConstants.MODEL_PROPERTY_NAMING, MODEL_PROPERTY_NAMING_VALUE)
.build();
}

View File

@@ -9,6 +9,7 @@ import java.util.Map;
public class TypeScriptNodeClientOptionsProvider implements OptionsProvider {
public static final String SORT_PARAMS_VALUE = "false";
public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true";
public static final String MODEL_PROPERTY_NAMING_VALUE = "camelCase";
@Override
public String getLanguage() {
@@ -20,6 +21,7 @@ public class TypeScriptNodeClientOptionsProvider implements OptionsProvider {
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
return builder.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE)
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE)
.put(CodegenConstants.MODEL_PROPERTY_NAMING, MODEL_PROPERTY_NAMING_VALUE)
.build();
}

View File

@@ -28,6 +28,8 @@ public class TypeScriptAngularClientOptionsTest extends AbstractOptionsTest {
new Expectations(clientCodegen) {{
clientCodegen.setSortParamsByRequiredFlag(Boolean.valueOf(TypeScriptAngularClientOptionsProvider.SORT_PARAMS_VALUE));
times = 1;
clientCodegen.setModelPropertyNaming(TypeScriptAngularClientOptionsProvider.MODEL_PROPERTY_NAMING_VALUE);
times = 1;
}};
}
}

View File

@@ -28,6 +28,8 @@ public class TypeScriptNodeClientOptionsTest extends AbstractOptionsTest {
new Expectations(clientCodegen) {{
clientCodegen.setSortParamsByRequiredFlag(Boolean.valueOf(TypeScriptNodeClientOptionsProvider.SORT_PARAMS_VALUE));
times = 1;
clientCodegen.setModelPropertyNaming(TypeScriptNodeClientOptionsProvider.MODEL_PROPERTY_NAMING_VALUE);
times = 1;
}};
}
}