Skip to content

Commit 4001d3a

Browse files
wing328bu3
andauthored
Add support for OpenAPI Generator import-mappings property (#68)
* Add support for OpenAPI Generator import-mappings property This allows users to specify custom import mappings for generated code, enabling control over which classes are imported for specific types. * revert change to readme --------- Co-authored-by: Fabio Mangione <[email protected]>
1 parent 7f8464d commit 4001d3a

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,3 @@ openapi_generator(
3737
spec = "petstore.yaml",
3838
)
3939
```
40-
41-

internal/openapi_generator.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ def _new_generator_command(ctx, declared_dir, rjars):
4343
mappings = _comma_separated_pairs(ctx.attr.type_mappings),
4444
)
4545

46+
gen_cmd += ' --import-mappings "{mappings}"'.format(
47+
mappings = _comma_separated_pairs(ctx.attr.import_mappings),
48+
)
49+
4650
gen_cmd += ' --reserved-words-mappings "{reserved_words_mappings}"'.format(
4751
reserved_words_mappings = ",".join(ctx.attr.reserved_words_mappings),
4852
)
@@ -166,6 +170,7 @@ _openapi_generator = rule(
166170
"system_properties": attr.string_dict(),
167171
"engine": attr.string(),
168172
"type_mappings": attr.string_dict(),
173+
"import_mappings": attr.string_dict(),
169174
"reserved_words_mappings": attr.string_list(),
170175
"is_windows": attr.bool(mandatory = True),
171176
"_jdk": attr.label(

internal/test/basic/BUILD.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,13 @@ openapi_generator(
6464
spec = "petstore.yaml",
6565
template_dir = "python-templates"
6666
)
67+
68+
openapi_generator(
69+
name = "petstore_java_import_mappings",
70+
generator = "java",
71+
spec = "petstore.yaml",
72+
import_mappings = {
73+
"Date": "java.time.LocalDate",
74+
"DateTime": "java.time.OffsetDateTime",
75+
},
76+
)

0 commit comments

Comments
 (0)