Skip to content

open-traffic-generator/openapiart

Repository files navigation

openapiart - OpenAPI Artifact Generator

CICD Project Status: Active – The project has reached a stable, usable state and is being actively developed. python license

The OpenAPIArt (OpenAPI Artifact Generator) python package does the following:

  • pre-processes OpenAPI yaml files according to the MODELGUIDE
  • using the path keyword bundles all dependency OpenAPI yaml files into a single openapi.yaml file
  • post-processes any MODELGUIDE extensions
  • validates the bundled openapi.yaml file
  • generates a .proto file from the openapi file
  • optionally generates a static redocly documentation file
  • optionally generates a python ux sdk from the openapi file
  • optionally generates a go ux sdk from the openapi file

Getting started

Install the package

pip install openapiart

Generate artifacts from OpenAPI files

""" 
The following command will produce these artifacts:
    - ./artifacts/openapi.yaml
    - ./artifacts/openapi.json
    - ./artifacts/openapi.html
    - ./artifacts/sample.proto
    - ./artifacts/sample/__init__.py
    - ./artifacts/sample/sample.py
    - ./artifacts/sample/sample_pb2.py
    - ./artifacts/sample/sample_pb2_grpc.py
    - ./pkg/openapiart.go
    - ./pkg/go.mod
    - ./pkg/go.sum
    - ./pkg/sanity/sanity_grpc.pb.go
    - ./pkg/sanity/sanity.pb.go
"""
import openapiart

# bundle api files
# validate the bundled file
# generate the documentation file
art = openapiart.OpenApiArt(
    api_files=[
        "./openapiart/tests/api/info.yaml",
        "./openapiart/tests/common/common.yaml",
        "./openapiart/tests/api/api.yaml",
    ],
    artifact_dir="./artifacts",
    protobuf_name="sanity",
    extension_prefix="sanity",
)

# optionally generate a python ux sdk and python protobuf/grpc stubs
art.GeneratePythonSdk(
    package_name="sanity"
)

# optionally generate a go ux sdk and go protobuf/grpc stubs
art.GenerateGoSdk(
    package_dir="github.com/open-traffic-generator/openapiart/pkg", 
    package_name="openapiart"
)

Specifications

This repository is based on the OpenAPI specification which is a standard, language-agnostic interface to RESTful APIs.

Modeling guide specific to this package