All Projects → scalalandio → sbt-swagger-2

scalalandio / sbt-swagger-2

Licence: Apache-2.0 license
sbt plugin for generating Swagger JSON schemas during build

Programming Languages

shell
77523 projects
scala
5932 projects

Projects that are alternatives of or similar to sbt-swagger-2

Sbt Docker Compose
Integrates Docker Compose functionality into sbt
Stars: ✭ 168 (+1192.31%)
Mutual labels:  sbt, sbt-plugin
sbt-sass
A fork of the sbt-sass repository which seems to be abandoned.
Stars: ✭ 32 (+146.15%)
Mutual labels:  sbt, sbt-plugin
Sbt Crossproject
Cross-platform compilation support for sbt.
Stars: ✭ 176 (+1253.85%)
Mutual labels:  sbt, sbt-plugin
Stryker4s
Mutation testing for Scala. Work in progress...
Stars: ✭ 118 (+807.69%)
Mutual labels:  sbt, sbt-plugin
sbt-findbugs
FindBugs static analysis plugin for sbt.
Stars: ✭ 47 (+261.54%)
Mutual labels:  sbt, sbt-plugin
Gatling Sbt Plugin Demo
Showcase of the Gatling Plugin for SBT
Stars: ✭ 137 (+953.85%)
Mutual labels:  sbt, sbt-plugin
Sbt Dynver
An sbt plugin to dynamically set your version from git
Stars: ✭ 243 (+1769.23%)
Mutual labels:  sbt, sbt-plugin
Sbt S3 Resolver
☁️Amazon S3-based resolver for sbt
Stars: ✭ 112 (+761.54%)
Mutual labels:  sbt, sbt-plugin
gatling-sbt-plugin
Gatling Plugin for SBT
Stars: ✭ 105 (+707.69%)
Mutual labels:  sbt, sbt-plugin
Sbt Fresh
sbt-plugin to create an opinionated fresh sbt project
Stars: ✭ 229 (+1661.54%)
Mutual labels:  sbt, sbt-plugin
sbt-ghpages
git, site and ghpages support for sbt projects.
Stars: ✭ 94 (+623.08%)
Mutual labels:  sbt, sbt-plugin
sbt-sonar
An sbt plugin which provides an easy way to integrate Scala projects with SonarQube.
Stars: ✭ 62 (+376.92%)
Mutual labels:  sbt, sbt-plugin
Sbt Jacoco
JaCoCo Code Coverage plug-in for sbt.
Stars: ✭ 115 (+784.62%)
Mutual labels:  sbt, sbt-plugin
Sbt Protobuf
sbt plugin for compiling protobuf files
Stars: ✭ 163 (+1153.85%)
Mutual labels:  sbt, sbt-plugin
Sbt Unidoc
sbt plugin to create a unified API document across projects
Stars: ✭ 113 (+769.23%)
Mutual labels:  sbt, sbt-plugin
Sbt Dependency Check
SBT Plugin for OWASP DependencyCheck. Monitor your dependencies and report if there are any publicly known vulnerabilities (e.g. CVEs). 🌈
Stars: ✭ 187 (+1338.46%)
Mutual labels:  sbt, sbt-plugin
Sbt Prompt
An SBT plugin for making your SBT prompt more awesome
Stars: ✭ 107 (+723.08%)
Mutual labels:  sbt, sbt-plugin
Sbt Native Packager
sbt Native Packager
Stars: ✭ 1,480 (+11284.62%)
Mutual labels:  sbt, sbt-plugin
Sbt Tpolecat
scalac options for the enlightened
Stars: ✭ 227 (+1646.15%)
Mutual labels:  sbt, sbt-plugin
sbt-graphql
SBT plugin to generate and validate graphql schemas written with Sangria
Stars: ✭ 94 (+623.08%)
Mutual labels:  sbt, sbt-plugin

sbt-swagger-2

Build Status Maven Central License

This project is archived. I moved away from using swagger-core in general, I am very happy about it and I cannot support this plugin anymore. If you are interested in using it and you need some modifications, I suggest forking it. Alternatively - if you are able to - move away to endpoints or tapir.

This plugin is a sbt wrapper for a Swagger Akka HTTP, that allows you to generate one (or more) Swagger JSON files during build instead of doing it in runtime.

As such you can annotate your APIs, the same way you did in Swagger Akka HTTP. Then you can generate swagger.json only after you modified files, remove all dependencies from build, and use getFromResource("swagger.json") to serve it.

Motivation

  • I wanted to limit dependencies used in runtime - as I used Circe and Jaws for JSON, shipping separate library (Jackson) as well as quite a lot other dependencies just for Swagger seems like unnnecessary overhead,
  • annotation-based Swagger generators use runtime reflection - for some people that solution itself is a disadvantage,
  • when I tried to create a native image in GraalVM, it failed due to usage of reflection - moving Swagger generation to build stage is a part of the effort of overall removal of runtime reflection in my projects,
  • https://github.com/hootsuite/sbt-swagger is outdated: it isn't migrated to sbt 1.0.0 and uses older version of Swagger.

Usage

First add plugin to project/plugins.sbt file:

addSbtPlugin("io.scalaland" % "sbt-swagger-2" % sbtSwagger2Version)

Project basically reuse all constructs from Swagger Akka HTTP. It add aliases for them in io.scalaland.sbtswagger2.SbtSwagger2Plugin.autoImport, so classes used for creating config can be found within Swagger object.

// API v1
swaggerOutputs += Swagger.Output(
  inputFilter = clazz => Set(
    "backend.healthcheck",
    "backend.auth",
    "backend.api.v1"
  ).exists(prefix => clazz.getName.startsWith(prefix)),
  output = (Compile / classDirectory).value / "docs" / "v1" / "swagger.json",
  host = "http://localhost",
  schemes = List(Swagger.Scheme.HTTP, Swagger.Scheme.HTTPS),
  securitySchemeDefinitions = Map("token" -> new Swagger.OAuth2Definition().password("/auth")),
  info = Swagger.Info(
    title = "Backend API v1",
    version = version.value,
    description = """V1 API description""".stripMargin
  )
)

// API v2
swaggerOutputs += Swagger.Output(
  inputFilter = clazz => Set(
    "backend.healthcheck",
    "backend.auth",
    "backend.api.v2"
  ).exists(prefix => clazz.getName.startsWith(prefix)),
  ...
)

It adds however whilelisting ability, so that one could cherry-pick classes to use in each of (potentially) many files.

Once configured one can run it with:

sbt> swaggerGenerate

Requirements and limitations

This plugin requires sbt 1.1.0+.

So far I haven't found a way to run generator automatically after each compilation without having issue with circular depenendencies and sbt freeze, so you should select resources dir as the target and run swaggerGenerate manually.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].