Skip to content

Commit 2b293e5

Browse files
Namozagpedja4
authored andcommitted
BAEL-1116 Spring swagger codegen (eugenp#2527)
* Spring integration with Swagger client code genrator * Refactor * format pom.xml
1 parent acf9bf7 commit 2b293e5

52 files changed

Lines changed: 5411 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎pom.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
<module>rest-testing</module>
126126
<module>resteasy</module>
127127
<module>rxjava</module>
128+
<module>spring-swagger-codegen</module>
128129

129130
<module>selenium-junit-testng</module>
130131
<module>solr</module>

‎spring-swagger-codegen/pom.xml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.baeldung</groupId>
5+
<artifactId>spring-swagger-codegen</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<packaging>pom</packaging>
8+
<modules>
9+
<module>spring-swagger-codegen-api-client</module>
10+
<module>spring-swagger-codegen-app</module>
11+
</modules>
12+
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
*.class
2+
3+
# Mobile Tools for Java (J2ME)
4+
.mtj.tmp/
5+
6+
# Package Files #
7+
*.jar
8+
*.war
9+
*.ear
10+
11+
# exclude jar for gradle wrapper
12+
!gradle/wrapper/*.jar
13+
14+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
15+
hs_err_pid*
16+
17+
# build files
18+
**/target
19+
target
20+
.gradle
21+
build
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Swagger Codegen Ignore
2+
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.2.3
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Generated by: https://github.com/swagger-api/swagger-codegen.git
3+
#
4+
language: java
5+
jdk:
6+
- oraclejdk8
7+
- oraclejdk7
8+
before_install:
9+
# ensure gradlew has proper permission
10+
- chmod a+x ./gradlew
11+
script:
12+
# test using maven
13+
- mvn test
14+
# uncomment below to test using gradle
15+
# - gradle test
16+
# uncomment below to test using sbt
17+
# - sbt test
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# spring-swagger-codegen-api-client
2+
3+
## Requirements
4+
5+
Building the API client library requires [Maven](https://maven.apache.org/) to be installed.
6+
7+
## Installation
8+
9+
To install the API client library to your local Maven repository, simply execute:
10+
11+
```shell
12+
mvn install
13+
```
14+
15+
To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:
16+
17+
```shell
18+
mvn deploy
19+
```
20+
21+
Refer to the [official documentation](https://maven.apache.org/plugins/maven-deploy-plugin/usage.html) for more information.
22+
23+
### Maven users
24+
25+
Add this dependency to your project's POM:
26+
27+
```xml
28+
<dependency>
29+
<groupId>com.baeldung</groupId>
30+
<artifactId>spring-swagger-codegen-api-client</artifactId>
31+
<version>0.0.1-SNAPSHOT</version>
32+
<scope>compile</scope>
33+
</dependency>
34+
```
35+
36+
### Gradle users
37+
38+
Add this dependency to your project's build file:
39+
40+
```groovy
41+
compile "com.baeldung:spring-swagger-codegen-api-client:0.0.1-SNAPSHOT"
42+
```
43+
44+
### Others
45+
46+
At first generate the JAR by executing:
47+
48+
mvn package
49+
50+
Then manually install the following JARs:
51+
52+
* target/spring-swagger-codegen-api-client-0.0.1-SNAPSHOT.jar
53+
* target/lib/*.jar
54+
55+
## Getting Started
56+
57+
Please follow the [installation](#installation) instruction and execute the following Java code:
58+
59+
```java
60+
61+
import com.baeldung.petstore.client.invoker.*;
62+
import com.baeldung.petstore.client.invoker.auth.*;
63+
import com.baeldung.petstore.client.model.*;
64+
import com.baeldung.petstore.client.api.PetApi;
65+
66+
import java.io.File;
67+
import java.util.*;
68+
69+
public class PetApiExample {
70+
71+
public static void main(String[] args) {
72+
ApiClient defaultClient = Configuration.getDefaultApiClient();
73+
74+
// Configure OAuth2 access token for authorization: petstore_auth
75+
OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth");
76+
petstore_auth.setAccessToken("YOUR ACCESS TOKEN");
77+
78+
PetApi apiInstance = new PetApi();
79+
Pet body = new Pet(); // Pet | Pet object that needs to be added to the store
80+
try {
81+
apiInstance.addPet(body);
82+
} catch (ApiException e) {
83+
System.err.println("Exception when calling PetApi#addPet");
84+
e.printStackTrace();
85+
}
86+
}
87+
}
88+
89+
```
90+
91+
## Documentation for API Endpoints
92+
93+
All URIs are relative to *http://petstore.swagger.io/v2*
94+
95+
Class | Method | HTTP request | Description
96+
------------ | ------------- | ------------- | -------------
97+
*PetApi* | [**addPet**](docs/PetApi.md#addPet) | **POST** /pet | Add a new pet to the store
98+
*PetApi* | [**deletePet**](docs/PetApi.md#deletePet) | **DELETE** /pet/{petId} | Deletes a pet
99+
*PetApi* | [**findPetsByStatus**](docs/PetApi.md#findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status
100+
*PetApi* | [**findPetsByTags**](docs/PetApi.md#findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags
101+
*PetApi* | [**getPetById**](docs/PetApi.md#getPetById) | **GET** /pet/{petId} | Find pet by ID
102+
*PetApi* | [**updatePet**](docs/PetApi.md#updatePet) | **PUT** /pet | Update an existing pet
103+
*PetApi* | [**updatePetWithForm**](docs/PetApi.md#updatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data
104+
*PetApi* | [**uploadFile**](docs/PetApi.md#uploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image
105+
*StoreApi* | [**deleteOrder**](docs/StoreApi.md#deleteOrder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
106+
*StoreApi* | [**getInventory**](docs/StoreApi.md#getInventory) | **GET** /store/inventory | Returns pet inventories by status
107+
*StoreApi* | [**getOrderById**](docs/StoreApi.md#getOrderById) | **GET** /store/order/{orderId} | Find purchase order by ID
108+
*StoreApi* | [**placeOrder**](docs/StoreApi.md#placeOrder) | **POST** /store/order | Place an order for a pet
109+
*UserApi* | [**createUser**](docs/UserApi.md#createUser) | **POST** /user | Create user
110+
*UserApi* | [**createUsersWithArrayInput**](docs/UserApi.md#createUsersWithArrayInput) | **POST** /user/createWithArray | Creates list of users with given input array
111+
*UserApi* | [**createUsersWithListInput**](docs/UserApi.md#createUsersWithListInput) | **POST** /user/createWithList | Creates list of users with given input array
112+
*UserApi* | [**deleteUser**](docs/UserApi.md#deleteUser) | **DELETE** /user/{username} | Delete user
113+
*UserApi* | [**getUserByName**](docs/UserApi.md#getUserByName) | **GET** /user/{username} | Get user by user name
114+
*UserApi* | [**loginUser**](docs/UserApi.md#loginUser) | **GET** /user/login | Logs user into the system
115+
*UserApi* | [**logoutUser**](docs/UserApi.md#logoutUser) | **GET** /user/logout | Logs out current logged in user session
116+
*UserApi* | [**updateUser**](docs/UserApi.md#updateUser) | **PUT** /user/{username} | Updated user
117+
118+
119+
## Documentation for Models
120+
121+
- [Category](docs/Category.md)
122+
- [ModelApiResponse](docs/ModelApiResponse.md)
123+
- [Order](docs/Order.md)
124+
- [Pet](docs/Pet.md)
125+
- [Tag](docs/Tag.md)
126+
- [User](docs/User.md)
127+
128+
129+
## Documentation for Authorization
130+
131+
Authentication schemes defined for the API:
132+
### api_key
133+
134+
- **Type**: API key
135+
- **API key parameter name**: api_key
136+
- **Location**: HTTP header
137+
138+
### petstore_auth
139+
140+
- **Type**: OAuth
141+
- **Flow**: implicit
142+
- **Authorization URL**: http://petstore.swagger.io/oauth/dialog
143+
- **Scopes**:
144+
- write:pets: modify pets in your account
145+
- read:pets: read your pets
146+
147+
148+
## Recommendation
149+
150+
It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues.
151+
152+
## Author
153+
154+
apiteam@swagger.io
155+
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
apply plugin: 'idea'
2+
apply plugin: 'eclipse'
3+
4+
group = 'com.baeldung'
5+
version = '0.0.1-SNAPSHOT'
6+
7+
buildscript {
8+
repositories {
9+
jcenter()
10+
}
11+
dependencies {
12+
classpath 'com.android.tools.build:gradle:1.5.+'
13+
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
14+
}
15+
}
16+
17+
repositories {
18+
jcenter()
19+
}
20+
21+
22+
if(hasProperty('target') && target == 'android') {
23+
24+
apply plugin: 'com.android.library'
25+
apply plugin: 'com.github.dcendents.android-maven'
26+
27+
android {
28+
compileSdkVersion 23
29+
buildToolsVersion '23.0.2'
30+
defaultConfig {
31+
minSdkVersion 14
32+
targetSdkVersion 22
33+
}
34+
compileOptions {
35+
sourceCompatibility JavaVersion.VERSION_1_7
36+
targetCompatibility JavaVersion.VERSION_1_7
37+
}
38+
39+
// Rename the aar correctly
40+
libraryVariants.all { variant ->
41+
variant.outputs.each { output ->
42+
def outputFile = output.outputFile
43+
if (outputFile != null && outputFile.name.endsWith('.aar')) {
44+
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
45+
output.outputFile = new File(outputFile.parent, fileName)
46+
}
47+
}
48+
}
49+
50+
dependencies {
51+
provided 'javax.annotation:jsr250-api:1.0'
52+
}
53+
}
54+
55+
afterEvaluate {
56+
android.libraryVariants.all { variant ->
57+
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
58+
task.description = "Create jar artifact for ${variant.name}"
59+
task.dependsOn variant.javaCompile
60+
task.from variant.javaCompile.destinationDir
61+
task.destinationDir = project.file("${project.buildDir}/outputs/jar")
62+
task.archiveName = "${project.name}-${variant.baseName}-${version}.jar"
63+
artifacts.add('archives', task);
64+
}
65+
}
66+
67+
task sourcesJar(type: Jar) {
68+
from android.sourceSets.main.java.srcDirs
69+
classifier = 'sources'
70+
}
71+
72+
artifacts {
73+
archives sourcesJar
74+
}
75+
76+
} else {
77+
78+
apply plugin: 'java'
79+
apply plugin: 'maven'
80+
81+
sourceCompatibility = JavaVersion.VERSION_1_7
82+
targetCompatibility = JavaVersion.VERSION_1_7
83+
84+
install {
85+
repositories.mavenInstaller {
86+
pom.artifactId = 'spring-swagger-codegen-api-client'
87+
}
88+
}
89+
90+
task execute(type:JavaExec) {
91+
main = System.getProperty('mainClass')
92+
classpath = sourceSets.main.runtimeClasspath
93+
}
94+
}
95+
96+
ext {
97+
swagger_annotations_version = "1.5.15"
98+
jackson_version = "2.8.9"
99+
spring_web_version = "4.3.9.RELEASE"
100+
jodatime_version = "2.9.9"
101+
junit_version = "4.12"
102+
}
103+
104+
dependencies {
105+
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
106+
compile "org.springframework:spring-web:$spring_web_version"
107+
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
108+
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
109+
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
110+
compile "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:$jackson_version"
111+
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version"
112+
compile "joda-time:joda-time:$jodatime_version"
113+
testCompile "junit:junit:$junit_version"
114+
}

‎spring-swagger-codegen/spring-swagger-codegen-api-client/build.sbt‎

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
# Category
3+
4+
## Properties
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**id** | **Long** | | [optional]
8+
**name** | **String** | | [optional]
9+
10+
11+

0 commit comments

Comments
 (0)