Skip to content

Commit 4bd9ef4

Browse files
committed
Issue #179: added kotlint client and server templates.
1 parent b639773 commit 4bd9ef4

Some content is hidden

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

50 files changed

+1570
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# {{packageName}} - Kotlin client library for {{appName}}
2+
3+
## Requires
4+
5+
* Kotlin 1.1.2
6+
* Gradle 3.3
7+
8+
## Build
9+
10+
First, create the gradle wrapper script:
11+
12+
```
13+
gradle wrapper
14+
```
15+
16+
Then, run:
17+
18+
```
19+
./gradlew check assemble
20+
```
21+
22+
This runs all tests and packages the library.
23+
24+
## Features/Implementation Notes
25+
26+
* Supports JSON inputs/outputs, File inputs, and Form inputs.
27+
* Supports collection formats for query parameters: csv, tsv, ssv, pipes.
28+
* Some Kotlin and Java types are fully qualified to avoid conflicts with types defined in Swagger definitions.
29+
* Implementation of ApiClient is intended to reduce method counts, specifically to benefit Android targets.
30+
31+
{{#generateApiDocs}}
32+
<a name="documentation-for-api-endpoints"></a>
33+
## Documentation for API Endpoints
34+
35+
All URIs are relative to *{{{basePath}}}*
36+
37+
Class | Method | HTTP request | Description
38+
------------ | ------------- | ------------- | -------------
39+
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{{summary}}}{{/summary}}
40+
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
41+
{{/generateApiDocs}}
42+
43+
{{#generateModelDocs}}
44+
<a name="documentation-for-models"></a>
45+
## Documentation for Models
46+
47+
{{#modelPackage}}
48+
{{#models}}{{#model}} - [{{{modelPackage}}}.{{{classname}}}]({{modelDocPath}}{{{classname}}}.md)
49+
{{/model}}{{/models}}
50+
{{/modelPackage}}
51+
{{^modelPackage}}
52+
No model defined in this package
53+
{{/modelPackage}}
54+
{{/generateModelDocs}}
55+
56+
<a name="documentation-for-authorization"></a>{{! TODO: optional documentation for authorization? }}
57+
## Documentation for Authorization
58+
59+
{{^authMethods}}
60+
All endpoints do not require authorization.
61+
{{/authMethods}}
62+
{{#authMethods}}
63+
{{#last}}
64+
Authentication schemes defined for the API:
65+
{{/last}}
66+
{{/authMethods}}
67+
{{#authMethods}}
68+
<a name="{{name}}"></a>
69+
### {{name}}
70+
71+
{{#isApiKey}}- **Type**: API key
72+
- **API key parameter name**: {{keyParamName}}
73+
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
74+
{{/isApiKey}}
75+
{{#isBasic}}- **Type**: HTTP basic authentication
76+
{{/isBasic}}
77+
{{#isOAuth}}- **Type**: OAuth
78+
- **Flow**: {{flow}}
79+
- **Authorization URL**: {{authorizationUrl}}
80+
- **Scopes**: {{^scopes}}N/A{{/scopes}}
81+
{{#scopes}} - {{scope}}: {{description}}
82+
{{/scopes}}
83+
{{/isOAuth}}
84+
85+
{{/authMethods}}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{{>licenseInfo}}
2+
package {{apiPackage}}
3+
4+
{{#imports}}import {{import}}
5+
{{/imports}}
6+
7+
import {{packageName}}.infrastructure.*
8+
{{#threetenbp}}
9+
import org.threeten.bp.LocalDateTime
10+
{{/threetenbp}}
11+
12+
{{#operations}}
13+
class {{classname}}(basePath: kotlin.String = "{{{basePath}}}") : ApiClient(basePath) {
14+
15+
{{#operation}}
16+
/**
17+
* {{summary}}
18+
* {{notes}}
19+
{{#allParams}}* @param {{paramName}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
20+
{{/allParams}}* @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
21+
*/{{#returnType}}
22+
@Suppress("UNCHECKED_CAST"){{/returnType}}
23+
fun {{operationId}}({{#allParams}}{{paramName}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}} {
24+
val localVariableBody: kotlin.Any? = {{#hasBodyParam}}{{#bodyParams}}{{paramName}}{{/bodyParams}}{{/hasBodyParam}}{{^hasBodyParam}}{{^hasFormParams}}null{{/hasFormParams}}{{#hasFormParams}}mapOf({{#formParams}}"{{{baseName}}}" to "${{paramName}}"{{#hasMore}}, {{/hasMore}}{{/formParams}}){{/hasFormParams}}{{/hasBodyParam}}
25+
val localVariableQuery: MultiValueMap = {{^hasQueryParams}}mapOf(){{/hasQueryParams}}{{#hasQueryParams}}mapOf({{#queryParams}}"{{baseName}}" to {{#isContainer}}toMultiValue({{paramName}}.toList(), "{{collectionFormat}}"){{/isContainer}}{{^isContainer}}listOf("${{paramName}}"){{/isContainer}}{{#hasMore}}, {{/hasMore}}{{/queryParams}}){{/hasQueryParams}}
26+
val localVariableHeaders: kotlin.collections.Map<kotlin.String,kotlin.String> = mapOf({{#hasFormParams}}"Content-Type" to "multipart/form-data"{{/hasFormParams}}{{^hasHeaderParams}}){{/hasHeaderParams}}{{#hasHeaderParams}}{{#hasFormParams}}, {{/hasFormParams}}{{#headerParams}}"{{baseName}}" to {{#isContainer}}{{paramName}}.joinToString(separator = collectionDelimiter("{{collectionFormat}}"){{/isContainer}}{{^isContainer}}{{paramName}}{{/isContainer}}{{#hasMore}}, {{/hasMore}}{{/headerParams}}){{/hasHeaderParams}}
27+
val localVariableConfig = RequestConfig(
28+
RequestMethod.{{httpMethod}},
29+
"{{path}}"{{#pathParams}}.replace("{"+"{{baseName}}"+"}", "${{paramName}}"){{/pathParams}},
30+
query = localVariableQuery,
31+
headers = localVariableHeaders
32+
)
33+
val response = request<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Any?{{/returnType}}>(
34+
localVariableConfig,
35+
localVariableBody
36+
)
37+
38+
return when (response.responseType) {
39+
ResponseType.Success -> {{#returnType}}(response as Success<*>).data as {{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}
40+
ResponseType.Informational -> TODO()
41+
ResponseType.Redirection -> TODO()
42+
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
43+
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
44+
else -> throw kotlin.IllegalStateException("Undefined ResponseType.")
45+
}
46+
}
47+
48+
{{/operation}}
49+
}
50+
{{/operations}}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
```kotlin
23+
// Import classes:
24+
//import {{{packageName}}}.infrastructure.*
25+
//import {{{modelPackage}}}.*
26+
27+
{{! TODO: Auth method documentation examples}}
28+
val apiInstance = {{{classname}}}()
29+
{{#allParams}}
30+
val {{{paramName}}} : {{{dataType}}} = {{{example}}} // {{{dataType}}} | {{{description}}}
31+
{{/allParams}}
32+
try {
33+
{{#returnType}}val result : {{{returnType}}} = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{{paramName}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}){{#returnType}}
34+
println(result){{/returnType}}
35+
} catch (e: ClientException) {
36+
println("4xx response calling {{{classname}}}#{{{operationId}}}")
37+
e.printStackTrace()
38+
} catch (e: ServerException) {
39+
println("5xx response calling {{{classname}}}#{{{operationId}}}")
40+
e.printStackTrace()
41+
}
42+
```
43+
44+
### Parameters
45+
{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}}
46+
Name | Type | Description | Notes
47+
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}
48+
{{#allParams}} **{{paramName}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isFile}}**{{dataType}}**{{/isFile}}{{^isFile}}{{#generateModelDocs}}[**{{dataType}}**]({{baseType}}.md){{/generateModelDocs}}{{^generateModelDocs}}**{{dataType}}**{{/generateModelDocs}}{{/isFile}}{{/isPrimitiveType}}| {{description}} |{{^required}} [optional]{{/required}}{{#defaultValue}} [default to {{defaultValue}}]{{/defaultValue}}{{#allowableValues}} [enum: {{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}]{{/allowableValues}}
49+
{{/allParams}}
50+
51+
### Return type
52+
53+
{{#returnType}}{{#returnTypeIsPrimitive}}**{{returnType}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}{{#generateModelDocs}}[**{{returnType}}**]({{returnBaseType}}.md){{/generateModelDocs}}{{^generateModelDocs}}**{{returnType}}**{{/generateModelDocs}}{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}null (empty response body){{/returnType}}
54+
55+
### Authorization
56+
57+
{{^authMethods}}No authorization required{{/authMethods}}{{#authMethods}}[{{name}}](../README.md#{{name}}){{^-last}}, {{/-last}}{{/authMethods}}
58+
59+
### HTTP request headers
60+
61+
- **Content-Type**: {{#consumes}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/consumes}}{{^consumes}}Not defined{{/consumes}}
62+
- **Accept**: {{#produces}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/produces}}{{^produces}}Not defined{{/produces}}
63+
64+
{{/operation}}
65+
{{/operations}}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
group '{{groupId}}'
2+
version '{{artifactVersion}}'
3+
4+
task wrapper(type: Wrapper) {
5+
gradleVersion = '3.3'
6+
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
7+
}
8+
9+
buildscript {
10+
ext.kotlin_version = '1.1.2'
11+
12+
repositories {
13+
mavenCentral()
14+
}
15+
dependencies {
16+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
17+
}
18+
}
19+
20+
apply plugin: 'kotlin'
21+
22+
repositories {
23+
mavenCentral()
24+
}
25+
26+
dependencies {
27+
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
28+
compile "com.squareup.moshi:moshi-kotlin:1.5.0"
29+
compile "com.squareup.moshi:moshi-adapters:1.5.0"
30+
compile "com.squareup.okhttp3:okhttp:3.8.0"
31+
compile "org.threeten:threetenbp:1.3.6"
32+
testCompile "io.kotlintest:kotlintest:2.0.2"
33+
}
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}}[**inline**](#{{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>{{!NOTE: see java's resources "pojo_doc.mustache" once enums are fully implemented}}
11+
## Enum: {{baseName}}
12+
Name | Value
13+
---- | -----{{#allowableValues}}
14+
{{name}} | {{#values}}{{.}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}
15+
{{/isEnum}}{{/vars}}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{{#hasEnums}}
2+
import com.squareup.moshi.Json
3+
{{/hasEnums}}
4+
/**
5+
* {{{description}}}
6+
{{#vars}}
7+
* @param {{name}} {{{description}}}
8+
{{/vars}}
9+
*/
10+
data class {{classname}} (
11+
{{#requiredVars}}
12+
{{>data_class_req_var}}{{^-last}},
13+
{{/-last}}{{/requiredVars}}{{#hasRequired}}{{#hasOptional}},
14+
{{/hasOptional}}{{/hasRequired}}{{#optionalVars}}{{>data_class_opt_var}}{{^-last}},
15+
{{/-last}}{{/optionalVars}}
16+
) {
17+
{{#hasEnums}}{{#vars}}{{#isEnum}}
18+
/**
19+
* {{{description}}}
20+
* Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}
21+
*/
22+
enum class {{nameInCamelCase}}(val value: {{datatype}}){
23+
{{#allowableValues}}{{#enumVars}}
24+
@Json(name = {{{value}}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}
25+
{{/enumVars}}{{/allowableValues}}
26+
}
27+
{{/isEnum}}{{/vars}}{{/hasEnums}}
28+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{{#description}}
2+
/* {{{description}}} */
3+
{{/description}}
4+
val {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{{#description}}
2+
/* {{{description}}} */
3+
{{/description}}
4+
val {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import com.squareup.moshi.Json
2+
3+
/**
4+
* {{{description}}}
5+
* Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}
6+
*/
7+
enum class {{classname}}(val value: {{dataType}}){
8+
{{#allowableValues}}{{#enumVars}}
9+
@Json(name = {{{value}}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}
10+
{{/enumVars}}{{/allowableValues}}
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# {{classname}}
2+
3+
## Enum
4+
5+
{{#allowableValues}}{{#enumVars}}
6+
* `{{name}}` (value: `{{{value}}}`)
7+
{{/enumVars}}{{/allowableValues}}

0 commit comments

Comments
 (0)