swagger-api / swagger-api/swagger-ui

XML example cannot be generated with 'allOf'

Open
#4,423 9 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cat: rendering type: bug
Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the OpenAPI 3.0 YAML example in Swagger Editor with application/xml, comparing the request schema using allOf with the direct $ref version. Check whether XML example generation differs only for allOf while JSON generation remains correct. Done means the allOf case produces a valid XML example or the expected behavior is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.