Created
June 12, 2018 15:21
-
-
Save clounie/9506da45dacb3a70ee28d2264639d76f to your computer and use it in GitHub Desktop.
Example files with Bankdata/gradle-swagger-plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
classpath (group: 'dk.bankdata.gradle.swagger', name: 'gradle-swagger-plugin', version: '1.0.0' | |
) | |
} | |
} | |
plugins { | |
id 'java' | |
} | |
apply plugin: 'dk.bankdata.swagger' | |
swagger { | |
resourcePackages = ['net.nw.test'] | |
} | |
group 'net.nw' | |
version '0.1.0' | |
sourceCompatibility = 1.8 | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7' | |
// Added to support @Api for now | |
compile group: 'io.swagger', name: 'swagger-annotations', version: '1.5.20' | |
compile group: 'io.swagger.core.v3', name: 'swagger-jaxrs2', version: '2.0.2' | |
compile group: 'io.swagger.core.v3', name: 'swagger-jaxrs2-servlet-initializer', version: '2.0.2' | |
compile group: 'org.glassfish.jersey.core', name: 'jersey-server', version: '2.27' | |
compile group: 'org.glassfish.grizzly', name: 'grizzly-http-server', version: '2.4.3' | |
compile group: 'org.glassfish.jersey.containers', name: 'jersey-container-grizzly2-http', version: '2.27' | |
compile group: 'org.glassfish.jersey.inject', name: 'jersey-hk2', version: '2.27' | |
testCompile group: 'junit', name: 'junit', version: '4.12' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
swagger: "2.0" | |
tags: | |
- name: "transactions" | |
paths: | |
/transactions/{transactionId}: | |
get: | |
tags: | |
- "transactions" | |
operationId: "getTransactionById" | |
consumes: | |
- "application/json" | |
produces: | |
- "application/json" | |
parameters: | |
- name: "transactionId" | |
in: "path" | |
required: true | |
type: "string" | |
responses: | |
200: | |
description: "successful operation" | |
schema: | |
type: "object" | |
headers: {} | |
/transactions/hello/{transactionId}: | |
get: | |
tags: | |
- "transactions" | |
operationId: "getTransactionById2" | |
consumes: | |
- "application/json" | |
produces: | |
- "application/json" | |
parameters: | |
- name: "transactionId" | |
in: "path" | |
required: true | |
type: "string" | |
responses: | |
200: | |
description: "successful operation" | |
schema: | |
type: "object" | |
headers: {} | |
/transactions/{regNo}-{accountNo}: | |
put: | |
tags: | |
- "transactions" | |
summary: "Create new or update existing account" | |
description: "" | |
operationId: "updateAccount" | |
consumes: | |
- "application/json" | |
produces: | |
- "application/hal+json" | |
parameters: | |
- name: "regNo" | |
in: "path" | |
required: true | |
type: "string" | |
pattern: "^[0-9]{4}$" | |
- name: "accountNo" | |
in: "path" | |
required: true | |
type: "string" | |
pattern: "^[0-9]+$" | |
responses: | |
default: | |
description: "successful operation" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.nw.test; | |
import io.swagger.annotations.Api; | |
import io.swagger.annotations.ApiOperation; | |
import io.swagger.v3.oas.annotations.OpenAPIDefinition; | |
import io.swagger.v3.oas.annotations.Operation; | |
import io.swagger.v3.oas.annotations.Parameter; | |
import io.swagger.v3.oas.annotations.responses.ApiResponse; | |
import io.swagger.v3.oas.annotations.responses.ApiResponses; | |
import javax.validation.Valid; | |
import javax.validation.constraints.Pattern; | |
import javax.ws.rs.*; | |
import javax.ws.rs.core.Context; | |
import javax.ws.rs.core.MediaType; | |
import javax.ws.rs.core.Request; | |
import javax.ws.rs.core.Response; | |
import javax.ws.rs.core.UriInfo; | |
import java.util.List; | |
@Api("/transactions") | |
@Path("/transactions") | |
@Consumes(MediaType.APPLICATION_JSON) | |
@Produces(MediaType.APPLICATION_JSON) | |
public class Test { | |
@GET | |
@Path("/{transactionId}") | |
@Operation(summary = "Retrieves a transaction by id", | |
responses = { | |
@ApiResponse(responseCode = "200", description = "Successfully found and returned the transaction"), | |
@ApiResponse(responseCode = "404", description = "Unable to find the specified transaction") | |
} | |
) | |
public Object getTransactionById( | |
@PathParam("transactionId") String transactionId | |
) { | |
return null; // TODO | |
} | |
@GET | |
@Path("/hello/{someId}") | |
@Operation(summary = "Retrieves a transaction by id", | |
responses = { | |
@ApiResponse(responseCode = "404", description = "Unable to find the specified transaction"), | |
@ApiResponse(responseCode = "200", description = "Successfully found and returned the transaction") | |
} | |
) | |
public Object getTransactionById2( | |
@PathParam("someId") String transactionId | |
) { | |
return null; // TODO | |
} | |
@PUT | |
@Path("{regNo}-{accountNo}") | |
@Produces({"application/hal+json"}) | |
@Consumes(MediaType.APPLICATION_JSON) | |
@ApiOperation(value = "Create new or update existing account", nickname = "updateAccount") | |
@ApiResponses(value = { | |
@ApiResponse(responseCode = "400", description = "No updating possible") | |
}) | |
public Response createOrUpdate(@PathParam("regNo") @Pattern(regexp = "^[0-9]{4}$") String regNo, | |
@PathParam("accountNo") @Pattern(regexp = "^[0-9]+$") String accountNo, | |
@Context UriInfo uriInfo, @Context Request request) { | |
return Response.ok().build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment