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.
Java API invocation flexibility (OpenAPITools#18078)
* add direct invocation methods for java (httpclient) * add direct invocation methods for java (resttemplate) * handle methods only if endpoints exist for api client * preserve previous newline to minimize changes * update httpclient/resttemplate samples * add common methods in base class * regenerate samples with base class
- Loading branch information
Showing
70 changed files
with
2,500 additions
and
590 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
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
110 changes: 110 additions & 0 deletions
110
...es/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/BaseApi.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,110 @@ | ||
{{>licenseInfo}} | ||
package {{invokerPackage}}; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
{{>generatedAnnotation}} | ||
public abstract class BaseApi { | ||
protected ApiClient apiClient; | ||
public BaseApi() { | ||
this(Configuration.getDefaultApiClient()); | ||
} | ||
|
||
public BaseApi(ApiClient apiClient) { | ||
this.apiClient = apiClient; | ||
} | ||
|
||
public ApiClient getApiClient() { | ||
return apiClient; | ||
} | ||
|
||
public void setApiClient(ApiClient apiClient) { | ||
this.apiClient = apiClient; | ||
} | ||
|
||
/** | ||
* Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests. | ||
* @param url The URL for the request, either full URL or only the path. | ||
* @param method The HTTP method for the request. | ||
* @throws ApiException if fails to make API call. | ||
*/ | ||
public void invokeAPI(String url, String method) throws ApiException { | ||
invokeAPI(url, method, null, null, Collections.emptyMap()); | ||
} | ||
|
||
/** | ||
* Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests. | ||
* @param url The URL for the request, either full URL or only the path. | ||
* @param method The HTTP method for the request. | ||
* @param additionalHeaders Additional headers for the request. | ||
* @throws ApiException if fails to make API call. | ||
*/ | ||
public void invokeAPI(String url, String method, Map<String, String> additionalHeaders) throws ApiException { | ||
invokeAPI(url, method, null, null, additionalHeaders); | ||
} | ||
|
||
/** | ||
* Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests. | ||
* @param url The URL for the request, either full URL or only the path. | ||
* @param method The HTTP method for the request. | ||
* @param request The request object. | ||
* @throws ApiException if fails to make API call. | ||
*/ | ||
public void invokeAPI(String url, String method, Object request) throws ApiException { | ||
invokeAPI(url, method, request, null, Collections.emptyMap()); | ||
} | ||
|
||
/** | ||
* Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests. | ||
* @param url The URL for the request, either full URL or only the path. | ||
* @param method The HTTP method for the request. | ||
* @param request The request object. | ||
* @param additionalHeaders Additional headers for the request. | ||
* @throws ApiException if fails to make API call. | ||
*/ | ||
public void invokeAPI(String url, String method, Object request, Map<String, String> additionalHeaders) throws ApiException { | ||
invokeAPI(url, method, request, null, additionalHeaders); | ||
} | ||
|
||
/** | ||
* Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests. | ||
* @param url The URL for the request, either full URL or only the path. | ||
* @param method The HTTP method for the request. | ||
* @param returnType The return type. | ||
* @return The API response in the specified type. | ||
* @throws ApiException if fails to make API call. | ||
*/ | ||
public <T> T invokeAPI(String url, String method, TypeReference<T> returnType) throws ApiException { | ||
return invokeAPI(url, method, null, returnType, Collections.emptyMap()); | ||
} | ||
|
||
/** | ||
* Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests. | ||
* @param url The URL for the request, either full URL or only the path. | ||
* @param method The HTTP method for the request. | ||
* @param request The request object. | ||
* @param returnType The return type. | ||
* @return The API response in the specified type. | ||
* @throws ApiException if fails to make API call. | ||
*/ | ||
public <T> T invokeAPI(String url, String method, Object request, TypeReference<T> returnType) throws ApiException { | ||
return invokeAPI(url, method, request, returnType, Collections.emptyMap()); | ||
} | ||
|
||
/** | ||
* Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests. | ||
* @param url The URL for the request, either full URL or only the path. | ||
* @param method The HTTP method for the request. | ||
* @param request The request object. | ||
* @param returnType The return type. | ||
* @param additionalHeaders Additional headers for the request. | ||
* @return The API response in the specified type. | ||
* @throws ApiException if fails to make API call. | ||
*/ | ||
public abstract <T> T invokeAPI(String url, String method, Object request, TypeReference<T> returnType, Map<String, String> additionalHeaders) throws ApiException; | ||
} |
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
74 changes: 74 additions & 0 deletions
74
modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/BaseApi.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,74 @@ | ||
package {{invokerPackage}}; | ||
|
||
import org.springframework.web.client.RestClientException; | ||
import org.springframework.core.ParameterizedTypeReference; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
{{>generatedAnnotation}} | ||
public abstract class BaseApi { | ||
protected ApiClient apiClient; | ||
public BaseApi() { | ||
this(new ApiClient()); | ||
} | ||
|
||
public BaseApi(ApiClient apiClient) { | ||
this.apiClient = apiClient; | ||
} | ||
|
||
public ApiClient getApiClient() { | ||
return apiClient; | ||
} | ||
|
||
public void setApiClient(ApiClient apiClient) { | ||
this.apiClient = apiClient; | ||
} | ||
|
||
/** | ||
* Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests. | ||
* @param url The URL for the request, either full URL or only the path. | ||
* @param method The HTTP method for the request. | ||
* @return ResponseEntity<Void> | ||
* @throws RestClientException if an error occurs while attempting to invoke the API | ||
*/ | ||
public ResponseEntity<Void> invokeAPI(String url, HttpMethod method) throws RestClientException { | ||
return invokeAPI(url, method, null, new ParameterizedTypeReference<Void>() {}); | ||
} | ||
|
||
/** | ||
* Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests. | ||
* @param url The URL for the request, either full URL or only the path. | ||
* @param method The HTTP method for the request. | ||
* @param request The request object. | ||
* @return ResponseEntity<Void> | ||
* @throws RestClientException if an error occurs while attempting to invoke the API | ||
*/ | ||
public ResponseEntity<Void> invokeAPI(String url, HttpMethod method, Object request) throws RestClientException { | ||
return invokeAPI(url, method, request, new ParameterizedTypeReference<Void>() {}); | ||
} | ||
|
||
/** | ||
* Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests. | ||
* @param url The URL for the request, either full URL or only the path. | ||
* @param method The HTTP method for the request. | ||
* @param returnType The return type. | ||
* @return ResponseEntity in the specified type. | ||
* @throws RestClientException if an error occurs while attempting to invoke the API | ||
*/ | ||
public <T> ResponseEntity<T> invokeAPI(String url, HttpMethod method, ParameterizedTypeReference<T> returnType) throws RestClientException { | ||
return invokeAPI(url, method, null, returnType); | ||
} | ||
|
||
/** | ||
* Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests. | ||
* @param url The URL for the request, either full URL or only the path. | ||
* @param method The HTTP method for the request. | ||
* @param request The request object. | ||
* @param returnType The return type. | ||
* @return ResponseEntity in the specified type. | ||
* @throws RestClientException if an error occurs while attempting to invoke the API | ||
*/ | ||
public abstract <T> ResponseEntity<T> invokeAPI(String url, HttpMethod method, Object request, ParameterizedTypeReference<T> returnType) throws RestClientException; | ||
} |
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.