- Created: 2022-11-09
- Author: Yusuke Oda (@odashi)
- License: MIT
-
You must initialize rules_python, and prepare a local package index as "pip_deps". In requirements.txt for the local package index, you need to add the following packages:
- pydantic
- datamodel-code-generator
-
Put files in this gist somewhere on your repository (//path/to).
-
prepare a directory (//path/to/another) with the following files:
- BUILD
- openapi.yaml (your schema)
- server.py (your server implementation)
-
In your BUILD, define rules for the schema and the server:
load("//path/to/openapi.bzl", "py_openapi_schema") # Rule to generate schema.py py_openapi_schema( name = "schema", schema = "openapi.yaml", ) # Rule to generate the server binary. py_binary( name = "server", srcs = ["server.py"], deps = [":schema"], )
-
schema.py will be generated onto the runfiles directory. In server.py, you can import schema.py as a local module:
from path.to.another import schema