Skip to main content

No project description provided

Project description

openapy Logo

pypi version python versions license Unittest codecov Code style Downloads Downloads

Openapy simplifies continuous development with OpenAPI generator. What this tool does is reading python source files and copying functions into individual files. This will prevent the openapi generator from overwriting the code you have written.

Quick start

docker run --rm -v "$PWD:/src" edgem/openapy \
openapy generate --src /src/openapi-server/apis
pip install openapy
openapy generate --src ./openapi-server/apis

What openapy does

Openapy just splits each of the functions into a single file under processor directory.

# processor directory and the files will be generated
 .
 ├── api
    └── source.py
#└── processor
#    ├── __init__.py
#    ├── function_a.py
#    └── function_b.py
# api/source.py
def function_a(name: str, age: int)->None:
    ...

def function_b(height: int, weight: int)-> int:
    ...

This command generates following files

openapy generate --src ./api
# processor/__init__.py
from .function_a import function_a # noqa: F401
from .function_b import function_b # noqa: F401
# processor/function_a.py
def function_a(name: str, age: int)->None:
    ...
# processor/function_b.py
def function_b(height: int, weight: int)-> int:
    ...

Working with OpenAPI generator

The expected usage is using the file generated with OpenAPI Generator as interfaces, and using the file generated with Openapy as the implementation.

# apis/pet_api.py
import .processor
from fastapi import APIRouter
router = APIRouter()

@router.get("/pet/{petId}")
async def get_pet_by_id(petId: int = Path(None, description="ID of pet to return")) -> Pet:
    return processor.get_pet_by_id(petId)
# processor/get_pet_by_id.py
def get_pet_by_id(petId: int) -> Pet:
    """Returns a single pet"""
    # implement me
    ...

In this use case, api.mustache file should be customized. It is possible to generate an example of mustache file with following command.

openapy example mustache > ./mustache/api.mustache

NOTE: Without this structure, which means writing the implementation of apis on the files generated by OpenAPI generator, a regeneration of OpenAPI generator will overwrite any existing code you have written, even if only one api has been updated. This is because the OpenAPI generator aggregates apis into a file with a tag.

Features

Custom Template

It is possible to define the format of generated code with Openapy just like the mustache for OpenAPI generator. For more details, see the documentation.

Difference Detection

TBD

Move to docs

Following variables with {} brackets are available.

  • IMPORTS: All of imports of the source file like import X, from X import Y
  • ASSIGNS: All assigns of the source file like var = "string"
  • DEF: async def or def of the function
  • NAME: The function name
  • ARGS: Arguments of the function with type annotations
  • RETURN_TYPE: A type annotation for the return of the function
  • COMMENT: A comment inside of the function
  • BODY: A body of the function, like assign statement
  • RETURN: A return statement of the function

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

openapy-0.3.2.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

openapy-0.3.2-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file openapy-0.3.2.tar.gz.

File metadata

  • Download URL: openapy-0.3.2.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.2 Linux/5.11.0-1028-azure

File hashes

Hashes for openapy-0.3.2.tar.gz
Algorithm Hash digest
SHA256 de1a9ab593582a6a5649e8fa2744daa30295f579c98db9df4a38cd89bea74663
MD5 ba6f62b28a1ca14fde8755665bfe234a
BLAKE2b-256 515c4f9555ae031ec905640bdfee399bdde15d3b4c1680fecc1b9d67912eaac0

See more details on using hashes here.

File details

Details for the file openapy-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: openapy-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.2 Linux/5.11.0-1028-azure

File hashes

Hashes for openapy-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f41b2965b52478e50431240d6f63bb291f2d8188338604eac34ae7f04856330d
MD5 fe7e2daa1ec21d0579a826312e4dc98b
BLAKE2b-256 e7ff6f232057fd47a3b3ab757ca6eb062db51b190a483cdb0db21e1b1154a0e7

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