Skip to content

Commit 64d17b3

Browse files
authored
Add config and templateDir tags (#41)
* Add config and templateDir tags * Remove unused print * Add CI * Add CI and test
1 parent fb7e302 commit 64d17b3

File tree

7 files changed

+85
-3
lines changed

7 files changed

+85
-3
lines changed

.github/workflows/ci.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
# virtual environments: https://github.com/actions/virtual-environments
8+
runs-on: ubuntu-20.04
9+
10+
steps:
11+
# Caches and restores the bazelisk download directory.
12+
- name: Cache bazelisk download
13+
uses: actions/cache@v2
14+
env:
15+
cache-name: bazel-cache
16+
with:
17+
path: ~/.cache/bazelisk
18+
key: ${{ runner.os }}-${{ env.cache-name }}-${{ github.ref }}
19+
restore-keys: |
20+
${{ runner.os }}-${{ env.cache-name }}-development
21+
22+
# Checks-out your repository under $GITHUB_WORKSPACE, which is the CWD for
23+
# the rest of the steps
24+
- uses: actions/checkout@v2
25+
26+
# Build
27+
- name: Build all target
28+
run: |
29+
cd internal/test
30+
bazel build //...

BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright 2019 OpenAPI-Generator-Bazel Contributors
22

3-
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
3+
load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_deb")
44

55
package(default_visibility = ["//visibility:public"])
66

WORKSPACE

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,14 @@
33
workspace(name = "openapi_tools_generator_bazel")
44

55
load("//:defs.bzl", "openapi_tools_generator_bazel_repositories")
6-
76
openapi_tools_generator_bazel_repositories()
7+
8+
# Load rules_pkg
9+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
10+
http_archive(
11+
name = "rules_pkg",
12+
url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.3.0/rules_pkg-0.3.0.tar.gz",
13+
sha256 = "6b5969a7acd7b60c02f816773b06fcf32fbe8ba0c7919ccdc2df4f8fb923804a",
14+
)
15+
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
16+
rules_pkg_dependencies()

internal/openapi_generator.bzl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,20 @@ def _new_generator_command(ctx, declared_dir, rjars):
5959
gen_cmd += ' --type-mappings "{mappings}"'.format(
6060
mappings = _comma_separated_pairs(ctx.attr.type_mappings),
6161
)
62-
62+
6363
gen_cmd += ' --reserved-words-mappings "{reserved_words_mappings}"'.format(
6464
reserved_words_mappings = ",".join(ctx.attr.reserved_words_mappings),
6565
)
6666

67+
if ctx.attr.config:
68+
gen_cmd += " --config {config}".format(
69+
config = ctx.attr.config.files.to_list()[0].path,
70+
)
71+
if ctx.attr.template_dir:
72+
gen_cmd += " --template-dir {template_dir}".format(
73+
template_dir = ctx.attr.template_dir.files.to_list()[0].path,
74+
)
75+
6776
if ctx.attr.api_package:
6877
gen_cmd += " --api-package {package}".format(
6978
package = ctx.attr.api_package,
@@ -97,6 +106,12 @@ def _impl(ctx):
97106
ctx.file.spec,
98107
] + cjars.to_list() + rjars.to_list()
99108

109+
if ctx.attr.config:
110+
inputs += ctx.attr.config.files.to_list()
111+
112+
if ctx.attr.template_dir:
113+
inputs += ctx.attr.template_dir.files.to_list()
114+
100115
# TODO: Convert to run
101116
ctx.actions.run_shell(
102117
inputs = inputs,
@@ -157,6 +172,8 @@ _openapi_generator = rule(
157172
".yml",
158173
],
159174
),
175+
"template_dir": attr.label(allow_single_file = True),
176+
"config": attr.label(allow_single_file = True),
160177
"generator": attr.string(mandatory = True),
161178
"api_package": attr.string(),
162179
"invoker_package": attr.string(),

internal/test/BUILD.bazel

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,16 @@ openapi_generator(
5151
],
5252
)
5353

54+
openapi_generator(
55+
name = "petstore_python_flask_with_config_tag",
56+
generator = "python-flask",
57+
spec = "petstore.yaml",
58+
config = "config.yaml"
59+
)
60+
61+
openapi_generator(
62+
name = "petstore_python_flask_with_template_dir",
63+
generator = "python-flask",
64+
spec = "petstore.yaml",
65+
template_dir = "python-templates"
66+
)

internal/test/config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# openapi-generator configuration
2+
---
3+
generatorName: python-flask
4+
packageName: openapi.bazel.test
5+
enablePostProcessFile: false
6+
globalProperties:
7+
skipFormModel: false
8+
additionalProperties:
9+
generated: generated
10+
packageRoot: openapi.bazel
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @{{generated}}
2+
3+
GENERATOR_CHECKSUM = '{{generatorChecksum}}'

0 commit comments

Comments
 (0)