From 19fe46835815148546b1de75be20dad7b6c559f8 Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Fri, 30 May 2025 11:36:24 +0200 Subject: [PATCH] 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 --- codegenerator/openapi/base.py | 24 +++++++++---------- .../openapi/cinder_schemas/extension.py | 2 +- codegenerator/openapi/cinder_schemas/limit.py | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/codegenerator/openapi/base.py b/codegenerator/openapi/base.py index 0ed7de2..c1ee83f 100644 --- a/codegenerator/openapi/base.py +++ b/codegenerator/openapi/base.py @@ -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, diff --git a/codegenerator/openapi/cinder_schemas/extension.py b/codegenerator/openapi/cinder_schemas/extension.py index 8a9e709..b22eb72 100644 --- a/codegenerator/openapi/cinder_schemas/extension.py +++ b/codegenerator/openapi/cinder_schemas/extension.py @@ -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.”", diff --git a/codegenerator/openapi/cinder_schemas/limit.py b/codegenerator/openapi/cinder_schemas/limit.py index 2e336c3..39ac556 100644 --- a/codegenerator/openapi/cinder_schemas/limit.py +++ b/codegenerator/openapi/cinder_schemas/limit.py @@ -21,7 +21,7 @@ LIMITS_SCHEMA: dict[str, Any] = { "limits": { "type": "object", "properties": { - "rate": {"type": "array"}, + "rate": {"type": "array", "items": {}}, "absolute": { "type": "object", "properties": {