From 13d350be2e37c2d6fc0c04236d7f5961870240c6 Mon Sep 17 00:00:00 2001 From: xhh Date: Tue, 23 Jun 2015 21:23:48 +0800 Subject: [PATCH] Fix warnings and upgrade jersey for Scala client * Upgrade jersey to latest version (from 1.7 to 1.19) * Replace getClientResponseStatus() with getStatusInfo() * Fix the following maven warnings and model import warnings [WARNING] 'build.plugins.plugin.version' for org.codehaus.mojo:build-helper-maven-plugin is missing. @ line 72, column 15 [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [WARNING] Expected all dependencies to require Scala version: 2.10.4 [WARNING] com.fasterxml.jackson.module:jackson-module-scala_2.10:2.4.2 requires scala version: 2.10.4 [WARNING] org.scala-lang:scala-reflect:2.10.4 requires scala version: 2.10.4 [WARNING] io.swagger:swagger-scala-client:1.0.0 requires scala version: 2.10.4 [WARNING] org.scalatest:scalatest_2.10:2.1.3 requires scala version: 2.10.3 [WARNING] Multiple versions of scala libraries detected! [WARNING] /Users/xhh/projects/swagger-codegen/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Pet.scala:3: warning: imported `Category' is permanently hidden by definition of object Category in package model --- .../codegen/languages/ScalaClientCodegen.java | 16 ++++++++++++++++ .../src/main/resources/scala/apiInvoker.mustache | 7 +++---- .../src/main/resources/scala/pom.mustache | 7 +++++-- samples/client/petstore/scala/pom.xml | 7 +++++-- .../scala/io/swagger/client/ApiInvoker.scala | 7 +++---- .../main/scala/io/swagger/client/model/Pet.scala | 2 -- 6 files changed, 32 insertions(+), 14 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ScalaClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ScalaClientCodegen.java index d8c143aad1d..6ad296a0210 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ScalaClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ScalaClientCodegen.java @@ -20,6 +20,9 @@ import java.io.File; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig { protected String invokerPackage = "io.swagger.client"; @@ -214,4 +217,17 @@ public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig return camelize(operationId, true); } + @Override + public Map postProcessModels(Map objs) { + // remove model imports to avoid warnings for importing class in the same package in Scala + List> imports = (List>) objs.get("imports"); + final String prefix = modelPackage() + "."; + Iterator> iterator = imports.iterator(); + while (iterator.hasNext()) { + String _import = iterator.next().get("import"); + if (_import.startsWith(prefix)) iterator.remove(); + } + return objs; + } + } diff --git a/modules/swagger-codegen/src/main/resources/scala/apiInvoker.mustache b/modules/swagger-codegen/src/main/resources/scala/apiInvoker.mustache index f432c2dc59e..9c2e9c073cd 100644 --- a/modules/swagger-codegen/src/main/resources/scala/apiInvoker.mustache +++ b/modules/swagger-codegen/src/main/resources/scala/apiInvoker.mustache @@ -141,7 +141,7 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, } case _ => null } - response.getClientResponseStatus().getStatusCode() match { + response.getStatusInfo().getStatusCode() match { case 204 => "" case code: Int if (Range(200, 299).contains(code)) => { response.hasEntity() match { @@ -155,7 +155,7 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, case false => "no data" } throw new ApiException( - response.getClientResponseStatus().getStatusCode(), + response.getStatusInfo().getStatusCode(), entity) } } @@ -172,7 +172,7 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, } } } - + def newClient(host: String): Client = asyncHttpClient match { case true => { import org.sonatype.spice.jersey.client.ahc.config.DefaultAhcConfig @@ -200,4 +200,3 @@ object ApiInvoker extends ApiInvoker(mapper = ScalaJsonUtil.getJsonMapper, authPreemptive = {{authPreemptive}}) class ApiException(val code: Int, msg: String) extends RuntimeException(msg) - diff --git a/modules/swagger-codegen/src/main/resources/scala/pom.mustache b/modules/swagger-codegen/src/main/resources/scala/pom.mustache index 2d8a1257eb4..c6fe4a1f356 100644 --- a/modules/swagger-codegen/src/main/resources/scala/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/scala/pom.mustache @@ -72,6 +72,7 @@ org.codehaus.mojo build-helper-maven-plugin + 1.9.1 add_sources @@ -208,7 +209,7 @@ 2.10.4 1.2 2.2 - 1.7 + 1.19 1.5.0 1.0.5 1.0.0 @@ -216,6 +217,8 @@ 4.8.1 3.1.5 - 2.1.3 + 2.2.4 + + UTF-8 diff --git a/samples/client/petstore/scala/pom.xml b/samples/client/petstore/scala/pom.xml index 7e56a41c890..9f39f4e45ce 100644 --- a/samples/client/petstore/scala/pom.xml +++ b/samples/client/petstore/scala/pom.xml @@ -72,6 +72,7 @@ org.codehaus.mojo build-helper-maven-plugin + 1.9.1 add_sources @@ -208,7 +209,7 @@ 2.10.4 1.2 2.2 - 1.7 + 1.19 1.5.0 1.0.5 1.0.0 @@ -216,6 +217,8 @@ 4.8.1 3.1.5 - 2.1.3 + 2.2.4 + + UTF-8 diff --git a/samples/client/petstore/scala/src/main/scala/io/swagger/client/ApiInvoker.scala b/samples/client/petstore/scala/src/main/scala/io/swagger/client/ApiInvoker.scala index 91ab98471e9..1f9d3c012d5 100644 --- a/samples/client/petstore/scala/src/main/scala/io/swagger/client/ApiInvoker.scala +++ b/samples/client/petstore/scala/src/main/scala/io/swagger/client/ApiInvoker.scala @@ -141,7 +141,7 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, } case _ => null } - response.getClientResponseStatus().getStatusCode() match { + response.getStatusInfo().getStatusCode() match { case 204 => "" case code: Int if (Range(200, 299).contains(code)) => { response.hasEntity() match { @@ -155,7 +155,7 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, case false => "no data" } throw new ApiException( - response.getClientResponseStatus().getStatusCode(), + response.getStatusInfo().getStatusCode(), entity) } } @@ -172,7 +172,7 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, } } } - + def newClient(host: String): Client = asyncHttpClient match { case true => { import org.sonatype.spice.jersey.client.ahc.config.DefaultAhcConfig @@ -200,4 +200,3 @@ object ApiInvoker extends ApiInvoker(mapper = ScalaJsonUtil.getJsonMapper, authPreemptive = false) class ApiException(val code: Int, msg: String) extends RuntimeException(msg) - diff --git a/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Pet.scala b/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Pet.scala index 430f6a3659c..30dc8750976 100644 --- a/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Pet.scala +++ b/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Pet.scala @@ -1,7 +1,5 @@ package io.swagger.client.model -import io.swagger.client.model.Category -import io.swagger.client.model.Tag