1

add swagger-API and example controller

This commit is contained in:
killerber4t
2020-03-04 13:42:45 +01:00
parent ec69171458
commit ffabc5ce53
4 changed files with 57 additions and 0 deletions

View File

@ -1,3 +1,5 @@
import com.github.spotbugs.SpotBugsTask
plugins { plugins {
id 'org.springframework.boot' version '2.2.5.RELEASE' id 'org.springframework.boot' version '2.2.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE' id 'io.spring.dependency-management' version '1.0.9.RELEASE'
@ -11,7 +13,12 @@ spotbugs{
reportLevel = "high" reportLevel = "high"
toolVersion = '4.0.0-RC1' toolVersion = '4.0.0-RC1'
} }
<<<<<<< Updated upstream
tasks.withType(com.github.spotbugs.SpotBugsTask) { tasks.withType(com.github.spotbugs.SpotBugsTask) {
=======
tasks.withType(SpotBugsTask) {
>>>>>>> Stashed changes
reports { reports {
html { html {
enabled = true enabled = true
@ -52,8 +59,14 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-web'
<<<<<<< Updated upstream
implementation 'org.keycloak:keycloak-spring-boot-starter:9.0.0' implementation 'org.keycloak:keycloak-spring-boot-starter:9.0.0'
implementation 'org.keycloak.bom:keycloak-adapter-bom:3.3.0.Final' implementation 'org.keycloak.bom:keycloak-adapter-bom:3.3.0.Final'
=======
implementation 'mops:styleguide:2.0.0'
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.7.0'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.7.0'
>>>>>>> Stashed changes
compileOnly 'org.projectlombok:lombok' compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools' developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2' runtimeOnly 'com.h2database:h2'
@ -62,8 +75,10 @@ dependencies {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
} }
testImplementation 'org.springframework.security:spring-security-test' testImplementation 'org.springframework.security:spring-security-test'
compile('org.springframework.boot:spring-boot-starter-web')
} }
test { test {
useJUnitPlatform() useJUnitPlatform()
} }

View File

@ -2,10 +2,22 @@ package mops.gruppen2;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication @SpringBootApplication
@EnableSwagger2
public class Gruppen2Application { public class Gruppen2Application {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(Gruppen2Application.class, args); SpringApplication.run(Gruppen2Application.class, args);
} }
@Bean
public Docket productAPI(){
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("mops.gruppen2")).build();
}
} }

View File

@ -0,0 +1,24 @@
package mops.gruppen2.controllers;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
@RestController
public class SwaggerAPIController {
@RequestMapping(value = "/products", method = RequestMethod.GET)
public List<String> getProducts(){
List<String> productList = new ArrayList<>();
productList.add("Honey");
productList.add("Almond");
return productList;
}
@RequestMapping(value = "/products", method = RequestMethod.POST)
public String createProduct() {
return "Product is saved successfully";
}
}

View File

@ -9,9 +9,15 @@ spring.datasource.username=root
spring.datasource.password=geheim spring.datasource.password=geheim
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
<<<<<<< Updated upstream
keycloak.principal-attribute=preferred_username keycloak.principal-attribute=preferred_username
keycloak.auth-server-url=https://keycloak.cs.hhu.de/auth keycloak.auth-server-url=https://keycloak.cs.hhu.de/auth
keycloak.realm=MOPS keycloak.realm=MOPS
keycloak.resource=demo keycloak.resource=demo
keycloak.public-client=true keycloak.public-client=true
=======
spring.security.user.name=root
spring.security.user.password=1234
spring.security.user.roles=ADMIN
>>>>>>> Stashed changes