diff --git a/AutoRest/Generators/Java/Azure.Java/TemplateModels/AzureMethodTemplateModel.cs b/AutoRest/Generators/Java/Azure.Java/TemplateModels/AzureMethodTemplateModel.cs index 6e368ecfc2a5..4ea67d6a6215 100644 --- a/AutoRest/Generators/Java/Azure.Java/TemplateModels/AzureMethodTemplateModel.cs +++ b/AutoRest/Generators/Java/Azure.Java/TemplateModels/AzureMethodTemplateModel.cs @@ -118,7 +118,7 @@ public override string MethodParameterDeclaration } else { - declarations.Add("final " + parameter.Type.ToString() + " " + parameter.Name); + declarations.Add("final " + parameter.Type.UserHandledType().ToString() + " " + parameter.Name); } } @@ -138,7 +138,7 @@ public override string MethodRequiredParameterDeclaration List declarations = new List(); foreach (var parameter in LocalParameters.Where(p => !p.IsConstant && p.IsRequired)) { - declarations.Add("final " + parameter.Type.ToString() + " " + parameter.Name); + declarations.Add("final " + parameter.Type.UserHandledType().ToString() + " " + parameter.Name); } var declaration = string.Join(", ", declarations); @@ -528,6 +528,19 @@ public override string GenericReturnTypeString } } + public override string CallbackGenericTypeString + { + get + { + if (ReturnType.Body is SequenceType && + (this.IsPagingOperation || this.IsPagingNextOperation)) + { + return JavaCodeNamer.WrapPrimitiveType(ReturnType.Body).Name; + } + return base.CallbackGenericTypeString; + } + } + public override string ServiceCallConstruction { get diff --git a/AutoRest/Generators/Java/Azure.Java/Templates/AzureMethodTemplate.cshtml b/AutoRest/Generators/Java/Azure.Java/Templates/AzureMethodTemplate.cshtml index cc0c3349ff9c..c35f3214704c 100644 --- a/AutoRest/Generators/Java/Azure.Java/Templates/AzureMethodTemplate.cshtml +++ b/AutoRest/Generators/Java/Azure.Java/Templates/AzureMethodTemplate.cshtml @@ -14,7 +14,7 @@ } else { -@if (Model.LocalParameters.Any(p => !p.IsConstant && !p.IsRequired)) +if (Model.LocalParameters.Any(p => !p.IsConstant && !p.IsRequired)) { /** diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/bodycomplex/models/Datetimerfc1123Wrapper.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/bodycomplex/models/Datetimerfc1123Wrapper.java index c4c2699ae09a..73e3b74ff626 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/bodycomplex/models/Datetimerfc1123Wrapper.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/bodycomplex/models/Datetimerfc1123Wrapper.java @@ -11,6 +11,7 @@ package fixtures.bodycomplex.models; import com.microsoft.rest.DateTimeRfc1123; +import org.joda.time.DateTime; /** * The Datetimerfc1123Wrapper model. @@ -31,8 +32,8 @@ public class Datetimerfc1123Wrapper { * * @return the field value */ - public DateTimeRfc1123 getField() { - return this.field; + public DateTime getField() { + return this.field.getDateTime(); } /** @@ -40,8 +41,8 @@ public DateTimeRfc1123 getField() { * * @param field the field value to set */ - public void setField(DateTimeRfc1123 field) { - this.field = field; + public void setField(DateTime field) { + this.field = new DateTimeRfc1123(field); } /** @@ -49,8 +50,8 @@ public void setField(DateTimeRfc1123 field) { * * @return the now value */ - public DateTimeRfc1123 getNow() { - return this.now; + public DateTime getNow() { + return this.now.getDateTime(); } /** @@ -58,8 +59,8 @@ public DateTimeRfc1123 getNow() { * * @param now the now value to set */ - public void setNow(DateTimeRfc1123 now) { - this.now = now; + public void setNow(DateTime now) { + this.now = new DateTimeRfc1123(now); } } diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/bodydatetimerfc1123/Datetimerfc1123Operations.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/bodydatetimerfc1123/Datetimerfc1123Operations.java index eb34521f6f8b..5ce7050bfb07 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/bodydatetimerfc1123/Datetimerfc1123Operations.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/bodydatetimerfc1123/Datetimerfc1123Operations.java @@ -10,12 +10,12 @@ package fixtures.bodydatetimerfc1123; -import com.microsoft.rest.DateTimeRfc1123; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; import fixtures.bodydatetimerfc1123.models.ErrorException; import java.io.IOException; +import org.joda.time.DateTime; /** * An instance of this class provides access to all the operations defined @@ -29,7 +29,7 @@ public interface Datetimerfc1123Operations { * @throws IOException exception thrown from serialization/deserialization * @return the DateTimeRfc1123 object wrapped in {@link ServiceResponse} if successful. */ - ServiceResponse getNull() throws ErrorException, IOException; + ServiceResponse getNull() throws ErrorException, IOException; /** * Get null datetime value. @@ -38,7 +38,7 @@ public interface Datetimerfc1123Operations { * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall getNullAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall getNullAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * Get invalid datetime value. @@ -47,7 +47,7 @@ public interface Datetimerfc1123Operations { * @throws IOException exception thrown from serialization/deserialization * @return the DateTimeRfc1123 object wrapped in {@link ServiceResponse} if successful. */ - ServiceResponse getInvalid() throws ErrorException, IOException; + ServiceResponse getInvalid() throws ErrorException, IOException; /** * Get invalid datetime value. @@ -56,7 +56,7 @@ public interface Datetimerfc1123Operations { * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall getInvalidAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall getInvalidAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * Get overflow datetime value. @@ -65,7 +65,7 @@ public interface Datetimerfc1123Operations { * @throws IOException exception thrown from serialization/deserialization * @return the DateTimeRfc1123 object wrapped in {@link ServiceResponse} if successful. */ - ServiceResponse getOverflow() throws ErrorException, IOException; + ServiceResponse getOverflow() throws ErrorException, IOException; /** * Get overflow datetime value. @@ -74,7 +74,7 @@ public interface Datetimerfc1123Operations { * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall getOverflowAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall getOverflowAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * Get underflow datetime value. @@ -83,7 +83,7 @@ public interface Datetimerfc1123Operations { * @throws IOException exception thrown from serialization/deserialization * @return the DateTimeRfc1123 object wrapped in {@link ServiceResponse} if successful. */ - ServiceResponse getUnderflow() throws ErrorException, IOException; + ServiceResponse getUnderflow() throws ErrorException, IOException; /** * Get underflow datetime value. @@ -92,7 +92,7 @@ public interface Datetimerfc1123Operations { * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall getUnderflowAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall getUnderflowAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * Put max datetime value Fri, 31 Dec 9999 23:59:59 GMT. @@ -103,7 +103,7 @@ public interface Datetimerfc1123Operations { * @throws IllegalArgumentException exception thrown from invalid parameters * @return the {@link ServiceResponse} object if successful. */ - ServiceResponse putUtcMaxDateTime(DateTimeRfc1123 datetimeBody) throws ErrorException, IOException, IllegalArgumentException; + ServiceResponse putUtcMaxDateTime(DateTime datetimeBody) throws ErrorException, IOException, IllegalArgumentException; /** * Put max datetime value Fri, 31 Dec 9999 23:59:59 GMT. @@ -113,7 +113,7 @@ public interface Datetimerfc1123Operations { * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall putUtcMaxDateTimeAsync(DateTimeRfc1123 datetimeBody, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall putUtcMaxDateTimeAsync(DateTime datetimeBody, final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * Get max datetime value fri, 31 dec 9999 23:59:59 gmt. @@ -122,7 +122,7 @@ public interface Datetimerfc1123Operations { * @throws IOException exception thrown from serialization/deserialization * @return the DateTimeRfc1123 object wrapped in {@link ServiceResponse} if successful. */ - ServiceResponse getUtcLowercaseMaxDateTime() throws ErrorException, IOException; + ServiceResponse getUtcLowercaseMaxDateTime() throws ErrorException, IOException; /** * Get max datetime value fri, 31 dec 9999 23:59:59 gmt. @@ -131,7 +131,7 @@ public interface Datetimerfc1123Operations { * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall getUtcLowercaseMaxDateTimeAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall getUtcLowercaseMaxDateTimeAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * Get max datetime value FRI, 31 DEC 9999 23:59:59 GMT. @@ -140,7 +140,7 @@ public interface Datetimerfc1123Operations { * @throws IOException exception thrown from serialization/deserialization * @return the DateTimeRfc1123 object wrapped in {@link ServiceResponse} if successful. */ - ServiceResponse getUtcUppercaseMaxDateTime() throws ErrorException, IOException; + ServiceResponse getUtcUppercaseMaxDateTime() throws ErrorException, IOException; /** * Get max datetime value FRI, 31 DEC 9999 23:59:59 GMT. @@ -149,7 +149,7 @@ public interface Datetimerfc1123Operations { * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall getUtcUppercaseMaxDateTimeAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall getUtcUppercaseMaxDateTimeAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * Put min datetime value Mon, 1 Jan 0001 00:00:00 GMT. @@ -160,7 +160,7 @@ public interface Datetimerfc1123Operations { * @throws IllegalArgumentException exception thrown from invalid parameters * @return the {@link ServiceResponse} object if successful. */ - ServiceResponse putUtcMinDateTime(DateTimeRfc1123 datetimeBody) throws ErrorException, IOException, IllegalArgumentException; + ServiceResponse putUtcMinDateTime(DateTime datetimeBody) throws ErrorException, IOException, IllegalArgumentException; /** * Put min datetime value Mon, 1 Jan 0001 00:00:00 GMT. @@ -170,7 +170,7 @@ public interface Datetimerfc1123Operations { * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall putUtcMinDateTimeAsync(DateTimeRfc1123 datetimeBody, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall putUtcMinDateTimeAsync(DateTime datetimeBody, final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * Get min datetime value Mon, 1 Jan 0001 00:00:00 GMT. @@ -179,7 +179,7 @@ public interface Datetimerfc1123Operations { * @throws IOException exception thrown from serialization/deserialization * @return the DateTimeRfc1123 object wrapped in {@link ServiceResponse} if successful. */ - ServiceResponse getUtcMinDateTime() throws ErrorException, IOException; + ServiceResponse getUtcMinDateTime() throws ErrorException, IOException; /** * Get min datetime value Mon, 1 Jan 0001 00:00:00 GMT. @@ -188,6 +188,6 @@ public interface Datetimerfc1123Operations { * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall getUtcMinDateTimeAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall getUtcMinDateTimeAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; } diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/bodydatetimerfc1123/Datetimerfc1123OperationsImpl.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/bodydatetimerfc1123/Datetimerfc1123OperationsImpl.java index de0099cf3f27..ba0652d5a04d 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/bodydatetimerfc1123/Datetimerfc1123OperationsImpl.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/bodydatetimerfc1123/Datetimerfc1123OperationsImpl.java @@ -20,6 +20,7 @@ import fixtures.bodydatetimerfc1123.models.ErrorException; import java.io.IOException; import okhttp3.ResponseBody; +import org.joda.time.DateTime; import retrofit2.Call; import retrofit2.http.Body; import retrofit2.http.GET; @@ -99,9 +100,14 @@ interface Datetimerfc1123Service { * @throws IOException exception thrown from serialization/deserialization * @return the DateTimeRfc1123 object wrapped in {@link ServiceResponse} if successful. */ - public ServiceResponse getNull() throws ErrorException, IOException { + public ServiceResponse getNull() throws ErrorException, IOException { Call call = service.getNull(); - return getNullDelegate(call.execute()); + ServiceResponse response = getNullDelegate(call.execute()); + DateTime body = null; + if (response.getBody() != null) { + body = response.getBody().getDateTime(); + } + return new ServiceResponse(body, response.getResponse()); } /** @@ -111,17 +117,22 @@ public ServiceResponse getNull() throws ErrorException, IOExcep * @throws IllegalArgumentException thrown if callback is null * @return the {@link Call} object */ - public ServiceCall getNullAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { + public ServiceCall getNullAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { if (serviceCallback == null) { throw new IllegalArgumentException("ServiceCallback is required for async calls."); } Call call = service.getNull(); final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { + call.enqueue(new ServiceResponseCallback(serviceCallback) { @Override public void onResponse(Call call, Response response) { try { - serviceCallback.success(getNullDelegate(response)); + ServiceResponse result = getNullDelegate(response); + DateTime body = null; + if (result.getBody() != null) { + body = result.getBody().getDateTime(); + } + serviceCallback.success(new ServiceResponse(body, result.getResponse())); } catch (ErrorException | IOException exception) { serviceCallback.failure(exception); } @@ -144,9 +155,14 @@ private ServiceResponse getNullDelegate(Response * @throws IOException exception thrown from serialization/deserialization * @return the DateTimeRfc1123 object wrapped in {@link ServiceResponse} if successful. */ - public ServiceResponse getInvalid() throws ErrorException, IOException { + public ServiceResponse getInvalid() throws ErrorException, IOException { Call call = service.getInvalid(); - return getInvalidDelegate(call.execute()); + ServiceResponse response = getInvalidDelegate(call.execute()); + DateTime body = null; + if (response.getBody() != null) { + body = response.getBody().getDateTime(); + } + return new ServiceResponse(body, response.getResponse()); } /** @@ -156,17 +172,22 @@ public ServiceResponse getInvalid() throws ErrorException, IOEx * @throws IllegalArgumentException thrown if callback is null * @return the {@link Call} object */ - public ServiceCall getInvalidAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { + public ServiceCall getInvalidAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { if (serviceCallback == null) { throw new IllegalArgumentException("ServiceCallback is required for async calls."); } Call call = service.getInvalid(); final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { + call.enqueue(new ServiceResponseCallback(serviceCallback) { @Override public void onResponse(Call call, Response response) { try { - serviceCallback.success(getInvalidDelegate(response)); + ServiceResponse result = getInvalidDelegate(response); + DateTime body = null; + if (result.getBody() != null) { + body = result.getBody().getDateTime(); + } + serviceCallback.success(new ServiceResponse(body, result.getResponse())); } catch (ErrorException | IOException exception) { serviceCallback.failure(exception); } @@ -189,9 +210,14 @@ private ServiceResponse getInvalidDelegate(Response getOverflow() throws ErrorException, IOException { + public ServiceResponse getOverflow() throws ErrorException, IOException { Call call = service.getOverflow(); - return getOverflowDelegate(call.execute()); + ServiceResponse response = getOverflowDelegate(call.execute()); + DateTime body = null; + if (response.getBody() != null) { + body = response.getBody().getDateTime(); + } + return new ServiceResponse(body, response.getResponse()); } /** @@ -201,17 +227,22 @@ public ServiceResponse getOverflow() throws ErrorException, IOE * @throws IllegalArgumentException thrown if callback is null * @return the {@link Call} object */ - public ServiceCall getOverflowAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { + public ServiceCall getOverflowAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { if (serviceCallback == null) { throw new IllegalArgumentException("ServiceCallback is required for async calls."); } Call call = service.getOverflow(); final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { + call.enqueue(new ServiceResponseCallback(serviceCallback) { @Override public void onResponse(Call call, Response response) { try { - serviceCallback.success(getOverflowDelegate(response)); + ServiceResponse result = getOverflowDelegate(response); + DateTime body = null; + if (result.getBody() != null) { + body = result.getBody().getDateTime(); + } + serviceCallback.success(new ServiceResponse(body, result.getResponse())); } catch (ErrorException | IOException exception) { serviceCallback.failure(exception); } @@ -234,9 +265,14 @@ private ServiceResponse getOverflowDelegate(Response getUnderflow() throws ErrorException, IOException { + public ServiceResponse getUnderflow() throws ErrorException, IOException { Call call = service.getUnderflow(); - return getUnderflowDelegate(call.execute()); + ServiceResponse response = getUnderflowDelegate(call.execute()); + DateTime body = null; + if (response.getBody() != null) { + body = response.getBody().getDateTime(); + } + return new ServiceResponse(body, response.getResponse()); } /** @@ -246,17 +282,22 @@ public ServiceResponse getUnderflow() throws ErrorException, IO * @throws IllegalArgumentException thrown if callback is null * @return the {@link Call} object */ - public ServiceCall getUnderflowAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { + public ServiceCall getUnderflowAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { if (serviceCallback == null) { throw new IllegalArgumentException("ServiceCallback is required for async calls."); } Call call = service.getUnderflow(); final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { + call.enqueue(new ServiceResponseCallback(serviceCallback) { @Override public void onResponse(Call call, Response response) { try { - serviceCallback.success(getUnderflowDelegate(response)); + ServiceResponse result = getUnderflowDelegate(response); + DateTime body = null; + if (result.getBody() != null) { + body = result.getBody().getDateTime(); + } + serviceCallback.success(new ServiceResponse(body, result.getResponse())); } catch (ErrorException | IOException exception) { serviceCallback.failure(exception); } @@ -281,11 +322,11 @@ private ServiceResponse getUnderflowDelegate(Response putUtcMaxDateTime(DateTimeRfc1123 datetimeBody) throws ErrorException, IOException, IllegalArgumentException { + public ServiceResponse putUtcMaxDateTime(DateTime datetimeBody) throws ErrorException, IOException, IllegalArgumentException { if (datetimeBody == null) { throw new IllegalArgumentException("Parameter datetimeBody is required and cannot be null."); } - Call call = service.putUtcMaxDateTime(datetimeBody); + Call call = service.putUtcMaxDateTime(new DateTimeRfc1123(datetimeBody)); return putUtcMaxDateTimeDelegate(call.execute()); } @@ -297,7 +338,7 @@ public ServiceResponse putUtcMaxDateTime(DateTimeRfc1123 datetimeBody) thr * @throws IllegalArgumentException thrown if callback is null * @return the {@link Call} object */ - public ServiceCall putUtcMaxDateTimeAsync(DateTimeRfc1123 datetimeBody, final ServiceCallback serviceCallback) throws IllegalArgumentException { + public ServiceCall putUtcMaxDateTimeAsync(DateTime datetimeBody, final ServiceCallback serviceCallback) throws IllegalArgumentException { if (serviceCallback == null) { throw new IllegalArgumentException("ServiceCallback is required for async calls."); } @@ -305,7 +346,7 @@ public ServiceCall putUtcMaxDateTimeAsync(DateTimeRfc1123 datetimeBody, final Se serviceCallback.failure(new IllegalArgumentException("Parameter datetimeBody is required and cannot be null.")); return null; } - Call call = service.putUtcMaxDateTime(datetimeBody); + Call call = service.putUtcMaxDateTime(new DateTimeRfc1123(datetimeBody)); final ServiceCall serviceCall = new ServiceCall(call); call.enqueue(new ServiceResponseCallback(serviceCallback) { @Override @@ -334,9 +375,14 @@ private ServiceResponse putUtcMaxDateTimeDelegate(Response r * @throws IOException exception thrown from serialization/deserialization * @return the DateTimeRfc1123 object wrapped in {@link ServiceResponse} if successful. */ - public ServiceResponse getUtcLowercaseMaxDateTime() throws ErrorException, IOException { + public ServiceResponse getUtcLowercaseMaxDateTime() throws ErrorException, IOException { Call call = service.getUtcLowercaseMaxDateTime(); - return getUtcLowercaseMaxDateTimeDelegate(call.execute()); + ServiceResponse response = getUtcLowercaseMaxDateTimeDelegate(call.execute()); + DateTime body = null; + if (response.getBody() != null) { + body = response.getBody().getDateTime(); + } + return new ServiceResponse(body, response.getResponse()); } /** @@ -346,17 +392,22 @@ public ServiceResponse getUtcLowercaseMaxDateTime() throws Erro * @throws IllegalArgumentException thrown if callback is null * @return the {@link Call} object */ - public ServiceCall getUtcLowercaseMaxDateTimeAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { + public ServiceCall getUtcLowercaseMaxDateTimeAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { if (serviceCallback == null) { throw new IllegalArgumentException("ServiceCallback is required for async calls."); } Call call = service.getUtcLowercaseMaxDateTime(); final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { + call.enqueue(new ServiceResponseCallback(serviceCallback) { @Override public void onResponse(Call call, Response response) { try { - serviceCallback.success(getUtcLowercaseMaxDateTimeDelegate(response)); + ServiceResponse result = getUtcLowercaseMaxDateTimeDelegate(response); + DateTime body = null; + if (result.getBody() != null) { + body = result.getBody().getDateTime(); + } + serviceCallback.success(new ServiceResponse(body, result.getResponse())); } catch (ErrorException | IOException exception) { serviceCallback.failure(exception); } @@ -379,9 +430,14 @@ private ServiceResponse getUtcLowercaseMaxDateTimeDelegate(Resp * @throws IOException exception thrown from serialization/deserialization * @return the DateTimeRfc1123 object wrapped in {@link ServiceResponse} if successful. */ - public ServiceResponse getUtcUppercaseMaxDateTime() throws ErrorException, IOException { + public ServiceResponse getUtcUppercaseMaxDateTime() throws ErrorException, IOException { Call call = service.getUtcUppercaseMaxDateTime(); - return getUtcUppercaseMaxDateTimeDelegate(call.execute()); + ServiceResponse response = getUtcUppercaseMaxDateTimeDelegate(call.execute()); + DateTime body = null; + if (response.getBody() != null) { + body = response.getBody().getDateTime(); + } + return new ServiceResponse(body, response.getResponse()); } /** @@ -391,17 +447,22 @@ public ServiceResponse getUtcUppercaseMaxDateTime() throws Erro * @throws IllegalArgumentException thrown if callback is null * @return the {@link Call} object */ - public ServiceCall getUtcUppercaseMaxDateTimeAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { + public ServiceCall getUtcUppercaseMaxDateTimeAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { if (serviceCallback == null) { throw new IllegalArgumentException("ServiceCallback is required for async calls."); } Call call = service.getUtcUppercaseMaxDateTime(); final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { + call.enqueue(new ServiceResponseCallback(serviceCallback) { @Override public void onResponse(Call call, Response response) { try { - serviceCallback.success(getUtcUppercaseMaxDateTimeDelegate(response)); + ServiceResponse result = getUtcUppercaseMaxDateTimeDelegate(response); + DateTime body = null; + if (result.getBody() != null) { + body = result.getBody().getDateTime(); + } + serviceCallback.success(new ServiceResponse(body, result.getResponse())); } catch (ErrorException | IOException exception) { serviceCallback.failure(exception); } @@ -426,11 +487,11 @@ private ServiceResponse getUtcUppercaseMaxDateTimeDelegate(Resp * @throws IllegalArgumentException exception thrown from invalid parameters * @return the {@link ServiceResponse} object if successful. */ - public ServiceResponse putUtcMinDateTime(DateTimeRfc1123 datetimeBody) throws ErrorException, IOException, IllegalArgumentException { + public ServiceResponse putUtcMinDateTime(DateTime datetimeBody) throws ErrorException, IOException, IllegalArgumentException { if (datetimeBody == null) { throw new IllegalArgumentException("Parameter datetimeBody is required and cannot be null."); } - Call call = service.putUtcMinDateTime(datetimeBody); + Call call = service.putUtcMinDateTime(new DateTimeRfc1123(datetimeBody)); return putUtcMinDateTimeDelegate(call.execute()); } @@ -442,7 +503,7 @@ public ServiceResponse putUtcMinDateTime(DateTimeRfc1123 datetimeBody) thr * @throws IllegalArgumentException thrown if callback is null * @return the {@link Call} object */ - public ServiceCall putUtcMinDateTimeAsync(DateTimeRfc1123 datetimeBody, final ServiceCallback serviceCallback) throws IllegalArgumentException { + public ServiceCall putUtcMinDateTimeAsync(DateTime datetimeBody, final ServiceCallback serviceCallback) throws IllegalArgumentException { if (serviceCallback == null) { throw new IllegalArgumentException("ServiceCallback is required for async calls."); } @@ -450,7 +511,7 @@ public ServiceCall putUtcMinDateTimeAsync(DateTimeRfc1123 datetimeBody, final Se serviceCallback.failure(new IllegalArgumentException("Parameter datetimeBody is required and cannot be null.")); return null; } - Call call = service.putUtcMinDateTime(datetimeBody); + Call call = service.putUtcMinDateTime(new DateTimeRfc1123(datetimeBody)); final ServiceCall serviceCall = new ServiceCall(call); call.enqueue(new ServiceResponseCallback(serviceCallback) { @Override @@ -479,9 +540,14 @@ private ServiceResponse putUtcMinDateTimeDelegate(Response r * @throws IOException exception thrown from serialization/deserialization * @return the DateTimeRfc1123 object wrapped in {@link ServiceResponse} if successful. */ - public ServiceResponse getUtcMinDateTime() throws ErrorException, IOException { + public ServiceResponse getUtcMinDateTime() throws ErrorException, IOException { Call call = service.getUtcMinDateTime(); - return getUtcMinDateTimeDelegate(call.execute()); + ServiceResponse response = getUtcMinDateTimeDelegate(call.execute()); + DateTime body = null; + if (response.getBody() != null) { + body = response.getBody().getDateTime(); + } + return new ServiceResponse(body, response.getResponse()); } /** @@ -491,17 +557,22 @@ public ServiceResponse getUtcMinDateTime() throws ErrorExceptio * @throws IllegalArgumentException thrown if callback is null * @return the {@link Call} object */ - public ServiceCall getUtcMinDateTimeAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { + public ServiceCall getUtcMinDateTimeAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { if (serviceCallback == null) { throw new IllegalArgumentException("ServiceCallback is required for async calls."); } Call call = service.getUtcMinDateTime(); final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { + call.enqueue(new ServiceResponseCallback(serviceCallback) { @Override public void onResponse(Call call, Response response) { try { - serviceCallback.success(getUtcMinDateTimeDelegate(response)); + ServiceResponse result = getUtcMinDateTimeDelegate(response); + DateTime body = null; + if (result.getBody() != null) { + body = result.getBody().getDateTime(); + } + serviceCallback.success(new ServiceResponse(body, result.getResponse())); } catch (ErrorException | IOException exception) { serviceCallback.failure(exception); } diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/header/HeaderOperations.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/header/HeaderOperations.java index f9eb8aecbb25..a7281ac020fc 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/header/HeaderOperations.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/header/HeaderOperations.java @@ -10,7 +10,6 @@ package fixtures.header; -import com.microsoft.rest.DateTimeRfc1123; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; @@ -521,7 +520,7 @@ public interface HeaderOperations { * @throws IllegalArgumentException exception thrown from invalid parameters * @return the {@link ServiceResponse} object if successful. */ - ServiceResponse paramDatetimeRfc1123(String scenario, DateTimeRfc1123 value) throws ErrorException, IOException, IllegalArgumentException; + ServiceResponse paramDatetimeRfc1123(String scenario, DateTime value) throws ErrorException, IOException, IllegalArgumentException; /** * Send a post request with header values "scenario": "valid", "value": "Wed, 01 Jan 2010 12:34:56 GMT" or "scenario": "min", "value": "Mon, 01 Jan 0001 00:00:00 GMT". @@ -532,7 +531,7 @@ public interface HeaderOperations { * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall paramDatetimeRfc1123Async(String scenario, DateTimeRfc1123 value, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall paramDatetimeRfc1123Async(String scenario, DateTime value, final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * Get a response with header values "Wed, 01 Jan 2010 12:34:56 GMT" or "Mon, 01 Jan 0001 00:00:00 GMT". diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/header/HeaderOperationsImpl.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/header/HeaderOperationsImpl.java index 9c0fa819e1ee..80c9db76accc 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/header/HeaderOperationsImpl.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/header/HeaderOperationsImpl.java @@ -1364,8 +1364,8 @@ public ServiceResponse paramDatetimeRfc1123(String scenario) throws ErrorE if (scenario == null) { throw new IllegalArgumentException("Parameter scenario is required and cannot be null."); } - final DateTimeRfc1123 value = null; - Call call = service.paramDatetimeRfc1123(scenario, value); + final DateTime value = null; + Call call = service.paramDatetimeRfc1123(scenario, new DateTimeRfc1123(value)); return paramDatetimeRfc1123Delegate(call.execute()); } @@ -1385,8 +1385,8 @@ public ServiceCall paramDatetimeRfc1123Async(String scenario, final ServiceCallb serviceCallback.failure(new IllegalArgumentException("Parameter scenario is required and cannot be null.")); return null; } - final DateTimeRfc1123 value = null; - Call call = service.paramDatetimeRfc1123(scenario, value); + final DateTime value = null; + Call call = service.paramDatetimeRfc1123(scenario, new DateTimeRfc1123(value)); final ServiceCall serviceCall = new ServiceCall(call); call.enqueue(new ServiceResponseCallback(serviceCallback) { @Override @@ -1411,11 +1411,11 @@ public void onResponse(Call call, Response response) * @throws IllegalArgumentException exception thrown from invalid parameters * @return the {@link ServiceResponse} object if successful. */ - public ServiceResponse paramDatetimeRfc1123(String scenario, DateTimeRfc1123 value) throws ErrorException, IOException, IllegalArgumentException { + public ServiceResponse paramDatetimeRfc1123(String scenario, DateTime value) throws ErrorException, IOException, IllegalArgumentException { if (scenario == null) { throw new IllegalArgumentException("Parameter scenario is required and cannot be null."); } - Call call = service.paramDatetimeRfc1123(scenario, value); + Call call = service.paramDatetimeRfc1123(scenario, new DateTimeRfc1123(value)); return paramDatetimeRfc1123Delegate(call.execute()); } @@ -1428,7 +1428,7 @@ public ServiceResponse paramDatetimeRfc1123(String scenario, DateTimeRfc11 * @throws IllegalArgumentException thrown if callback is null * @return the {@link Call} object */ - public ServiceCall paramDatetimeRfc1123Async(String scenario, DateTimeRfc1123 value, final ServiceCallback serviceCallback) throws IllegalArgumentException { + public ServiceCall paramDatetimeRfc1123Async(String scenario, DateTime value, final ServiceCallback serviceCallback) throws IllegalArgumentException { if (serviceCallback == null) { throw new IllegalArgumentException("ServiceCallback is required for async calls."); } @@ -1436,7 +1436,7 @@ public ServiceCall paramDatetimeRfc1123Async(String scenario, DateTimeRfc1123 va serviceCallback.failure(new IllegalArgumentException("Parameter scenario is required and cannot be null.")); return null; } - Call call = service.paramDatetimeRfc1123(scenario, value); + Call call = service.paramDatetimeRfc1123(scenario, new DateTimeRfc1123(value)); final ServiceCall serviceCall = new ServiceCall(call); call.enqueue(new ServiceResponseCallback(serviceCallback) { @Override diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/header/models/HeaderResponseDatetimeRfc1123Headers.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/header/models/HeaderResponseDatetimeRfc1123Headers.java index b396b1153a02..627af266e694 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/header/models/HeaderResponseDatetimeRfc1123Headers.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/header/models/HeaderResponseDatetimeRfc1123Headers.java @@ -11,6 +11,7 @@ package fixtures.header.models; import com.microsoft.rest.DateTimeRfc1123; +import org.joda.time.DateTime; /** * Defines headers for responseDatetimeRfc1123 operation. @@ -27,8 +28,8 @@ public class HeaderResponseDatetimeRfc1123Headers { * * @return the value value */ - public DateTimeRfc1123 getValue() { - return this.value; + public DateTime getValue() { + return this.value.getDateTime(); } /** @@ -36,8 +37,8 @@ public DateTimeRfc1123 getValue() { * * @param value the value value to set */ - public void setValue(DateTimeRfc1123 value) { - this.value = value; + public void setValue(DateTime value) { + this.value = new DateTimeRfc1123(value); } } diff --git a/AutoRest/Generators/Java/Java.Tests/src/test/java/fixtures/bodycomplex/PrimitiveTests.java b/AutoRest/Generators/Java/Java.Tests/src/test/java/fixtures/bodycomplex/PrimitiveTests.java index 246de73cdd6f..3bd56fd2e756 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/test/java/fixtures/bodycomplex/PrimitiveTests.java +++ b/AutoRest/Generators/Java/Java.Tests/src/test/java/fixtures/bodycomplex/PrimitiveTests.java @@ -1,6 +1,13 @@ package fixtures.bodycomplex; -import com.microsoft.rest.DateTimeRfc1123; +import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; +import org.joda.time.LocalDate; +import org.joda.time.Period; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + import fixtures.bodycomplex.models.BooleanWrapper; import fixtures.bodycomplex.models.ByteWrapper; import fixtures.bodycomplex.models.DateWrapper; @@ -12,13 +19,6 @@ import fixtures.bodycomplex.models.IntWrapper; import fixtures.bodycomplex.models.LongWrapper; import fixtures.bodycomplex.models.StringWrapper; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.LocalDate; -import org.joda.time.Period; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; public class PrimitiveTests { private static AutoRestComplexTestService client; @@ -154,15 +154,15 @@ public void putDateTime() throws Exception { @Test public void getDateTimeRfc1123() throws Exception { Datetimerfc1123Wrapper result = client.getPrimitiveOperations().getDateTimeRfc1123().getBody(); - Assert.assertEquals(new DateTime(1, 1, 1, 0, 0, 0, DateTimeZone.UTC), result.getField().getDateTime()); - Assert.assertEquals(new DateTime(2015, 5, 18, 11, 38, 0, DateTimeZone.UTC), result.getNow().getDateTime()); + Assert.assertEquals(new DateTime(1, 1, 1, 0, 0, 0, DateTimeZone.UTC), result.getField()); + Assert.assertEquals(new DateTime(2015, 5, 18, 11, 38, 0, DateTimeZone.UTC), result.getNow()); } @Test public void putDateTimeRfc1123() throws Exception { Datetimerfc1123Wrapper body = new Datetimerfc1123Wrapper(); - body.setField(new DateTimeRfc1123(new DateTime(1, 1, 1, 0, 0, 0, DateTimeZone.UTC))); - body.setNow(new DateTimeRfc1123(new DateTime(2015, 5, 18, 11, 38, 0, DateTimeZone.UTC))); + body.setField(new DateTime(1, 1, 1, 0, 0, 0, DateTimeZone.UTC)); + body.setNow(new DateTime(2015, 5, 18, 11, 38, 0, DateTimeZone.UTC)); client.getPrimitiveOperations().putDateTimeRfc1123(body); } diff --git a/AutoRest/Generators/Java/Java.Tests/src/test/java/fixtures/bodydatetimerfc1123/DateTimeRfc1123OperationsTests.java b/AutoRest/Generators/Java/Java.Tests/src/test/java/fixtures/bodydatetimerfc1123/DateTimeRfc1123OperationsTests.java index 36438d4525e6..4b7693bf18a7 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/test/java/fixtures/bodydatetimerfc1123/DateTimeRfc1123OperationsTests.java +++ b/AutoRest/Generators/Java/Java.Tests/src/test/java/fixtures/bodydatetimerfc1123/DateTimeRfc1123OperationsTests.java @@ -1,7 +1,7 @@ package fixtures.bodydatetimerfc1123; import com.fasterxml.jackson.databind.JsonMappingException; -import com.microsoft.rest.DateTimeRfc1123; + import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.junit.Assert; @@ -34,10 +34,10 @@ public void getInvalidDate() throws Exception { @Test public void getOverflowDate() throws Exception { - DateTimeRfc1123 result = client.getDatetimerfc1123Operations().getOverflow().getBody(); + DateTime result = client.getDatetimerfc1123Operations().getOverflow().getBody(); DateTime expected = new DateTime(10000, 1, 1, 00, 00, 00, 0, DateTimeZone.UTC); expected = expected.toDateTime(DateTimeZone.UTC); - Assert.assertEquals(expected, result.getDateTime()); + Assert.assertEquals(expected, result); } @Test @@ -53,34 +53,34 @@ public void getUnderflowDate() throws Exception { @Test public void putUtcMaxDateTime() throws Exception { - DateTimeRfc1123 body = new DateTimeRfc1123(new DateTime(9999, 12, 31, 23, 59, 59, 0, DateTimeZone.UTC)); + DateTime body = new DateTime(9999, 12, 31, 23, 59, 59, 0, DateTimeZone.UTC); client.getDatetimerfc1123Operations().putUtcMaxDateTime(body); } @Test public void getUtcLowercaseMaxDateTime() throws Exception { - DateTimeRfc1123 result = client.getDatetimerfc1123Operations().getUtcLowercaseMaxDateTime().getBody(); + DateTime result = client.getDatetimerfc1123Operations().getUtcLowercaseMaxDateTime().getBody(); DateTime expected = new DateTime(9999, 12, 31, 23, 59, 59, 0, DateTimeZone.UTC); - Assert.assertEquals(expected, result.getDateTime()); + Assert.assertEquals(expected, result); } @Test public void getUtcUppercaseMaxDateTime() throws Exception { - DateTimeRfc1123 result = client.getDatetimerfc1123Operations().getUtcUppercaseMaxDateTime().getBody(); + DateTime result = client.getDatetimerfc1123Operations().getUtcUppercaseMaxDateTime().getBody(); DateTime expected = new DateTime(9999, 12, 31, 23, 59, 59, 0, DateTimeZone.UTC); - Assert.assertEquals(expected, result.getDateTime()); + Assert.assertEquals(expected, result); } @Test public void putUtcMinDateTime() throws Exception { - DateTimeRfc1123 body = new DateTimeRfc1123(new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC)); + DateTime body = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); client.getDatetimerfc1123Operations().putUtcMinDateTime(body); } @Test public void getUtcMinDateTime() throws Exception { - DateTimeRfc1123 result = client.getDatetimerfc1123Operations().getUtcMinDateTime().getBody(); + DateTime result = client.getDatetimerfc1123Operations().getUtcMinDateTime().getBody(); DateTime expected = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); - Assert.assertEquals(expected, result.getDateTime()); + Assert.assertEquals(expected, result); } } diff --git a/AutoRest/Generators/Java/Java.Tests/src/test/java/fixtures/header/HeaderOperationsTests.java b/AutoRest/Generators/Java/Java.Tests/src/test/java/fixtures/header/HeaderOperationsTests.java index 4d8b193d5160..a01af84bccaa 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/test/java/fixtures/header/HeaderOperationsTests.java +++ b/AutoRest/Generators/Java/Java.Tests/src/test/java/fixtures/header/HeaderOperationsTests.java @@ -1,11 +1,8 @@ package fixtures.header; -import com.microsoft.rest.DateTimeRfc1123; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; -import okhttp3.Headers; -import fixtures.header.models.ErrorException; -import fixtures.header.models.GreyscaleColors; + import org.apache.commons.codec.binary.Base64; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; @@ -20,6 +17,10 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import fixtures.header.models.ErrorException; +import fixtures.header.models.GreyscaleColors; +import okhttp3.Headers; + import static org.junit.Assert.fail; public class HeaderOperationsTests { @@ -441,8 +442,8 @@ public void success(ServiceResponse response) { @Test public void paramDatetimeRfc1123() throws Exception { - client.getHeaderOperations().paramDatetimeRfc1123("valid", new DateTimeRfc1123(new DateTime(2010, 1, 1, 12, 34, 56, DateTimeZone.UTC))); - client.getHeaderOperations().paramDatetimeRfc1123("min", new DateTimeRfc1123(new DateTime(1, 1, 1, 0, 0, 0, DateTimeZone.UTC))); + client.getHeaderOperations().paramDatetimeRfc1123("valid", new DateTime(2010, 1, 1, 12, 34, 56, DateTimeZone.UTC)); + client.getHeaderOperations().paramDatetimeRfc1123("min", new DateTime(1, 1, 1, 0, 0, 0, DateTimeZone.UTC)); } @Test @@ -463,7 +464,7 @@ public void success(ServiceResponse response) { } } }); - Assert.assertTrue(lock.await(1000, TimeUnit.MILLISECONDS)); + Assert.assertTrue(lock.await(100000, TimeUnit.MILLISECONDS)); lock = new CountDownLatch(1); client.getHeaderOperations().responseDatetimeRfc1123Async("min", new ServiceCallback() { @Override diff --git a/AutoRest/Generators/Java/Java/ClientModelExtensions.cs b/AutoRest/Generators/Java/Java/ClientModelExtensions.cs index cff7627ba8ba..e7ef1baa88fd 100644 --- a/AutoRest/Generators/Java/Java/ClientModelExtensions.cs +++ b/AutoRest/Generators/Java/Java/ClientModelExtensions.cs @@ -124,6 +124,19 @@ public static void AddRange(this HashSet hashSet, IEnumerable range) } } + public static IType UserHandledType(this IType type) + { + PrimaryType primaryType = type as PrimaryType; + if (primaryType.IsPrimaryType(KnownPrimaryType.DateTimeRfc1123)) + { + return new PrimaryType(KnownPrimaryType.DateTime); + } + else + { + return type; + } + } + public static List ImportFrom(this IType type, string ns, JavaCodeNamer namer) { if (namer == null) diff --git a/AutoRest/Generators/Java/Java/GlobalSuppressions.cs b/AutoRest/Generators/Java/Java/GlobalSuppressions.cs index 48dbd84708d6..061a6e9f8b86 100644 --- a/AutoRest/Generators/Java/Java/GlobalSuppressions.cs +++ b/AutoRest/Generators/Java/Java/GlobalSuppressions.cs @@ -136,3 +136,11 @@ [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists", Scope = "member", Target = "Microsoft.Rest.Generator.Java.TemplateModels.ClientModelExtensions.#ImportFrom(Microsoft.Rest.Generator.ClientModel.IType,System.String,Microsoft.Rest.Generator.Java.JavaCodeNamer)")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists", Scope = "member", Target = "Microsoft.Rest.Generator.Java.JavaCodeNamer.#ImportType(Microsoft.Rest.Generator.ClientModel.IType,System.String)")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Scope = "member", Target = "Microsoft.Rest.Generator.Java.JavaCodeNamer.#ImportType(Microsoft.Rest.Generator.ClientModel.IType,System.String)")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Microsoft.Rest.Generator.Utilities.IndentedStringBuilder.AppendLine(System.String)", Scope = "member", Target = "Microsoft.Rest.Generator.Java.MethodTemplateModel.#ResponseGeneration")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "getBody", Scope = "member", Target = "Microsoft.Rest.Generator.Java.MethodTemplateModel.#ResponseGeneration")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "getDateTime", Scope = "member", Target = "Microsoft.Rest.Generator.Java.MethodTemplateModel.#ResponseGeneration")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "DateTime", Scope = "member", Target = "Microsoft.Rest.Generator.Java.MethodTemplateModel.#SuccessCallback")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "getBody", Scope = "member", Target = "Microsoft.Rest.Generator.Java.MethodTemplateModel.#SuccessCallback")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "getDateTime", Scope = "member", Target = "Microsoft.Rest.Generator.Java.MethodTemplateModel.#SuccessCallback")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Microsoft.Rest.Generator.Utilities.IndentedStringBuilder.AppendLine(System.String)", Scope = "member", Target = "Microsoft.Rest.Generator.Java.MethodTemplateModel.#SuccessCallback")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "DateTime", Scope = "member", Target = "Microsoft.Rest.Generator.Java.MethodTemplateModel.#ResponseGeneration")] diff --git a/AutoRest/Generators/Java/Java/JavaCodeNamer.cs b/AutoRest/Generators/Java/Java/JavaCodeNamer.cs index 048f9cab5fdc..af18dbb59f6b 100644 --- a/AutoRest/Generators/Java/Java/JavaCodeNamer.cs +++ b/AutoRest/Generators/Java/Java/JavaCodeNamer.cs @@ -456,50 +456,51 @@ public static IType WrapPrimitiveType(IType type) } } - public static string ImportPrimaryType(PrimaryType primaryType) + public static IEnumerable ImportPrimaryType(PrimaryType primaryType) { if (primaryType == null) { - return null; + yield break; } if (primaryType.Type == KnownPrimaryType.Date || primaryType.Name == "LocalDate") { - return "org.joda.time.LocalDate"; + yield return "org.joda.time.LocalDate"; } else if (primaryType.Type == KnownPrimaryType.DateTime || primaryType.Name == "DateTime") { - return "org.joda.time.DateTime"; + yield return "org.joda.time.DateTime"; } else if (primaryType.Type == KnownPrimaryType.Decimal || primaryType.Name == "Decimal") { - return "java.math.BigDecimal"; + yield return "java.math.BigDecimal"; } else if (primaryType.Type == KnownPrimaryType.DateTimeRfc1123 || primaryType.Name == "DateTimeRfc1123") { - return "com.microsoft.rest.DateTimeRfc1123"; + yield return "com.microsoft.rest.DateTimeRfc1123"; + yield return "org.joda.time.DateTime"; } else if (primaryType.Type == KnownPrimaryType.Stream || primaryType.Name == "InputStream") { - return "java.io.InputStream"; + yield return "java.io.InputStream"; } else if (primaryType.Type == KnownPrimaryType.TimeSpan || primaryType.Name == "Period") { - return "org.joda.time.Period"; + yield return "org.joda.time.Period"; } else if (primaryType.Type == KnownPrimaryType.Uuid || primaryType.Name == "Uuid") { - return "java.util.UUID"; + yield return "java.util.UUID"; } else { - return null; + yield break; } } @@ -556,7 +557,7 @@ public virtual List ImportType(IType type, string ns) var importedFrom = JavaCodeNamer.ImportPrimaryType(primaryType); if (importedFrom != null) { - imports.Add(importedFrom); + imports.AddRange(importedFrom); } } return imports; diff --git a/AutoRest/Generators/Java/Java/TemplateModels/MethodTemplateModel.cs b/AutoRest/Generators/Java/Java/TemplateModels/MethodTemplateModel.cs index 90336f36dea7..4c613a265e16 100644 --- a/AutoRest/Generators/Java/Java/TemplateModels/MethodTemplateModel.cs +++ b/AutoRest/Generators/Java/Java/TemplateModels/MethodTemplateModel.cs @@ -147,7 +147,7 @@ public virtual string MethodParameterDeclaration } else { - declarations.Add(parameter.Type.ToString() + " " + parameter.Name); + declarations.Add(parameter.Type.UserHandledType().ToString() + " " + parameter.Name); } } @@ -163,7 +163,7 @@ public virtual string MethodRequiredParameterDeclaration List declarations = new List(); foreach (var parameter in LocalParameters.Where(p => !p.IsConstant && p.IsRequired)) { - declarations.Add(parameter.Type.ToString() + " " + parameter.Name); + declarations.Add(parameter.Type.UserHandledType().ToString() + " " + parameter.Name); } var declaration = string.Join(", ", declarations); @@ -198,6 +198,10 @@ public string MethodParameterApiInvocation { declarations.Add(parameter.ToString(parameter.Name, ClientReference)); } + else if (parameter.Type.UserHandledType() != parameter.Type) + { + declarations.Add(string.Format(CultureInfo.InvariantCulture, "new {0}({1})", parameter.Type.Name, parameter.Name)); + } else if (parameter.Type.IsPrimaryType(KnownPrimaryType.Stream)) { declarations.Add(string.Format(CultureInfo.InvariantCulture, @@ -252,20 +256,6 @@ public string LocalMethodParameterInvocation } } - public string LocalMethodParameterInvocationWithCallback - { - get - { - var parameters = LocalMethodParameterInvocation; - if (!parameters.IsNullOrEmpty()) - { - parameters += ", "; - } - parameters += string.Format(CultureInfo.InvariantCulture, "new ServiceCallback<" + GenericReturnTypeString + ">()"); - return parameters; - } - } - /// /// Generates input mapping code block. /// @@ -419,7 +409,7 @@ public virtual string MethodParameterDeclarationWithCallback parameters += ", "; } parameters += string.Format(CultureInfo.InvariantCulture, "final ServiceCallback<{0}> serviceCallback", - ReturnType.Body != null ? JavaCodeNamer.WrapPrimitiveType(ReturnType.Body).ToString() : "Void"); + GenericReturnTypeString); return parameters; } } @@ -434,7 +424,7 @@ public virtual string MethodRequiredParameterDeclarationWithCallback parameters += ", "; } parameters += string.Format(CultureInfo.InvariantCulture, "final ServiceCallback<{0}> serviceCallback", - ReturnType.Body != null ? JavaCodeNamer.WrapPrimitiveType(ReturnType.Body).ToString() : "Void"); + GenericReturnTypeString); return parameters; } } @@ -552,13 +542,13 @@ public virtual string GenericReturnTypeString { if (ReturnType.Body != null) { - return JavaCodeNamer.WrapPrimitiveType(ReturnType.Body).Name; + return JavaCodeNamer.WrapPrimitiveType(ReturnType.Body.UserHandledType()).Name; } return "Void"; } } - public virtual string DelegateReturnTypeString + public virtual string CallbackGenericTypeString { get { @@ -566,6 +556,18 @@ public virtual string DelegateReturnTypeString } } + public virtual string DelegateReturnTypeString + { + get + { + if (ReturnType.Body != null) + { + return JavaCodeNamer.WrapPrimitiveType(ReturnType.Body).Name; + } + return "Void"; + } + } + public virtual string TypeTokenType(IType type) { return JavaCodeNamer.WrapPrimitiveType(type).Name; @@ -666,6 +668,19 @@ public virtual string ResponseGeneration { get { + var userType = ReturnType.Body.UserHandledType(); + if (ReturnType.Body != userType) + { + userType = JavaCodeNamer.WrapPrimitiveType(userType); + IndentedStringBuilder builder= new IndentedStringBuilder(); + builder.AppendLine("ServiceResponse<{0}> response = {1}Delegate(call.execute());", + DelegateReturnTypeString, this.Name.ToCamelCase()); + builder.AppendLine("{0} body = null;", userType.Name) + .AppendLine("if (response.getBody() != null) {") + .Indent().AppendLine("body = response.getBody().get{0}();", userType.Name) + .Outdent().AppendLine("}"); + return builder.ToString(); + } return ""; } } @@ -674,6 +689,10 @@ public virtual string ReturnValue { get { + if (ReturnType.Body.UserHandledType() != ReturnType.Body) + { + return "new ServiceResponse<" + this.GenericReturnTypeString + ">(body, response.getResponse())"; + } return this.Name + "Delegate(call.execute())"; } } @@ -682,6 +701,19 @@ public virtual string SuccessCallback { get { + var userType = ReturnType.Body.UserHandledType(); + if (ReturnType.Body != userType) + { + userType = JavaCodeNamer.WrapPrimitiveType(userType); + IndentedStringBuilder builder = new IndentedStringBuilder(); + builder.AppendLine("ServiceResponse<{0}> result = {1}Delegate(response);", DelegateReturnTypeString, this.Name); + builder.AppendLine("{0} body = null;", userType.Name) + .AppendLine("if (result.getBody() != null) {") + .Indent().AppendLine("body = result.getBody().get{0}();", userType.Name) + .Outdent().AppendLine("}"); + builder.AppendLine("serviceCallback.success(new ServiceResponse<{0}>(body, result.getResponse()));", GenericReturnTypeString); + return builder.ToString(); + } return string.Format(CultureInfo.InvariantCulture, "serviceCallback.success({0}Delegate(response));", this.Name); } } @@ -715,6 +747,12 @@ public virtual List InterfaceImports this.Parameters.ForEach(p => imports.AddRange(p.Type.ImportFrom(ServiceClient.Namespace, Namer))); // return type imports.AddRange(this.ReturnType.Body.ImportFrom(ServiceClient.Namespace, Namer)); + if (Parameters.Any(p => p.Type.IsPrimaryType(KnownPrimaryType.DateTimeRfc1123)) + || ReturnType.Body.IsPrimaryType(KnownPrimaryType.DateTimeRfc1123) + || ReturnType.Headers.IsPrimaryType(KnownPrimaryType.DateTimeRfc1123)) + { + imports.Remove("com.microsoft.rest.DateTimeRfc1123"); + } // Header type imports.AddRange(this.ReturnType.Headers.ImportFrom(ServiceClient.Namespace, Namer)); // exceptions diff --git a/AutoRest/Generators/Java/Java/Templates/MethodTemplate.cshtml b/AutoRest/Generators/Java/Java/Templates/MethodTemplate.cshtml index 59dd9c09d601..c90a59e9b7f9 100644 --- a/AutoRest/Generators/Java/Java/Templates/MethodTemplate.cshtml +++ b/AutoRest/Generators/Java/Java/Templates/MethodTemplate.cshtml @@ -49,11 +49,12 @@ public @Model.OperationResponseReturnTypeString @(Model.Name)(@Model.MethodRequi { if (!parameter.IsRequired) { -@: final @(parameter.Type.Name) @(parameter.Name) = null; +@: final @(parameter.Type.UserHandledType().Name) @(parameter.Name) = null; } if (parameter.IsConstant) { -@: final @(parameter.Type.Name) @(parameter.Name) = @(parameter.DefaultValue); +@: final @(parameter.Type.UserHandledType().Name) @(parameter.Name) = @(parameter.DefaultValue); + } } @Model.BuildInputMappings() @@ -108,11 +109,11 @@ public ServiceCall @(Model.Name)Async(@Model.MethodRequiredParameterDeclarationW { if (!parameter.IsRequired) { -@: final @(parameter.Type.Name) @(parameter.Name) = null; +@: final @(parameter.Type.UserHandledType().Name) @(parameter.Name) = null; } if (parameter.IsConstant) { -@: final @(parameter.Type.Name) @(parameter.Name) = @(parameter.DefaultValue); +@: final @(parameter.Type.UserHandledType().Name) @(parameter.Name) = @(parameter.DefaultValue); } } @Model.BuildInputMappings() @@ -126,7 +127,7 @@ foreach (var param in Model.Parameters.Where(p => p.Extensions.ContainsKey("host } Call<@Model.CallType> call = service.@(Model.Name)(@Model.MethodParameterApiInvocation); @Model.ServiceCallConstruction - call.enqueue(new @Model.InternalCallback<@(JavaCodeNamer.WrapPrimitiveType(Model.ReturnType.Body).Name)>(serviceCallback) { + call.enqueue(new @Model.InternalCallback<@(Model.CallbackGenericTypeString)>(serviceCallback) { @@Override public void onResponse(Call<@Model.CallType> call, Response<@Model.CallType> response) { try { @@ -252,7 +253,7 @@ foreach (var param in Model.Parameters.Where(p => p.Extensions.ContainsKey("host } Call<@Model.CallType> call = service.@(Model.Name)(@Model.MethodParameterApiInvocation); @Model.ServiceCallConstruction - call.enqueue(new @Model.InternalCallback<@(JavaCodeNamer.WrapPrimitiveType(Model.ReturnType.Body).Name)>(serviceCallback) { + call.enqueue(new @Model.InternalCallback<@(Model.CallbackGenericTypeString)>(serviceCallback) { @@Override public void onResponse(Call<@Model.CallType> call, Response<@Model.CallType> response) { try { diff --git a/AutoRest/Generators/Java/Java/Templates/ModelTemplate.cshtml b/AutoRest/Generators/Java/Java/Templates/ModelTemplate.cshtml index 5e58c254e36e..deb64fca76b2 100644 --- a/AutoRest/Generators/Java/Java/Templates/ModelTemplate.cshtml +++ b/AutoRest/Generators/Java/Java/Templates/ModelTemplate.cshtml @@ -86,8 +86,15 @@ if (!jsonSetting.IsNullOrEmpty()) @: * @: * @@return the @property.Name value @: */ -@: public @property.Type get@(property.Name.ToPascalCase())() { +@: public @property.Type.UserHandledType().Name get@(property.Name.ToPascalCase())() { +if (property.Type.UserHandledType() != property.Type) +{ +@: return this.@(property.Name).get@(property.Type.UserHandledType().Name)(); +} +else +{ @: return this.@(property.Name); +} @: } @EmptyLine if (!property.IsReadOnly) @@ -97,8 +104,15 @@ if (!property.IsReadOnly) @: * @: * @@param @property.Name the @property.Name value to set @: */ -@: public void set@(property.Name.ToPascalCase())(@property.Type @property.Name) { +@: public void set@(property.Name.ToPascalCase())(@property.Type.UserHandledType().Name @property.Name) { +if (property.Type.UserHandledType() != property.Type) +{ +@: this.@(property.Name) = new @(property.Type.Name)(@property.Name); +} +else +{ @: this.@(property.Name) = @property.Name; +} @: } @EmptyLine } diff --git a/ClientRuntimes/Java/client-runtime/src/main/java/com/microsoft/rest/DateTimeRfc1123.java b/ClientRuntimes/Java/client-runtime/src/main/java/com/microsoft/rest/DateTimeRfc1123.java index 4e61173fd711..d4e8078cb717 100644 --- a/ClientRuntimes/Java/client-runtime/src/main/java/com/microsoft/rest/DateTimeRfc1123.java +++ b/ClientRuntimes/Java/client-runtime/src/main/java/com/microsoft/rest/DateTimeRfc1123.java @@ -48,6 +48,9 @@ public DateTimeRfc1123(String formattedString) { * @return The underlying DateTime. */ public DateTime getDateTime() { + if (this.dateTime == null) { + return null; + } return this.dateTime; } diff --git a/ClientRuntimes/Java/client-runtime/src/main/java/com/microsoft/rest/serializer/JacksonMapperAdapter.java b/ClientRuntimes/Java/client-runtime/src/main/java/com/microsoft/rest/serializer/JacksonMapperAdapter.java index 97abf853630b..ae2af3c5f6ac 100644 --- a/ClientRuntimes/Java/client-runtime/src/main/java/com/microsoft/rest/serializer/JacksonMapperAdapter.java +++ b/ClientRuntimes/Java/client-runtime/src/main/java/com/microsoft/rest/serializer/JacksonMapperAdapter.java @@ -7,6 +7,7 @@ package com.microsoft.rest.serializer; +import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; @@ -58,6 +59,10 @@ protected void initializeObjectMapper(ObjectMapper mapper) { .registerModule(DateTimeSerializer.getModule()) .registerModule(DateTimeRfc1123Serializer.getModule()) .registerModule(HeadersSerializer.getModule()); + mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker() + .withFieldVisibility(JsonAutoDetect.Visibility.ANY) + .withSetterVisibility(JsonAutoDetect.Visibility.NONE) + .withGetterVisibility(JsonAutoDetect.Visibility.NONE)); } /**