Skip to content

Commit 1c0bef8

Browse files
authored
refactor: [OpenAPI] Part 1: Refactor Apache related files and templates (#1048)
1 parent 50a0e0f commit 1c0bef8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+960
-2318
lines changed

datamodel/openapi/openapi-api-apache-sample/pom.xml

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,36 @@
88
<artifactId>openapi-parent</artifactId>
99
<version>5.26.0-SNAPSHOT</version>
1010
</parent>
11-
1211
<artifactId>openapi-api-apache-sample</artifactId>
13-
14-
<properties>
15-
<maven.compiler.source>22</maven.compiler.source>
16-
<maven.compiler.target>22</maven.compiler.target>
17-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18-
</properties>
19-
12+
<name>Data Model - OpenAPI Services - Sample API</name>
13+
<description>Sample generated API classes of the OpenAPI VDM</description>
14+
<url>https://sap.github.io/cloud-sdk/docs/java/getting-started</url>
15+
<organization>
16+
<name>SAP SE</name>
17+
<url>https://www.sap.com</url>
18+
</organization>
19+
<licenses>
20+
<license>
21+
<name>The Apache Software License, Version 2.0</name>
22+
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
23+
</license>
24+
</licenses>
25+
<developers>
26+
<developer>
27+
<name>SAP</name>
28+
<email>[email protected]</email>
29+
<organization>SAP SE</organization>
30+
<organizationUrl>https://www.sap.com</organizationUrl>
31+
</developer>
32+
</developers>
2033
<dependencies>
2134
<dependency>
2235
<groupId>com.sap.cloud.sdk.datamodel</groupId>
2336
<artifactId>openapi-core</artifactId>
2437
</dependency>
2538
<dependency>
26-
<groupId>com.google.guava</groupId>
27-
<artifactId>guava</artifactId>
39+
<groupId>com.sap.cloud.sdk.cloudplatform</groupId>
40+
<artifactId>cloudplatform-connectivity</artifactId>
2841
</dependency>
2942
<dependency>
3043
<groupId>com.fasterxml.jackson.core</groupId>
@@ -41,13 +54,25 @@
4154
<groupId>com.sap.cloud.sdk.datamodel</groupId>
4255
<artifactId>openapi-generator-maven-plugin</artifactId>
4356
<configuration>
57+
<apiMaturity>released</apiMaturity>
4458
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
45-
<enableOneOfAnyOfGeneration>true</enableOneOfAnyOfGeneration>
4659
<deleteOutputDirectory>true</deleteOutputDirectory>
4760
</configuration>
4861
<executions>
4962
<execution>
50-
<id>sample-generation</id>
63+
<id>sample-apache-swagger-v2</id>
64+
<phase>generate-sources</phase>
65+
<goals>
66+
<goal>generate</goal>
67+
</goals>
68+
<configuration>
69+
<inputSpec>${project.basedir}/src/main/resources/petstore-swagger2.json</inputSpec>
70+
<apiPackage>com.sap.cloud.sdk.datamodel.openapi.petstore.api</apiPackage>
71+
<modelPackage>com.sap.cloud.sdk.datamodel.openapi.petstore.model</modelPackage>
72+
</configuration>
73+
</execution>
74+
<execution>
75+
<id>sample-apache-openapi-v3</id>
5176
<goals>
5277
<goal>generate</goal>
5378
</goals>
@@ -57,19 +82,17 @@
5782
<apiPackage>com.sap.cloud.sdk.datamodel.openapi.apache.sample.api</apiPackage>
5883
<modelPackage>com.sap.cloud.sdk.datamodel.openapi.apache.sample.model</modelPackage>
5984
<additionalProperties>
60-
<supportingFiles>true</supportingFiles>
61-
<invokerPackage>com.sap.cloud.sdk.services.openapi.apache</invokerPackage>
6285
<library>apache-httpclient</library>
6386
<supportUrlQuery>false</supportUrlQuery>
64-
<useOneOfInterfaces>true</useOneOfInterfaces>
65-
<enumUnknownDefaultCase>true</enumUnknownDefaultCase>
66-
<removeOperationIdPrefix>true</removeOperationIdPrefix>
67-
<removeOperationIdPrefixDelimiter>\.</removeOperationIdPrefixDelimiter>
68-
<removeOperationIdPrefixCount>3</removeOperationIdPrefixCount>
69-
<!-- Custom Cloud SDK settings -->
87+
<pojoBuilderMethodName>create</pojoBuilderMethodName>
7088
<pojoConstructorVisibility>protected</pojoConstructorVisibility>
89+
<useOneOfInterfaces>true</useOneOfInterfaces>
7190
<useOneOfCreators>true</useOneOfCreators>
91+
<enumUnknownDefaultCase>true</enumUnknownDefaultCase>
92+
<useFloatArrays>true</useFloatArrays>
7293
</additionalProperties>
94+
<sapCopyrightHeader>true</sapCopyrightHeader>
95+
<enableOneOfAnyOfGeneration>true</enableOneOfAnyOfGeneration>
7396
</configuration>
7497
</execution>
7598
</executions>
Lines changed: 49 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,104 @@
11
/*
2-
* SodaStore API
3-
* API for managing soda products and orders in SodaStore.
4-
*
5-
*
6-
*
7-
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
8-
* https://openapi-generator.tech
9-
* Do not edit the class manually.
10-
*/
2+
* Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved.
3+
*/
114

125
package com.sap.cloud.sdk.datamodel.openapi.apache.sample.api;
136

147
import java.util.ArrayList;
15-
import java.util.Collections;
168
import java.util.HashMap;
179
import java.util.List;
1810
import java.util.Map;
1911
import java.util.StringJoiner;
2012

13+
import javax.annotation.Nonnull;
14+
2115
import com.fasterxml.jackson.core.type.TypeReference;
16+
import com.sap.cloud.sdk.cloudplatform.connectivity.Destination;
2217
import com.sap.cloud.sdk.datamodel.openapi.apache.sample.model.Order;
2318
import com.sap.cloud.sdk.services.openapi.apache.ApiClient;
24-
import com.sap.cloud.sdk.services.openapi.apache.ApiException;
2519
import com.sap.cloud.sdk.services.openapi.apache.BaseApi;
26-
import com.sap.cloud.sdk.services.openapi.apache.Configuration;
2720
import com.sap.cloud.sdk.services.openapi.apache.Pair;
21+
import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException;
2822

23+
/**
24+
* SodaStore API in version 1.0.0.
25+
*
26+
* API for managing soda products and orders in SodaStore.
27+
*/
2928
public class OrdersApi extends BaseApi
3029
{
3130

31+
/**
32+
* Instantiates this API class to invoke operations on the SodaStore API
33+
*/
3234
public OrdersApi()
3335
{
34-
super(Configuration.getDefaultApiClient());
3536
}
3637

37-
public OrdersApi( ApiClient apiClient )
38+
/**
39+
* Instantiates this API class to invoke operations on the SodaStore API.
40+
*
41+
* @param httpDestination
42+
* The destination that API should be used with
43+
*/
44+
public OrdersApi( @Nonnull final Destination httpDestination )
3845
{
39-
super(apiClient);
46+
super(httpDestination);
4047
}
4148

4249
/**
43-
* Create a new order
50+
* Instantiates this API class to invoke operations on the SodaStore API based on a given {@link ApiClient}.
4451
*
45-
* @param order
46-
* The order details (required)
47-
* @return Order
48-
* @throws ApiException
49-
* if fails to make API call
52+
* @param apiClient
53+
* ApiClient to invoke the API on
5054
*/
51-
public Order ordersPost( @javax.annotation.Nonnull Order order )
52-
throws ApiException
55+
public OrdersApi( @Nonnull final ApiClient apiClient )
5356
{
54-
return this.ordersPost(order, Collections.emptyMap());
57+
super(apiClient);
5558
}
5659

5760
/**
61+
* <p>
5862
* Create a new order
63+
* <p>
64+
* <p>
65+
* <b>201</b> - The created order
5966
*
6067
* @param order
61-
* The order details (required)
62-
* @param additionalHeaders
63-
* additionalHeaders for this call
68+
* The order details
6469
* @return Order
65-
* @throws ApiException
66-
* if fails to make API call
70+
* @throws OpenApiRequestException
71+
* if an error occurs while attempting to invoke the API
6772
*/
68-
public Order ordersPost( @javax.annotation.Nonnull Order order, Map<String, String> additionalHeaders )
69-
throws ApiException
73+
@Nonnull
74+
public Order ordersPost( @Nonnull final Order order )
75+
throws OpenApiRequestException
7076
{
71-
Object localVarPostBody = order;
77+
final Object localVarPostBody = order;
7278

7379
// verify the required parameter 'order' is set
7480
if( order == null ) {
75-
throw new ApiException(400, "Missing the required parameter 'order' when calling ordersPost");
81+
throw new OpenApiRequestException("Missing the required parameter 'order' when calling ordersPost")
82+
.statusCode(400);
7683
}
7784

7885
// create path and map variables
79-
String localVarPath = "/orders";
86+
final String localVarPath = "/orders";
8087

81-
StringJoiner localVarQueryStringJoiner = new StringJoiner("&");
88+
final StringJoiner localVarQueryStringJoiner = new StringJoiner("&");
8289
String localVarQueryParameterBaseName;
83-
List<Pair> localVarQueryParams = new ArrayList<Pair>();
84-
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
85-
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
86-
Map<String, String> localVarCookieParams = new HashMap<String, String>();
87-
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
88-
89-
localVarHeaderParams.putAll(additionalHeaders);
90+
final List<Pair> localVarQueryParams = new ArrayList<Pair>();
91+
final List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
92+
final Map<String, String> localVarHeaderParams = new HashMap<String, String>();
93+
final Map<String, Object> localVarFormParams = new HashMap<String, Object>();
9094

9195
final String[] localVarAccepts = { "application/json" };
92-
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
96+
final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts);
9397

9498
final String[] localVarContentTypes = { "application/json" };
95-
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
96-
97-
String[] localVarAuthNames = new String[] { "apiKeyAuth" };
99+
final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes);
98100

99-
TypeReference<Order> localVarReturnType = new TypeReference<Order>()
101+
final TypeReference<Order> localVarReturnType = new TypeReference<Order>()
100102
{
101103
};
102104
return apiClient
@@ -108,55 +110,9 @@ public Order ordersPost( @javax.annotation.Nonnull Order order, Map<String, Stri
108110
localVarQueryStringJoiner.toString(),
109111
localVarPostBody,
110112
localVarHeaderParams,
111-
localVarCookieParams,
112113
localVarFormParams,
113114
localVarAccept,
114115
localVarContentType,
115-
localVarAuthNames,
116116
localVarReturnType);
117117
}
118-
119-
@Override
120-
public <T> T invokeAPI(
121-
String url,
122-
String method,
123-
Object request,
124-
TypeReference<T> returnType,
125-
Map<String, String> additionalHeaders )
126-
throws ApiException
127-
{
128-
String localVarPath = url.replace(apiClient.getBaseURL(), "");
129-
StringJoiner localVarQueryStringJoiner = new StringJoiner("&");
130-
List<Pair> localVarQueryParams = new ArrayList<Pair>();
131-
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
132-
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
133-
Map<String, String> localVarCookieParams = new HashMap<String, String>();
134-
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
135-
136-
localVarHeaderParams.putAll(additionalHeaders);
137-
138-
final String[] localVarAccepts = { "application/json" };
139-
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
140-
141-
final String[] localVarContentTypes = { "application/json" };
142-
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
143-
144-
String[] localVarAuthNames = new String[] { "apiKeyAuth" };
145-
146-
return apiClient
147-
.invokeAPI(
148-
localVarPath,
149-
method,
150-
localVarQueryParams,
151-
localVarCollectionQueryParams,
152-
localVarQueryStringJoiner.toString(),
153-
request,
154-
localVarHeaderParams,
155-
localVarCookieParams,
156-
localVarFormParams,
157-
localVarAccept,
158-
localVarContentType,
159-
localVarAuthNames,
160-
returnType);
161-
}
162118
}

0 commit comments

Comments
 (0)