From 38b477e0adf2abd488528b2fa53d3ff45f3e7fd9 Mon Sep 17 00:00:00 2001 From: raj_mathe Date: Sat, 11 Jun 2022 16:07:09 +0200 Subject: [PATCH] master > master: code py - documentation generation --- code/python/justfile | 30 ++++++++++++++++++++++++++++-- code/python/requirements.txt | 1 + 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/code/python/justfile b/code/python/justfile index 1d625ef..8dd7185 100644 --- a/code/python/justfile +++ b/code/python/justfile @@ -12,6 +12,7 @@ _default: PYTHON := if os_family() == "windows" { "py -3" } else { "python3" } GEN_MODELS := "datamodel-codegen" +GEN_MODELS_DOCUMENTATION := "openapi-generator" # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Macros @@ -56,6 +57,16 @@ _generate-models path name: --input {{path}}/{{name}}-schema.yaml \ --output {{path}}/generated/{{name}}.py +_generate-models-documentation path name: + @- just _delete-if-folder-exists "docs/{{name}}" + @- just _create-folder-if-not-exists "docs/{{name}}" + @- {{GEN_MODELS_DOCUMENTATION}} generate \ + --input-spec {{path}}/{{name}}-schema.yaml \ + --generator-name markdown \ + --output "docs/{{name}}" + @- just _clean-all-files .openapi-generator* + @- just _clean-all-folders .openapi-generator* + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # TARGETS # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -68,12 +79,23 @@ build: _build-requirements _build-skip-requirements _build-skip-requirements: build-models _build-requirements: @{{PYTHON}} -m pip install --disable-pip-version-check -r requirements.txt -build-models: _check-system-requirements _build-models-nochecks -_build-models-nochecks: +build-models: + @just _check-system-requirements + @just _build-models + @just _build-models-documentation +_build-models: @echo "Generate data models from schemata." + @just _delete-if-folder-exists "models/generated" @just _create-folder-if-not-exists "models/generated" @- just _generate-models "models" "config" @- just _generate-models "models" "commands" +_build-models-documentation: + @echo "Generate documentations data models from schemata." + @just _delete-if-folder-exists "docs" + @just _create-folder-if-not-exists "docs" + @- just _generate-models-documentation "models" "config" + @- just _generate-models-documentation "models" "commands" + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # TARGETS: run @@ -172,3 +194,7 @@ _check-system-requirements: echo "Command '{{GEN_MODELS}}' did not work. Ensure that the installation of 'datamodel-code-generator' worked and that system paths are set." \ exit 1; \ fi + @if ! ( {{GEN_MODELS_DOCUMENTATION}} --help >> /dev/null 2> /dev/null ); then \ + echo "Command '{{GEN_MODELS_DOCUMENTATION}}' did not work. Ensure that the installation of 'datamodel-code-generator' worked and that system paths are set." \ + exit 1; \ + fi diff --git a/code/python/requirements.txt b/code/python/requirements.txt index f178918..2b4d920 100644 --- a/code/python/requirements.txt +++ b/code/python/requirements.txt @@ -23,6 +23,7 @@ lazy-load>=0.8.2 pyyaml>=6.0 pydantic>=1.9.0 datamodel-code-generator>=0.13.0 +openapi-generator-cli>=4.3.1 # misc lorem>=0.1.1