Skip to content

Commit f3f1289

Browse files
committed
Add command to generate java models and clean
1 parent 9f0ef57 commit f3f1289

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ target/
4242
demo/jars/*
4343
demo/notebook/.ipynb_checkpoints/*
4444
my_config.yaml
45+
46+
# REST generated models
47+
spec/generated

spec/Makefile

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ PIP := $(VENV_DIR)/bin/pip
2525
VALIDATOR := $(VENV_DIR)/bin/openapi-spec-validator
2626
SPEC := rest-service-open-api.yaml
2727

28-
.PHONY: all venv install lint clean
28+
# Configuration for model generation
29+
GEN_DIR := generated
30+
MODEL_PKG := org.apache.xtable.service.models
31+
32+
.PHONY: all venv install lint clean clean-models
2933

3034
all: lint
3135

@@ -49,4 +53,20 @@ lint: install
4953
# Remove the virtualenv
5054
clean:
5155
@echo "→ removing $(VENV_DIR)"
52-
rm -rf $(VENV_DIR)
56+
rm -rf $(VENV_DIR)
57+
58+
# Generate Java model classes from OpenAPI spec
59+
generate-models:
60+
@echo "→ generating Java model classes from $(SPEC)"
61+
openapi-generator generate \
62+
-i $(SPEC) \
63+
-g java \
64+
-o $(GEN_DIR) \
65+
--model-package $(MODEL_PKG) \
66+
--global-property models,modelTests=false,modelDocs=false
67+
@echo "→ models generated in $(GEN_DIR)/src/main/java/$(subst .,/,$(MODEL_PKG))"
68+
69+
# Remove all generated model classes
70+
clean-models:
71+
@echo "→ removing generated models in $(GEN_DIR)"
72+
rm -rf $(GEN_DIR)

spec/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,20 @@ make lint
3333
if you want to wipe out the venv and start fresh run make clean
3434
```sh
3535
make clean
36+
```
37+
38+
## Generate
39+
40+
Note: You’ll need the OpenAPI Generator CLI installed and on your `PATH`. You can install it using Homebrew:
41+
```sh
42+
brew install openapi-generator
43+
```
44+
Then to generate the java models from the open-api spec, you can run the `generate-models` command.
45+
46+
```sh
47+
make generate-models
48+
```
49+
If you would to remove the generated models, you can run the `clean-models` command:
50+
```sh
51+
make clean-models
3652
```

0 commit comments

Comments
 (0)