Skip to content

Commit d1cc248

Browse files
committed
Merge pull request #2773 from zhenjun115/master
add pom.xml based on build.gradle for android api client( using the v…
2 parents 8a9ba0b + 6709a92 commit d1cc248

File tree

24 files changed

+2548
-2
lines changed

24 files changed

+2548
-2
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AndroidClientCodegen.java

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.swagger.codegen.CliOption;
44
import io.swagger.codegen.CodegenConfig;
55
import io.swagger.codegen.CodegenConstants;
6+
import io.swagger.codegen.CodegenParameter;
67
import io.swagger.codegen.CodegenType;
78
import io.swagger.codegen.DefaultCodegen;
89
import io.swagger.codegen.SupportingFile;
@@ -32,6 +33,8 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
3233
// requestPackage and authPackage are used by the "volley" template/library
3334
protected String requestPackage = "io.swagger.client.request";
3435
protected String authPackage = "io.swagger.client.auth";
36+
protected String apiDocPath = "docs/";
37+
protected String modelDocPath = "docs/";
3538

3639
public AndroidClientCodegen() {
3740
super();
@@ -123,6 +126,26 @@ public String modelFileFolder() {
123126
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
124127
}
125128

129+
@Override
130+
public String apiDocFileFolder() {
131+
return (outputFolder + "/" + apiDocPath).replace( '/', File.separatorChar );
132+
}
133+
134+
@Override
135+
public String modelDocFileFolder() {
136+
return ( outputFolder + "/" + modelDocPath ).replace( '/', File.separatorChar );
137+
}
138+
139+
@Override
140+
public String toApiDocFilename( String name ) {
141+
return toApiName( name );
142+
}
143+
144+
@Override
145+
public String toModelDocFilename( String name ) {
146+
return toModelName( name );
147+
}
148+
126149
@Override
127150
public String getTypeDeclaration(Property p) {
128151
if (p instanceof ArrayProperty) {
@@ -224,6 +247,70 @@ public String toModelFilename(String name) {
224247
return toModelName(name);
225248
}
226249

250+
@Override
251+
public void setParameterExampleValue(CodegenParameter p) {
252+
String example;
253+
254+
if (p.defaultValue == null) {
255+
example = p.example;
256+
} else {
257+
example = p.defaultValue;
258+
}
259+
260+
String type = p.baseType;
261+
if (type == null) {
262+
type = p.dataType;
263+
}
264+
265+
if ("String".equals(type)) {
266+
if (example == null) {
267+
example = p.paramName + "_example";
268+
}
269+
example = "\"" + escapeText(example) + "\"";
270+
} else if ("Integer".equals(type) || "Short".equals(type)) {
271+
if (example == null) {
272+
example = "56";
273+
}
274+
} else if ("Long".equals(type)) {
275+
if (example == null) {
276+
example = "56";
277+
}
278+
example = example + "L";
279+
} else if ("Float".equals(type)) {
280+
if (example == null) {
281+
example = "3.4";
282+
}
283+
example = example + "F";
284+
} else if ("Double".equals(type)) {
285+
example = "3.4";
286+
example = example + "D";
287+
} else if ("Boolean".equals(type)) {
288+
if (example == null) {
289+
example = "true";
290+
}
291+
} else if ("File".equals(type)) {
292+
if (example == null) {
293+
example = "/path/to/file";
294+
}
295+
example = "new File(\"" + escapeText(example) + "\")";
296+
} else if ("Date".equals(type)) {
297+
example = "new Date()";
298+
} else if (!languageSpecificPrimitives.contains(type)) {
299+
// type is a model class, e.g. User
300+
example = "new " + type + "()";
301+
}
302+
303+
if (example == null) {
304+
example = "null";
305+
} else if (Boolean.TRUE.equals(p.isListContainer)) {
306+
example = "Arrays.asList(" + example + ")";
307+
} else if (Boolean.TRUE.equals(p.isMapContainer)) {
308+
example = "new HashMap()";
309+
}
310+
311+
p.example = example;
312+
}
313+
227314
@Override
228315
public String toOperationId(String operationId) {
229316
// throw exception if method name is empty
@@ -290,9 +377,23 @@ public void processOpts() {
290377
this.setLibrary((String) additionalProperties.get(CodegenConstants.LIBRARY));
291378
}
292379

380+
//make api and model doc path available in mustache template
381+
additionalProperties.put( "apiDocPath", apiDocPath );
382+
additionalProperties.put( "modelDocPath", modelDocPath );
383+
293384
if (StringUtils.isEmpty(getLibrary())) {
385+
modelDocTemplateFiles.put( "model_doc.mustache", ".md" );
386+
apiDocTemplateFiles.put( "api_doc.mustache", ".md" );
387+
//supportingFiles.add(new SupportingFile("api_doc.mustache", apiDocPath, "api.md"));
388+
//supportingFiles.add(new SupportingFile("model_doc.mustache", modelDocPath, "model.md"));
389+
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
294390
addSupportingFilesForDefault();
295391
} else if ("volley".equals(getLibrary())) {
392+
modelDocTemplateFiles.put( "model_doc.mustache", ".md" );
393+
apiDocTemplateFiles.put( "api_doc.mustache", ".md" );
394+
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
395+
//supportingFiles.add(new SupportingFile("api_doc.mustache", apiDocPath, "api.md"));
396+
//supportingFiles.add(new SupportingFile("model_doc.mustache", modelDocPath, "model.md"));
296397
addSupportingFilesForVolley();
297398
}
298399
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# {{artifactId}}
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>{{{groupId}}}</groupId>
30+
<artifactId>{{{artifactId}}}</artifactId>
31+
<version>{{{artifactVersion}}}</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 "{{{groupId}}}:{{{artifactId}}}:{{{artifactVersion}}}"
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/{{{artifactId}}}-{{{artifactVersion}}}.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+
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}
61+
import {{{package}}}.{{{classname}}};
62+
63+
public class {{{classname}}}Example {
64+
65+
public static void main(String[] args) {
66+
{{{classname}}} apiInstance = new {{{classname}}}();
67+
{{#allParams}}
68+
{{{dataType}}} {{{paramName}}} = {{{example}}}; // {{{dataType}}} | {{{description}}}
69+
{{/allParams}}
70+
try {
71+
{{#returnType}}{{{returnType}}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{{paramName}}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
72+
System.out.println(result);{{/returnType}}
73+
} catch (ApiException e) {
74+
System.err.println("Exception when calling {{{classname}}}#{{{operationId}}}");
75+
e.printStackTrace();
76+
}
77+
}
78+
}
79+
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
80+
```
81+
82+
## Documentation for API Endpoints
83+
84+
All URIs are relative to *{{basePath}}*
85+
86+
Class | Method | HTTP request | Description
87+
------------ | ------------- | ------------- | -------------
88+
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}}
89+
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
90+
91+
## Documentation for Models
92+
93+
{{#models}}{{#model}} - [{{classname}}]({{modelDocPath}}{{classname}}.md)
94+
{{/model}}{{/models}}
95+
96+
## Documentation for Authorization
97+
98+
{{^authMethods}}All endpoints do not require authorization.
99+
{{/authMethods}}Authentication schemes defined for the API:
100+
{{#authMethods}}### {{name}}
101+
102+
{{#isApiKey}}- **Type**: API key
103+
- **API key parameter name**: {{keyParamName}}
104+
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
105+
{{/isApiKey}}
106+
{{#isBasic}}- **Type**: HTTP basic authentication
107+
{{/isBasic}}
108+
{{#isOAuth}}- **Type**: OAuth
109+
- **Flow**: {{flow}}
110+
- **Authorizatoin URL**: {{authorizationUrl}}
111+
- **Scopes**: {{^scopes}}N/A{{/scopes}}
112+
{{#scopes}} - {{scope}}: {{description}}
113+
{{/scopes}}
114+
{{/isOAuth}}
115+
116+
{{/authMethods}}
117+
118+
## Recommendation
119+
120+
It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issue.
121+
122+
## Author
123+
124+
{{#apiInfo}}{{#apis}}{{^hasMore}}{{infoEmail}}
125+
{{/hasMore}}{{/apis}}{{/apiInfo}}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# {{classname}}{{#description}}
2+
{{description}}{{/description}}
3+
4+
All URIs are relative to *{{basePath}}*
5+
6+
Method | HTTP request | Description
7+
------------- | ------------- | -------------
8+
{{#operations}}{{#operation}}[**{{operationId}}**]({{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}}
9+
{{/operation}}{{/operations}}
10+
11+
{{#operations}}
12+
{{#operation}}
13+
<a name="{{operationId}}"></a>
14+
# **{{operationId}}**
15+
> {{#returnType}}{{returnType}} {{/returnType}}{{operationId}}({{#allParams}}{{{paramName}}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
16+
17+
{{summary}}{{#notes}}
18+
19+
{{notes}}{{/notes}}
20+
21+
### Example
22+
```java
23+
// Import classes:
24+
//import {{{package}}}.{{{classname}}};
25+
26+
{{{classname}}} apiInstance = new {{{classname}}}();
27+
{{#allParams}}
28+
{{{dataType}}} {{{paramName}}} = {{{example}}}; // {{{dataType}}} | {{{description}}}
29+
{{/allParams}}
30+
try {
31+
{{#returnType}}{{{returnType}}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{{paramName}}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
32+
System.out.println(result);{{/returnType}}
33+
} catch (ApiException e) {
34+
System.err.println("Exception when calling {{{classname}}}#{{{operationId}}}");
35+
e.printStackTrace();
36+
}
37+
```
38+
39+
### Parameters
40+
{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}}
41+
Name | Type | Description | Notes
42+
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}
43+
{{#allParams}} **{{paramName}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isFile}}**{{dataType}}**{{/isFile}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} |{{^required}} [optional]{{/required}}{{#defaultValue}} [default to {{defaultValue}}]{{/defaultValue}}{{#allowableValues}} [enum: {{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}]{{/allowableValues}}
44+
{{/allParams}}
45+
46+
### Return type
47+
48+
{{#returnType}}{{#returnTypeIsPrimitive}}**{{returnType}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{returnType}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}null (empty response body){{/returnType}}
49+
50+
### Authorization
51+
52+
{{^authMethods}}No authorization required{{/authMethods}}{{#authMethods}}[{{name}}](../README.md#{{name}}){{^-last}}, {{/-last}}{{/authMethods}}
53+
54+
### HTTP request headers
55+
56+
- **Content-Type**: {{#consumes}}{{mediaType}}{{#hasMore}}, {{/hasMore}}{{/consumes}}{{^consumes}}Not defined{{/consumes}}
57+
- **Accept**: {{#produces}}{{mediaType}}{{#hasMore}}, {{/hasMore}}{{/produces}}{{^produces}}Not defined{{/produces}}
58+
59+
{{/operation}}
60+
{{/operations}}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{{#models}}{{#model}}
2+
{{#isEnum}}{{>enum_outer_doc}}{{/isEnum}}{{^isEnum}}{{>pojo_doc}}{{/isEnum}}
3+
{{/model}}{{/models}}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# {{classname}}
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
{{#vars}}**{{name}}** | {{#isEnum}}[**{{datatypeWithEnum}}**](#{{datatypeWithEnum}}){{/isEnum}}{{^isEnum}}{{#isPrimitiveType}}**{{datatype}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{datatype}}**]({{complexType}}.md){{/isPrimitiveType}}{{/isEnum}} | {{description}} | {{^required}} [optional]{{/required}}{{#readOnly}} [readonly]{{/readOnly}}
7+
{{/vars}}
8+
{{#vars}}{{#isEnum}}
9+
10+
<a name="{{{datatypeWithEnum}}}"></a>
11+
## Enum: {{datatypeWithEnum}}
12+
Name | Value
13+
---- | -----{{#allowableValues}}{{#enumVars}}
14+
{{name}} | {{value}}{{/enumVars}}{{/allowableValues}}
15+
{{/isEnum}}{{/vars}}

0 commit comments

Comments
 (0)