Open ikill69 opened 2 years ago
thanks for reporting the issue
cc @devhl-labs
How many parameters does the spec say there are? I suspect the problem is not about the format, but rather the readOnly. In either case, I'm not sure why the RestSharp library would be ignoring properties. Can you shed some light on it? FYI, I have a lot of changes pending and I'm working with wing to get it merged.
@devhl-labs You are absolutely right.
I did another diff and compared to the swagger and it is the readOnly. When I did my first check I thought I had some readonly ones in the restsharp ctor but I don't.
Why should readOnly be excluded? If it is excluded, how do the properties ever get populated?
@devhl-labs good point. That brings it back to "format" being the issue again. It is the only other property that mirrors the output.
This is the section of the swagger for user, it is one of the objects having a problem
They are making some movement in the issue System.Text.Json can't deserialize type with more than 64 ctor parameters. see the PR here https://github.com/dotnet/runtime/pull/75982
So limiting the number of parameters in the constructor may not be as important soon.
@devhl-labs perhaps simply changing the output for each property that is readonly from " { get; private set; }" to " { get; init; }" could be part of the solution. I have added this as a temporary workaround for now to the issue.
Actually I saw this. As far as I can tell, the issue here is not that generic-host is making too many parameters, it's that other libraries don't have enough, plus that STJ issue you just posted.
init is a newer language feature, so I can't use it right now, but I do plan on doing something to use new language features. After I get my pending work merged, I will consider how to do that.
@devhl-labs I came to the exact same conclusion. The other library is doing it differently and I think it is to do with Newtonsoft being able to set Private properties.
This is what they are using in the "restsharp" output as the constructor and I debugged the code in both applications and watch the Deserialize set a property that is marked as private.
The particular property that I am taking about is in fact the "ID" so this is extremely important and is required almost all of the time after it is created. And as you can see in my comment above https://github.com/OpenAPITools/openapi-generator/issues/13480#issuecomment-1253256791 The "restsharp" constructor does not include it either and yet it is still able to be set even thought it is "private set;".
Bug Report Checklist
Description
I have hit a problem with a hard limit in the MaxParameterCount in the System.Text.Json class. See issue 12792 for details
After looking closely at the issue I have noticed that when I run the generator with the "--library=generichost" set i get 68 Parameters in the cstor. However when I run it with the "restsharp" library set I only get 32
Both of these instances are using the exact same Swagger file.
It looks like it is something to do with "format" field in the JSON. When "restsharp" is used these fields are excluded but when "generichost" is used they are all included. I thought at first it was "Readonly" but that does not seem to match up with what is generated.
This is what the Swagger looks like:
restsharp ctor
generichost ctor
openapi-generator version
docker run --rm -v C:\Dev\OpenAPI_CodeGen:/local openapitools/openapi-generator-cli:v6.1.0 generate -i /local/My_swagger.json -g csharp-netcore -o /local/csharp/OpenApi --skip-validate-spec --additional-properties=netCoreProjectFile=true,targetFramework=net6.0,packageName=MyClient.SDK --library=generichost
OpenAPI declaration file content or url
Unfortunately I can not post the exact Swagger
Steps to reproduce
You need a Swagger file that has more properties than 64 on a particular object and have some of the properties setup using the format property.
docker run --rm -v C:\Dev\OpenAPI_CodeGen:/local openapitools/openapi-generator-cli:v6.1.0 generate -i /local/My_swagger.json -g csharp-netcore -o /local/csharp/OpenApi --skip-validate-spec --additional-properties=netCoreProjectFile=true,targetFramework=net6.0,packageName=MyClient.SDK --library=generichost
docker run --rm -v C:\Dev\OpenAPI_CodeGen:/local openapitools/openapi-generator-cli:v6.1.0 generate -i /local/My_swagger.json -g csharp-netcore -o /local/csharp/OpenApi --skip-validate-spec --additional-properties=netCoreProjectFile=true,targetFramework=net6.0,packageName=MyClient.SDK --library=restsharp
Related issues/PRs
Suggest a fix
Suggest a Temporary Work Around
Replace all the "private set;" with "init;" in the affected classes. (So that the JsonSerializer.Deserialize can work with them properly. and they can still be set on create of the object)
You can also copy the constructor from the affected "restsharp" generated classes into the "generichost" classes. (This may not match exactly the readonly fields so I suggest the following step above as well if your going to do this)