Skip to content

Commit

Permalink
Add Makefile for python code generation from jsonschema
Browse files Browse the repository at this point in the history
  • Loading branch information
elchupanebrej committed Sep 7, 2024
1 parent bdb4991 commit 41dd55d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ schemas = \
./jsonschema/UndefinedParameterType.json \
./jsonschema/Envelope.json

languages = cpp go java javascript perl php ruby dotnet
languages = cpp dotnet go java javascript perl php python ruby

.DEFAULT_GOAL = help

Expand Down
33 changes: 33 additions & 0 deletions python/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
schemas = $(shell find ../jsonschema -name "*.json")

.DEFAULT_GOAL = help

MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
HERE := $(dir $(MKFILE_PATH))

help: ## Show this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make <target>\n\nWhere <target> is one of:\n"} /^[$$()% a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

generate: require install-deps
datamodel-codegen \
--output-model-type "pydantic_v2.BaseModel" \
--input $(HERE)../jsonschema/Envelope.json \
--output $(HERE)src/_messages.py \
--use-generic-container-types \
--allow-population-by-field-name \
--snake-case-field \
--input-file-type=jsonschema \
--class-name Envelope \
--use-double-quotes \
--use-union-operator \
--disable-timestamp

require: ## Check requirements for the code generation (python is required)
@python --version >/dev/null 2>&1 || (echo "ERROR: python is required."; exit 1)

clean: ## Remove automatically generated files and related artifacts
rm -rf $(HERE)src/_messages.py

install-deps: ## Install generation dependencies
python -m ensurepip --upgrade
pip install $(HERE)[generation]

0 comments on commit 41dd55d

Please sign in to comment.