Skip to content

XML example not rendered correctly with oneOf #4943

@pratikpai

Description

@pratikpai
  • OS: Windows 10 Pro (64 bit)
  • Browser: Chrome
  • Version: 69.0.3497.100 (Official Build) (64-bit)
  • Method of installation: dist assets
  • Swagger-UI version: 3.19.3
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.0.0
info:
  description: Test API
  version: v1
  title: Test API
tags:
  - name: Test
    description: Test API
servers:
  - url: /v1
paths:
  /test:
    post:
      tags:
        - Test
      summary: Test endpoint
      description: Test
      operationId: postTest
      responses:
        '200':
          description: Returns response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/test'
            application/xml:
              schema:
                $ref: '#/components/schemas/test'
components:
  schemas:
    test:
      type: object
      properties:
        a: 
          type: string
        b:
          type: integer
        c:
          oneOf: 
            - type: object
            - type: array
            - type: boolean
            - type: integer
            - type: number

Swagger-UI configuration options:

SwaggerUI({
    url: 'v1.yaml',
    dom_id: '#swagger-ui-container',
    deepLinking: false,
    presets: [
      SwaggerUIBundle.presets.apis
    ],
    plugins: [],
    docExpansion: "none",
    validatorUrl: null
})

Describe the bug you're encountering

XML schema is not rendered correctly when I use oneOf for one of the model properties. It just display the first element in the generated example and skips the other two. With reference to my example, it skips properties 'b' and 'c'. It displays the example like below:

<?xml version="1.0" encoding="UTF-8"?>
<test>
	<a>string</a>
</test>

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://editor.swagger.io/
  2. Copy paste the provided spec
  3. Click on POST /test endpoint
  4. Under Responses, change the Response Content Type/Accept to "application/xml"

Expected behavior

It must display atleast the first two attributes which has a valid type.

<?xml version="1.0" encoding="UTF-8"?>
<test>
	<a>string</a>
        <b>0</b>
</test>

Additional context or thoughts

Unrelated Question:
Is there a way to display property 'c' as well in the response example? I understand that the type can be one of the specified types and cannot be displayed like property 'a' & 'b'. However, I just wanted to make sure that I have not missed anything.

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