Search code examples
c#openapi-generator.net-standard-2.0

OpenAPI CodeGen adds "operationIndex" parameter to all calls


We're migrating a .NET C# class library from .NET Framework 4.6.2 to .NET Standard 2.0. We use the OpenAPI client code generator to generate code from a bunch of API definition files.

Using CodeGen 6.0.1 against OpenAPI 2.0 documents.

The code generator looks fine apart from the fact that it includes parameters named "operationIndex" for every call, eg:

    /// <summary>
    /// Get a list of lists.
    /// </summary>
    /// <param name="listType">The type of list to return.</param>
    /// <param name="operationIndex">Index associated with the operation.</param>
    /// <returns>ApiCollectionOfList</returns>
    public ApiCollectionOfList GetLists(string listType, int operationIndex = 0);

I've searched through the OpenAPI doco, and the web generally, but I can't find any reference to this. The OpenAPI definition files don't contain any reference to this parameter. To us, it's just noise in the code we'd like to dispense with.

Does anyone now anything about this and how to suppress it?

UPDATE

Powershell command:

java -jar openapi-generator-cli-6.0.1.jar generate -i "2022-08-17\aaa_Definition Files\List.swagger.json" -g csharp-netcore -o "2022-08-17\List" -c "NetStd2\List.config.json"

CodeGen config (List.config.json):

{
"packageName": "SKYLib.List",
"targetFramework": "netstandard2.0",
"modelPropertyNaming": "PascalCase",
"nonPublicApi": "false",
"useCollection": "false",
"validatable": "false",
"optionalAssemblyInfo": "false",
"optionalEmitDefaultValues": "false",
"optionalMethodArgument": "true",
"optionalProjectFile": "false",
"releaseNote": null
}

Sample definition file

https://developer.sky.blackbaud.com/docs/services/list/export?DocumentFormat=Swagger


Solution

  • Turns out that this was added in version 6.0.0 of the OpenAPI Code Generator for C# Net Core ("csharp-netcore"). There was no explicit change note to that effect but some discussions on GitHub confirmed it.

    Apparently, the operationIndex parameter is supposed to provide a mechanism for directing methods/calls to different servers. (I would have thought that serverId might be a clearer parameter name.) My own opinion is that this is quite an esoteric use case and that the overhead in code and potential confusion warrants that adding these parameters not be the default behavior.

    I've suggested that a config switch should be provided to suppress this behavior, eg optionalOperationIndex, int, default false.