Skip to content

Commit 2efd1ab

Browse files
committed
Ruby - Move serialization/deserialization into clientruntime from sdk
1 parent 6b8360d commit 2efd1ab

File tree

18 files changed

+1029
-541
lines changed

18 files changed

+1029
-541
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ ipch/
5656
*.psess
5757
*.vsp
5858

59+
# VS Code settings
60+
*.vscode
61+
5962
# Code analysis
6063
*.CodeAnalysisLog.xml
6164

AutoRest/Generators/Ruby/Azure.Ruby/TemplateModels/AzureMethodTemplateModel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public string DeserializePollingResponse(string variableName, IType type)
8282
{
8383
var builder = new IndentedStringBuilder(" ");
8484

85-
string serializationLogic = type.DeserializeType(this.Scope, variableName);
85+
string serializationLogic = GetDeserializationString(type, variableName, variableName);
8686
return builder.AppendLine(serializationLogic).ToString();
8787
}
8888

@@ -119,9 +119,9 @@ public override List<string> ClassNamespaces
119119
get
120120
{
121121
return new List<string>
122-
{
123-
"MsRestAzure"
124-
};
122+
{
123+
"MsRestAzure"
124+
};
125125
}
126126
}
127127

AutoRest/Generators/Ruby/Azure.Ruby/TemplateModels/AzureModelTemplateModel.cs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System.Collections.Generic;
5+
using Microsoft.Rest.Generator.Azure.Ruby.Templates;
56
using Microsoft.Rest.Generator.ClientModel;
67
using Microsoft.Rest.Generator.Ruby;
78
using Microsoft.Rest.Generator.Utilities;
8-
using Microsoft.Rest.Generator.Azure.Ruby.Templates;
99

1010
namespace Microsoft.Rest.Generator.Azure.Ruby
1111
{
@@ -45,36 +45,6 @@ public override string GetBaseTypeName()
4545

4646
return string.Empty;
4747
}
48-
49-
/// <summary>
50-
/// Generates code for model serialization.
51-
/// </summary>
52-
/// <param name="variableName">Variable serialize model from.</param>
53-
/// <param name="type">The type of the model.</param>
54-
/// <returns>The code for serialization in string format.</returns>
55-
public override string SerializeProperty(string variableName, IType type)
56-
{
57-
var builder = new IndentedStringBuilder(" ");
58-
59-
string serializationLogic = type.AzureSerializeType(this.Scope, variableName);
60-
builder.AppendLine(serializationLogic);
61-
62-
return builder.ToString();
63-
}
64-
65-
/// <summary>
66-
/// Generates code for model deserialization.
67-
/// </summary>
68-
/// <param name="variableName">Variable deserialize model from.</param>
69-
/// <param name="type">The type of the model.</param>
70-
/// <returns>The code for вуserialization in string format.</returns>
71-
public override string DeserializeProperty(string variableName, IType type)
72-
{
73-
var builder = new IndentedStringBuilder(" ");
74-
75-
string serializationLogic = type.AzureDeserializeType(this.Scope, variableName);
76-
return builder.AppendLine(serializationLogic).ToString();
77-
}
7848

7949
/// <summary>
8050
/// Gets the list of modules/classes which need to be included.

AutoRest/Generators/Ruby/Azure.Ruby/Templates/AzureMethodTemplate.cshtml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ def @(Model.Name)(@(Model.MethodParameterDeclaration))
3737
promise = promise.then do |response|
3838
# Defining deserialization method.
3939
deserialize_method = lambda do |parsed_response|
40-
@(Model.DeserializePollingResponse("parsed_response", Model.ReturnType.Body))
40+
@if(Model.ReturnType.Body != null)
41+
{
42+
@:@(Model.DeserializePollingResponse("parsed_response", Model.ReturnType.Body))
43+
}
4144
end
4245

4346
@EmptyLine
@@ -79,7 +82,10 @@ def @(Model.Name)(@(Model.MethodParameterDeclaration))
7982
promise = promise.then do |response|
8083
# Defining deserialization method.
8184
deserialize_method = lambda do |parsed_response|
82-
@(Model.DeserializePollingResponse("parsed_response", Model.ReturnType.Body))
85+
@if(Model.ReturnType.Body != null)
86+
{
87+
@:@(Model.DeserializePollingResponse("parsed_response", Model.ReturnType.Body))
88+
}
8389
end
8490

8591
@EmptyLine

AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/string_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
client = AutoRestSwaggerBATService.new(@credentials, @base_url)
1717
@string_client = StringModule::String.new(client)
18+
19+
@enum_client = StringModule::Enum.new(client)
1820
end
1921

2022
it 'should create test service' do
@@ -62,4 +64,12 @@
6264
expect(result.response.status).to eq(200)
6365
expect(result.body).to be_nil
6466
end
67+
it 'should support valid enum valid value' do
68+
result = @enum_client.get_not_expandable_async().value!
69+
expect(result.response.status).to eq(200)
70+
expect(result.response.body).to include('red color')
71+
end
72+
it 'should correctly handle invalid values for enum' do
73+
expect { @enum_client.put_not_expandable_async('orange color').value! }.to raise_error(MsRest::ValidationError)
74+
end
6575
end

0 commit comments

Comments
 (0)