xml - 如何在 Swagger 文档中添加 xml 示例

标签 xml api swagger documentation

您好,我正在为 api 创建 swagger 文档,我想添加 xml 示例,但我做不到。

这是我写的 swagger 文档

swagger: "2.0"
info:
  title: Documentatie API 
  description: Descriere documentatie API metode POST
  version: 1.0.0
host: xxx.ro
basePath: /v1
schemes:
  - https
paths:
  /stareMesaj:
    post:
      summary: Stare mesaj
      description: Descriere stare mesaj
      consumes:

            - application/xml
      produces:

            - application/xml
      responses:
        200:
          description: OK
          schema:
            type: object
            properties:
              id:
                type: integer
                example: 4
              name:
                type: string
                example: Arthur Dent

我认为模式下的属性会在示例中进行转换,但它说:

<?xml version="1.0" encoding="UTF-8"?>
<!-- XML example cannot be generated; root element name is undefined -->

能给我举个例子吗?

提前致谢

最佳答案

您的内联架构没有名称,因此 Swagger UI 不知道如何在 XML 中命名根元素。

xml.name 添加到您的架构中:

      responses:
        200:
          description: OK
          schema:
            type: object
            properties:
              ...
            xml:           # <-----
              name: user

或者在definitions部分定义一个命名模式并引用它:

      responses:
        200:
          description: OK
          schema:
            $ref: '#/definitions/user'

definitions:
  user:
    type: object
    properties:
      id:
        type: integer
        example: 4
      name:
        type: string
        example: Arthur Dent

关于xml - 如何在 Swagger 文档中添加 xml 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60560283/

相关文章:

c# - 从 XML 模式生成 C# 类文件

python - 如何使用Python分割XML文件(在特定的N节点上),同时保留页眉和页脚?

java - Http 请求不接受参数中的空格并抛出 ClientProtocolException

c# - 带有 dotnet 核心的 Swagger 文档的文件返回类型

java - 如何使用 Java 在 XML 文件中保存加密/散列密码

c# - 避免在 xml 文件中重复输入 c#

java - Springfox Swagger 一代创建了奇怪的模式

java - 在 Swagger UI 中执行需要一些时间才能显示结果

php - php-如何从随机YouTube视频ID列表中生成YouTube视频列表?

api - Twitter4j 只收集某个国家