【发布时间】:2019-09-19 10:10:10
【问题描述】:
我正在使用 OpenAPI 3.0 和 SwaggerHub 设计一个 API。我的 API 有一个 GET 端点,它以 XML 格式返回一组员工:
<Employees>
<Employee>
<EmpId>001</EmpId>
<Name>Steven</Name>
<Mobile>1-541-754-3010</Mobile>
<EmailId>steven@yourcomany.com</EmailId>
</Employee>
<Employee>
<EmpId>002</EmpId>
<Name>Mark</Name>
<Mobile>1-551-754-3010</Mobile>
<EmailId>mark@yourcomany.com</EmailId>
</Employee>
</Employees>
到目前为止,这是我的 OpenAPI YAML 文件:
openapi: 3.0.0
info:
title: General Document
version: "1.0"
contact:
email: developer@email.com
description: >
# Introduction
This document describes a list of API's available. \
paths:
/employees:
get:
description: This will return employees information in JSON and XML formats
responses:
200:
$ref: '#/components/responses/employeesAPI'
components:
responses:
employeesAPI:
description: This will return information about employees
content:
application/xml:
schema:
$ref: '#/components/schemas/EmployeesInfo'
schemas:
Employee:
type: object
required:
- EmpId
- Name
- Mobile
- EmailId
properties:
EmpId:
type: string
example: Employee id goes here
description: Employee id
Name:
type: string
example: Employee name goes here
description: Employee name
Mobile:
type: string
example: Employee mobile goes here
description: Employee mobile
EmailId:
type: string
example: Employee email goes here
description: Employee email
EmployeesInfo:
type: object
required:
- Employee
properties:
Employee:
$ref: '#/components/schemas/Employee'
xml:
name: EmployeesInfo
# Added by API Auto Mocking Plugin
servers:
- description: SwaggerHub API Auto Mocking
url: https://virtserver.swaggerhub.com/name2200/test/1.0
问题是 SwaggerHub 中显示的 XML 响应示例与预期的响应 XML 不匹配。
如何正确定义 XML 对象数组?
【问题讨论】:
标签: swagger openapi swaggerhub