I like to use an created api client from a swagger hub.
I use the following swagger api:
https://app.swaggerhub.com/apis/Comline/helic-portal-mandant-api-arze/1.11.0#/info
I have downloaded the api in json from swagger hub. See the following screenshot.
After that, i create a "service reference" to my c# project (.NET 6)
I thought I can use this API client directly, but there was still a problem in the generated C# file.
There was an object with the name UserDTO which was not generated automatically.
/// <summary>Service für die Vorgangsanlage (Berichtigung)</summary>
/// <param name="processBerichtigungCreateRequestV5,UserDTO">Datenobjekt beinhaltet die Attribute für die Vorgangsanlage (Berichtigung)</param>
/// <returns>Aufruf des Service für die Vorgangsanlage wurde erfolgreich durchgeführt</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public System.Threading.Tasks.Task<ProcessBerichtigungResponseV5> ProcessBerichtigungCreateV5Async(ProcessBerichtigungCreateRequestV5 processBerichtigungCreateRequestV5,UserDTO)
{
return ProcessBerichtigungCreateV5Async(processBerichtigungCreateRequestV5,UserDTO, System.Threading.CancellationToken.None);
}
Questions:
Now I am not sure, is it normal that when generating the API for a C# API client via the swaggerhub.com in Visual Studio 2022 there can be objects that are not automatically generated?
Did the creator of the API make a mistake when creating the API?
Should I recreate this object every time I update the API?
Did the creator of the API make a mistake when creating the API?
Yes, it seems so. The problem is that some parameter names in the API definition include a comma - which makes them invalid identifiers in programming languages. This is why the generated code is not quite correct.
parameters:
- in: body
name: processBerichtigungCreateRequestV5,UserDTO
^^^
To try and work around the issue, you can open the downloaded OpenAPI JSON file in a text editor and do a search/replace and replace ,UserDTO
with an empty string. Then try to import the updated file into Visual Studio again.