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 property and root schemas

See original GitHub issue

This is a question about the specification, and the intent of the following description in the Schema Object, relating to the xml property:

This MAY be used only on properties schemas. It has no effect on root schemas. Adds additional metadata to describe the XML representation of this property.

This has the effect of banning the construct

components:
  schemas:
    mySchema:
      type: object
      properties:
        a:
          type: string
      xml:
        name: xmlSchema

As a point-of-reference only, both swagger-ui and swagger-editor appear to honour this (useful) construct.

Is it possible to align the specification with real-world use for this case, and possibly move the restriction on xml properties on root schemas to those sub-properties (such as attribute and wrapped) where it seems to make sense?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
handrewscommented, Sep 26, 2019

@MikeRalphson JSON Schema 2019-09 has definitions for “schema document”, “schema resource”, “root schema”, “schema object”, and “subschema”. It shouldn’t be too hard to adapt that for the OAS situation of schema objects embedded in a non-schema document.

0reactions
hrennaucommented, Mar 2, 2021

It is helpful to be aware of the analogies between JSON Schema and XSD. What seems to be called here a “root schema” (if I understand the comments correctly) is named schemas, that is, the schemas contained by /components/schemas (V3) or /definitions (V2). They are equivalent to a named type definition in XSD. Such a type definition is used by element declarations or attribute declarations. The name of the item (corresponding to a JSON property name) is NEVER assigned by the type definition, always by the element/attribute declaration. These declarations are equivalent to the fields in a properties object. Like the name, also cardinality constraints can only be placed in those declarations, never in the types. Cardinality constraints are roughly equivalent to “required”, @fmvilas - hence we only have to look at XSD and understand the equivalences in order to have a clear idea what belongs where. (Not that we could not do it differently, but we should think very carefully before doing it, and be aware of the deliberate deviation.)

And because of this analogy, it makes sense to me to keep the xml keyword out of “root schemas” = named schemas (alias type definitions): property naming is not the business of the type used to constrain the property value. Arguments in favor of allowing xml there in the interest of code generation should be reviewed crititically - they would have to be very convincing.

There is a real issue with translation into XML, which is the necessity to insert an XML root node, for which there is no correspondence in JSON. Currently, OAS foresees no possibility to control the invented name, leaving the integration developer in the lurch.

Read more comments on GitHub >

github_iconTop Results From Across the Web

XML Schema Tutorial - Defining Elements and Attributes
The XML schema defines the shape, or structure, of an XML document, along with rules for data content and semantics such as what...
Read more >
XML Schema Part 1: Structures Second Edition - W3C
The purpose of an XML Schema: Structures schema is to define and describe a class of XML documents by using schema components to...
Read more >
XML schema Element - W3Schools
The <schema> element is the root element of every XML Schema: <?xml version="1.0"?> ... The <schema> element may contain some attributes. A schema...
Read more >
Root Reference (Node Property of All Schemas)
Use the Root Reference property to specify the node that represents the outermost element in the XML business document represented by the ...
Read more >
XML Schema: Understanding Namespaces - Oracle
As defined by the W3C Namespaces in XML Recommendation , an XML namespace is a collection of XML elements and attributes identified by...
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