如何编写一个Swagger文件来捕获<>块内的信息?

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

How to write a swagger file to capture the information within the <> block?

问题

我正在建立用于API调用的数据管道,其响应遵循以下格式:

&lt;drivers&gt;
 &lt;driver id=&quot;103721&quot;&gt;
  &lt;reported_driver_id&gt;5555&lt;/reported_driver_id&gt;
  &lt;display_ref&gt;5555&lt;/display_ref&gt;
  &lt;name&gt;Toronto Training 1&lt;/name&gt;
  &lt;/driver&gt;
&lt;drivers&gt;

总共有数千名司机在响应中。

我现在编写的Swagger文件如下所示:

&quot;definitions&quot; : {
&quot;sg_response##drivers##driver&quot; : {
  &quot;properties&quot; : {
    &quot;id&quot; : {
      &quot;type&quot; : &quot;number&quot;
    },
    &quot;reported_driver_id&quot; : {
      &quot;type&quot; : &quot;number&quot;
    },
    &quot;display_ref&quot; : {
      &quot;type&quot; : &quot;number&quot;
    },
    &quot;name&quot; : {
      &quot;type&quot; : &quot;string&quot;
    }
  }
}

当我检查结果数据时,我发现无法捕获第一个 'id' 列,以下是我从ETL获取的示例:

&quot;id&quot;,&quot;reported_driver_id&quot;,&quot;display_ref&quot;,&quot;name&quot;
 ,&quot;5555&quot;,&quot;5555&quot;,&quot;Toronto Training 1&quot;
 ,&quot;6666&quot;,&quot;6666&quot;,&quot;Toronto Training 2&quot;
 ,&quot;6161&quot;,&quot;6161&quot;,&quot;Billings Demo 4&quot;
 ,&quot;169168&quot;,&quot;169168&quot;,&quot;Dharminder Grewal&quot;

我真的希望这个API可以以以下格式返回结果:

&lt;drivers&gt;
 &lt;driver&gt;
  &lt;id&gt;123&lt;id&gt;
  &lt;reported_driver_id&gt;5555&lt;/reported_driver_id&gt;
  &lt;display_ref&gt;5555&lt;/display_ref&gt;
  &lt;name&gt;Toronto Training 1&lt;/name&gt;
  &lt;/driver&gt;
&lt;drivers&gt;

但它没有,id位于driver对象的块内。请问你是否可以帮助我修改我的Swagger文件以捕获id信息?
如果由于API的编写方式而无法捕获id信息,也请告诉我,这样我可以推动后端团队更改API结构。

感谢您帮助数据工程行业的新手 如何编写一个Swagger文件来捕获<>块内的信息?

英文:

I am working on building data pipeline for an API call whose response follows the below format:

&lt;drivers&gt;
 &lt;driver id=&quot;103721&quot;&gt;
  &lt;reported_driver_id&gt;5555&lt;/reported_driver_id&gt;
  &lt;display_ref&gt;5555&lt;/display_ref&gt;
  &lt;name&gt;Toronto Training 1&lt;/name&gt;
  &lt;/driver&gt;
&lt;drivers&gt;

And there are in total thousands of drivers within the response.

Right now the swagger file I wrote looks like this:

&quot;definitions&quot; : {
&quot;sg_response##drivers##driver&quot; : {
  &quot;properties&quot; : {
    &quot;id&quot; : {
      &quot;type&quot; : &quot;number&quot;
    },
    &quot;reported_driver_id&quot; : {
      &quot;type&quot; : &quot;number&quot;
    },
    &quot;display_ref&quot; : {
      &quot;type&quot; : &quot;number&quot;
    },
    &quot;name&quot; : {
      &quot;type&quot; : &quot;string&quot;
    }
  }
}

And when I check the result data, I found that I cannot capture the first 'id' column, below is a sample of what I got from my ETL:

&quot;id&quot;,&quot;reported_driver_id&quot;,&quot;display_ref&quot;,&quot;name&quot;
 ,&quot;5555&quot;,&quot;5555&quot;,&quot;Toronto Training 1&quot;
 ,&quot;6666&quot;,&quot;6666&quot;,&quot;Toronto Training 2&quot;
 ,&quot;6161&quot;,&quot;6161&quot;,&quot;Billings Demo 4&quot;
 ,&quot;169168&quot;,&quot;169168&quot;,&quot;Dharminder Grewal&quot;

I really hope that this API can return the result in this format:

&lt;drivers&gt;
 &lt;driver&gt;
  &lt;id&gt;123&lt;id&gt;
  &lt;reported_driver_id&gt;5555&lt;/reported_driver_id&gt;
  &lt;display_ref&gt;5555&lt;/display_ref&gt;
  &lt;name&gt;Toronto Training 1&lt;/name&gt;
  &lt;/driver&gt;
&lt;drivers&gt;

But it's not, the id is within the driver object's block. Could you please help me to modify my swagger file to capture the id information?
If it is not possible to capture the id information due to the nature of how the API is wrote, please also let me know so I can push the backend team to change the API structure.

Thank you for helping a newbee in data engineering industry 如何编写一个Swagger文件来捕获<>块内的信息?

答案1

得分: 2

问题已解决,在Swagger文件中添加以下内容:

"sg_response##drivers##driver" : {
  "properties" : {
    "id" : {
      "type" : "number",
      "xml":{
        "attribute" : "true"
      }
    }
  }
}

基本上添加:

"xml":{
  "attribute" : "true"
}
英文:

the question is solved, in the swagger file, add this:

&quot;sg_response##drivers##driver&quot; : {
  &quot;properties&quot; : {
    &quot;id&quot; : {
      &quot;type&quot; : &quot;number&quot;,
      &quot;xml&quot;:{
        &quot;attribute&quot; : &quot;true&quot;
      }
    },

basically add :

&quot;xml&quot;:{
        &quot;attribute&quot; : &quot;true&quot;
      }

huangapple
  • 本文由 发表于 2023年6月29日 00:56:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76575275.html
匿名

发表评论

匿名网友

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

确定