Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ruby] Adding resource group accessor to all the resources #1668

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ def create_async(resource_group_name, account_name, parameters, custom_headers =
deserialize_method = lambda do |parsed_response|
result_mapper = StorageAccount.mapper()
parsed_response = @client.deserialize(result_mapper, parsed_response, 'parsed_response')
parsed_response.resource_group = resource_group_name if defined?resource_group_name
parsed_response
end

# Waiting for response.
Expand Down Expand Up @@ -364,6 +366,8 @@ def get_properties_async(resource_group_name, account_name, custom_headers = nil
parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
result_mapper = StorageAccount.mapper()
result.body = @client.deserialize(result_mapper, parsed_response, 'result.body')
result.body.resource_group = resource_group_name if defined?resource_group_name
result.body
rescue Exception => e
fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
end
Expand Down Expand Up @@ -516,6 +520,8 @@ def update_async(resource_group_name, account_name, parameters, custom_headers =
parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
result_mapper = StorageAccount.mapper()
result.body = @client.deserialize(result_mapper, parsed_response, 'result.body')
result.body.resource_group = resource_group_name if defined?resource_group_name
result.body
rescue Exception => e
fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
end
Expand Down Expand Up @@ -1030,6 +1036,8 @@ def begin_create_async(resource_group_name, account_name, parameters, custom_hea
parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
result_mapper = StorageAccount.mapper()
result.body = @client.deserialize(result_mapper, parsed_response, 'result.body')
result.body.resource_group = resource_group_name if defined?resource_group_name
result.body
rescue Exception => e
fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
end
Expand Down
27 changes: 27 additions & 0 deletions src/generator/AutoRest.Ruby.Azure/Model/MethodRba.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,5 +270,32 @@ public override string OperationReturnTypeString
return base.OperationReturnTypeString;
}
}

/// <summary>
/// Creates deserialization logic for the given <paramref name="type"/>.
/// </summary>
/// <param name="type">Type for which deserialization logic being constructed.</param>
/// <param name="valueReference">Reference variable name.</param>
/// <param name="responseVariable">Response variable name.</param>
/// <returns>Deserialization logic for the given <paramref name="type"/> as string.</returns>
public override string GetDeserializationString(IModelType type, string valueReference = "result", string responseVariable = "parsed_response")
{
var builder = new IndentedStringBuilder(" ");

string deserializedString = base.GetDeserializationString(type, valueReference, responseVariable);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we be calling super(type, valueReference, responseVariable) ? is there a difference in doing super vs base.method?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base is used in C#. not super

builder.AppendLine(deserializedString);

if (type is CompositeType)
{
var composite = type as CompositeType;
if (composite.BaseModelType != null && composite.BaseModelType.Name == "Resource")
{
builder.AppendLine("{0}.resource_group = resource_group_name if defined?resource_group_name", valueReference);
builder.AppendLine("{0}", valueReference);
}
}

return builder.ToString();
}
}
}
2 changes: 1 addition & 1 deletion src/generator/AutoRest.Ruby/Model/MethodRb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ public string ConstructRequestBodyMapper(string outputVariable = "request_mapper
/// <param name="responseVariable">Response variable name.</param>
/// <returns>Deserialization logic for the given <paramref name="type"/> as string.</returns>
/// <exception cref="ArgumentNullException">Thrown when a required parameter is null.</exception>
public string GetDeserializationString(IModelType type, string valueReference = "result", string responseVariable = "parsed_response")
public virtual string GetDeserializationString(IModelType type, string valueReference = "result", string responseVariable = "parsed_response")
{
if (type == null)
{
Expand Down