connexion-code-generator
connexion-code-generator is a code CLI tool that generates Abstract or Protocol class definitions
based on your openapi.yaml specification. These class definitions then will be used to make sure our
connexion MethodViews are compatible with our API definition using static type checkers like mypy or pyright.
It currently only supports OpenAPI 3.0.
Table of Contents
Installation
connexion-code-generator is available on PyPi, so you can install it using the following command.
pip install connexion-code-generator
Keep in mind that this project in beta stage so please pin the minor version of the package, as there will be no backward incompatible changes in patch versions with the same minor version, but there's no backward compatibility and API stability guaranteed between minor versions.
Usage
To run it with its default config simply run the connexion-protocol-generator generate command
in the same directory as your openapi.yaml file. It will create an api python module with a
view.py file inside it.
Using datamodel-code-generator to generate DTOs
connexion-code-generator does not care about the way you convert your OpenAPI object schemas to python
classes, it just assumes that any object defined in your schema has an equivalent python class in the
api.dtos module. As the convention for schema names in OpenAPI are snake-case but the convention for
class names in python is PascalCase, it assumes the conversion has been done, i.g: an schema with the name
some-api-request should have a class named SomeApiRequest.
This is done to prevent re-inventing the wheel as there are many good library and CLI applications that achieve this conversion task with a high quality.
We use datamodel-code-generator for this. We first run datamodel-code-generator on our schema and store its
result in the api.dtos module, then we run connexion-code-generator.
Advance options
connexion-code-generator provides the following options (available to you by running connexion-code-generator generate -h):
- -i, --input OpenAPI specification file, defaults to
./openapi.yaml - -d, --dto-module-path DTOs module name, defaults to
api.dtos - -o, --output Output file path, default to
./api/views.py - -e, --error-type The DTO type for unknown error responses, defaults to
ErrorResponse - --abstract Generate abstract class instead of protocol class
- --sync Generate sync methods instead of async methods
License
connexion-code-generator is distributed under the terms of the MIT license.
Metadata
Release files for connexion-code-generator 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| connexion_code_generator-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for connexion_code_generator-0.0.1-py3-none-any.whl |
Release files / connexion_code_generator-0.0.1-py3-none-any.whl
| Download URL | connexion_code_generator-0.0.1-py3-none-any.whl |
|---|---|
| Size | 18.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
52e86f9f6194c28560dfd8dbfe8dc3fd16a5041b19003bc9959d77dab8baa99d
|
|
BLAKE2b-256 checksum How to use checksums |
26065b3e2f533dac2e9f3a0eda74d7bdc8df27469a611bed237a335b88bbef78
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.24.0
|
Security for connexion-code-generator 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.