OpenAPITools / OpenAPITools/openapi-generator
[BUG] [csharp] ToString() on OneOf produces string with class description artifact
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
When you use schema oneOf on the in path parameter (and maybe response as well) the resulting object's ToString method that is used to generate the full URL produces artifacts like so:
stringBuilder.Append("class IntOrString{\n");
stringBuilder.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
stringBuilder.Append("}\n");
openapi-generator version
7.0.1
OpenAPI declaration file content or url
Generation Details
Relevant part of my csharp.json file:
"generatorName": "csharp",
"targetFramework": "net7.0",
openapi-generator-cli generate -i openapi.json -o client -c csharp.json
Steps to reproduce
Executing code to fetch Resource using the apiInstance
int value = 777777;
try
{
// GET resource by int
Resource result = apiInstance.GetResourceByIntOrString(new IntOrString(value));
catch (ApiException e)
{
_logger.LogInformation("Exception when calling DefaultApi.GetResource: " + e.Message );
_logger.LogInformation("Status Code: "+ e.ErrorCode);
_logger.LogInformation(e.StackTrace);
}
fails with:
Related issues/PRs
Suggest a fix
Make ToString() method return only the content of ActualInstance.
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
Generate the C# client with the supplied csharp.json settings and reproduce the request using the IntOrString path parameter. Start by locating the generated OneOf model's ToString() implementation and compare its output with the URL construction. Done means ToString() contributes only the ActualInstance content, without the class-description artifact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100