ethereal_rust_sdk 0.1.32

Trading client for Ethereal exchange
Documentation
TOML_FILE := Cargo.toml

# Extract version from TOML
VERSION := $(shell sed -n 's/^version *= *"\(.*\)"/\1/p' $(TOML_FILE))

# Default: bump patch
PATCH_VERSION := $(shell \
	echo $(VERSION) | awk -F. '{printf "%d.%d.%d", $$1, $$2, $$3+1}' \
)

# Allow override
NEW_VERSION ?= $(PATCH_VERSION)

.PHONY: version tag release fmt lint codegen


version:
	@echo "Current version: $(VERSION)"
	# Update version in Cargo.toml
	@sed -i.bak 's/^version *= *".*"/version = "$(NEW_VERSION)"/' $(TOML_FILE)
	@rm -f $(TOML_FILE).bak
	@echo "Release version: $(NEW_VERSION)"
	cargo check
tag:
	@git tag -a v$(NEW_VERSION) -m "Release v$(NEW_VERSION)"
	@git push origin v$(NEW_VERSION)

package:
	@echo packaging crate
	git add $(TOML_FILE) Cargo.lock
	@git commit -m "Bump version to v$(NEW_VERSION)"
	@git push
	echo added git
	@cargo package

release: version package tag
	@echo "Creating GitHub release v$(NEW_VERSION)"
	@gh release create v$(NEW_VERSION) \
		--title "v$(NEW_VERSION)" \
		--notes "Release v$(NEW_VERSION)"
	@echo "Creating crate release v$(NEW_VERSION)"
	@cargo publish

lint: 
	cargo clippy --all-features --all-targets --examples --tests -- -D warnings 
fmt:
	cargo fmt --all
	cargo clippy --all-features --all-targets --examples --tests --fix --allow-dirty -- -D warnings
build:
	cargo build --all-features
test:
	cargo test --all-features
run:
	cargo run --all-features

codegen:
	bash build_scripts/pre_processing.sh
	python build_scripts/patch_spec.py

	jq '.components.schemas |= (to_entries | sort_by(.key) | from_entries)' ws_messages.json > tmp.json && mv tmp.json ws_messages.json
	redocly bundle ws_messages.json -o ws_spec_updated.json

	openapi-generator-cli generate \
	  -i ws_spec_updated.json \
	  -g rust \
	  -o ./generated \
	  --type-mappings decimal=rust_decimal::Decimal \
	--additional-properties=supportAsync=true,useSingleRequestParameter=true,avoidBoxedModels=true \
	--skip-validate-spec
	cp ./generated/src/models/* ./src/models/
	rm -rf ./generated ws_spec_updated.json

	openapi-generator-cli generate \
	  -i openapi.json \
	  -g rust \
	  -o ./generated \
	  --type-mappings decimal=rust_decimal::Decimal \
	--additional-properties=supportAsync=true,useSingleRequestParameter=true,avoidBoxedModels=true



	cp ./generated/src/models/* ./src/models/
	cp -r ./generated/src/apis ./src/


	# rebuild mod.rs
	@echo "#![allow(clippy::all)]" > ./src/models/mod.rs
	@echo "#![allow(unused_imports)]" >> ./src/models/mod.rs
	@echo "#![allow(dead_code)]" >> ./src/models/mod.rs
	@echo "#![allow(non_camel_case_types)]" >> ./src/models/mod.rs
	@echo "#![allow(clippy::upper_case_acronyms)]" >> ./src/models/mod.rs
	# rebuild api mod.rs

	@echo "#![allow(clippy::all)]" > ./src/apis/mod.rs
	cat ./generated/src/apis/mod.rs >> ./src/apis/mod.rs

	# cleanup
	rm -rf ./generated

	find ./src/models -maxdepth 1 -type f -name '*.rs' ! -name 'mod.rs' | LC_ALL=C sort | while IFS= read -r f; do \
		base=$$(basename "$$f"); \
		name=$${base%.rs}; \
		camel=$$(echo "$$name" | sed -E 's/(^|_)([a-z])/\U\2/g'); \
		printf "\tpub mod %s;\n" "$$name" >> ./src/models/mod.rs; \
		printf "\tpub use %s::%s;\n" "$$name" "$$camel" >> ./src/models/mod.rs; \
	done

	openapi-generator-cli generate \
	  -i archive_openapi.json \
	  -g rust \
	  -o ./generated \
	  --type-mappings decimal=rust_decimal::Decimal \
	--additional-properties=supportAsync=true,useSingleRequestParameter=true,avoidBoxedModels=true

	cp ./generated/src/models/* ./src/archive_models
	cp ./generated/src/apis/* ./src/archive_apis
	for f in ./src/archive_apis/*.rs ./src/archive_models/*.rs; do \
		sed -i \
			-e 's/\bapis::/archive_apis::/g' \
			-e 's/\bmodels\b/archive_models/g' \
			"$$f"; \
	done
	for f in ./src/archive_models/*.rs; do \
		sed -i '1s/^/#![allow(clippy::empty_docs, clippy::too_many_arguments)]\n/' "$$f"; \
	done

	rm -rf ./generated
	python build_scripts/post_processing.py

docs:
	python build_scripts/readme.py

all: codegen fmt lint build test docs
	@echo "All tasks completed successfully."