英文:
Uncreated objects in generated api client using Swagger-API
问题
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?
英文:
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?
答案1
得分: 2
是的,看起来是这样。问题在于API定义中的一些参数名称包含逗号,这使它们在编程语言中无效。这就是为什么生成的代码不完全正确。
parameters:
- in: body
name: processBerichtigungCreateRequestV5,UserDTO
^^^
为了尝试解决这个问题,您可以在文本编辑器中打开下载的OpenAPI JSON文件,然后进行搜索/替换操作,将,UserDTO
替换为一个空字符串。然后尝试再次导入更新后的文件到Visual Studio中。
英文:
> 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论