BAEL-1116 Spring swagger codegen (#2527)

* Spring integration with Swagger client code genrator

* Refactor

* format pom.xml
This commit is contained in:
Hany Ahmed
2017-09-04 05:41:49 +02:00
committed by Predrag Maric
parent acf9bf7c4a
commit 2b293e51e0
52 changed files with 5411 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId>
<artifactId>spring-swagger-codegen-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>com.baeldung</groupId>
<artifactId>spring-swagger-codegen-api-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,30 @@
package com.baeldung.petstore.app;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baeldung.petstore.client.api.PetApi;
import com.baeldung.petstore.client.model.Pet;
@Service
public class DefaultPetService implements PetService {
@Autowired
private PetApi petApi;
public List<Pet> findAvailablePets() {
return petApi.findPetsByStatus(Arrays.asList("available"));
}
public List<Pet> findPendingPets() {
return petApi.findPetsByStatus(Arrays.asList("pending"));
}
public List<Pet> findSoldPets() {
return petApi.findPetsByStatus(Arrays.asList("sold"));
}
}

View File

@@ -0,0 +1,26 @@
package com.baeldung.petstore.app;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class PetController {
@Autowired
private PetService petService;
@RequestMapping("/pets")
@ResponseBody
public String listAvailablePets() {
StringBuilder sb = new StringBuilder("<h1>Available pets:</h1>");
sb.append("<ul>");
petService.findAvailablePets()
.forEach( p -> sb.append("<li>" + p.getName() + "</li>"));
sb.append("</ul>");
return sb.toString();
}
}

View File

@@ -0,0 +1,27 @@
package com.baeldung.petstore.app;
import java.util.List;
import com.baeldung.petstore.client.model.Pet;
public interface PetService {
/**
* Find available pets
* @return List of available pets
*/
List<Pet> findAvailablePets();
/**
* Find Pending pets
* @return List of pending pets
*/
List<Pet> findPendingPets();
/**
* Find sold pets
* @return List of sold pets
*/
List<Pet> findSoldPets();
}

View File

@@ -0,0 +1,15 @@
package com.baeldung.petstore.app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;
@SpringBootApplication
@Import(PetStoreIntegrationConfig.class)
public class PetStoreApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(PetStoreApplication.class, args);
}
}

View File

@@ -0,0 +1,23 @@
package com.baeldung.petstore.app;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.baeldung.petstore.client.api.PetApi;
import com.baeldung.petstore.client.invoker.ApiClient;
@Configuration
public class PetStoreIntegrationConfig {
@Bean
public PetApi petpi() {
return new PetApi(apiClient());
}
@Bean
public ApiClient apiClient() {
ApiClient apiClient = new ApiClient();
return apiClient;
}
}