【问题标题】:represent a xml on Swagger yaml在 Swagger yaml 上表示一个 xml
【发布时间】:2016-10-19 19:54:00
【问题描述】:

我正在swagger编辑器上制作文档,但我不知道如何解决..

我需要在 YAML 文件中写入什么才能得到这个结果?

<tag>
    <example Amount='100.00' NumberOfGuests='1'/>
    <example Amount='120.00' NumberOfGuests='2'/>
    <example Amount='140.00' NumberOfGuests='3'/>
</tag>

我多次尝试写“示例”,但出现错误:

(YAML 语法错误 第 621 行重复的映射键)

我需要怎么做才能在同一属性上用不同的值多次表示同一个标签?

【问题讨论】:

  • 欢迎来到 Stack Overflow!你可以先拿tour 学习How to Ask 一个好问题。这让我们更容易为您提供帮助。

标签: xml yaml swagger


【解决方案1】:

我相信你会这样做:

definitions:
  Tag:
    xml:
      # use `tag` instead of `Tag` as the name
      name: tag
    properties:
      example:
        type: array
        items:
          $ref: '#/definitions/Example'
        xml:
          # don't wrap array
          wrapped: false
  Example:
    type: object
    properties:
      Amount:
        type: number
        format: float
        xml:
          # it's an attribute, not an element
          attribute: true
      NumberOfGuests:
        type: integer
        format: int32
        xml:
          attribute: true

注意xml 属性,以告知如何在 JSON Schema 中格式化特定于 XML 的负载。有关该结构的更多信息,请参见 here

【讨论】:

  • 感谢@fehguy!有没有办法在默认情况下定义两个或更多对象?
猜你喜欢
  • 2021-06-04
  • 2019-10-18
  • 2010-09-08
  • 2022-01-12
  • 1970-01-01
  • 2021-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多