Skip to content

XML rendering for array-level examples uses duplicates of the 1st array item #3826

@hkosova

Description

@hkosova
Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version? 2.0, 3.0
Which Swagger-UI version? 3.4.0
How did you install Swagger-UI? http://editor.swagger.io
Which browser & version? Chrome 62
Which operating system? Windows 7

Demonstration API definition

2.0:

swagger: '2.0'
info:
  title: test
  version: 0.0.0

paths:
  /:
    get:
      produces: 
        - application/xml
        - application/json
      responses:
        200:
          description: OK
          schema:
            $ref: '#/definitions/Users'

definitions:
  Users:
    type: array
    items:
      $ref: '#/definitions/User'
    xml:
      name: users
      wrapped: true
    example:
      - id: 1
        name: Arthur Dent
      - id: 2
        name: Ford Prefect
  User:
    type: object
    properties:
      id:
        type: integer
      name:
        type: string
    xml:
      name: user

3.0:

openapi: 3.0.0
info:
  title: test
  version: 0.0.0

paths:
  /:
    get:
      responses:
        '200':
          description: OK
          content:
            application/xml:
              schema:
                $ref: '#/components/schemas/Users'
            application/json:
              schema:
                $ref: '#/components/schemas/Users'

components:
  schemas:
    Users:
      type: array
      items:
        $ref: '#/components/schemas/User'
      xml:
        name: users
        wrapped: true
      example:
        - id: 1
          name: Arthur Dent
        - id: 2
          name: Ford Prefect
    User:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
      xml:
        name: user

Expected Behavior

XML response example consists of the items specified in the array example:

<?xml version="1.0" encoding="UTF-8"?>
<users>
	<user>
		<id>1</id>
		<name>Arthur Dent</name>
	</user>
	<user>
		<id>2</id>
		<name>Ford Prefect</name>
	</user>
</users>

Current Behavior

XML response example contains duplicates of the 1st array item:

<?xml version="1.0" encoding="UTF-8"?>
<users>
	<user>
		<id>1</id>
		<name>Arthur Dent</name>
	</user>
	<user>
		<id>1</id>
		<name>Arthur Dent</name>   <!-- Should be id=2, name="Ford Prefect" -->
	</user>
</users>

Context

Array-level examples are rendered correctly in JSON. This issue applies to XML rendering only.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions