OAI / OpenAPI-Specification

The OpenAPI Specification Repository
https://openapis.org
Apache License 2.0
28.91k stars 9.07k forks source link

XML Object - unfortunate default rule for name changes #2096

Closed hrennau closed 4 months ago

hrennau commented 4 years ago

In the OpenAPI spec, section "XML Object", https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#xmlObject

the examples show a default rule which I think is a bad decision.

Consider the case (see also spec example at the end of this text):

So we an array type with a wrapped XML representation, a wrapper name explicitly set, and an item name not explicitly set.

Proposal In this case the item name should correspond to the property name, it should not be changed to the wrapper name.

Rationale Almost certainly one wants wrapper name and item name to be different; it should suffice to manipulate one of the two to achieve this goal. To let the name change of the wrapper be "inherited" by the items makes no sense at all.

Status quo, however ... See below for the spec example, demonstrating undesirable behavior.

Schema:

{
  "animals": {
    "type": "array",
    "items": {
      "type": "string"
    },
    "xml": {
      "name": "aliens",
      "wrapped": true
    }
  }
}

XML

<aliens>
  <aliens>value</aliens>
  <aliens>value</aliens>
</aliens>`
tedepstein commented 4 years ago

@hrennau , I agree, it's not a great design decision. Where wrapped is true, the wrapper element name should be independent of the inner element name. That's much more intuitive, IMO.

I don't think we can do this in a v3.x version, because it would be a breaking change. We can consider it for v4, but it may also depend on whether the TSC wants to continue evolving XML Object, or adopt a more comprehensive approach like Alternative Schemas.

handrews commented 4 months ago

I agree that this can't be done in 3.x. Feel free to start a discussion about XML in the OAI/sig-moonwalk repository, and see:

for discussions in the context of alternative schemas.