Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML attributes and namespaces not rendered correctly in examples #7693

Open
sdengineering77 opened this issue Dec 7, 2021 · 2 comments
Open

Comments

@sdengineering77
Copy link

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

@dhawaldhingra
Copy link

Did you find a fix or a solution for this issue? I'm facing the same issue unfortunately.

@sdengineering77
Copy link
Author

Did you find a fix or a solution for this issue? I'm facing the same issue unfortunately.

No unfortunately not, I guess they expect me to fix it myself but I haven't had any time to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants