OpenAPITools / OpenAPITools/openapi-generator

[BUG][C#][CSharp] Newline character at the example field of the property leads to incorrect CSharp generation

Open
#18,321 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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

If example of the property contains (somehow) sign "\n" at the end

example: |
Succeeded, OrderNo=326123, EndTime={08.08.18 23:59:59}, OrderEndTime=(None)

it leads to rolling to the next line of close tag

    /// <summary>
    /// correct summary
    /// </summary>
    /// <value>correct value </value>
    /// <example>Incorrect example with end tag rolled to the next line

< / example> (I inserted spaces here to show it in the github page)

openapi-generator version

7.4.0

OpenAPI declaration file content or url

please take from https://github.com/OpenAPITools/openapi-generator/issues/18308

Generation Details
Steps to reproduce

call openapi-generator-cli generate -g csharp -i alor_api.yml -o generated --additional-properties=targetFramework=net8.0

Related issues/PRs

please take from https://github.com/OpenAPITools/openapi-generator/issues/18308

Suggest a fix

I've found that it probably should be added replace("\n", " ") in toExampleValue function at least in AbstractCSharpCodegen class

@Override
public String toExampleValue(Schema p) {
return p.getExample() == null
? null
: p.getExample().toString().replace("\n", " ");
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with AbstractCSharpCodegen.toExampleValue and reproduce the issue using the openapi-generator-cli command and the alor_api.yml input referenced from issue 18308. Compare the generated C# XML documentation around the example value; done means the closing tag remains correctly placed when the property example ends with a newline.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, java
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.