rules_openapi icon indicating copy to clipboard operation
rules_openapi copied to clipboard

Handle other implementations

Open abergmeier opened this issue 7 years ago • 3 comments

To me the question is how to handle other openapi implementations e.g. go-swagger? We have prel. support in rules_go since it needs the go toolchain.

abergmeier avatar Apr 27 '18 12:04 abergmeier

This project is current based on swagger. I'm not familiar with go-swagger or what differentiates it from swagger. Swagger supports arbitrary programming languages and is extensible in allowing you to define your own code generators. We actually do this with our own scala client and server generators at Meetup.

Here is an example client generator

load(
    "@io_bazel_rules_openapi//openapi:openapi.bzl",
    "openapi_gen",
)

load(
    "@io_bazel_rules_scala//scala:scala.bzl",
    "scala_library",
)

# helpers for meetup classic's common case
_base_package = "com.meetup"
def openapi_client(svc):
    openapi_gen(
        name = "{svc}-client-src".format(svc=svc),
        api_package = "{base_package}.{svc}.api".format(base_package = _base_package, svc = svc),
        invoker_package = "{base_package}.{svc}".format(base_package = _base_package, svc = svc),
        language = "meetup-scala-client",
        model_package = "{base_package}.{svc}.model".format(base_package = _base_package, svc = svc),
        spec = "src/main/openapi/meetup-scala-client/{svc}.yaml".format(svc = svc),
        deps = [
            "@meetuplib//:meetup-scala-generator",
        ],
    )

    scala_library(
        name = "{svc}-client".format(svc=svc),
        srcs = ["{svc}-client-src".format(svc=svc)],
        deps = ["@meetuplib//:meetup-scala-gen-deps"],
        visibility = ["//visibility:public"],
    )

Can you elaborate a bit more on go-swagger and how it differs in goals from swagger proper?

softprops avatar Apr 28 '18 15:04 softprops

I'm not sure if this is exactly the OP's question, but I'd like to be able to use this rule to generate both typescript-fetch and go libraries (as supported by swagger-codegen -l ...). In other words:

openapi_gen(
    language = "go",
    # ...
)

But it seems like the openapi_gen rule always packages the generated files into a jar, which I don't think can be easily consumed by languages other than java/scala. Am I missing an obvious way to depend on and openapi_gen rule from another language?

tony-scio avatar Feb 25 '20 14:02 tony-scio

We've only implemented what we've needed, in our case jvm bundles. The underlying tool itself supports a number of languages. What would be the ideal archive type you'd be looking for?

I could help guide you on how to add support for other package types. The current format of is implemented here

softprops avatar Feb 25 '20 15:02 softprops