question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

XML example cannot be generated with 'allOf'

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
heldersepucommented, Apr 9, 2018

Sounds like a good time to kick XML out your API !

Sorry I know is not helpful, I just could not resist…

1reaction
kalatchevcommented, Sep 17, 2018

Same issue 😦 Enterprise APIs relay on XML. JSON is primary for web development. XML can be transformed with XSLT, data can be found with XPath and defined with XSD. JSON … OMG! Do you know any bank or health system, which works with JSON? I mean in core of systems, not web site integrations? Common, XML is here to stay for a long time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Representing XML - Swagger
Representing XML. In your API specification, you can describe data in both XML and JSON formats as they are easily interchangeable. For example,...
Read more >
XML for the uninitiated - Microsoft Support
For example, school teachers mark up student papers all of the time. ... A well-formed XML file conforms to a set of very...
Read more >
Creating an IS Document Type from an XML Schema Definition
If the cache is not large enough to include all of the generated IS ... if the content models in the XML schema...
Read more >
WH-347 Form to Payroll XML Example
Start with the minimal example we created in the last section, but with all of the data left blank, as shown below: Empty...
Read more >
Creating XML schemas with Rational Application ... - IBM
If you intend to generate Java™ beans from your XML schema, create a Java ... If you cannot see the XML option, select...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found