Skip to content

davschm/rules_openapi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bazel openapi rules Build Status

Bazel rules for generating sources and libraries from openapi schemas

Rules

Getting started

To use the Openapi rules, add the following to your projects WORKSPACE file

rules_openapi_version="c449fd6d1ac8b3dffb8bae3bca7305167b800267" # update this as needed

git_repository(
    name = "io_bazel_rules_openapi",
    commit = rules_openapi_version,
    remote = "git@github.com:meetup/rules_openapi.git",
)

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

Then in your BUILD file, just add the following so the rules will be available:

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

openapi_gen

openapi_gen(name, spec, api_package, model_package, invoker_package)

Generates .srcjar containing generated source files from a given openapi specification

These rules rely on swagger-codegen which defines many configuration options. Not all configuration options are implemented in these rules yet but contributions are welcome. You can also request features here

Attributes
name Name, required

A unique name for this rule.

spec String, required

Path to .yaml or .json file containing openapi specification

language String, required

Name of language to generate.

If you wish to use a custom language, you'll need to create a jar containing your custom codegen module, then use deps to add the custom codegen module to the classpath.

Note, not all swagger codegen provided langugages generate the exact same source given the exact same set of arguments. Be aware of this in cases where you expect bazel not to perform a previous executed action for the same sources.

api_package String, optional

package for api.

module_package String, optional

package for models.

invoker_package String, optional

package for invoker.

An example of what a custom language may look like

java_import(
  name = "custom-scala-codegen",
  jars = ["custom-scala-codegen.jar"]
)

openapi_gen(
  name = "petstore-client-src",
  language = "custom-scala",
  spec = "petstore-spec.json",
  api_package = "com.example.api",
  model_package = "com.example.model",
  invoker_package = "com.example",
  deps = [
    ":custom-scala-codegen"
  ]
)

scala_library(
   name = "petstore-client",
   srcs = [":petstore-client-src"]
)

Meetup 2017

About

🍃 bazel rules for generating code from openapi specifications

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 85.6%
  • Shell 13.4%
  • Makefile 1.0%