forked from loafle/openapi-generator-original
Merge branch 'master' into feature/jaxrs-no-sys-property
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:
@@ -51,6 +51,7 @@ public abstract class AbstractOptionsTest {
|
||||
|
||||
private Function<CliOption, String> getCliOptionTransformer() {
|
||||
return new Function<CliOption, String>() {
|
||||
@Override
|
||||
public String apply(CliOption option) {
|
||||
return option.getOpt();
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ public class CodegenTest {
|
||||
final Swagger model = parseAndPrepareSwagger("src/test/resources/2_0/requiredTest.json");
|
||||
|
||||
final DefaultCodegen codegen = new DefaultCodegen() {
|
||||
@Override
|
||||
public String getSwaggerType(Property p) {
|
||||
if (p != null && !p.getRequired()) {
|
||||
return "Optional<" + super.getSwaggerType(p) + ">";
|
||||
|
||||
@@ -73,6 +73,7 @@ public class InlineModelResolverTest {
|
||||
ModelImpl model = (ModelImpl)swagger.getDefinitions().get("inline_response_200");
|
||||
assertTrue(model.getProperties().size() == 1);
|
||||
assertNotNull(model.getProperties().get("name"));
|
||||
assertTrue(model.getProperties().get("name") instanceof StringProperty);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -174,13 +175,30 @@ public class InlineModelResolverTest {
|
||||
|
||||
ArrayModel am = (ArrayModel) schema;
|
||||
Property inner = am.getItems();
|
||||
assertTrue(inner instanceof RefProperty);
|
||||
|
||||
ObjectProperty op = (ObjectProperty) inner;
|
||||
Property name = op.getProperties().get("address");
|
||||
assertTrue(name instanceof RefProperty);
|
||||
RefProperty rp = (RefProperty) inner;
|
||||
|
||||
assertEquals(rp.getType(), "ref");
|
||||
assertEquals(rp.get$ref(), "#/definitions/body");
|
||||
assertEquals(rp.getSimpleRef(), "body");
|
||||
|
||||
Model model = swagger.getDefinitions().get("hello_address");
|
||||
assertNotNull(model);
|
||||
Model inline = swagger.getDefinitions().get("body");
|
||||
assertNotNull(inline);
|
||||
assertTrue(inline instanceof ModelImpl);
|
||||
ModelImpl impl = (ModelImpl) inline;
|
||||
RefProperty rpAddress = (RefProperty) impl.getProperties().get("address");
|
||||
assertNotNull(rpAddress);
|
||||
assertEquals(rpAddress.getType(), "ref");
|
||||
assertEquals(rpAddress.get$ref(), "#/definitions/hello_address");
|
||||
assertEquals(rpAddress.getSimpleRef(), "hello_address");
|
||||
|
||||
Model inlineProp = swagger.getDefinitions().get("hello_address");
|
||||
assertNotNull(inlineProp);
|
||||
assertTrue(inlineProp instanceof ModelImpl);
|
||||
ModelImpl implProp = (ModelImpl) inlineProp;
|
||||
assertNotNull(implProp.getProperties().get("street"));
|
||||
assertTrue(implProp.getProperties().get("street") instanceof StringProperty);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -213,9 +231,17 @@ public class InlineModelResolverTest {
|
||||
|
||||
assertNotNull(p);
|
||||
|
||||
ObjectProperty innerModel = (ObjectProperty) p;
|
||||
assertTrue(innerModel.getProperties().size() == 1);
|
||||
assertNotNull(innerModel.getProperties().get("name"));
|
||||
RefProperty rp = (RefProperty) p;
|
||||
assertEquals(rp.getType(), "ref");
|
||||
assertEquals(rp.get$ref(), "#/definitions/inline_response_200");
|
||||
assertEquals(rp.getSimpleRef(), "inline_response_200");
|
||||
|
||||
Model inline = swagger.getDefinitions().get("inline_response_200");
|
||||
assertNotNull(inline);
|
||||
assertTrue(inline instanceof ModelImpl);
|
||||
ModelImpl impl = (ModelImpl) inline;
|
||||
assertNotNull(impl.getProperties().get("name"));
|
||||
assertTrue(impl.getProperties().get("name") instanceof StringProperty);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -258,20 +284,15 @@ public class InlineModelResolverTest {
|
||||
new InlineModelResolver().flatten(swagger);
|
||||
|
||||
Response response = swagger.getPaths().get("/foo/baz").getGet().getResponses().get("200");
|
||||
|
||||
Property property = response.getSchema();
|
||||
assertTrue(property instanceof RefProperty);
|
||||
assertTrue(property instanceof MapProperty);
|
||||
assertTrue(swagger.getDefinitions().size() == 1);
|
||||
|
||||
Model inline = swagger.getDefinitions().get("inline_response_200");
|
||||
assertTrue(inline instanceof ModelImpl);
|
||||
ModelImpl impl = (ModelImpl) inline;
|
||||
|
||||
Property innerProperty = impl.getAdditionalProperties();
|
||||
assertTrue(innerProperty instanceof ObjectProperty);
|
||||
|
||||
ObjectProperty obj = (ObjectProperty) innerProperty;
|
||||
Property name = obj.getProperties().get("name");
|
||||
assertTrue(name instanceof StringProperty);
|
||||
assertNotNull(impl.getProperties().get("name"));
|
||||
assertTrue(impl.getProperties().get("name") instanceof StringProperty);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -295,10 +316,17 @@ public class InlineModelResolverTest {
|
||||
|
||||
ArrayProperty am = (ArrayProperty) response.getSchema();
|
||||
Property items = am.getItems();
|
||||
assertTrue(items instanceof ObjectProperty);
|
||||
ObjectProperty op = (ObjectProperty) items;
|
||||
Property name = op.getProperties().get("name");
|
||||
assertTrue(name instanceof StringProperty);
|
||||
assertTrue(items instanceof RefProperty);
|
||||
RefProperty rp = (RefProperty) items;
|
||||
assertEquals(rp.getType(), "ref");
|
||||
assertEquals(rp.get$ref(), "#/definitions/inline_response_200");
|
||||
assertEquals(rp.getSimpleRef(), "inline_response_200");
|
||||
|
||||
Model inline = swagger.getDefinitions().get("inline_response_200");
|
||||
assertTrue(inline instanceof ModelImpl);
|
||||
ModelImpl impl = (ModelImpl) inline;
|
||||
assertNotNull(impl.getProperties().get("name"));
|
||||
assertTrue(impl.getProperties().get("name") instanceof StringProperty);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -4,8 +4,6 @@ import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.java.JavaClientOptionsTest;
|
||||
import io.swagger.codegen.languages.JavaInflectorServerCodegen;
|
||||
import io.swagger.codegen.options.JavaInflectorServerOptionsProvider;
|
||||
import io.swagger.codegen.options.JavaOptionsProvider;
|
||||
|
||||
import mockit.Expectations;
|
||||
import mockit.Tested;
|
||||
|
||||
@@ -50,6 +48,8 @@ public class JavaInflectorServerOptionsTest extends JavaClientOptionsTest {
|
||||
times = 1;
|
||||
clientCodegen.setFullJavaUtil(Boolean.valueOf(JavaInflectorServerOptionsProvider.FULL_JAVA_UTIL_VALUE));
|
||||
times = 1;
|
||||
clientCodegen.setSerializeBigDecimalAsString(true);
|
||||
times = 1;
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,11 @@ 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;
|
||||
|
||||
@@ -83,7 +81,7 @@ public class JavaModelEnumTest {
|
||||
Assert.assertEquals(cm.name, "sample");
|
||||
Assert.assertEquals(cm.classname, "Sample");
|
||||
Assert.assertEquals(cm.parent, "ParentModel");
|
||||
Assert.assertEquals(cm.imports, Collections.singletonList("ParentModel"));
|
||||
Assert.assertTrue(cm.imports.contains("ParentModel"));
|
||||
|
||||
// Assert that only the unshared/uninherited enum remains
|
||||
Assert.assertEquals(cm.vars.size(), 1);
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class AllowableValuesTest {
|
||||
|
||||
private static final String TEMPLATE_FILE = "JavaJaxRS/allowableValues.mustache";
|
||||
private static final String TEMPLATE_FILE = "JavaJaxRS/jersey1_18/allowableValues.mustache";
|
||||
private static final String PROVIDER_NAME = "operations";
|
||||
|
||||
private static String loadClassResource(Class<?> cls, String name) throws IOException {
|
||||
|
||||
@@ -49,6 +49,8 @@ public class JaxRSServerOptionsTest extends JavaClientOptionsTest {
|
||||
times = 1;
|
||||
clientCodegen.setFullJavaUtil(Boolean.valueOf(JaxRSServerOptionsProvider.FULL_JAVA_UTIL_VALUE));
|
||||
times = 1;
|
||||
clientCodegen.setDateLibrary("joda");
|
||||
times = 1;
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package io.swagger.codegen.jaxrs;
|
||||
|
||||
import io.swagger.codegen.CodegenModel;
|
||||
import io.swagger.codegen.languages.JaxRSServerCodegen;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.ModelImpl;
|
||||
import io.swagger.models.properties.DateProperty;
|
||||
import io.swagger.models.properties.DateTimeProperty;
|
||||
import io.swagger.models.properties.LongProperty;
|
||||
import io.swagger.util.Json;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
public class JaxrsJava8ModelTest {
|
||||
@Test(description = "convert a simple java model with java8 types")
|
||||
public void simpleModelTest() {
|
||||
final Model model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("id", new LongProperty())
|
||||
.property("theDate", new DateProperty())
|
||||
.property("createdAt", new DateTimeProperty())
|
||||
.required("id")
|
||||
.required("name");
|
||||
|
||||
final JaxRSServerCodegen codegen = new JaxRSServerCodegen();
|
||||
codegen.setDateLibrary("java8");
|
||||
codegen.processOpts();
|
||||
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||
|
||||
Json.prettyPrint(cm);
|
||||
assertEquals(cm.vars.get(0).datatype, "Long");
|
||||
assertEquals(cm.vars.get(1).datatype, "LocalDate");
|
||||
assertEquals(cm.vars.get(2).datatype, "LocalDateTime");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package io.swagger.codegen.jaxrs;
|
||||
|
||||
import io.swagger.codegen.CodegenModel;
|
||||
import io.swagger.codegen.languages.JaxRSServerCodegen;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.ModelImpl;
|
||||
import io.swagger.models.properties.DateProperty;
|
||||
import io.swagger.models.properties.DateTimeProperty;
|
||||
import io.swagger.models.properties.LongProperty;
|
||||
import io.swagger.util.Json;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
public class JaxrsJodaModelTest {
|
||||
@Test(description = "convert a simple java model with Joda types")
|
||||
public void simpleModelTest() {
|
||||
final Model model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("id", new LongProperty())
|
||||
.property("theDate", new DateProperty())
|
||||
.property("createdAt", new DateTimeProperty())
|
||||
.required("id")
|
||||
.required("name");
|
||||
|
||||
final JaxRSServerCodegen codegen = new JaxRSServerCodegen();
|
||||
codegen.setDateLibrary("joda");
|
||||
codegen.processOpts();
|
||||
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||
|
||||
Json.prettyPrint(cm);
|
||||
assertEquals(cm.vars.get(0).datatype, "Long");
|
||||
assertEquals(cm.vars.get(1).datatype, "LocalDate");
|
||||
assertEquals(cm.vars.get(2).datatype, "DateTime");
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@ public class JavaOptionsProvider implements OptionsProvider {
|
||||
.put(CodegenConstants.SERIALIZABLE_MODEL, SERIALIZABLE_MODEL_VALUE)
|
||||
.put(JavaClientCodegen.FULL_JAVA_UTIL, FULL_JAVA_UTIL_VALUE)
|
||||
.put(CodegenConstants.LIBRARY, LIBRARY_VALUE)
|
||||
.put(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING, "true")
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,14 @@
|
||||
package io.swagger.codegen.options;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.swagger.codegen.languages.JaxRSServerCodegen;
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
|
||||
public class JaxRSServerOptionsProvider extends JavaOptionsProvider {
|
||||
public static final String IMPL_FOLDER_VALUE = "src/main/java/impl";
|
||||
|
||||
@Override
|
||||
public Map<String, String> createOptions() {
|
||||
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
|
||||
return builder.putAll(super.createOptions())
|
||||
.put(CodegenConstants.IMPL_FOLDER, IMPL_FOLDER_VALUE)
|
||||
.build();
|
||||
}
|
||||
public static final String JODA_DATE_LIBRARY = "joda";
|
||||
public static final String IMPL_FOLDER_VALUE = "src/main/java/impl";
|
||||
|
||||
@Override
|
||||
public boolean isServer() {
|
||||
@@ -26,4 +19,16 @@ public class JaxRSServerOptionsProvider extends JavaOptionsProvider {
|
||||
public String getLanguage() {
|
||||
return "jaxrs";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> createOptions() {
|
||||
Map<String, String> options = super.createOptions();
|
||||
|
||||
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
|
||||
builder.putAll(options)
|
||||
.put(CodegenConstants.IMPL_FOLDER, IMPL_FOLDER_VALUE)
|
||||
.put(JaxRSServerCodegen.DATE_LIBRARY, "joda");
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.swagger.codegen.options;
|
||||
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.languages.SpringMVCServerCodegen;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -7,6 +8,7 @@ import java.util.Map;
|
||||
|
||||
public class SpringMVCServerOptionsProvider extends JavaOptionsProvider {
|
||||
public static final String CONFIG_PACKAGE_VALUE = "configPackage";
|
||||
public static final String LIBRARY_VALUE = "j8-async";
|
||||
|
||||
@Override
|
||||
public String getLanguage() {
|
||||
@@ -17,6 +19,7 @@ public class SpringMVCServerOptionsProvider extends JavaOptionsProvider {
|
||||
public Map<String, String> createOptions() {
|
||||
Map<String, String> options = new HashMap<String, String>(super.createOptions());
|
||||
options.put(SpringMVCServerCodegen.CONFIG_PACKAGE, CONFIG_PACKAGE_VALUE);
|
||||
options.put(CodegenConstants.LIBRARY, LIBRARY_VALUE);
|
||||
return options;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user