Giter Club home page Giter Club logo

cake-openapi-generator's Introduction

Cake OpenAPI Generator Addin

Cake Addin for code generation via the OpenAPI Generator (f.k.a. Swagger Codegen)

Motivation

The OpenAPI Generator tool provides a lot of powerful code generators, but since its implemented in Java, the only build tools directly supported are Maven and Gradle. This addin provides a simple wrapper around the command line version of the tool to invoke code generation from Cake.

Installation

Since the addin is available on NuGet, it can simply be registered in your build.cake file using the #addin preprocessor directive:

#addin nuget:?package=Cake.OpenApiGenerator&version=<version>

As an additional dependency, Java needs to be installed and available to Cake. It may be either added to the PATH environment variable or registered manually in the build script:

Setup(context => {
    context.Tools.RegisterFile("/path/to/java(.exe)");
});

Usage

Once the addin is registered, the alias OpenApiGenerator provides a wrapper around the OpenAPI Generator. The first example shows a minimal example for the method Generate:

Task("My-Task")
    .Does(() =>
{
    OpenApiGenerator.Generate(new OpenApiGeneratorGenerateSettings()
    {
        Specification = "specification.yaml",
        Generator = "csharp",
        OutputDirectory = "./src"
    });
});

Alternatively, you may pass an Action that configures the OpenApiGeneratorGenerateSettings:

OpenApiGenerator.Generate(settings =>
{
    setttings.Specification = "specification.yaml";
    // ...
})

Reproducible builds

By default, the latest version of the OpenAPI generator will be resolved and used. Of course, this requires access to the Internet and may break builds that worked with previous tool versions. It is recommended to pin the tool version as shown in the example below:

Task("My-Task")
    .Does(() =>
{
    OpenApiGenerator["3.3.4"].Generate(...);
});

This shorthand notation is useful for build scripts that only use the OpenApiGenerator once. If there are multiple calls to the OpenApiGenerator, the version should be defined at the top of the build script or using a Setup method:

Setup(context =>
{
    OpenApiGenerator.ToolPackage.Version = "3.3.4";
});

Validate specifications

OpenApiGenerator.Validate("specification.yaml", recommend: true);

Batch processing

OpenApiGenerator.Batch("csharp-server.yaml", "javascript-client.yaml");

OpenApiGenerator.Batch(new OpenApiBatchSettings()
{
    ConfigurationFiles = new FilePathCollection(new FilePath[] { "csharp-server.yaml", "javascript-client.yaml" })
    // ...
});

OpenApiGenerator.Batch(settings =>
{
    settings.ConfigurationFiles.Add("csharp-server.yaml");
    settings.ConfigurationFiles.Add("javascript-client.yaml");
    // ...
});

Advanced usage

Setup(context =>
{
    OpenApiGenerator.ToolPackage = new MavenPackage("io.swagger", "swagger-codegen-cli");
});

Task("Swagger-Codegen")
    .Does(() =>
{
    OpenApiGenerator.Generate(new OpenApiGeneratorGenerateSettings()
    {
        Specification = "./petstore.json",
        // Use Language (-l) instead of Generator (-g)
        Language = "html",
        OutputDirectory = "./src"
    });
});
Setup(context =>
{
    OpenApiGenerator.ToolPath = context.Tools.Resolve("openapi-generator");
});

License

The software is licensed under the MIT license.

cake-openapi-generator's People

Contributors

cjlotz 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.