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

Update charp generator to generate RestSharp 107.x compliant source code, update other dependencies in generated packages.config #11744

Closed
bakgerman opened this issue Mar 20, 2022 · 7 comments

Comments

@bakgerman
Copy link

Description

The csharp generator uses RestSharp 105.1.0 in its packages.config.
This dates to 4/30//2015.
While one can manually update to the latest 106.x release, the 107.x release is a breaking change from previous
RestSharp releases. See https://restsharp.dev/v107/#restsharp-v107
This requires changes to the generated source code.

Swagger-codegen version

The version used was the latest released on editor.swgger.io as of March 20, 2022, 3.0.33

Command line used for generation
Steps to reproduce

Create a client using the csharp language selected

Related issues/PRs
Suggest a fix/enhancement

Update the dependencies emitted by the csharp generator in general

@MusicMonkey5555
Copy link

I was able to make the changes pretty easily so I don't think it would be a big deal to make the required changes and there are actually security concerns with older version of RestSharp as well as Newtonsoft.json.

@vahanij
Copy link

vahanij commented Oct 26, 2022

I would love to second this. While I can change the generated code, it kind of defeats the purpose of generating code.
@MusicMonkey5555 do you have a diff by chance?

@MusicMonkey5555
Copy link

@vahanij Like a complete diff between one client vs the updated one? I guess I could make a very simple one, but the ones I have are mostly private so wouldn't want to give them out, but I could provide some of the most common changes (VS picked up most of them by just clicking on the error.

Things like Timeout, UserAgent, BaseUrl are now part of Options: Ex: RestClient.Timeout = Configuration.Timeout; -> RestClient.Options.MaxTimeout = Configuration.Timeout;
IRestResponse is now RestResponse
response.Headers now returns an IReadOnlyCollection<HeaderParameter> rather than IList<Parameter> I also remember seeing an issue around requests made with two header keys that were the same since some place it's stores them as a dictionary, but can't remember details.
IRestRequest is now RestRequest
Method.POST is now Method.Post (Camel case and all enum values for Method have changed the same ie: Get, Put, Delete... CTR+Space makes this easy)
In PrepareRequest file related changes were made:
request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType); -> request.AddFile(param.Value.Name, param.Value.GetFile, param.Value.FileName, param.Value.ContentType); Haven't tested if this works as nothing I'm working with sends a file.
RestClient.ExecuteTaskAsync -> RestClient.ExecuteAsync

I think that covers it all the changes I made and it was pretty easy. I would note of course that RestSharp changed to using a bunch of Microsoft libraries for things like parsing. I think a lot of that is to support newer versions of .net (I'm on 4.8 so nuget asked me to download them). For instance System.Text.Json is included, but a lot of the swagger hub codegen still uses Newtonsoft.Json. I didn't make any changes to not use that so it still relies on that, but I updated it to the newer version as I think the security related update was around Json parsing. I've read that the new Microsoft parsing is a lot quicker, but it doesn't yet handle some things Netwonsoft does.
My goal was pretty much just get it working, test the common calls and make sure things didn't break. I didn't really dive that deep into them as I'm short on time. Hopefully that helps a bit.

@MusicMonkey5555
Copy link

MusicMonkey5555 commented Jan 13, 2023

I updated another project and also noticed I had to add the reference System.Net.Http because of using BaseUrl.

@afust003
Copy link

afust003 commented May 22, 2023

Any updated on this? We are seeing an error that might be related to this issue.
Currently, we are attempting to use SwaggerCodegen v3.0.41 from 02/2023
(see: https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.41) and consume api client code in a .NET Core 6 application but get the following error:
"method not found" -> Method not found: 'Void RestSharp.RestClient.set_BaseUrl(System.Uri)'

Just invoking the constructor generates runtime exception but compile-time shows no errors.

The work-around we implemented was to use "fixed" RestSharp version v105.1 on the client consuming app as this is the version "Swagger Codegen" uses by default at the moment. Hope this helps someone else!

@PeterExtrapreneur
Copy link

Any updates on this?

@frantuma
Copy link
Member

Please try using latest release 3.0.63+ which includes csharp generator refactor. Closing ticket, please reopen if still experiencing issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants