forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate interfaces for APIs (as well as impl classes); misc. other i…
…mprovements (OpenAPITools#51)
- Loading branch information
Showing
11 changed files
with
532 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...penapi-generator/src/main/resources/java-helidon/client/libraries/se/ApiResponse.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{{>licenseInfo}} | ||
package {{invokerPackage}}; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
|
||
import io.helidon.common.GenericType; | ||
import io.helidon.common.reactive.Single; | ||
import io.helidon.webclient.WebClientResponse; | ||
|
||
{{#appName}} | ||
/** | ||
* Generic-typed response. | ||
* | ||
* Return type for generated API methods. | ||
* | ||
* @param <T> type of the return value from the generated API method | ||
*/ | ||
{{/appName}} | ||
public interface ApiResponse<T> { | ||
static <T> ApiResponse<T> create(GenericType<T> responseType, Single<WebClientResponse> webClientResponse) { | ||
return new ApiResponseBase<>(responseType, webClientResponse); | ||
} | ||
|
||
/** | ||
* @returns reactive access to the {@link WebClientResponse} describing the response from the server | ||
*/ | ||
Single<WebClientResponse> webClientResponse(); | ||
|
||
/** | ||
* @return reactive access to the value returned in the response from the server | ||
*/ | ||
Single<T> result() throws ExecutionException, InterruptedException; | ||
} |
36 changes: 36 additions & 0 deletions
36
...pi-generator/src/main/resources/java-helidon/client/libraries/se/ApiResponseBase.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{{>licenseInfo}} | ||
package {{invokerPackage}}; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
|
||
import io.helidon.common.GenericType; | ||
import io.helidon.common.reactive.Single; | ||
import io.helidon.webclient.WebClientResponse; | ||
|
||
{{#appName}} | ||
/** | ||
* Implementation of a generic-typed response. | ||
* | ||
* @param <T> type of the return value from the generated API method | ||
*/ | ||
{{/appName}} | ||
class ApiResponseBase<T> implements ApiResponse<T> { | ||
private final Single<WebClientResponse> webClientResponse; | ||
private final GenericType<T> responseType; | ||
protected ApiResponseBase(GenericType<T> responseType, Single<WebClientResponse> webClientResponse) { | ||
this.webClientResponse = webClientResponse; | ||
this.responseType = responseType; | ||
} | ||
|
||
@Override | ||
public Single<WebClientResponse> webClientResponse() { | ||
return webClientResponse; | ||
} | ||
|
||
@Override | ||
public Single<T> result() throws ExecutionException, InterruptedException { | ||
return webClientResponse.get().content().as(responseType); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...les/openapi-generator/src/main/resources/java-helidon/client/libraries/se/README.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# {{appName}} | ||
|
||
{{#appDescriptionWithNewLines}} | ||
{{{.}}} | ||
|
||
{{/appDescriptionWithNewLines}} | ||
|
||
## Overview | ||
This project was generated using the Helidon OpenAPI Generator. | ||
|
||
The generated classes use the programming model from the Helidon WebClient implementation, primarily the `WebClient` interface and its | ||
`WebClient.Builder` class. Refer to the Helidon WebClient documentation for complete information about them. | ||
|
||
## Using the Generated Classes and Interfaces | ||
The generated `ApiClient` class wraps a `WebClient` instance. Similarly, the `ApiClient.Builder` class wraps the `WebClient.Builder` class. | ||
|
||
The generated `xxxApi` interfaces and `xxxApiImpl` classes make it very simple for your code to send requests (with input parameters) to the remote service which the OpenAPI document describes and to process the response (with output values) from the remote service. | ||
|
||
To use the generated API, your code performs the following steps. | ||
|
||
1. Create an instance of the `ApiClient` using its `Builder`. | ||
2. Create an instance of a `xxxApi` it wants to access, typically by invoking `xxxApiImpl.create(ApiClient)` and passing the `ApiClient` instance just created. | ||
3. Invoke any of the `public` methods on the `xxxApi` instance, passing the input parameters and saving the returned `Single<WebClientResponse>` object. | ||
4. Invoke methods on the returned `Single<WebClientResponse>` to process the response and any output from it. | ||
|
||
Browse the methods and JavaDoc on the generated classes for more information. |
32 changes: 32 additions & 0 deletions
32
...enapi-generator/src/main/resources/java-helidon/client/libraries/se/ResponseType.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{{>licenseInfo}} | ||
package {{apiPackage}}; | ||
|
||
import java.lang.reflect.ParameterizedType; | ||
import java.lang.reflect.Type; | ||
|
||
import io.helidon.common.GenericType; | ||
|
||
class ResponseType<T> { | ||
static <T> GenericType<T> create(Type rawType, Type... typeParams) { | ||
return typeParams.length == 0 | ||
? GenericType.create(rawType) | ||
: GenericType.create(new ParameterizedType() { | ||
@Override | ||
public Type[] getActualTypeArguments() { | ||
return typeParams; | ||
} | ||
|
||
@Override | ||
public Type getRawType() { | ||
return rawType; | ||
} | ||
|
||
@Override | ||
public Type getOwnerType() { | ||
return null; | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.