Skip to main content

This library allows us to generate django models and drf serializers using an OpenAPI schema

Project description

openapi_model_generator

This library allows us to generate django models and drf serializers using an OpenAPI schema.

HowTo Use

pip install openapi_model_generator

python -m openapi_model_generator {open_api_path.json} {destination}
python -m openapi_model_generator {open_api_path.yaml} {destination}

As an example:

python -m openapi_model_generator schema.esb.json base_dir

or

python -m openapi_model_generator /home/user/schema.esb.json /home/user/base_dir

This command creates base models and serializers based on its models into the directory provided.

Then you can use them to define models and serializers in your Django+DRF application.

models.py:

from utils import define_models

from base_dir import base_models


define_models(['Model1', 'Model2', ...], base_models, locals())

serializers.py:

from utils import define_serializers

from base_dir import base_serializers
from . import models


define_serializers(['Model1', 'Model2', ...], base_serializers, locals(), models)

After that you can use them:

import pydoc
model_1 = pydoc.locate('{django_app}.models.Model1')
model_2 = pydoc.locate('{django_app}.models.Model2')
...
serializer_1 = pydoc.locate('{django_app}.serializers.Model1Serializer')
serializer_2 = pydoc.locate('{django_app}.serializers.Model2Serializer')

Project details


Download files

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

Source Distribution

File details

Details for the file openapi_model_generator-0.1.15.linux-x86_64.tar.gz.

File metadata

File hashes

Hashes for openapi_model_generator-0.1.15.linux-x86_64.tar.gz
Algorithm Hash digest
SHA256 c42bd8de4fc091b224037f67316b2189264af4b7f9f86d24d9df619eee2360dd
MD5 511a4b08df21043a7aae662a656650a3
BLAKE2b-256 ca6f96705fd4ee7fa77ae32f91a8af402f0ee460766e5082fdaa4a128baf2175

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