swagger-api / swagger-api/swagger-ui

XML attributes and namespaces not rendered correctly in examples

Open
#7,693 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Q&A (please complete the following information)
  • OS: *
  • Browser: chrome, ff
  • Version: latest
  • Method of installation: web
  • Swagger-UI version: 4.1.2
  • Swagger/OpenAPI version: OpenAPI 3.0.3
Content & configuration

I defined a schema and want to render the example in XML. Everything goes pretty well, but elements of string type don't render any attributes. And xml attributes in different namespaces do not show the corresponding namespace or prefix. This results in faulty examples that are not accepted by my server.

Example Swagger/OpenAPI definition:

openapi: 3.0.3
info:
  title: Servicelayer SKOS API
  description: |
  version: 1.0.0
paths:

  /api/concept:
    post:
      tags:
        - Concepts
      requestBody:
        content:
          application/rdf+xml:
            schema:
              $ref: '#/components/schemas/Concept'
      responses:
        '201':
          description: 'Concept candidate created succesfully. Note, the returned data will contain the subjectIDs generated by the system. NOTE: the XML attributes require namespace prefix, which are omitted by this OpenAPI documentation''s renderer!!!'
components:
  schemas:
    Concept:
      type: object
      description: Concept RDFWrapper
      xml:
        name: RDF
        prefix: rdf
        namespace: http://www.w3.org/1999/02/22-rdf-syntax-ns#
        wrapped: true
      properties:
        concept:
          $ref: '#/components/schemas/ConceptDescription'
    ConceptDescription:
      type: object
      xml:
        name: Description
        prefix: rdf
        namespace: http://www.w3.org/1999/02/22-rdf-syntax-ns#
      properties:
        about:
          type: string
          description: the concept's subjectID. Only valid for updates of existing concepts
          example: http://data.beeldengeluid.nl/gtaa/12345
          xml:
            prefix: rdf
            namespace: http://www.w3.org/1999/02/22-rdf-syntax-ns#
            attribute: true
        type:
          type: object
          xml:
            prefix: rdf
            namespace: http://www.w3.org/1999/02/22-rdf-syntax-ns#
          properties:
            resource:
              type: string
              enum: ['http://www.w3.org/2004/02/skos/core#Concept']
              example: http://www.w3.org/2004/02/skos/core#Concept
              xml:
                prefix: rdf
                namespace: http://www.w3.org/1999/02/22-rdf-syntax-ns#
                attribute: true
        prefLabel:
          $ref: '#/components/schemas/Label'
        hasTopConcept:
          $ref: '#/components/schemas/RdfRef'
    RdfRef:
      type: object
      xml:
        prefix: skos
        namespace: http://www.w3.org/2004/02/skos/core#
      properties:
        resource:
          type: string
          example: 'http://data.beeldengeluid.nl/gtaa/--something--'
          xml:
            attribute: true
            prefix: rdf
            namespace: http://www.w3.org/1999/02/22-rdf-syntax-ns#
    Label:
      type: string
      example: 'my text'
      xml:
        prefix: skos
        namespace: http://www.w3.org/2004/02/skos/core#
      properties:
        lang:
          type: string
          example: 'nl'
          xml:
            attribute: true
            prefix: xml
            namespace: http://www.w3.org/XML/1998/namespace

Swagger-UI configuration options:

SwaggerUI({
        url: getSwaggerUrlParam(),
        dom_id: '#swagger-ui',
        deepLinking: true,
        presets: [
          SwaggerUIBundle.presets.apis,
          SwaggerUIStandalonePreset
        ],
        plugins: [
          SwaggerUIBundle.plugins.DownloadUrl
        ],
        layout: "BaseLayout",
        validatorUrl: null
      })
Describe the bug you're encountering

xml attributes are not rendered correctly in example:

  • namespace prefixes are omitted in embedded property definitions
  • namespace prefixes are omitted in referenced property definitions (See RdfRef)
  • in case of elements of string type, attributes are omitted completely (See Label)
To reproduce...

Steps to reproduce the behavior:

  1. Load the yaml in swagger-ui (or https://editor.swagger.io/)
  2. open the post command
  3. scroll to the example
  4. See error
Actual behaviour
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" about="http://example.com">
		<rdf:type xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" resource="http://www.w3.org/2004/02/skos/core#Concept">
		</rdf:type>
		<skos:prefLabel xmlns:skos="http://www.w3.org/2004/02/skos/core#">my text</skos:prefLabel>
		<skos:hasTopConcept xmlns:skos="http://www.w3.org/2004/02/skos/core#" resource="http://example.com/--something--">
		</skos:hasTopConcept>
	</rdf:Description>
</rdf:RDF>
Expected behavior

I expect attribute namespaces, attribute prefixes and attributes of non object type elements to be shown in the example xml:

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:about="http://example.com">
		<rdf:type xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:resource="http://www.w3.org/2004/02/skos/core#Concept">
		</rdf:type>
		<skos:prefLabel xmlns:skos="http://www.w3.org/2004/02/skos/core#" xml:lang="nl">my text</skos:prefLabel>
		<skos:hasTopConcept xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:resource="http://example.com/--something--">
		</skos:hasTopConcept>
	</rdf:Description>
</rdf:RDF>

So I expect:

rdf:about="http://example.com" (prefix not rendered in embedded property of ConceptDescription)
rdf:resource="http://www.w3.org/2004/02/skos/core#Concept" (prefix not rendered in embedded property of ConceptDescription)
xml:lang="nl" (attribute missing in Label, a string type)
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:resource="http://example.com/--something--" (namespace and prefix missing in RdfRef)

Additional context or thoughts

From http://www.xmlplease.com/xml/attributexmlns/
An attribute never inherits the namespace of its parent element. For that reason an attribute is only in a namespace if it has a proper namespace prefix. An attribute can never be in a default namespace

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

No source files or tests are named. Start by loading the provided OpenAPI YAML in Swagger UI using the shown configuration and reproduce the XML example output; trace the example-rendering path for embedded, referenced, and string schemas. Done means the output includes the expected attribute prefixes, namespaces, and non-object string attributes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
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.