#11055·swagger-ui

Swagger UI XML example generator does not self-close empty tags

Author: adrianodpdiazCreated Sep 18, 2026Updated Sep 19, 2026

Content & configuration

Swagger/OpenAPI definition:

yaml
openapi: 3.0.3
info:
  title: XML Empty Tag Example
  version: 1.0.0

paths:
  /example:
    get:
      responses:
        '200':
          description: Example XML response
          content:
            application/xml:
              schema:
                type: object
                xml:
                  name: Response
                properties:
                  id:
                    type: string
                  name:
                    type: string
                  emptyTag:
                    type: object
                    xml:
                      name: EmptyTag

Swagger-UI configuration options:

javascript
SwaggerUI({
  // default configuration
})

Is your feature request related to a problem?

Yes. When Swagger UI generates an XML example for an empty XML element, it does not self-close the element (EmptyTag in the following example):

xml
<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <id>string</id>
  <name>string</name>
  <EmptyTag>
  </EmptyTag>
</Response>

Describe the solution you'd like

When generating XML examples, Swagger UI should generate empty elements using the self-closing XML syntax:

xml
<EmptyTag/>

instead of:

xml
<EmptyTag>
</EmptyTag>