Swagger对JSON和XML的不同定义

时间:2017-04-11 10:02:14

标签: json xml swagger openapi

我目前正在使用Swagger 2.0记录API。

API会生成application/jsonapplication/xml

定义部分是:

definitions:
  newsFeed:
    type: object
    description: the object is wrapped...
    properties:
      feedId:
        type: string
        example: '987654'
        xml:
          attribute: true
      title:
        type: string
      description:
        type: string
      feedUrl:
        type: string
        example: http://heise.de.feedsportal.com/c/35207/f/653902/index.rss
      logoUrl:
        type: string
        example: http://example.com/logo.png
      language:
        type: string
        example: de_DE
      pos:
        type: string
        example: '0'
      active:
        type: boolean

Swagger-UI生成此XML。

<?xml version="1.0" encoding="UTF-8"?>
<newsFeed feedId="987654">
    <title>string</title>
    <description>string</description>
    <feedUrl>http://heise.de.feedsportal.com/c/35207/f/653902/index.rss</feedUrl>
    <logoUrl>http://example.com/logo.png</logoUrl>
    <language>de_DE</language>
    <pos>0</pos>
    <active>true</active>
</newsFeed>

这个JSON:

{
  "feedId": "987654",
  "title": "string",
  "description": "string",
  "feedUrl": "http://heise.de.feedsportal.com/c/35207/f/653902/index.rss",
  "logoUrl": "http://example.com/logo.png",
  "language": "de_DE",
  "pos": "0",
  "active": true
}

两者都是正确的,但API提供了不同的JSON。

{
    "newsFeed": {
        "feedId": "987654",
        "title": "string",
        "description": "string",
        "feedUrl": "http://heise.de.feedsportal.com/c/35207/f/653902/index.rss",
        "logoUrl": "http://example.com/logo.png",
        "language": "de_DE",
        "pos": "0",
        "active": true
    }
}

如何使用Swagger记录此内容?

0 个答案:

没有答案