OpenAPI: Fix arrays without items

As explained in the documentation `arrays` have an `items` section, and
arrays that can have arbitrary values are defined like this [1]:

```
type: array
items: {}
```

In the cinder schemas we have a couple of cases where we are defining an
`array` without `items`, all other arrays in the openapi codebase seem
to be right.

In this patch we fix these issues and introduce code in the
`_sanitize_schema` to detect future cases of this issue and fix the
schema automatically for the output.

[1]: https://swagger.io/docs/specification/v3_0/data-models/data-types/#mixed-type-arrays

Change-Id: I49cadcccf64ed9699a4b41674109b4afbfa1e106
This commit is contained in:
Gorka Eguileor
2025-05-30 11:36:24 +02:00
parent bd3c647035
commit 19fe468358
3 changed files with 14 additions and 14 deletions

View File

@@ -1208,18 +1208,18 @@ class OpenStackServerSourceBase:
typ = v.get("type")
if typ == "object":
schema.properties[k] = self._sanitize_schema(v)
if typ == "array" and "additionalItems" in v:
# additionalItems have nothing to do under the type array (create servergroup)
schema.properties[k].pop("additionalItems")
if (
typ == "array"
and "items" in v
and isinstance(v["items"], list)
):
# server_group create - type array "items" is a dict and not list
# NOTE: server_groups recently changed to "prefixItems",
# so this may be not necessary anymore
schema.properties[k]["items"] = v["items"][0]
if typ == "array":
if "additionalItems" in v:
# additionalItems have nothing to do under the type array (create servergroup)
schema.properties[k].pop("additionalItems")
# Arrays must always have 'items'
if "items" not in v:
schema.properties[k]["items"] = {}
elif isinstance(v["items"], list):
# server_group create - type array "items" is a dict and not list
# NOTE: server_groups recently changed to "prefixItems",
# so this may be not necessary anymore
schema.properties[k]["items"] = v["items"][0]
if start_version and self._api_ver_major(start_version) not in [
"0",
0,

View File

@@ -27,7 +27,7 @@ EXTENSION_SCHEMA: dict[str, Any] = {
"type": "string",
"description": "The extension description.",
},
"links": {"type": "array", "description": ""},
"links": {"type": "array", "description": "", "items": {}},
"alias": {
"type": "string",
"description": "The alias for the extension. For example, “FOXNSOX”, “os- availability-zone”, “os-extended-quotas”, “os- share-unmanage” or “os-used-limits.”",

View File

@@ -21,7 +21,7 @@ LIMITS_SCHEMA: dict[str, Any] = {
"limits": {
"type": "object",
"properties": {
"rate": {"type": "array"},
"rate": {"type": "array", "items": {}},
"absolute": {
"type": "object",
"properties": {