OpenAPITools / OpenAPITools/openapi-generator
[csharp-netcore] Generic Host: Generated Model ctor has more Parameters than the other Library types
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file or test is named, and the exact Swagger file is unavailable. Start by reproducing with a comparable spec containing more than 64 properties and formatted fields, using the csharp-netcore generichost and restsharp commands in the issue; inspect the generated model constructors and serialization behavior. Done means the generichost output no longer exceeds the relevant constructor parameter limit while preserving expected model behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100