19fe46835815148546b1de75be20dad7b6c559f8
Go to file
Gorka Eguileor 19fe468358 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
2025年06月30日 14:31:24 +00:00
2025年06月30日 14:31:24 +00:00
2025年04月03日 17:03:47 +02:00
2025年05月05日 13:44:44 +02:00
2024年09月19日 09:00:54 +02:00
2025年04月18日 07:46:27 +00:00
2025年06月26日 07:54:34 +00:00
2024年03月06日 10:07:54 +00:00
2024年03月01日 14:43:11 +00:00
2025年05月30日 18:29:17 +00:00
2024年03月06日 10:07:54 +00:00
2024年08月21日 18:24:33 +00:00
2025年06月27日 09:32:41 +01:00
2025年06月25日 18:12:19 +00:00
2024年04月22日 18:44:27 +02:00
2025年04月03日 17:03:47 +02:00
2024年03月06日 10:07:54 +00:00
2024年03月06日 10:07:54 +00:00
2025年04月03日 17:03:47 +02:00

OpenStack CodeGenerator

Primary goal of the project is to simplify maintainers life by generating complete or at least parts of the code.

CodeGenerator is able to generate OpenAPI specs for certain services by inspecting their code and API Reference (api-ref) documentation. This requires the service package be installed in the environment where the generator is running. The generator then tries to initialize the service application and for supported services scans for the exposed operations. At the moment the following services are covered:

  • Cinder
  • Designate
  • Glance
  • Ironic
  • Keystone
  • Magnum
  • Manila
  • Neutron
  • Nova
  • Octavia
  • Placement

In addition to building OpenAPI specs CodeGenerator is also used to build SDK, CLI and TUI in Rust for OpenStack. Those live currently in this GitHub repository.

Note

CodeGenerator is not intended to be used outside of OpenStack context (while maybe it will even work). It is used primarily in the automatic pipelines. For this reason it is not published to the PyPy.

Getting started

CodeGenerator is not currently packaged on PyPI (and may never be). As a result, you must install from Git. For example:

$ git clone https://opendev.org/openstack/codegenerator
$ cd codegenerator
$ virtualenv .venv
$ source .venv/bin/activate
$ pip install -e .

Once installed, you can use the openstack-codegenerator for all operations. The openstack-codegenerator provides a number of targets. These correspond to the various steps required to get a functioning OpenAPI schema. The first target is the openapi-spec target. This will generate an initial OpenAPI schema through inspection of the chosen projects code and api-ref documentation.

Let's generate an OpenAPI schema for the Compute service, Nova. To do this, we first need to install Nova in the same virtualenv that we have installed CodeGenerator in. Let's pull the Nova repo down locally and install it:

$ cd ..
$ git clone https://opendev.org/openstack/nova
$ cd -
$ pip install \
 -c https://releases.openstack.org/constraints/upper/master \
 -r ../nova/requirements.txt
$ pip install -e ../nova

With Nova installed, we can now run openstack-codegenerator:

$ openstack-codegenerator \
 --work-dir wrk --target openapi-spec --service-type compute \
 --validate

If you look in the path indicated by the --work-dir argument, you will find a OpenAPI schema! However, this schema is rather incomplete. That's because we inspected the Nova code but not the api-ref docs. To do that, we need to pass a path to our docs, which means we need to build the docs locally. Let's do this:

$ cd ../nova
$ tox -e api-ref

Note

The api-ref target should be consistent across projects. However, it's not currently part of the Project Testing Interface__ so this isn't guaranteed. If you find this target doesn't exist, look at your project's tox.ini file for clues.

You should now have the documentation built in HTML format and available in the api-ref/build/html directory. Let's change back to the codegenerator directory and run openstack-codegenerator again, this time with an additional --api-ref-src argument:

$ cde ../code-generator
$ openstack-codegenerator \
 --work-dir wrk --target openapi-spec --service-type compute \
 --api-ref-src ../nova/api-ref/build/html/index.html \
 --validate

Your API documentation should now be looking much better. You'll even have documentation available inline.

There are a variety of options available, which you can view with the --help option.

Description
Generate OpenAPI of API bindings for OpenStack services
Readme 2.9 MiB
Languages
Python 87.9%
Jinja 10.8%
Shell 1.3%