generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 21
feat: [OpenAPI] Part 2: Testing Apache Client Support and some fixes. #1062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rpanackal
wants to merge
12
commits into
feat/openapi/refactor-apache-templates
Choose a base branch
from
feat/openapi/test-apache-client-templates
base: feat/openapi/refactor-apache-templates
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f16b2c9
Generate and test sodastore and petstore
rpanackal c56376c
Merge branch 'feat/openapi/refactor-apache-templates' into feat/opena…
rpanackal 0773674
Extending existing integration test
rpanackal 943de3c
Complete and cleanup integration test
rpanackal cc08bfb
Make url building more forgiving
rpanackal bdc8c72
Almost @Value class but not final
rpanackal 3387432
Remove as much unnecessary integration test files
rpanackal 64c7bdd
Add unit testing for Apache components
rpanackal 8257a9a
Add unit testing for Apache components
rpanackal 45e4dbc
Merge remote-tracking branch 'origin/feat/openapi/test-apache-client-…
rpanackal 41ef22f
Add unit test for query params, client factory config and objectmappe…
rpanackal 9f00a54
Merge branch 'feat/openapi/refactor-apache-templates' into feat/opena…
rpanackal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
333 changes: 333 additions & 0 deletions
333
...ple/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/petstore/api/DefaultApi.java
This file contains hidden or 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,333 @@ | ||
| /* | ||
| * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. | ||
| */ | ||
|
|
||
| package com.sap.cloud.sdk.datamodel.openapi.apache.petstore.api; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.StringJoiner; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| import com.fasterxml.jackson.core.type.TypeReference; | ||
| import com.sap.cloud.sdk.cloudplatform.connectivity.Destination; | ||
| import com.sap.cloud.sdk.datamodel.openapi.apache.petstore.model.Pet; | ||
| import com.sap.cloud.sdk.datamodel.openapi.apache.petstore.model.PetInput; | ||
| import com.sap.cloud.sdk.services.openapi.apache.ApiClient; | ||
| import com.sap.cloud.sdk.services.openapi.apache.BaseApi; | ||
| import com.sap.cloud.sdk.services.openapi.apache.OpenApiResponse; | ||
| import com.sap.cloud.sdk.services.openapi.apache.Pair; | ||
| import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; | ||
|
|
||
| /** | ||
| * Swagger Petstore in version 1.0.0. | ||
| * | ||
| * A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification | ||
| */ | ||
| public class DefaultApi extends BaseApi | ||
| { | ||
|
|
||
| /** | ||
| * Instantiates this API class to invoke operations on the Swagger Petstore | ||
| */ | ||
| public DefaultApi() | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Instantiates this API class to invoke operations on the Swagger Petstore. | ||
| * | ||
| * @param httpDestination | ||
| * The destination that API should be used with | ||
| */ | ||
| public DefaultApi( @Nonnull final Destination httpDestination ) | ||
| { | ||
| super(httpDestination); | ||
| } | ||
|
|
||
| /** | ||
| * Instantiates this API class to invoke operations on the Swagger Petstore based on a given {@link ApiClient}. | ||
| * | ||
| * @param apiClient | ||
| * ApiClient to invoke the API on | ||
| */ | ||
| public DefaultApi( @Nonnull final ApiClient apiClient ) | ||
| { | ||
| super(apiClient); | ||
| } | ||
|
|
||
| /** | ||
| * <p> | ||
| * <p> | ||
| * Creates a new pet in the store. Duplicates are allowed | ||
| * <p> | ||
| * <b>200</b> - pet response | ||
| * <p> | ||
| * <b>0</b> - unexpected error | ||
| * | ||
| * @param pet | ||
| * Pet to add to the store | ||
| * @return Pet | ||
| * @throws OpenApiRequestException | ||
| * if an error occurs while attempting to invoke the API | ||
| */ | ||
| @Nonnull | ||
| public Pet addPet( @Nonnull final PetInput pet ) | ||
| throws OpenApiRequestException | ||
| { | ||
| final Object localVarPostBody = pet; | ||
|
|
||
| // verify the required parameter 'pet' is set | ||
| if( pet == null ) { | ||
| throw new OpenApiRequestException("Missing the required parameter 'pet' when calling addPet") | ||
| .statusCode(400); | ||
| } | ||
|
|
||
| // create path and map variables | ||
| final String localVarPath = "/pets"; | ||
|
|
||
| final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); | ||
| String localVarQueryParameterBaseName; | ||
| final List<Pair> localVarQueryParams = new ArrayList<Pair>(); | ||
| final List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>(); | ||
| final Map<String, String> localVarHeaderParams = new HashMap<String, String>(); | ||
| final Map<String, Object> localVarFormParams = new HashMap<String, Object>(); | ||
|
|
||
| final String[] localVarAccepts = { "application/json" }; | ||
| final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); | ||
| final String[] localVarContentTypes = { "application/json" }; | ||
| final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); | ||
|
|
||
| final TypeReference<Pet> localVarReturnType = new TypeReference<Pet>() | ||
| { | ||
| }; | ||
|
|
||
| return apiClient | ||
| .invokeAPI( | ||
| localVarPath, | ||
| "POST", | ||
| localVarQueryParams, | ||
| localVarCollectionQueryParams, | ||
| localVarQueryStringJoiner.toString(), | ||
| localVarPostBody, | ||
| localVarHeaderParams, | ||
| localVarFormParams, | ||
| localVarAccept, | ||
| localVarContentType, | ||
| localVarReturnType); | ||
| } | ||
|
|
||
| /** | ||
| * <p> | ||
| * <p> | ||
| * deletes a single pet based on the ID supplied | ||
| * <p> | ||
| * <b>204</b> - pet deleted | ||
| * <p> | ||
| * <b>0</b> - unexpected error | ||
| * | ||
| * @param id | ||
| * ID of pet to delete | ||
| * @return An OpenApiResponse containing the status code of the HttpResponse. | ||
| * @throws OpenApiRequestException | ||
| * if an error occurs while attempting to invoke the API | ||
| */ | ||
| @Nonnull | ||
| public OpenApiResponse deletePet( @Nonnull final Long id ) | ||
| throws OpenApiRequestException | ||
| { | ||
| final Object localVarPostBody = null; | ||
|
|
||
| // verify the required parameter 'id' is set | ||
| if( id == null ) { | ||
| throw new OpenApiRequestException("Missing the required parameter 'id' when calling deletePet") | ||
| .statusCode(400); | ||
| } | ||
|
|
||
| // create path and map variables | ||
| final String localVarPath = | ||
| "/pets/{id}".replaceAll("\\{" + "id" + "\\}", ApiClient.escapeString(ApiClient.parameterToString(id))); | ||
|
|
||
| final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); | ||
| String localVarQueryParameterBaseName; | ||
| final List<Pair> localVarQueryParams = new ArrayList<Pair>(); | ||
| final List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>(); | ||
| final Map<String, String> localVarHeaderParams = new HashMap<String, String>(); | ||
| final Map<String, Object> localVarFormParams = new HashMap<String, Object>(); | ||
|
|
||
| final String[] localVarAccepts = { "application/json" }; | ||
| final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); | ||
| final String[] localVarContentTypes = { | ||
|
|
||
| }; | ||
| final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); | ||
|
|
||
| final TypeReference<OpenApiResponse> localVarReturnType = new TypeReference<OpenApiResponse>() | ||
| { | ||
| }; | ||
|
|
||
| return apiClient | ||
| .invokeAPI( | ||
| localVarPath, | ||
| "DELETE", | ||
| localVarQueryParams, | ||
| localVarCollectionQueryParams, | ||
| localVarQueryStringJoiner.toString(), | ||
| localVarPostBody, | ||
| localVarHeaderParams, | ||
| localVarFormParams, | ||
| localVarAccept, | ||
| localVarContentType, | ||
| localVarReturnType); | ||
| } | ||
|
|
||
| /** | ||
| * <p> | ||
| * <p> | ||
| * Returns a user based on a single ID, if the user does not have access to the pet | ||
| * <p> | ||
| * <b>200</b> - pet response | ||
| * <p> | ||
| * <b>0</b> - unexpected error | ||
| * | ||
| * @param id | ||
| * ID of pet to fetch | ||
| * @return Pet | ||
| * @throws OpenApiRequestException | ||
| * if an error occurs while attempting to invoke the API | ||
| */ | ||
| @Nonnull | ||
| public Pet findPetById( @Nonnull final Long id ) | ||
| throws OpenApiRequestException | ||
| { | ||
| final Object localVarPostBody = null; | ||
|
|
||
| // verify the required parameter 'id' is set | ||
| if( id == null ) { | ||
| throw new OpenApiRequestException("Missing the required parameter 'id' when calling findPetById") | ||
| .statusCode(400); | ||
| } | ||
|
|
||
| // create path and map variables | ||
| final String localVarPath = | ||
| "/pets/{id}".replaceAll("\\{" + "id" + "\\}", ApiClient.escapeString(ApiClient.parameterToString(id))); | ||
|
|
||
| final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); | ||
| String localVarQueryParameterBaseName; | ||
| final List<Pair> localVarQueryParams = new ArrayList<Pair>(); | ||
| final List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>(); | ||
| final Map<String, String> localVarHeaderParams = new HashMap<String, String>(); | ||
| final Map<String, Object> localVarFormParams = new HashMap<String, Object>(); | ||
|
|
||
| final String[] localVarAccepts = { "application/json", "application/xml", "text/xml", "text/html" }; | ||
| final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); | ||
| final String[] localVarContentTypes = { | ||
|
|
||
| }; | ||
| final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); | ||
|
|
||
| final TypeReference<Pet> localVarReturnType = new TypeReference<Pet>() | ||
| { | ||
| }; | ||
|
|
||
| return apiClient | ||
| .invokeAPI( | ||
| localVarPath, | ||
| "GET", | ||
| localVarQueryParams, | ||
| localVarCollectionQueryParams, | ||
| localVarQueryStringJoiner.toString(), | ||
| localVarPostBody, | ||
| localVarHeaderParams, | ||
| localVarFormParams, | ||
| localVarAccept, | ||
| localVarContentType, | ||
| localVarReturnType); | ||
| } | ||
|
|
||
| /** | ||
| * <p> | ||
| * <p> | ||
| * Returns all pets from the system that the user has access to | ||
| * <p> | ||
| * <b>200</b> - pet response | ||
| * <p> | ||
| * <b>0</b> - unexpected error | ||
| * | ||
| * @param tags | ||
| * (optional) tags to filter by | ||
| * @param limit | ||
| * (optional) maximum number of results to return | ||
| * @return List<Pet> | ||
| * @throws OpenApiRequestException | ||
| * if an error occurs while attempting to invoke the API | ||
| */ | ||
| @Nonnull | ||
| public List<Pet> findPets( @Nullable final List<String> tags, @Nullable final Integer limit ) | ||
| throws OpenApiRequestException | ||
| { | ||
| final Object localVarPostBody = null; | ||
|
|
||
| // create path and map variables | ||
| final String localVarPath = "/pets"; | ||
|
|
||
| final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); | ||
| String localVarQueryParameterBaseName; | ||
| final List<Pair> localVarQueryParams = new ArrayList<Pair>(); | ||
| final List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>(); | ||
| final Map<String, String> localVarHeaderParams = new HashMap<String, String>(); | ||
| final Map<String, Object> localVarFormParams = new HashMap<String, Object>(); | ||
|
|
||
| localVarCollectionQueryParams.addAll(ApiClient.parameterToPairs("csv", "tags", tags)); | ||
| localVarQueryParams.addAll(ApiClient.parameterToPair("limit", limit)); | ||
|
|
||
| final String[] localVarAccepts = { "application/json", "application/xml", "text/xml", "text/html" }; | ||
| final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); | ||
| final String[] localVarContentTypes = { | ||
|
|
||
| }; | ||
| final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); | ||
|
|
||
| final TypeReference<List<Pet>> localVarReturnType = new TypeReference<List<Pet>>() | ||
| { | ||
| }; | ||
|
|
||
| return apiClient | ||
| .invokeAPI( | ||
| localVarPath, | ||
| "GET", | ||
| localVarQueryParams, | ||
| localVarCollectionQueryParams, | ||
| localVarQueryStringJoiner.toString(), | ||
| localVarPostBody, | ||
| localVarHeaderParams, | ||
| localVarFormParams, | ||
| localVarAccept, | ||
| localVarContentType, | ||
| localVarReturnType); | ||
| } | ||
|
|
||
| /** | ||
| * <p> | ||
| * <p> | ||
| * Returns all pets from the system that the user has access to | ||
| * <p> | ||
| * <b>200</b> - pet response | ||
| * <p> | ||
| * <b>0</b> - unexpected error | ||
| * | ||
| * @return List<Pet> | ||
| * @throws OpenApiRequestException | ||
| * if an error occurs while attempting to invoke the API | ||
| */ | ||
| @Nonnull | ||
| public List<Pet> findPets() | ||
| throws OpenApiRequestException | ||
| { | ||
| return findPets(null, null); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
@Nonullannotaion is a lie. The same exists in Spring equivalent.I am assuming this was intentional to not force handling possible null value at the caller. Still, would like some confirmation.
To add some details,
invokeAPI()calls will return null when response body is empty or status is.204