Skip to content

Commit

Permalink
Fix parameter flattening codes handling of documentation string (Azur…
Browse files Browse the repository at this point in the history
…e#1199)

* Update parameter flattening documentation handling

* Regenerate expected
  • Loading branch information
matthchr authored and tbombach committed Jun 29, 2016
1 parent 44645a6 commit ab8f357
Show file tree
Hide file tree
Showing 20 changed files with 260 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public AvailabilitySets(AutoRestParameterFlattening client)
/// The name of the storage availability set.
/// </param>
/// <param name='tags'>
/// A set of tags. A description about the set of tags.
/// </param>
/// <param name='customHeaders'>
/// Headers that will be added to request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static partial class AvailabilitySetsExtensions
/// The name of the storage availability set.
/// </param>
/// <param name='tags'>
/// A set of tags. A description about the set of tags.
/// </param>
public static void Update(this IAvailabilitySets operations, string resourceGroupName, string avset, IDictionary<string, string> tags)
{
Expand All @@ -53,6 +54,7 @@ public static void Update(this IAvailabilitySets operations, string resourceGrou
/// The name of the storage availability set.
/// </param>
/// <param name='tags'>
/// A set of tags. A description about the set of tags.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public partial interface IAvailabilitySets
/// The name of the storage availability set.
/// </param>
/// <param name='tags'>
/// A set of tags. A description about the set of tags.
/// </param>
/// <param name='customHeaders'>
/// The headers that will be added to request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ public AvailabilitySetUpdateParameters(IDictionary<string, string> tags)
}

/// <summary>
/// Gets or sets a set of tags.
/// </summary>
/// <remarks>
/// A description about the set of tags.
/// </remarks>
[JsonProperty(PropertyName = "tags")]
public IDictionary<string, string> Tags { get; set; }

Expand Down
5 changes: 5 additions & 0 deletions AutoRest/Generators/Extensions/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ public static void FlattenMethodParameters(ServiceClient serviceClient, Settings
{
var newMethodParameter = new Parameter();
newMethodParameter.LoadFrom(property);

var documentationString = !string.IsNullOrEmpty(property.Summary) ? property.Summary + " " : string.Empty;
documentationString += property.Documentation;
newMethodParameter.Documentation = documentationString;

bodyParameter.Extensions.ForEach(kv => { newMethodParameter.Extensions[kv.Key] = kv.Value; });
method.Parameters.Add(newMethodParameter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,22 @@ public interface HttpFailureOperations {
*/
ServiceCall getNoModelErrorAsync(final ServiceCallback<Boolean> serviceCallback) throws IllegalArgumentException;

/**
* Get empty response from server.
*
* @throws ServiceException exception thrown from REST call
* @throws IOException exception thrown from serialization/deserialization
* @return the boolean object wrapped in {@link ServiceResponse} if successful.
*/
ServiceResponse<Boolean> getNoModelEmpty() throws ServiceException, IOException;

/**
* Get empty response from server.
*
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if callback is null
* @return the {@link ServiceCall} object
*/
ServiceCall getNoModelEmptyAsync(final ServiceCallback<Boolean> serviceCallback) throws IllegalArgumentException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ interface HttpFailureService {
@GET("http/failure/nomodel/error")
Call<ResponseBody> getNoModelError();

@Headers("Content-Type: application/json; charset=utf-8")
@GET("http/failure/nomodel/empty")
Call<ResponseBody> getNoModelEmpty();

}

/**
Expand Down Expand Up @@ -151,4 +155,48 @@ private ServiceResponse<Boolean> getNoModelErrorDelegate(Response<ResponseBody>
.build(response);
}

/**
* Get empty response from server.
*
* @throws ServiceException exception thrown from REST call
* @throws IOException exception thrown from serialization/deserialization
* @return the boolean object wrapped in {@link ServiceResponse} if successful.
*/
public ServiceResponse<Boolean> getNoModelEmpty() throws ServiceException, IOException {
Call<ResponseBody> call = service.getNoModelEmpty();
return getNoModelEmptyDelegate(call.execute());
}

/**
* Get empty response from server.
*
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if callback is null
* @return the {@link Call} object
*/
public ServiceCall getNoModelEmptyAsync(final ServiceCallback<Boolean> serviceCallback) throws IllegalArgumentException {
if (serviceCallback == null) {
throw new IllegalArgumentException("ServiceCallback is required for async calls.");
}
Call<ResponseBody> call = service.getNoModelEmpty();
final ServiceCall serviceCall = new ServiceCall(call);
call.enqueue(new ServiceResponseCallback<Boolean>(serviceCallback) {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
try {
serviceCallback.success(getNoModelEmptyDelegate(response));
} catch (ServiceException | IOException exception) {
serviceCallback.failure(exception);
}
}
});
return serviceCall;
}

private ServiceResponse<Boolean> getNoModelEmptyDelegate(Response<ResponseBody> response) throws ServiceException, IOException {
return new ServiceResponseBuilder<Boolean, ServiceException>(this.client.getMapperAdapter())
.register(200, new TypeToken<Boolean>() { }.getType())
.build(response);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface AvailabilitySetsOperations {
*
* @param resourceGroupName The name of the resource group.
* @param avset The name of the storage availability set.
* @param tags the Map&lt;String, String&gt; value
* @param tags A set of tags. A description about the set of tags.
* @throws ServiceException exception thrown from REST call
* @throws IOException exception thrown from serialization/deserialization
* @throws IllegalArgumentException exception thrown from invalid parameters
Expand All @@ -40,7 +40,7 @@ public interface AvailabilitySetsOperations {
*
* @param resourceGroupName The name of the resource group.
* @param avset The name of the storage availability set.
* @param tags the Map&lt;String, String&gt; value
* @param tags A set of tags. A description about the set of tags.
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if callback is null
* @return the {@link ServiceCall} object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ interface AvailabilitySetsService {
*
* @param resourceGroupName The name of the resource group.
* @param avset The name of the storage availability set.
* @param tags the Map&lt;String, String&gt; value
* @param tags A set of tags. A description about the set of tags.
* @throws ServiceException exception thrown from REST call
* @throws IOException exception thrown from serialization/deserialization
* @throws IllegalArgumentException exception thrown from invalid parameters
Expand Down Expand Up @@ -95,7 +95,7 @@ public ServiceResponse<Void> update(String resourceGroupName, String avset, Map<
*
* @param resourceGroupName The name of the resource group.
* @param avset The name of the storage availability set.
* @param tags the Map&lt;String, String&gt; value
* @param tags A set of tags. A description about the set of tags.
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if callback is null
* @return the {@link Call} object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/
public class AvailabilitySetUpdateParameters {
/**
* The tags property.
* A set of tags.
* A description about the set of tags.
*/
@JsonProperty(required = true)
private Map<String, String> tags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,115 @@ HttpFailure.prototype.getNoModelError = function (options, callback) {
});
};

/**
* Get empty response from server
*
* @param {object} [options] Optional Parameters.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @param {function} callback
*
* @returns {function} callback(err, result, request, response)
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {boolean} [result] - The deserialized result object.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
* {stream} [response] - The HTTP Response stream if an error did not occur.
*/
HttpFailure.prototype.getNoModelEmpty = function (options, callback) {
var client = this.client;
if(!callback && typeof options === 'function') {
callback = options;
options = null;
}
if (!callback) {
throw new Error('callback cannot be null.');
}

// Construct URL
var requestUrl = this.client.baseUri +
'//http/failure/nomodel/empty';
// trim all duplicate forward slashes in the url
var regex = /([^:]\/)\/+/gi;
requestUrl = requestUrl.replace(regex, '$1');

// Create HTTP transport objects
var httpRequest = new WebResource();
httpRequest.method = 'GET';
httpRequest.headers = {};
httpRequest.url = requestUrl;
// Set Headers
if(options) {
for(var headerName in options['customHeaders']) {
if (options['customHeaders'].hasOwnProperty(headerName)) {
httpRequest.headers[headerName] = options['customHeaders'][headerName];
}
}
}
httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
httpRequest.body = null;
// Send Request
return client.pipeline(httpRequest, function (err, response, responseBody) {
if (err) {
return callback(err);
}
var statusCode = response.statusCode;
if (statusCode !== 200) {
var error = new Error(responseBody);
error.statusCode = response.statusCode;
error.request = msRest.stripRequest(httpRequest);
error.response = msRest.stripResponse(response);
if (responseBody === '') responseBody = null;
var parsedErrorResponse;
try {
parsedErrorResponse = JSON.parse(responseBody);
if (parsedErrorResponse) {
if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
}
} catch (defaultError) {
error.message = util.format('Error "%s" occurred in deserializing the responseBody ' +
'- "%s" for the default response.', defaultError.message, responseBody);
return callback(error);
}
return callback(error);
}
// Create Result
var result = null;
if (responseBody === '') responseBody = null;
// Deserialize Response
if (statusCode === 200) {
var parsedResponse = null;
try {
parsedResponse = JSON.parse(responseBody);
result = JSON.parse(responseBody);
if (parsedResponse !== null && parsedResponse !== undefined) {
var resultMapper = {
required: false,
serializedName: 'parsedResponse',
type: {
name: 'Boolean'
}
};
result = client.deserialize(resultMapper, parsedResponse, 'result');
}
} catch (error) {
var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody));
deserializationError.request = msRest.stripRequest(httpRequest);
deserializationError.response = msRest.stripResponse(response);
return callback(deserializationError);
}
}

return callback(null, result, httpRequest, response);
});
};


module.exports = HttpFailure;
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ export interface HttpFailure {
*/
getNoModelError(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<boolean>): void;
getNoModelError(callback: ServiceCallback<boolean>): void;

/**
* Get empty response from server
*
* @param {object} [options] Optional Parameters.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @param {ServiceCallback} [callback] callback function; see ServiceCallback
* doc in ms-rest index.d.ts for details
*/
getNoModelEmpty(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<boolean>): void;
getNoModelEmpty(callback: ServiceCallback<boolean>): void;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @class
* Initializes a new instance of the AvailabilitySetUpdateParameters class.
* @constructor
* @member {object} tags
* @member {object} tags A set of tags. A description about the set of tags.
*
*/
function AvailabilitySetUpdateParameters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @class
* Initializes a new instance of the AvailabilitySetUpdateParameters class.
* @constructor
* @member {object} tags
* @member {object} tags A set of tags. A description about the set of tags.
*
*/
export interface AvailabilitySetUpdateParameters {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function AvailabilitySets(client) {
*
* @param {string} avset The name of the storage availability set.
*
* @param {object} tags
* @param {object} tags A set of tags. A description about the set of tags.
*
* @param {object} [options] Optional Parameters.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface AvailabilitySets {
*
* @param {string} avset The name of the storage availability set.
*
* @param {object} tags
* @param {object} tags A set of tags. A description about the set of tags.
*
* @param {object} [options] Optional Parameters.
*
Expand Down
Loading

0 comments on commit ab8f357

Please sign in to comment.