Skip to content

Commit

Permalink
Merge pull request #1 from meetup/master
Browse files Browse the repository at this point in the history
feat: add support for swagger codegen 3.x (chenrui333#60)
  • Loading branch information
rp-alexisrodriguez committed Sep 11, 2023
2 parents b839c4a + 314d9f6 commit 175a128
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ openapi_repositories(
codegen_cli_sha256 = "839fade01e54ce1eecf012b8c33adb1413cff0cf2e76e23bc8d7673f09626f8e",
prefix = "io_bazel_rules_openapi_openapi_5",
codegen_cli_provider = "openapi"
)

openapi_repositories(
codegen_cli_provider = "swaggerv3",
codegen_cli_sha256 = "5480e649661f132bdc547cd4ec3a7f334b9f57a33ee9b3e857af9c7b5f5be6c2",
codegen_cli_version = "3.0.43",
prefix = "io_bazel_rules_openapi_swagger_3_0_43",
)
19 changes: 19 additions & 0 deletions openapi/openapi.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ _SUPPORTED_PROVIDERS = {
"artifact": "io.swagger:swagger-codegen-cli",
"name": "io_swagger_swagger_codegen_cli"
},
"swaggerv3": {
"artifact": "io.swagger.codegen.v3:swagger-codegen-cli",
"name": "io_swagger_codegen_v3_swagger_codegen_cli"
},
"openapi": {
"artifact": "org.openapitools:openapi-generator-cli",
"name": "org_openapitools_openapi_generator_cli"
Expand Down Expand Up @@ -42,11 +46,16 @@ def _generator_provider(ctx):
codegen_provider = "openapi"
if "io_swagger_swagger_codegen_cli" in ctx.file.codegen_cli.path:
codegen_provider = "swagger"
if "io_swagger_codegen_v3_swagger_codegen_cli" in ctx.file.codegen_cli.path:
codegen_provider = "swaggerv3"
return codegen_provider

def _is_swagger_codegen(ctx):
return _generator_provider(ctx) == "swagger"

def _is_swagger_codegen_v3(ctx):
return _generator_provider(ctx) == "swaggerv3"

def _is_openapi_codegen(ctx):
return _generator_provider(ctx) == "openapi"

Expand Down Expand Up @@ -77,6 +86,16 @@ def _new_generator_command(ctx, gen_dir, rjars):
properties = _comma_separated_pairs(ctx.attr.system_properties),
)

if _is_swagger_codegen_v3(ctx):
gen_cmd += " io.swagger.codegen.v3.cli.SwaggerCodegen generate -i {spec} -l {language} -o {output}".format(
spec = ctx.file.spec.path,
language = ctx.attr.language,
output = gen_dir,
)
gen_cmd += ' -D "{properties}"'.format(
properties = _comma_separated_pairs(ctx.attr.system_properties),
)

if _is_openapi_codegen(ctx):
gen_cmd += " org.openapitools.codegen.OpenAPIGenerator generate --log-to-stderr -i {spec} -g {language} -o {output}".format(
spec = ctx.file.spec.path,
Expand Down
4 changes: 4 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,7 @@ run_test test_version \
"839fade01e54ce1eecf012b8c33adb1413cff0cf2e76e23bc8d7673f09626f8e" \
"openapi"

run_test test_version \
"3.0.43" \
"5480e649661f132bdc547cd4ec3a7f334b9f57a33ee9b3e857af9c7b5f5be6c2" \
"swaggerv3"
7 changes: 7 additions & 0 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,11 @@ openapi_gen(
"jsonLibrary": "circe",
"sttpClientVersion": "2.2.0"
},
)

openapi_gen(
name = "petstore_java_swagger3",
language = "java",
spec = "petstore.yaml",
codegen_cli = "//external:io_bazel_rules_openapi_swagger_3_0_43/dependency/openapi-cli",
)

0 comments on commit 175a128

Please sign in to comment.