OpenAPITools / OpenAPITools/openapi-generator

CSharp Generator Related: Unit Test(s) generated are commented out

Open
#10,566 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

After generating a Client library for a given api, the Unit Test Project that is generated contains test assertions which are commented out and comments in the generated code reading // TODO uncomment below to test the method and replace null with proper value

Generated code example portion relevant:

       /// <summary>
        /// Test ApiSomePostMethod
        /// </summary>
        [Test]
        public void ApiSomePostMethodTest()
        {
            // TODO uncomment below to test the method and replace null with proper value
            //SomePostMethodRequest SomePostMethodRequest = null;  // **THIS TYPE IS AVAILABLE VIA SCHEMA**
            //var response = instance.SomePostMethod(SomePostMethodRequest); // **THIS TYPE IS AVAILABLE VIA SCHEMA**
            //Assert.IsInstanceOf(typeof(SomePostMethodResponse), response, "response is SomePostMethodResponse");// **THIS TYPE IS AVAILABLE VIA SCHEMA**
        }
openapi-generator version

@openapitools/openapi-generator-cli@2.4.4

OpenAPI declaration file content or url

n/a - any csharp generator resulting Test Project will suffice

Command line used for generation

due to the CI environment, the call line is a little hairy, thanks for understanding

"node node_modules\\@openapitools\\openapi-generator-cli\\main.js generate -i swagger.json -g csharp -o $workspace\\gen --additional-properties=packageName=$SDKProjectName"
Steps to reproduce

just generate a csharp project set

Suggest a fix/enhancement

It may be im missing a configuration flag - please tell me! 🤣

If im not missing something in the configuration string : a simple fix would be to use the openapi json file's schema section to type matching to create stub results. If this is not something the current csharp generator does - could someone point me to where i could offer to add this via PR

Love this tool - thanks in advance!

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 the CSharp generator entry point and the generated Unit Test Project template, then compare the emitted test methods with the OpenAPI schema types described in the issue. Reproduce with a C# generation command and verify that generated assertions are active and use valid schema-based values rather than TODO/null placeholders.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi
Domain
testing-qa, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.