Skip to main content

A CLI tool that generates Protocol or Abstract Classes based on your OpenAPI specification.

Project description

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.

PyPI - Version PyPI - Python Version


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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

connexion_code_generator-0.0.1-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file connexion_code_generator-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for connexion_code_generator-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 52e86f9f6194c28560dfd8dbfe8dc3fd16a5041b19003bc9959d77dab8baa99d
MD5 b7bbcadadbad9563437cfc3ba46aec89
BLAKE2b-256 26065b3e2f533dac2e9f3a0eda74d7bdc8df27469a611bed237a335b88bbef78

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page