-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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 property and root schemas #1435
Comments
This also raises the question: what is a "root schema"? The term is not defined elsewhere in the spec. Given this fragment: components:
schemas:
container:
type: object
properties:
value:
$ref: "#/components/schemas/value"
value:
type: object
xml:
name: errorValue
properties:
error:
type: string Is this allowed or prohibited (i.e. is |
Agree with @MikeRalphson. We can define the root schema as the first one "hanging" from a, for instance, Media Type Object schema property. Given that schemas are reusable pieces, what is a root schema in one place will probably not be in another place. An example: paths:
/container:
get:
responses:
'200':
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/container' # Here "value" is not root
/value:
get:
responses:
'200':
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/value' # Here "value" is root
components:
schemas:
container:
type: object
properties:
value:
$ref: "#/components/schemas/value"
value:
type: object
xml:
name: errorValue
properties:
error:
type: string So, from the schema perspective, there's no way to know if it will be root or not because there's no information about its context (and I think there should not be, to make them more reusable). This reminds me of the components:
schemas:
container:
type: object
required:
- somethingRequired
properties:
somethingRequired:
type: string |
I second that. The And I would rather see this to be a part of the OAS 3.0.0 instead of some future release as it is currently being supported by Swagger 2.0 and we cannot migrate from that to OAS 3.0.0 without this feature. And, according to the OP @MikeRalphson, OAS3 should differentiate between Example
|
@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. |
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 And because of this analogy, it makes sense to me to keep the 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. |
@OAI/tsc review request: Should we add support for this, or does the following example indicate that it's actually supposed to be supported already for named Components? 4.7.26.2.3 XML Attribute, Prefix and Namespace In this example, a full model definition is shown. Person:
type: object
properties:
id:
type: integer
format: int32
xml:
attribute: true
name:
type: string
xml:
namespace: http://example.com/schema/sample
prefix: sample <Person id="123">
<sample:name xmlns:sample="http://example.com/schema/sample">example</sample:name>
</Person> The "full model" comment seems to contrast with the intro text of the whole series of XML examples:
But this "full model" example uses what looks like the name under Is this the intended solution? |
I'm in support of making OpenAPI more useful for those using XML format, and I think Mike's original suggestion of allowing xml in a root schema to support a name property, but disallowing some of its properties in that context is a sensible way to proceed. I don't have the bandwidth to drive those changes, but I suggest we leave the issue open as an invitation for that contribution if anyone would like to make it. |
@lornajane I've added it to the 3.2 milestone to indicate that we'd like to do it. We can always punt it out of that milestone if it does not fit or no one volunteers to do it. |
While investigating the background for PR #4126 , I noticed this again. Taking a look at the OAS 2.0 XML Object provides strong evidence that there is not actually a gap here, and that the name of the root element was intended to come from the schema name in the Components Object, as I previously speculated. The key to understanding this is the word "model", which appears in a few places, starting with the first line of the XML Object section:
and then in the XML Attribute, Prefix and Namespace subsection of XML Object Examples:
The "full model definition" (in YAML) looks like: Person:
type: object
properties:
id:
type: integer
format: int32
xml:
attribute: true
name:
type: string
xml:
namespace: https://example.com/schema/sample
prefix: sample corresponding to: <Person id="123">
<sample:name xmlns:sample="https://example.com/schema/sample">example</sample:name>
</Person> Everything I've quoted above appears in 2.0, 3.0, and 3.1, with the only variation being that 2.0 used swagger.io instead of example.com, and 3.1 uses So what's going on here? OAS 2.0 used the term "model" very specifically, which is illustrated by the explanation of
The Definitions Object, the precursor of the
This tells us that "models" specifically refers to This means that in 2.0 it is explicitly clear from the example and the use of the term "model" that the root element name is taken from the "model name", meaning the name under the This is clearly still the intent in 3.x, but the text was not updated to replace the word "model" with "schema component" or similar. There is no need for a new field in the XML Object for this. The only change that needs to be made is to update the text to match 3.x terminology, which was no doubt missed as the XML Object section hasn't really changed since 2.0 (except for the easy search-and-replace |
We can pick this up and improve the wording around the root element by describing the structure as being a component schema rather than a model definition. |
This is a question about the specification, and the intent of the following description in the Schema Object, relating to the
xml
property:This has the effect of banning the construct
As a point-of-reference only, both
swagger-ui
andswagger-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 asattribute
andwrapped
) where it seems to make sense?The text was updated successfully, but these errors were encountered: