Giter Club home page Giter Club logo

rules_openapi's Introduction

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 = "[email protected]: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 languages 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.

additional_properties Dict of strings, optional

Additional properties that can be referenced by the codegen templates. This allows setting parameters that you'd normally put in config.json, for example the Java library template:

    language = "java",
    additional_properties = {
        "library": "feign",
    },
system_properties Dict of strings, optional

System properties to pass to swagger-codegen. This allows setting parameters that you'd normally set with -D, for example to disable test generation:

    language = "java",
    system_properties = {
        "apiTests": "false",
        "modelTests": "false",
    },
type_mappings Dict of strings, optional

Allows control of the types used in generated code with swagger-codegen's --type-mappings parameter. For example to use Java 8's LocalDateTime class:

    language = "java",
    additional_properties = {
        "dateLibrary": "java8",
    },
    type_mappings = {
        "OffsetDateTime": "java.time.LocalDateTime",
    },

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

rules_openapi's People

Contributors

chrismcbride avatar davschm avatar drigz avatar markchadwick avatar mrmeku avatar philipl avatar softprops avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.