-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Java][okhttp-gson] Add option to employ builders for API requests (#…
…1341) * Generate APIs that use the builder pattern * Add option to use builders for API requests * Fix template spacing * Add new sample-generation script and generated samples * Update docs * Add new sample-generation script for Windows * Replace config option with vendor extension * Remove useBuildersForApiRequests config option * Remove builders sample-generation scripts * Replace config option with vendor extension in api_test template * Remove okhttp-gson-requestBuilders sample * Rename x-builders-for-api-requests to x-group-parameters * Add modified api_doc.mustache under okhttp-gson resources * Add modified README.mustache under okhttp-gson resources * Update petstore samples * Fix FakeApiTest.java in petstore samples * Add whitespace to rerun checks * Remove whitespace to rerun tests * Fix FakeApiTest.java in parcelable petstore sample * Update versions in samples * Update versions in samples
- Loading branch information
1 parent
3efe567
commit 9df7079
Showing
11 changed files
with
641 additions
and
123 deletions.
There are no files selected for viewing
169 changes: 169 additions & 0 deletions
169
modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/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,169 @@ | ||
# {{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 [OpenAPI Generator](https://openapi-generator.tech)* | ||
|
||
|
||
## Requirements | ||
|
||
Building the API client library requires: | ||
1. Java {{#supportJava6}}1.6{{/supportJava6}}{{^supportJava6}}{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}{{/supportJava6}}+ | ||
2. Maven/Gradle | ||
|
||
## Installation | ||
|
||
To install the API client library to your local Maven repository, simply execute: | ||
|
||
```shell | ||
mvn clean install | ||
``` | ||
|
||
To deploy it to a remote Maven repository instead, configure the settings of the repository and execute: | ||
|
||
```shell | ||
mvn clean deploy | ||
``` | ||
|
||
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> | ||
</dependency> | ||
``` | ||
|
||
### Gradle users | ||
|
||
Add this dependency to your project's build file: | ||
|
||
```groovy | ||
compile "{{{groupId}}}:{{{artifactId}}}:{{{artifactVersion}}}" | ||
``` | ||
|
||
### Others | ||
|
||
At first generate the JAR by executing: | ||
|
||
```shell | ||
mvn clean package | ||
``` | ||
|
||
Then manually install the following JARs: | ||
|
||
* `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}} | ||
import {{{invokerPackage}}}.*; | ||
import {{{invokerPackage}}}.auth.*; | ||
import {{{modelPackage}}}.*; | ||
import {{{package}}}.{{{classname}}}; | ||
|
||
import java.io.File; | ||
import java.util.*; | ||
|
||
public class {{{classname}}}Example { | ||
public static void main(String[] args) { | ||
{{#hasAuthMethods}}ApiClient defaultClient = Configuration.getDefaultApiClient(); | ||
{{#authMethods}}{{#isBasic}} | ||
// Configure HTTP basic authorization: {{{name}}} | ||
HttpBasicAuth {{{name}}} = (HttpBasicAuth) defaultClient.getAuthentication("{{{name}}}"); | ||
{{{name}}}.setUsername("YOUR USERNAME"); | ||
{{{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");{{/isApiKey}}{{#isOAuth}} | ||
// Configure OAuth2 access token for authorization: {{{name}}} | ||
OAuth {{{name}}} = (OAuth) defaultClient.getAuthentication("{{{name}}}"); | ||
{{{name}}}.setAccessToken("YOUR ACCESS TOKEN");{{/isOAuth}} | ||
{{/authMethods}} | ||
{{/hasAuthMethods}} | ||
|
||
{{{classname}}} apiInstance = new {{{classname}}}(); | ||
{{#allParams}} | ||
{{{dataType}}} {{{paramName}}} = {{{example}}}; // {{{dataType}}} | {{{description}}} | ||
{{/allParams}} | ||
try { | ||
{{#returnType}}{{{returnType}}} result = {{/returnType}}apiInstance.{{{operationId}}}{{^vendorExtensions.x-group-parameters}}({{#allParams}}{{{paramName}}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}({{#requiredParams}}{{{paramName}}}{{#hasMore}}, {{/hasMore}}{{/requiredParams}}){{#optionalParams}} | ||
.{{{paramName}}}({{{paramName}}}){{/optionalParams}} | ||
.execute();{{/vendorExtensions.x-group-parameters}}{{#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}} | ||
``` | ||
|
||
## Documentation for API Endpoints | ||
|
||
All URIs are relative to *{{basePath}}* | ||
|
||
Class | Method | HTTP request | Description | ||
------------ | ------------- | ------------- | ------------- | ||
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}} | ||
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} | ||
|
||
## Documentation for Models | ||
|
||
{{#models}}{{#model}} - [{{classname}}]({{modelDocPath}}{{classname}}.md) | ||
{{/model}}{{/models}} | ||
|
||
## Documentation for Authorization | ||
|
||
{{^authMethods}}All endpoints do not require authorization. | ||
{{/authMethods}}Authentication schemes defined for the API: | ||
{{#authMethods}}### {{name}} | ||
|
||
{{#isApiKey}}- **Type**: API key | ||
- **API key parameter name**: {{keyParamName}} | ||
- **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}} | ||
{{/isOAuth}} | ||
|
||
{{/authMethods}} | ||
|
||
## Recommendation | ||
|
||
It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues. | ||
|
||
## Author | ||
|
||
{{#apiInfo}}{{#apis}}{{^hasMore}}{{infoEmail}} | ||
{{/hasMore}}{{/apis}}{{/apiInfo}} |
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
Oops, something went wrong.