We’ve recently created a service and added the swagger plugin. The swagger UI all functions as expected. Consuming the service from a .net client works as expected.
We have tried to use the swagger code gen tool to create ruby and php clients. The clients generate, but there is some strange behavior around the return types
The intermediate functions don’t return an actual object but rather appear to have nil defined. I’ll provide both PHP and ruby examples. In this case it’s from the getTransaction get_transaction (php & ruby respectively) generated code from the reporting API.
Ruby:
#
#
# @param pnref
# @param [Hash] opts the optional parameters
# @return [nil]
def get_transaction(pnref, opts = {})
get_transaction_with_http_info(pnref, opts)
return nil
end
Note the return nil. Note too that the underlying fucnction called get_transaction_with_http_info is defined as:
#
#
# @param pnref
# @param [Hash] opts the optional parameters
# @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers
def get_transaction_with_http_info(pnref, opts = {})
Note the nil in the return array. However note the actual return.
data, status_code, headers = @api_client.call_api(:GET, local_var_path,
:header_params => header_params,
:query_params => query_params,
:form_params => form_params,
:body => post_body,
:auth_names => auth_names)
if @api_client.config.debugging
@api_client.config.logger.debug "API called: ReportingApi#get_transaction\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
PHP:
/**
* Operation getTransaction
*
*
*
* @param \Swagger\Client\Model\Object $pnref (required)
* @throws \Swagger\Client\ApiException on non-2xx response
* @return void
*/
public function getTransaction($pnref)
{
list($response) = $this->getTransactionWithHttpInfo($pnref);
return $response;
}
Here though it says return void it at least has the return $response in it. However if you look at the lower level call you will see:
/**
* Operation getTransactionWithHttpInfo
*
*
*
* @param \Swagger\Client\Model\Object $pnref (required)
* @throws \Swagger\Client\ApiException on non-2xx response
* @return array of null, HTTP status code, HTTP response headers (array of strings)
*/
public function getTransactionWithHttpInfo($pnref)
{
…
Where the return reads:
try {
list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
$resourcePath,
'GET',
$queryParams,
$httpBody,
$headerParams,
null,
'/reporting/{Pnref}'
);
return [null, $statusCode, $httpHeader];
} catch (ApiException $e) {
Where you see the null being thrown in where $response seems like it should be.
Is there anything I can so with the swagger plugin, or markup in the service itself, to change the way the code gen tool will consume the swagger json and generate these clients?