OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.81k stars 6.58k forks source link

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

Open bsolovij-ebsco opened 3 years ago

bsolovij-ebsco commented 3 years ago
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!

devhl-labs commented 3 years ago

As the comment suggests, this is on purpose. You have to provide the implementation, so it's no use having it be uncommented.

Blackclaws commented 3 years ago

If you'd like to automatically generate stub requests a good place to start would be the aspnetcore server generator that can generate stub serverside methods. However those are also semi-broken for some schemas.

If you want to add this you'd have to add an additional property that conditionally enables stub-tests. Feel free to open a pull request. See CONTRIBUTING.md in the root folder of this project.