未在使用Swagger-API生成的API客户端中创建的对象

huangapple go评论118阅读模式
英文:

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.

未在使用Swagger-API生成的API客户端中创建的对象

After that, i create a "service reference" to my c# project (.NET 6)

未在使用Swagger-API生成的API客户端中创建的对象
未在使用Swagger-API生成的API客户端中创建的对象

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.

未在使用Swagger-API生成的API客户端中创建的对象

After that, i create a "service reference" to my c# project (.NET 6)

未在使用Swagger-API生成的API客户端中创建的对象
未在使用Swagger-API生成的API客户端中创建的对象

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.

/// &lt;summary&gt;Service f&#252;r die Vorgangsanlage (Berichtigung)&lt;/summary&gt;
/// &lt;param name=&quot;processBerichtigungCreateRequestV5,UserDTO&quot;&gt;Datenobjekt beinhaltet die Attribute f&#252;r die Vorgangsanlage (Berichtigung)&lt;/param&gt;
/// &lt;returns&gt;Aufruf des Service f&#252;r die Vorgangsanlage wurde erfolgreich durchgef&#252;hrt&lt;/returns&gt;
/// &lt;exception cref=&quot;ApiException&quot;&gt;A server side error occurred.&lt;/exception&gt;
public System.Threading.Tasks.Task&lt;ProcessBerichtigungResponseV5&gt; 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.

huangapple
  • 本文由 发表于 2023年3月7日 23:24:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75663893.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定