From ffe12b0620b61ad6a0ca957b3941e07f1f811ac4 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Tue, 29 Dec 2015 23:28:09 -0800 Subject: [PATCH 1/3] added library, date library --- .../codegen/languages/JaxRSServerCodegen.java | 69 ++++++++++++++++++- .../codegen/jaxrs/JaxRSServerOptionsTest.java | 2 + .../options/JaxRSServerOptionsProvider.java | 18 +++++ 3 files changed, 88 insertions(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JaxRSServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JaxRSServerCodegen.java index a91b405d36..53a7bbffca 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JaxRSServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JaxRSServerCodegen.java @@ -9,8 +9,10 @@ import java.io.File; import java.util.*; public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConfig { + protected String dateLibrary = "default"; protected String title = "Swagger Server"; + public static final String DATE_LIBRARY = "dateLibrary"; public JaxRSServerCodegen() { super.processOpts(); @@ -24,7 +26,6 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf apiTemplateFiles.put("apiService.mustache", ".java"); apiTemplateFiles.put("apiServiceImpl.mustache", ".java"); apiTemplateFiles.put("apiServiceFactory.mustache", ".java"); - embeddedTemplateDir = templateDir = "JavaJaxRS"; apiPackage = System.getProperty("swagger.codegen.jaxrs.apipackage", "io.swagger.api"); modelPackage = System.getProperty("swagger.codegen.jaxrs.modelpackage", "io.swagger.model"); @@ -33,6 +34,34 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf additionalProperties.put(CodegenConstants.ARTIFACT_ID, artifactId); additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion); additionalProperties.put("title", title); + + embeddedTemplateDir = templateDir = "JavaJaxRS" + File.separator + "jersey1_18"; + + for(int i = 0; i < cliOptions.size(); i++) { + if(CodegenConstants.LIBRARY.equals(cliOptions.get(i).getOpt())) { + cliOptions.remove(i); + break; + } + } + + CliOption dateLibrary = new CliOption(DATE_LIBRARY, "Option. Date library to use"); + Map dateOptions = new HashMap(); + dateOptions.put("java8", "Java 8 native"); + dateOptions.put("joda", "Joda"); + dateLibrary.setEnum(dateOptions); + + cliOptions.add(dateLibrary); + + CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use"); + library.setDefault(DEFAULT_LIBRARY); + + Map supportedLibraries = new LinkedHashMap(); + + supportedLibraries.put(DEFAULT_LIBRARY, "Jersey core 1.18.1"); +// supportedLibraries.put("jersey2", "Jersey2 core library 2.x"); + library.setEnum(supportedLibraries); + + cliOptions.add(library); } @Override @@ -54,6 +83,10 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf public void processOpts() { super.processOpts(); +// if("jersey2".equals(getLibrary())) { +// embeddedTemplateDir = templateDir = "JavaJaxRS" + File.separator + "jersey2"; +// } + supportingFiles.clear(); supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml")); supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); @@ -68,6 +101,36 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf supportingFiles.add(new SupportingFile("web.mustache", ("src/main/webapp/WEB-INF"), "web.xml")); + if (additionalProperties.containsKey("dateLibrary")) { + setDateLibrary(additionalProperties.get("dateLibrary").toString()); + additionalProperties.put(dateLibrary, "true"); + } + + if("joda".equals(dateLibrary)) { + typeMapping.put("date", "LocalDate"); + typeMapping.put("DateTime", "DateTime"); + + importMapping.put("LocalDate", "org.joda.time.LocalDate"); + importMapping.put("DateTime", "org.joda.time.DateTime"); + + supportingFiles.add(new SupportingFile("JodaDateTimeProvider.mustache", + (sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaDateTimeProvider.java")); + supportingFiles.add(new SupportingFile("JodaLocalDateProvider.mustache", + (sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaLocalDateProvider.java")); + } + else if ("java8".equals(dateLibrary)) { + additionalProperties.put("java8", "true"); + additionalProperties.put("javaVersion", "1.8"); + typeMapping.put("date", "LocalDate"); + typeMapping.put("date-time", "LocalDateTime"); + importMapping.put("LocalDate", "java.time.LocalDate"); + importMapping.put("LocalDateTime", "java.time.LocalDateTime"); + + supportingFiles.add(new SupportingFile("LocalDateTimeProvider.mustache", + (sourceFolder + '/' + apiPackage).replace(".", "/"), "LocalDateTimeProvider.java")); + supportingFiles.add(new SupportingFile("LocalDateProvider.mustache", + (sourceFolder + '/' + apiPackage).replace(".", "/"), "LocalDateProvider.java")); + } } @Override @@ -237,4 +300,8 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf public boolean shouldOverwrite(String filename) { return super.shouldOverwrite(filename) && !filename.endsWith("ServiceImpl.java") && !filename.endsWith("ServiceFactory.java"); } + + public void setDateLibrary(String library) { + this.dateLibrary = library; + } } diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/jaxrs/JaxRSServerOptionsTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/jaxrs/JaxRSServerOptionsTest.java index ac6288b7f1..055bb721ad 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/jaxrs/JaxRSServerOptionsTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/jaxrs/JaxRSServerOptionsTest.java @@ -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; }}; } } diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JaxRSServerOptionsProvider.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JaxRSServerOptionsProvider.java index 0b735363b7..ae68a5dfb8 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JaxRSServerOptionsProvider.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JaxRSServerOptionsProvider.java @@ -1,6 +1,13 @@ package io.swagger.codegen.options; +import com.google.common.collect.ImmutableMap; +import io.swagger.codegen.languages.JaxRSServerCodegen; + +import java.util.Map; + public class JaxRSServerOptionsProvider extends JavaOptionsProvider { + public static final String JODA_DATE_LIBRARY = "joda"; + @Override public boolean isServer() { return true; @@ -10,4 +17,15 @@ public class JaxRSServerOptionsProvider extends JavaOptionsProvider { public String getLanguage() { return "jaxrs"; } + + @Override + public Map createOptions() { + Map options = super.createOptions(); + + ImmutableMap.Builder builder = new ImmutableMap.Builder(); + builder.putAll(options) + .put(JaxRSServerCodegen.DATE_LIBRARY, "joda"); + + return builder.build(); + } } From 29f928d644ff001557084d3be2d3472682d11fb9 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Tue, 29 Dec 2015 23:28:31 -0800 Subject: [PATCH 2/3] prepare for multiple jaxrs libraries --- config-feign.json | 1 - .../{ => jersey1_18}/ApiException.mustache | 0 .../{ => jersey1_18}/ApiOriginFilter.mustache | 0 .../ApiResponseMessage.mustache | 0 .../jersey1_18/JodaDateTimeProvider.mustache | 44 +++++++++++++++++++ .../jersey1_18/JodaLocalDateProvider.mustache | 44 +++++++++++++++++++ .../jersey1_18/LocalDateProvider.mustache | 44 +++++++++++++++++++ .../jersey1_18/LocalDateTimeProvider.mustache | 44 +++++++++++++++++++ .../NotFoundException.mustache | 0 .../{ => jersey1_18}/README.mustache | 0 .../{ => jersey1_18}/allowableValues.mustache | 0 .../JavaJaxRS/{ => jersey1_18}/api.mustache | 0 .../{ => jersey1_18}/apiService.mustache | 0 .../apiServiceFactory.mustache | 0 .../{ => jersey1_18}/apiServiceImpl.mustache | 0 .../{ => jersey1_18}/bodyParams.mustache | 0 .../{ => jersey1_18}/formParams.mustache | 0 .../generatedAnnotation.mustache | 0 .../{ => jersey1_18}/headerParams.mustache | 0 .../JavaJaxRS/{ => jersey1_18}/model.mustache | 0 .../{ => jersey1_18}/pathParams.mustache | 0 .../JavaJaxRS/{ => jersey1_18}/pom.mustache | 0 .../{ => jersey1_18}/project/build.properties | 0 .../{ => jersey1_18}/project/plugins.sbt | 0 .../{ => jersey1_18}/queryParams.mustache | 0 .../{ => jersey1_18}/returnTypes.mustache | 0 .../serviceBodyParams.mustache | 0 .../serviceFormParams.mustache | 0 .../serviceHeaderParams.mustache | 0 .../servicePathParams.mustache | 0 .../serviceQueryParams.mustache | 0 .../JavaJaxRS/{ => jersey1_18}/web.mustache | 0 .../java/jaxrs/AllowableValuesTest.java | 2 +- 33 files changed, 177 insertions(+), 2 deletions(-) delete mode 100644 config-feign.json rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/ApiException.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/ApiOriginFilter.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/ApiResponseMessage.mustache (100%) create mode 100644 modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/JodaDateTimeProvider.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/JodaLocalDateProvider.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/LocalDateProvider.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/LocalDateTimeProvider.mustache rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/NotFoundException.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/README.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/allowableValues.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/api.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/apiService.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/apiServiceFactory.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/apiServiceImpl.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/bodyParams.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/formParams.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/generatedAnnotation.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/headerParams.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/model.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/pathParams.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/pom.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/project/build.properties (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/project/plugins.sbt (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/queryParams.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/returnTypes.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/serviceBodyParams.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/serviceFormParams.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/serviceHeaderParams.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/servicePathParams.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/serviceQueryParams.mustache (100%) rename modules/swagger-codegen/src/main/resources/JavaJaxRS/{ => jersey1_18}/web.mustache (100%) diff --git a/config-feign.json b/config-feign.json deleted file mode 100644 index 3b8c48c3ca..0000000000 --- a/config-feign.json +++ /dev/null @@ -1 +0,0 @@ -{"library":"feign"} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/ApiException.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/ApiException.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/ApiException.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/ApiException.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/ApiOriginFilter.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/ApiOriginFilter.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/ApiOriginFilter.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/ApiOriginFilter.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/ApiResponseMessage.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/ApiResponseMessage.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/ApiResponseMessage.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/ApiResponseMessage.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/JodaDateTimeProvider.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/JodaDateTimeProvider.mustache new file mode 100644 index 0000000000..f942179098 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/JodaDateTimeProvider.mustache @@ -0,0 +1,44 @@ +package {{apiPackage}}; + +import com.sun.jersey.core.spi.component.ComponentContext; +import com.sun.jersey.spi.inject.Injectable; +import com.sun.jersey.spi.inject.PerRequestTypeInjectableProvider; + +import javax.ws.rs.QueryParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.core.UriInfo; +import javax.ws.rs.ext.Provider; +import org.joda.time.DateTime; +import java.util.List; + +@Provider +public class JodaDateTimeProvider extends PerRequestTypeInjectableProvider { + private final UriInfo uriInfo; + + public JodaDateTimeProvider(@Context UriInfo uriInfo) { + super(DateTime.class); + this.uriInfo = uriInfo; + } + + @Override + public Injectable getInjectable(final ComponentContext cc, final QueryParam a) { + return new Injectable() { + @Override + public DateTime getValue() { + final List values = uriInfo.getQueryParameters().get(a.value()); + + if (values == null || values.isEmpty()) + return null; + if (values.size() > 1) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST). + entity(a.value() + " cannot contain multiple values").build()); + } + + return DateTime.parse(values.get(0)); + } + }; + } +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/JodaLocalDateProvider.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/JodaLocalDateProvider.mustache new file mode 100644 index 0000000000..7bd4027e63 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/JodaLocalDateProvider.mustache @@ -0,0 +1,44 @@ +package {{apiPackage}}; + +import com.sun.jersey.core.spi.component.ComponentContext; +import com.sun.jersey.spi.inject.Injectable; +import com.sun.jersey.spi.inject.PerRequestTypeInjectableProvider; + +import javax.ws.rs.QueryParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.core.UriInfo; +import javax.ws.rs.ext.Provider; +import org.joda.time.LocalDate; +import java.util.List; + +@Provider +public class JodaLocalDateProvider extends PerRequestTypeInjectableProvider { + private final UriInfo uriInfo; + + public JodaLocalDateProvider(@Context UriInfo uriInfo) { + super(LocalDate.class); + this.uriInfo = uriInfo; + } + + @Override + public Injectable getInjectable(final ComponentContext cc, final QueryParam a) { + return new Injectable() { + @Override + public LocalDate getValue() { + final List values = uriInfo.getQueryParameters().get(a.value()); + + if (values == null || values.isEmpty()) + return null; + if (values.size() > 1) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST). + entity(a.value() + " cannot contain multiple values").build()); + } + + return LocalDate.parse(values.get(0)); + } + }; + } +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/LocalDateProvider.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/LocalDateProvider.mustache new file mode 100644 index 0000000000..8c4cd4cbd1 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/LocalDateProvider.mustache @@ -0,0 +1,44 @@ +package {{apiPackage}}; + +import com.sun.jersey.core.spi.component.ComponentContext; +import com.sun.jersey.spi.inject.Injectable; +import com.sun.jersey.spi.inject.PerRequestTypeInjectableProvider; + +import javax.ws.rs.QueryParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.core.UriInfo; +import javax.ws.rs.ext.Provider; +import java.time.LocalDate; +import java.util.List; + +@Provider +public class LocalDateProvider extends PerRequestTypeInjectableProvider { + private final UriInfo uriInfo; + + public LocalDateProvider(@Context UriInfo uriInfo) { + super(LocalDate.class); + this.uriInfo = uriInfo; + } + + @Override + public Injectable getInjectable(final ComponentContext cc, final QueryParam a) { + return new Injectable() { + @Override + public LocalDate getValue() { + final List values = uriInfo.getQueryParameters().get(a.value()); + + if (values == null || values.isEmpty()) + return null; + if (values.size() > 1) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST). + entity(a.value() + " cannot contain multiple values").build()); + } + + return LocalDate.parse(values.get(0)); + } + }; + } +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/LocalDateTimeProvider.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/LocalDateTimeProvider.mustache new file mode 100644 index 0000000000..93bb6f19d5 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/LocalDateTimeProvider.mustache @@ -0,0 +1,44 @@ +package {{apiPackage}}; + +import com.sun.jersey.core.spi.component.ComponentContext; +import com.sun.jersey.spi.inject.Injectable; +import com.sun.jersey.spi.inject.PerRequestTypeInjectableProvider; + +import javax.ws.rs.QueryParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.core.UriInfo; +import javax.ws.rs.ext.Provider; +import java.time.LocalDateTime; +import java.util.List; + +@Provider +public class LocalDateTimeProvider extends PerRequestTypeInjectableProvider { + private final UriInfo uriInfo; + + public LocalDateTimeProvider(@Context UriInfo uriInfo) { + super(LocalDateTime.class); + this.uriInfo = uriInfo; + } + + @Override + public Injectable getInjectable(final ComponentContext cc, final QueryParam a) { + return new Injectable() { + @Override + public LocalDateTime getValue() { + final List values = uriInfo.getQueryParameters().get(a.value()); + + if (values == null || values.isEmpty()) + return null; + if (values.size() > 1) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST). + entity(a.value() + " cannot contain multiple values").build()); + } + + return LocalDateTime.parse(values.get(0)); + } + }; + } +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/NotFoundException.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/NotFoundException.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/NotFoundException.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/NotFoundException.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/README.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/README.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/README.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/README.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/allowableValues.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/allowableValues.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/allowableValues.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/allowableValues.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/api.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/api.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/apiService.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/apiService.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/apiService.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/apiService.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/apiServiceFactory.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/apiServiceFactory.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/apiServiceFactory.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/apiServiceFactory.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/apiServiceImpl.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/apiServiceImpl.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/apiServiceImpl.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/apiServiceImpl.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/bodyParams.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/bodyParams.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/bodyParams.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/bodyParams.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/formParams.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/formParams.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/formParams.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/formParams.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/generatedAnnotation.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/generatedAnnotation.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/generatedAnnotation.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/generatedAnnotation.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/headerParams.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/headerParams.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/headerParams.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/headerParams.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/model.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/model.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/model.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/model.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/pathParams.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/pathParams.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/pathParams.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/pathParams.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/pom.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/pom.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/pom.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/pom.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/project/build.properties b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/project/build.properties similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/project/build.properties rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/project/build.properties diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/project/plugins.sbt b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/project/plugins.sbt similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/project/plugins.sbt rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/project/plugins.sbt diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/queryParams.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/queryParams.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/queryParams.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/queryParams.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/returnTypes.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/returnTypes.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/returnTypes.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/returnTypes.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/serviceBodyParams.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/serviceBodyParams.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/serviceBodyParams.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/serviceBodyParams.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/serviceFormParams.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/serviceFormParams.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/serviceFormParams.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/serviceFormParams.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/serviceHeaderParams.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/serviceHeaderParams.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/serviceHeaderParams.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/serviceHeaderParams.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/servicePathParams.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/servicePathParams.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/servicePathParams.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/servicePathParams.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/serviceQueryParams.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/serviceQueryParams.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/serviceQueryParams.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/serviceQueryParams.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/web.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/web.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaJaxRS/web.mustache rename to modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/web.mustache diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/java/jaxrs/AllowableValuesTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/java/jaxrs/AllowableValuesTest.java index ef24287b00..9ae5e6dc3e 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/java/jaxrs/AllowableValuesTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/java/jaxrs/AllowableValuesTest.java @@ -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 { From 405e09a0578755969ebb37c2f1c03148f01fdc6b Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Tue, 29 Dec 2015 23:44:15 -0800 Subject: [PATCH 3/3] added tests --- .../codegen/languages/JaxRSServerCodegen.java | 2 +- .../codegen/jaxrs/JaxrsJava8ModelTest.java | 36 +++++++++++++++++++ .../codegen/jaxrs/JaxrsJodaModelTest.java | 36 +++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 modules/swagger-codegen/src/test/java/io/swagger/codegen/jaxrs/JaxrsJava8ModelTest.java create mode 100644 modules/swagger-codegen/src/test/java/io/swagger/codegen/jaxrs/JaxrsJodaModelTest.java diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JaxRSServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JaxRSServerCodegen.java index 53a7bbffca..10b2ec7720 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JaxRSServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JaxRSServerCodegen.java @@ -122,7 +122,7 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf additionalProperties.put("java8", "true"); additionalProperties.put("javaVersion", "1.8"); typeMapping.put("date", "LocalDate"); - typeMapping.put("date-time", "LocalDateTime"); + typeMapping.put("DateTime", "LocalDateTime"); importMapping.put("LocalDate", "java.time.LocalDate"); importMapping.put("LocalDateTime", "java.time.LocalDateTime"); diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/jaxrs/JaxrsJava8ModelTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/jaxrs/JaxrsJava8ModelTest.java new file mode 100644 index 0000000000..55219787f8 --- /dev/null +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/jaxrs/JaxrsJava8ModelTest.java @@ -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"); + } +} diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/jaxrs/JaxrsJodaModelTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/jaxrs/JaxrsJodaModelTest.java new file mode 100644 index 0000000000..3f2ac1a9ec --- /dev/null +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/jaxrs/JaxrsJodaModelTest.java @@ -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"); + } +}