Skip to content

Commit

Permalink
Merge pull request #299 from swagger-api/issue-8679
Browse files Browse the repository at this point in the history
Issue 8679
  • Loading branch information
HugoMario authored Feb 9, 2019
2 parents d37f35c + 7c30686 commit dc36568
Show file tree
Hide file tree
Showing 106 changed files with 1,121 additions and 711 deletions.
69 changes: 44 additions & 25 deletions src/main/resources/handlebars/Java/README.mustache
Original file line number Diff line number Diff line change
@@ -1,35 +1,52 @@
# {{artifactId}}

{{appName}}
- API version: {{appVersion}}
{{^hideGenerationTimestamp}}
- Build date: {{generatedDate}}
{{/hideGenerationTimestamp}}

{{#appDescription}}{{{appDescription}}}{{/appDescription}}

{{#infoUrl}}
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/infoUrl}}

*Automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen)*


## Requirements

Building the API client library requires [Maven](https://maven.apache.org/) to be installed.
Building the API client library requires:
1. Java 1.7+
2. Maven/Gradle

## Installation

To install the API client library to your local Maven repository, simply execute:

```shell
mvn install
mvn clean install
```

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

```shell
mvn deploy
mvn clean deploy
```

Refer to the [official documentation](https://maven.apache.org/plugins/maven-deploy-plugin/usage.html) for more information.
Refer to the [OSSRH Guide](http://central.sonatype.org/pages/ossrh-guide.html) for more information.

### Maven users

Add this dependency to your project's POM:

```xml
<dependency>
<groupId>{{{groupId}}}</groupId>
<artifactId>{{{artifactId}}}</artifactId>
<version>{{{artifactVersion}}}</version>
<scope>compile</scope>
<groupId>{{{groupId}}}</groupId>
<artifactId>{{{artifactId}}}</artifactId>
<version>{{{artifactVersion}}}</version>
<scope>compile</scope>
</dependency>
```

Expand All @@ -45,19 +62,21 @@ compile "{{{groupId}}}:{{{artifactId}}}:{{{artifactVersion}}}"

At first generate the JAR by executing:

mvn package
```shell
mvn clean package
```

Then manually install the following JARs:

* target/{{{artifactId}}}-{{{artifactVersion}}}.jar
* target/lib/*.jar
* `target/{{{artifactId}}}-{{{artifactVersion}}}.jar`
* `target/lib/*.jar`

## Getting Started

Please follow the [installation](#installation) instruction and execute the following Java code:

```java
{{#apiInfo}}{{#apis}}{{#@first}}{{#operations}}{{#operation}}{{#@first}}
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#@first}}
import {{{invokerPackage}}}.*;
import {{{invokerPackage}}}.auth.*;
import {{{modelPackage}}}.*;
Expand All @@ -70,19 +89,19 @@ public class {{{classname}}}Example {
public static void main(String[] args) {
{{#hasAuthMethods}}ApiClient defaultClient = Configuration.getDefaultApiClient();
{{#authMethods}}{{#is this 'basic'}}
{{#authMethods}}{{#isBasic}}
// Configure HTTP basic authorization: {{{name}}}
HttpBasicAuth {{{name}}} = (HttpBasicAuth) defaultClient.getAuthentication("{{{name}}}");
{{{name}}}.setUsername("YOUR USERNAME");
{{{name}}}.setPassword("YOUR PASSWORD");{{/is}}{{#is this 'api-key'}}
{{{name}}}.setPassword("YOUR PASSWORD");{{/isBasic}}{{#isApiKey}}
// Configure API key authorization: {{{name}}}
ApiKeyAuth {{{name}}} = (ApiKeyAuth) defaultClient.getAuthentication("{{{name}}}");
{{{name}}}.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//{{{name}}}.setApiKeyPrefix("Token");{{/is}}{{#is this 'oauth'}}
//{{{name}}}.setApiKeyPrefix("Token");{{/isApiKey}}{{#isOAuth}}
// Configure OAuth2 access token for authorization: {{{name}}}
OAuth {{{name}}} = (OAuth) defaultClient.getAuthentication("{{{name}}}");
{{{name}}}.setAccessToken("YOUR ACCESS TOKEN");{{/is}}
{{{name}}}.setAccessToken("YOUR ACCESS TOKEN");{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}

Expand All @@ -91,15 +110,15 @@ public class {{{classname}}}Example {
{{{dataType}}} {{{paramName}}} = {{{example}}}; // {{{dataType}}} | {{{description}}}
{{/allParams}}
try {
{{#returnType}}{{{returnType}}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{{paramName}}}{{#has this 'more'}}, {{/has}}{{/allParams}});{{#returnType}}
{{#returnType}}{{{returnType}}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{{paramName}}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
System.out.println(result);{{/returnType}}
} catch (ApiException e) {
System.err.println("Exception when calling {{{classname}}}#{{{operationId}}}");
e.printStackTrace();
}
}
}
{{/@first}}{{/operation}}{{/operations}}{{/@first}}{{/apis}}{{/apiInfo}}
{{/@first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
```

## Documentation for API Endpoints
Expand All @@ -122,19 +141,19 @@ Class | Method | HTTP request | Description
{{/authMethods}}Authentication schemes defined for the API:
{{#authMethods}}### {{name}}

{{#is this 'api-key'}}- **Type**: API key
{{#isApiKey}}- **Type**: API key
- **API key parameter name**: {{keyParamName}}
- **Location**: {{#is this 'key-in-query'}}URL query string{{/is}}{{#is this 'key-in-header'}}HTTP header{{/is}}
{{/is}}
{{#is this 'basic'}}- **Type**: HTTP basic authentication
{{/is}}
{{#is this 'oauth'}}- **Type**: OAuth
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
{{/isApiKey}}
{{#isBasic}}- **Type**: HTTP basic authentication
{{/isBasic}}
{{#isOAuth}}- **Type**: OAuth
- **Flow**: {{flow}}
- **Authorization URL**: {{authorizationUrl}}
- **Scopes**: {{^scopes}}N/A{{/scopes}}
{{#scopes}} - {{scope}}: {{description}}
{{/scopes}}
{{/is}}
{{/isOAuth}}

{{/authMethods}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import retrofit2.Response;
{{#operations}}
public interface {{classname}} {
{{#operation}}
{{#contents}}
/**
* {{summary}}
* {{notes}}
{{#allParams}}
{{#parameters}}
* @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/allParams}}
{{/parameters}}
* @return Call&lt;{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Object{{/returnType}}&gt;
*/
{{#formParams}}
Expand All @@ -48,10 +49,11 @@ public interface {{classname}} {
{{/prioritizedContentTypes}}
{{/formParams}}
@{{httpMethod}}("{{{path}}}")
F.Promise<Response<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}>> {{operationId}}({{^allParams}});{{/allParams}}
{{#allParams}}{{>libraries/retrofit2/queryParams}}{{>libraries/retrofit2/pathParams}}{{>libraries/retrofit2/headerParams}}{{>libraries/retrofit2/bodyParams}}{{>libraries/retrofit2/formParams}}{{#has this 'more'}}, {{/has}}{{#hasNot this 'more'}}
);{{/hasNot}}{{/allParams}}
F.Promise<Response<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}>> {{operationId}}({{^parameters}});{{/parameters}}
{{#parameters}}{{>libraries/retrofit2/queryParams}}{{>libraries/retrofit2/pathParams}}{{>libraries/retrofit2/headerParams}}{{>libraries/retrofit2/bodyParams}}{{>libraries/retrofit2/formParams}}{{#hasMore}}, {{/hasMore}}{{^hasMore}}
);{{/hasMore}}{{/parameters}}

{{/contents}}
{{/operation}}
}
{{/operations}}
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,35 @@ import retrofit2.Response;
{{#operations}}
public interface {{classname}} {
{{#operation}}
{{#contents}}
/**
* {{summary}}
* {{notes}}
{{#allParams}}
{{#parameters}}
* @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/allParams}}
* @return Call&lt;{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Object{{/returnType}}&gt;
{{/parameters}}
* @return Call&lt;{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Void{{/returnType}}&gt;
*/
{{#formParams}}
{{#@first}}
{{#is ../this 'multipart'}}@retrofit2.http.Multipart{{/is}}{{#isNot ../this 'multipart'}}@retrofit2.http.FormUrlEncoded{{/isNot}}
{{#isMultipart}}@retrofit2.http.Multipart{{/isMultipart}}{{^isMultipart}}@retrofit2.http.FormUrlEncoded{{/isMultipart}}
{{/@first}}
{{/formParams}}
{{^formParams}}
{{#prioritizedContentTypes}}
{{#@first}}
@Headers({
"Content-Type:{{mediaType}}"
"Content-Type:{{{mediaType}}}"
})
{{/@first}}
{{/prioritizedContentTypes}}
{{/formParams}}
{{/formParams}}
@{{httpMethod}}("{{{path}}}")
CompletionStage<Response<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}>> {{operationId}}({{^allParams}});{{/allParams}}
{{#allParams}}{{>libraries/retrofit2/queryParams}}{{>libraries/retrofit2/pathParams}}{{>libraries/retrofit2/headerParams}}{{>libraries/retrofit2/bodyParams}}{{>libraries/retrofit2/formParams}}{{#has this 'more'}}, {{/has}}{{#hasNot this 'more'}}
);{{/hasNot}}{{/allParams}}
CompletionStage<Response<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}>> {{operationId}}({{^parameters}});{{/parameters}}
{{#parameters}}{{>libraries/retrofit2/queryParams}}{{>libraries/retrofit2/pathParams}}{{>libraries/retrofit2/headerParams}}{{>libraries/retrofit2/bodyParams}}{{>libraries/retrofit2/formParams}}{{#hasMore}}, {{/hasMore}}{{^hasMore}}
);{{/hasMore}}{{/parameters}}

{{/contents}}
{{/operation}}
}
{{/operations}}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ public interface {{classname}} {
{{#operations}}
{{#operation}}
void {{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}Handler<AsyncResult<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}>> handler);
{{#contents}}
void {{operationId}}({{#parameters}}{{{dataType}}} {{paramName}}, {{/parameters}}Handler<AsyncResult<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}>> handler);

{{/contents}}
{{/operation}}
{{/operations}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,24 @@ public class {{classname}}Impl implements {{classname}} {
}

{{#operation}}
{{#contents}}
/**
* {{summary}}
* {{notes}}
{{#allParams}}
{{#parameters}}
* @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/allParams}}
{{/parameters}}
* @param resultHandler Asynchronous result handler
*/
public void {{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}Handler<AsyncResult<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}>> resultHandler) {
public void {{operationId}}({{#parameters}}{{{dataType}}} {{paramName}}, {{/parameters}}Handler<AsyncResult<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}>> resultHandler) {
Object {{localVariablePrefix}}localVarBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
{{#allParams}}{{#required}}
{{#parameters}}{{#required}}
// verify the required parameter '{{paramName}}' is set
if ({{paramName}} == null) {
resultHandler.handle(ApiException.fail(400, "Missing the required parameter '{{paramName}}' when calling {{operationId}}"));
return;
}
{{/required}}{{/allParams}}
{{/required}}{{/parameters}}
// create path and map variables
String {{localVariablePrefix}}localVarPath = "{{{path}}}"{{#pathParams}}.replaceAll("\\{" + "{{baseName}}" + "\\}", {{{paramName}}}.toString()){{/pathParams}};

Expand Down Expand Up @@ -86,6 +87,7 @@ public class {{classname}}Impl implements {{classname}} {
{{localVariablePrefix}}apiClient.invokeAPI({{localVariablePrefix}}localVarPath, "{{httpMethod}}", {{localVariablePrefix}}localVarQueryParams, {{localVariablePrefix}}localVarBody, {{localVariablePrefix}}localVarHeaderParams, {{localVariablePrefix}}localVarFormParams, {{localVariablePrefix}}localVarAccepts, {{localVariablePrefix}}localVarContentTypes, {{localVariablePrefix}}localVarAuthNames, {{localVariablePrefix}}localVarReturnType, resultHandler);{{/returnType}}{{^returnType}}
{{localVariablePrefix}}apiClient.invokeAPI({{localVariablePrefix}}localVarPath, "{{httpMethod}}", {{localVariablePrefix}}localVarQueryParams, {{localVariablePrefix}}localVarBody, {{localVariablePrefix}}localVarHeaderParams, {{localVariablePrefix}}localVarFormParams, {{localVariablePrefix}}localVarAccepts, {{localVariablePrefix}}localVarContentTypes, {{localVariablePrefix}}localVarAuthNames, null, resultHandler);{{/returnType}}
}
{{/contents}}
{{/operation}}
}
{{/operations}}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class {{classname}}Test {
api = new {{classname}}Impl();
}
{{#operations}}{{#operation}}
{{#operations}}{{#operation}}{{#contents}}{{#@first}}
/**
* {{summary}}
* {{notes}}
Expand All @@ -58,13 +58,13 @@ public class {{classname}}Test {
@Test
public void {{operationId}}Test(TestContext context) {
Async async = context.async();
{{#allParams}}
{{#parameters}}
{{{dataType}}} {{paramName}} = null;
{{/allParams}}
api.{{operationId}}({{#allParams}}{{paramName}}, {{/allParams}}result -> {
{{/parameters}}
api.{{operationId}}({{#parameters}}{{paramName}}, {{/parameters}}result -> {
// TODO: test validations
async.complete();
});
}
{{/operation}}{{/operations}}
{{/@first}}{{/contents}}{{/operation}}{{/operations}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,33 @@ public class {{classname}} {
}

{{#operation}}
{{#contents}}
/**
* {{summary}}
* {{notes}}
{{#allParams}}
{{#parameters}}
* @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/allParams}}
{{/parameters}}
* @param resultHandler Asynchronous result handler
*/
public void {{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}Handler<AsyncResult<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}>> resultHandler) {
delegate.{{operationId}}({{#allParams}}{{paramName}}, {{/allParams}}resultHandler);
public void {{operationId}}({{#parameters}}{{{dataType}}} {{paramName}}, {{/parameters}}Handler<AsyncResult<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}>> resultHandler) {
delegate.{{operationId}}({{#parameters}}{{paramName}}, {{/parameters}}resultHandler);
}

/**
* {{summary}}
* {{notes}}
{{#allParams}}
{{#parameters}}
* @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/allParams}}
{{/parameters}}
* @return Asynchronous result handler (RxJava Single)
*/
public Single<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> rx{{operationIdCamelCase}}({{#allParams}}{{{dataType}}} {{paramName}}{{#has this 'more'}}, {{/has}}{{/allParams}}) {
public Single<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> rx{{operationIdCamelCase}}({{#parameters}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}}) {
return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
delegate.{{operationId}}({{#allParams}}{{paramName}}, {{/allParams}}fut);
delegate.{{operationId}}({{#parameters}}{{paramName}}, {{/parameters}}fut);
}));
}
{{/contents}}
{{/operation}}

public static {{classname}} newInstance({{package}}.{{classname}} arg) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/handlebars/JavaInflector/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ public class {{classname}} {
**/
{{#operation}}
{{#contents}}
/*
public ResponseContext {{operationId}}(RequestContext request {{#allParams}}, {{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{/allParams}}) {
public ResponseContext {{operationId}}(RequestContext request {{#parameters}}, {{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{/parameters}}) {
return new ResponseContext().status(Status.INTERNAL_SERVER_ERROR).entity( "Not implemented" );
}
*/

{{/contents}}
{{/operation}}
}
{{/operations}}
Expand Down
Loading

0 comments on commit dc36568

Please sign in to comment.