Skip to content

XML example cannot be generated with 'allOf' #4423

Open
@iambingoNJU

Description

@iambingoNJU

Look an example:

openapi: '3.0.0'
info:
  version: 1.0.0
  title: example
servers:
  - url: http://localhost:80

paths:
  /books:
    post:
      summary: add a book
      requestBody:
        content:
          application/xml:
            schema:
              description: book to be added
              allOf:
                - $ref: '#/components/schemas/book'
      responses:
        '200':
          description: OK
components:
  schemas:
    book:
      description: a book
      type: object
      properties:
        id:
          type: string
        author:
          type: string
        year:
          type: integer
          format: int32

Then if I click the 'Example Value' in swagger ui, it gives this info:

<?xml version="1.0" encoding="UTF-8"?>
<!-- XML example cannot be generated -->

However, if I remove 'allOf':

openapi: '3.0.0'
info:
  version: 1.0.0
  title: example
servers:
  - url: http://localhost:80

paths:
  /books:
    post:
      summary: add a book
      requestBody:
        content:
          application/xml:
            schema:
              $ref: '#/components/schemas/book'
      responses:
        '200':
          description: OK
components:
  schemas:
    book:
      description: a book
      type: object
      properties:
        id:
          type: string
        author:
          type: string
        year:
          type: integer
          format: int32

It shows example value correctly:

<?xml version="1.0" encoding="UTF-8"?>
<book>
	<id>string</id>
	<author>string</author>
	<year>0</year>
</book>

And if I change application format to json, it shows json example value correctly whether there is allOf or not.

The reason I want to use allOf is for this.

So is this a bug of allOf or an expected behaviour?
If it's an expected behaviour, then how to solve this two problems?

Currently, I'm using Swagger Editor online version in Chrome browser.

This issue seems related.

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