From c03c4dac862ee60ef14c993fb11e23d960f15840 Mon Sep 17 00:00:00 2001 From: snider Date: Sat, 11 Oct 2025 16:18:37 +0100 Subject: [PATCH] Add configuration files for SDK generation and OpenAPI specifications --- Makefile | 43 +++++++++++++++++++++++------------ utils/sdk/Makefile | 30 ++++++++++++++++++++++++ utils/sdk/openapitools.json | 7 ++++++ utils/sdk/packages/bash.json | 9 ++++++++ utils/sdk/packages/go.json | 6 +++++ utils/sdk/spec/oas-3.0.0.json | 1 + 6 files changed, 82 insertions(+), 14 deletions(-) create mode 100644 utils/sdk/Makefile create mode 100644 utils/sdk/openapitools.json create mode 100644 utils/sdk/packages/bash.json create mode 100644 utils/sdk/packages/go.json create mode 100644 utils/sdk/spec/oas-3.0.0.json diff --git a/Makefile b/Makefile index 5e48c267..674bbd4c 100644 --- a/Makefile +++ b/Makefile @@ -58,16 +58,17 @@ CPU_CORES := $(or $(CPU_CORES),1) CPU_CORES := $(shell expr $(CPU_CORES) + 0 2>/dev/null || echo 1) CONAN_CPU_COUNT=$(CPU_CORES) - -PROFILES := $(patsubst cmake/profiles/%,%,$(wildcard cmake/profiles/*)) -SORTED_PROFILES := $(sort $(PROFILES)) -CONAN_CACHE := $(CURDIR)/build/sdk -CONAN_URL:=https://artifacts.host.uk.com/artifactory/api/conan/conan-build -CONAN_USER:=public -CONAN_PASSWORD:=Lethean1234 -DEFAULT_CONAN_PROFILE := $(CONAN_CACHE)/profiles/default -CONAN_EXECUTABLE := $(CURDIR)/build/bin/conan -CC_DOCKER_FILE?=utils/docker/images/lthn-chain/Dockerfile +PROFILES :=$(patsubst cmake/profiles/%,%,$(wildcard cmake/profiles/*)) +SORTED_PROFILES :=$(sort $(PROFILES)) +CONAN_CACHE :=$(CURDIR)/build/sdk +CONAN_URL :=https://artifacts.host.uk.com/artifactory/api/conan/conan-build +CONAN_USER :=public +CONAN_PASSWORD :=Lethean1234 +CONAN_EXECUTABLE :=$(CURDIR)/build/bin/conan +CC_DOCKER_FILE ?=utils/docker/images/lthn-chain/Dockerfile +SDK_PACKAGES_JSON :=$(wildcard utils/sdk/packages/*.json) +SDK_TARGETS :=$(patsubst utils/sdk/packages/%.json,%,$(SDK_PACKAGES_JSON)) +SORTED_SDK_TARGETS :=$(sort $(SDK_TARGETS)) all: help @@ -98,6 +99,9 @@ docs: configure @echo "Building Documentation" cmake --build build/release --target=docs --config=Release --parallel=$(CPU_CORES) +sdk: + $(MAKE) -C utils/sdk $(filter-out $@,$(MAKECMDGOALS)) PACKAGE_VERSION=$(BUILD_VERSION) + # Rule for each profile $(PROFILES): conan-profile-detect @echo "Building profile: $@" @@ -107,6 +111,12 @@ $(PROFILES): conan-profile-detect (cd $(BUILD_FOLDER) && cpack) help: + @echo "Lethean VPN Blockchain" + @echo "======================" + @echo "Website: https://lt.hn" + @echo "GitHub: https://github.com/letheanVPN/blockchain/" + @echo "Discord: https://discord.lt.hn" + @echo "" @echo "Available targets:" @printf " %-42s %s\n" "make clean" "Clean all build directories" @printf " %-42s %s\n" "make get-conan" "Download and install conan locally" @@ -118,12 +128,14 @@ help: @printf " %-42s %s\n" "make docs-dev" "Runs local doc server, for editing/adding docs" @printf " %-42s %s\n" "make conan-profile-detect" "Creates host config" @printf " %-42s %s\n" "make configure" "Runs a cmake configure within conan build flow" + @printf "\n --- Conan Cross-Compilation Profiles ---\n" @$(foreach profile,$(SORTED_PROFILES),printf " %-42s %s\n" "make $(profile)" "Build the $(profile) profile";) + @printf "\n --- SDK Generation ---\n" + @printf " %-42s %s\n" "make sdk" "Build all SDK packages" + @$(foreach sdk,$(SORTED_SDK_TARGETS),printf " %-42s %s\n" "make sdk $(sdk)" "Build the $(sdk) SDK package";) + @printf "\n" @printf " %-42s %s\n" "make help" "Show this help message" -# -# Tests -# test: test-release test-release: @@ -156,6 +168,9 @@ docs-dev: configure @echo "Building Documentation" cmake --build build/release --target=serve_docs --config=Release +$(SDK_TARGETS): + @# This is a proxy target. Handled by the 'sdk' rule. + clean: @cmake -P cmake/CleanBuild.cmake @@ -165,4 +180,4 @@ clean-build: clean tags: ctags -R --sort=1 --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ src contrib tests/gtest -.PHONY: all release upload-conan-cache docs docs-dev configure static static-release test test-release test-debug clean tags conan-profile-detect get-conan $(PROFILES) +.PHONY: all release upload-conan-cache docs docs-dev configure static static-release test test-release test-debug clean tags conan-profile-detect get-conan $(PROFILES) sdk $(SDK_TARGETS) diff --git a/utils/sdk/Makefile b/utils/sdk/Makefile new file mode 100644 index 00000000..98afd90c --- /dev/null +++ b/utils/sdk/Makefile @@ -0,0 +1,30 @@ +PACKAGE_VERSION?=6.0.1 +BASE_DIR:=$(CURDIR) +BUILD_DIR:=$(BASE_DIR)/../../build/packages +SDK_TARGETS := $(patsubst packages/%.json,%,$(wildcard packages/*.json)) + +# Default target to build all SDKs. This is the main entry point. +all: build + +build: $(SDK_TARGETS) + @echo "All SDKs have been processed." + +# Rule to build each SDK package using OpenAPI Generator. +# It reads the corresponding JSON config file and generates the SDK in the build directory. +$(SDK_TARGETS): %: packages/%.json + @echo "--- Building package $@ with version $(PACKAGE_VERSION) ---" + rm -rf "$(BUILD_DIR)/$@/*" + export TS_POST_PROCESS_FILE="/usr/local/bin/prettier --write" && \ + openapi-generator generate --skip-validate-spec \ + -i "$(BASE_DIR)/spec/oas-3.0.0.json" \ + -g "$@" \ + -o "$(BUILD_DIR)/$@" \ + -c "$<" \ + --artifact-version "$(PACKAGE_VERSION)" \ + --group-id "lethean" \ + -p packageVersion="$(PACKAGE_VERSION)" \ + --global-property "apiTests=true" \ + --additional-properties=npmVersion="$(PACKAGE_VERSION)",artifactVersion="$(PACKAGE_VERSION)" + +# Phony targets to avoid conflicts with file names and to ensure they always run. +.PHONY: all build $(SDK_TARGETS) diff --git a/utils/sdk/openapitools.json b/utils/sdk/openapitools.json new file mode 100644 index 00000000..a82623d6 --- /dev/null +++ b/utils/sdk/openapitools.json @@ -0,0 +1,7 @@ +{ + "$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json", + "spaces": 2, + "generator-cli": { + "version": "7.14.0" + } +} diff --git a/utils/sdk/packages/bash.json b/utils/sdk/packages/bash.json new file mode 100644 index 00000000..b53bb667 --- /dev/null +++ b/utils/sdk/packages/bash.json @@ -0,0 +1,9 @@ +{ + "additionalProperties": { + "apiPackage": "lethean-chain-sdk-bash", + "generateBashCompletion": true, + "generateZshCompletion": true, + "processMarkdown": true, + "scriptName":"lthn-cli" + } +} \ No newline at end of file diff --git a/utils/sdk/packages/go.json b/utils/sdk/packages/go.json new file mode 100644 index 00000000..11efc703 --- /dev/null +++ b/utils/sdk/packages/go.json @@ -0,0 +1,6 @@ +{ + "additionalProperties": { + "packageName": "lethean-chain-sdk-go", + "generateInterfaces": true + } +} \ No newline at end of file diff --git a/utils/sdk/spec/oas-3.0.0.json b/utils/sdk/spec/oas-3.0.0.json new file mode 100644 index 00000000..61f62dd2 --- /dev/null +++ b/utils/sdk/spec/oas-3.0.0.json @@ -0,0 +1 @@ +{"openapi":"3.0.0","info":{"title":"Lethean Blockchain API","description":"New API layer for Lethean","contact":{"name":"Lethean","url":"https:\/\/lt.hn\/"},"license":{"name":"EUPL-1.2","url":"https:\/\/joinup.ec.europa.eu\/software\/page\/eupl\/licence-eupl"},"version":"6.0.1"},"servers":[{"url":"http:\/\/localhost:8000","description":"server on localhost"}],"paths":{"\/info\/version":{"get":{"description":"Returns the current version of the API.","summary":"Get API version","operationId":"version","tags":["Info"],"responses":{"200":{"description":"OK","content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/VersionDto"}}}}},"parameters":[]}},"\/block\/{hash}":{"get":{"summary":"Get a block by its hash","operationId":"getBlockByHash","tags":["Block"],"responses":{"200":{"description":"OK","content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/BlockDetailsDto"}}}}},"parameters":[{"name":"hash","description":"The hash of the block to retrieve","in":"path","required":true,"deprecated":false,"schema":{"type":"string"}}]}}},"components":{"schemas":{"VersionDto":{"type":"object","properties":{"version":{"type":"string"},"version_long":{"type":"string"},"major":{"type":"string"},"minor":{"type":"string"},"revision":{"type":"string"}},"required":[]},"TransactionOutputDto":{"type":"object","properties":{"amount":{"type":"integer"},"global_index":{"type":"integer"},"is_spent":{"type":"boolean"},"minimum_sigs":{"type":"integer","minimum":0,"maximum":4294967295},"pub_keys":{"type":"array","items":{"type":"string"}}},"required":[]},"TransactionInputDto":{"type":"object","properties":{"amount":{"type":"integer"},"global_indexes":{"type":"array","items":{"type":"integer"}},"htlc_origin":{"type":"string"},"kimage_or_ms_id":{"type":"string"},"multisig_count":{"type":"integer","minimum":0,"maximum":4294967295}},"required":[]},"TransactionExtraDto":{"type":"object","properties":{"type":{"type":"string"},"short_view":{"type":"string"},"details_view":{"type":"string"}},"required":[]},"TransactionAttachmentDto":{"type":"object","properties":{"type":{"type":"string"},"short_view":{"type":"string"},"details_view":{"type":"string"}},"required":[]},"TransactionDetailsDto":{"type":"object","properties":{"amount":{"type":"integer"},"attachments":{"type":"array","items":{"$ref":"#\/components\/schemas\/TransactionAttachmentDto"}},"blob":{"type":"string"},"blob_size":{"type":"integer"},"extra":{"type":"array","items":{"$ref":"#\/components\/schemas\/TransactionExtraDto"}},"fee":{"type":"integer"},"id":{"type":"string"},"ins":{"type":"array","items":{"$ref":"#\/components\/schemas\/TransactionInputDto"}},"keeper_block":{"type":"integer","format":"int64"},"object_in_json":{"type":"string"},"outs":{"type":"array","items":{"$ref":"#\/components\/schemas\/TransactionOutputDto"}},"pub_key":{"type":"string"},"timestamp":{"type":"integer"}},"required":[]},"BlockDetailsDto":{"type":"object","properties":{"actual_timestamp":{"type":"integer"},"already_generated_coins":{"type":"string"},"base_reward":{"type":"integer"},"blob":{"type":"string"},"block_cumulative_size":{"type":"integer"},"block_tself_size":{"type":"integer"},"cumulative_diff_adjusted":{"type":"string"},"cumulative_diff_precise":{"type":"string"},"difficulty":{"type":"string"},"effective_fee_median":{"type":"integer"},"height":{"type":"integer"},"id":{"type":"string"},"is_orphan":{"type":"boolean"},"miner_text_info":{"type":"string"},"object_in_json":{"type":"string"},"penalty":{"type":"integer"},"pow_seed":{"type":"string"},"prev_id":{"type":"string"},"summary_reward":{"type":"integer"},"this_block_fee_median":{"type":"integer"},"timestamp":{"type":"integer"},"total_fee":{"type":"integer"},"total_txs_size":{"type":"integer"},"transactions_details":{"type":"array","items":{"$ref":"#\/components\/schemas\/TransactionDetailsDto"}},"type":{"type":"integer","minimum":0,"maximum":4294967295}},"required":[]}}}} \ No newline at end of file