3

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

SteveCinq
  • 1,920
  • 1
  • 17
  • 22
  • Can you provide a [mre]? An example of an Openapi file and the command you use to run it would be helpful. – gunr2171 Aug 17 '22 at 20:03
  • The definition files are pretty big but I'll try to distill something minimal and post an update. I'll post the command line and the config as well. – SteveCinq Aug 17 '22 at 20:16
  • Ok, the question now has the PS command, the config file content and the URL of a sample definition file document. I hope that helps. Let me know if you need more. – SteveCinq Aug 17 '22 at 22:36

1 Answers1

1

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.

SteveCinq
  • 1,920
  • 1
  • 17
  • 22