Skip to content

[BUG] ApiClient using incorrect method signature for RestSharp 106.5.4 for csharp framework 4.5 #6532

Closed
@jburns24

Description

@jburns24

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Generated client does not compile with RestSharp verions 106.5.4.

In the generated readme I saw

I had another library that was dependent on RestSharp 106.5.4 so tried to use that version.

Trying to compile with that version of RestSharp failed with the following error

1>C:\git\sniper-regression\EbayApiRest.Order\Generated\Order\EbayApiRest.Order\Client\ApiClient.cs(137,51,137,69): error CS1503: Argument 2: cannot convert from 'System.Action<System.IO.Stream>' to 'byte[]'

The generated method that fails to compile

private RestRequest PrepareRequest(
    String path, RestSharp.Method method, List<KeyValuePair<String, String>> queryParams, Object postBody,
    Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
    Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams,
    String contentType)
{
    var request = new RestRequest(path, method);

    // add path parameter, if any
    foreach(var param in pathParams)
        request.AddParameter(param.Key, param.Value, ParameterType.UrlSegment);

    // add header parameter, if any
    foreach(var param in headerParams)
        request.AddHeader(param.Key, param.Value);

    // add query parameter, if any
    foreach(var param in queryParams)
        request.AddQueryParameter(param.Key, param.Value);

    // add form parameter, if any
    foreach(var param in formParams)
        request.AddParameter(param.Key, param.Value);

    // add file parameter, if any
    foreach(var param in fileParams)
    {
        request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);
    }

    if (postBody != null) // http body (model or byte[]) parameter
    {
        request.AddParameter(contentType, postBody, ParameterType.RequestBody);
    }

    return request;
}

The line request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType); fails to compile because in RestSharp (106.5.4) the method signature for this change.

The method signature from RestSharp that matches the closest is public IRestRequest AddFile(string name, Action<Stream> writer, string fileName, long contentLength, string contentType = null);. The generated method is just missing the contentLength paramater.

openapi-generator version

4.3.1

OpenAPI declaration file content or url

Contract I am generating from
https://developer.ebay.com/api-docs/master/buy/order/openapi/3/buy_order_v1_beta_oas3.json

This contract does not pass validation on the command line as it appears the contract is using a reserved word (basePath) in the servers array. Though this contract does pass validation on https://apitools.dev/swagger-parser/online/#

I have an open ticket with ebay to fix their contract as I was able to edit it locally and change the variable in the servers array to foo and it passed validation and generated. Though it also appears that if you skip validation (--skip-validate-spec) the generated code is still correct.

(for JSON code), so it becomes more readable. If it is longer than about ten lines,
please create a Gist (https://gist.github.com) or upload it somewhere else and
link it here.
-->

Command line used for generation

open-api-codegen-cli.jar

java -DapiTests=false -DmodelTests=false -jar .\open-api-codegen-cli.jar generate -i "https://developer.ebay.com/api-docs/master/buy/order/openapi/3/buy_order_v1_beta_oas3.json" -c ".\.swagger-config.json" -g csharp -o "Generated/Orders" --package-name="EbayApiRest.Order" --ignore-file-override=".\.swagger-codegen-ignore" --skip-validation-spec

swagger-config.json

{
  "sourceFolder": "",
  "targetFramework": "v4.5",
  "modelPropertyNaming": "PascalCase",
  "hideGenerationTimestamp": false,
  "optionalMethodArgument": false,
  "optionalAssemblyInfo": false,
  "optionalProjectFile": false,
  "nonPublicApi": false,
  "validatable": false
}

.swagger-codegen-ignore

**/.gitignore
**/.travis.yml
**/build.*
**/*.sh
Steps to reproduce

Generate Code
Add to Visual Studio .NET Framework 4.5 project
Add packagest Newtonsoft.json (7.0.0), JsonSubTypes (1.2.0), and RestSharp (106.5.4)
Build in visual studio

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions