Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
timezone: "Asia/Jerusalem"
- package-ecosystem: "gradle"
directory: "/"
schedule:
interval: "daily"
timezone: "Asia/Jerusalem"
reviewers:
- "muliyul"
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Dropwizard Swagger CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8

- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}-uidist-{{ hashFiles('src/main/resources/static/swagger-ui/*.*') }}
restore-keys: ${{ runner.os }}-gradle

- name: Clone Swagger UI distro
run: sh ./update-swagger-ui.sh

- name: Build
uses: eskatos/gradle-command-action@v1
with:
gradle-version: 6.7
arguments: build
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
dropwizard-swagger
==================

A Dropwizard bundle inspired by the original [dropwizard-swagger](https://github.com/federecio/dropwizard-swagger) and its popular [fork](https://github.com/smoketurner/dropwizard-swagger)
that serves [Swagger UI](https://github.com/swagger-api/swagger-ui) and loads [OpenApi](https://github.com/OAI/OpenAPI-Specification) 3.0 (or Swagger2) endpoints.

#### Notable improvements:

- Spec can be defined in standard locations (see [this](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#known-locations)). `config.yaml` takes precedence.
- UI is configurable (programmatically or via `config.yaml`).
- If `dropwizard-auth` is included, then by default your `@Auth` annotated parameters will be marked as `@Hidden` so they won't interfere with request body.

### Installation

#### Maven
```xml
<dependency>
<groupId>com.muliyul</groupId>
<artifactId>dropwizard-swagger</artifactId>
<version>0.0.1</version>
</dependency>
```

#### Gradle
```groovy
implementation('com.muliyul:dropwizard-swagger:0.0.1')
```

### Usage

See [example](src/test/java/com/muliyul/dropwizard/swagger/TestJavaConfiguration.java)
```java
class AppConfiguration extends Configuration implements com.muliyul.dropwizard.swagger.SwaggerConfiguration {
@JsonProperty("swagger")
private SwaggerConfiguration swaggerConfiguration = null;
@JsonProperty("swagger-ui")
private SwaggerUiConfiguration swaggerUiConfiguration = null;

public SwaggerConfiguration getSwaggerConfiguration() {
return swaggerConfiguration;
}

public SwaggerUiConfiguration getSwaggerUiConfiguration() {
return swaggerUiConfiguration;
}
}
```

#### In your Application class:
```java
@Override
public void initialize(Bootstrap<AppConfiguration> bootstrap) {
bootstrap.addBundle(new SwaggerBundle<>());

// or pass the packages to scan
// bootstrap.addBundle(new SwaggerBundle("com.example.resources", "com.example.resources2"));
// or specify them in config.yaml
// or specify them in one of the known OpenApi spec locations
// the choice is yours!
}
```

That's it!

The bundle will scan your classpath for any resources and expose them to swagger-ui via `/swagger`.

You can access the complete definitions in `/openapi`, `/openapi.json`, `/openapi.yaml` [see this](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#openapiresource).

#### Configuring Swagger-UI

See [SwaggerUiConfiguration](src/main/kotlin/com/muliyul/dropwizard/swagger/ui/configuration/SwaggerUiConfiguration.kt)

---
Check out OpenApi spec file/definitions [here]().

Check out the available Swagger-UI options [here]().

---
## Development

Clone the project and run `TestJavaApplication` or `TestKotlinApplication`.
58 changes: 58 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.4.21'
}

group 'com.muliyul'
version '0.0.1'

repositories {
mavenCentral()
}


java {
registerFeature('auth') {
usingSourceSet(sourceSets.main)
}
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

implementation platform("io.dropwizard:dropwizard-bom:2.0.17")
implementation("io.dropwizard:dropwizard-core")
implementation("io.dropwizard:dropwizard-assets")
authImplementation("io.dropwizard:dropwizard-auth")
// implementation("io.dropwizard:dropwizard-client")

implementation("io.swagger.core.v3:swagger-jaxrs2:2.1.2")

// Test
testImplementation("io.dropwizard:dropwizard-testing")

testImplementation('org.seleniumhq.selenium:selenium-java:3.141.59')
testImplementation('io.github.bonigarcia:selenium-jupiter:3.3.5')

testImplementation platform("org.glassfish.jersey:jersey-bom:2.33")
testImplementation("org.glassfish.jersey.ext:jersey-proxy-client")
testImplementation("io.dropwizard:dropwizard-auth")


// JUnit
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
testImplementation platform("org.junit:junit-bom:5.7.0")
testImplementation("org.junit.jupiter:junit-jupiter-api")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}

compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}


test {
useJUnitPlatform()
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kotlin.code.style=official
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
185 changes: 185 additions & 0 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading