Skip to content

Commit 053385a

Browse files
authored
fix: [openapi-generator-plugin] Resolve Jackson Dependency Convergence (#906)
1 parent 9963244 commit 053385a

9 files changed

Lines changed: 1437 additions & 20 deletions

File tree

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

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,29 +102,44 @@
102102
<artifactId>openapi-generator-maven-plugin</artifactId>
103103
<executions>
104104
<execution>
105+
<id>sample-swagger-v2</id>
105106
<phase>generate-sources</phase>
106107
<goals>
107108
<goal>generate</goal>
108109
</goals>
110+
<configuration>
111+
<inputSpec>${project.basedir}/src/main/resources/petstore-swagger2.json</inputSpec>
112+
<apiPackage>com.sap.cloud.sdk.datamodel.openapi.petstore.api</apiPackage>
113+
<modelPackage>com.sap.cloud.sdk.datamodel.openapi.petstore.model</modelPackage>
114+
</configuration>
115+
</execution>
116+
<execution>
117+
<id>sample-openapi-v3</id>
118+
<phase>generate-sources</phase>
119+
<goals>
120+
<goal>generate</goal>
121+
</goals>
122+
<configuration>
123+
<inputSpec>${project.basedir}/src/main/resources/sodastore.yaml</inputSpec>
124+
<apiPackage>com.sap.cloud.sdk.datamodel.openapi.sample.api</apiPackage>
125+
<modelPackage>com.sap.cloud.sdk.datamodel.openapi.sample.model</modelPackage>
126+
<additionalProperties>
127+
<pojoBuilderMethodName>create</pojoBuilderMethodName>
128+
<pojoBuildMethodName />
129+
<pojoConstructorVisibility>protected</pojoConstructorVisibility>
130+
<useOneOfInterfaces>true</useOneOfInterfaces>
131+
<useOneOfCreators>true</useOneOfCreators>
132+
<enumUnknownDefaultCase>true</enumUnknownDefaultCase>
133+
</additionalProperties>
134+
<sapCopyrightHeader>true</sapCopyrightHeader>
135+
<enableOneOfAnyOfGeneration>true</enableOneOfAnyOfGeneration>
136+
</configuration>
109137
</execution>
110138
</executions>
111139
<configuration>
112-
<inputSpec>${project.basedir}/src/main/resources/sodastore.yaml</inputSpec>
113-
<apiPackage>com.sap.cloud.sdk.datamodel.openapi.sample.api</apiPackage>
114-
<modelPackage>com.sap.cloud.sdk.datamodel.openapi.sample.model</modelPackage>
115140
<apiMaturity>released</apiMaturity>
116141
<deleteOutputDirectory>true</deleteOutputDirectory>
117142
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
118-
<sapCopyrightHeader>true</sapCopyrightHeader>
119-
<additionalProperties>
120-
<pojoBuilderMethodName>create</pojoBuilderMethodName>
121-
<pojoBuildMethodName />
122-
<pojoConstructorVisibility>protected</pojoConstructorVisibility>
123-
<useOneOfInterfaces>true</useOneOfInterfaces>
124-
<useOneOfCreators>true</useOneOfCreators>
125-
<enumUnknownDefaultCase>true</enumUnknownDefaultCase>
126-
</additionalProperties>
127-
<enableOneOfAnyOfGeneration>true</enableOneOfAnyOfGeneration>
128143
</configuration>
129144
</plugin>
130145
<!-- Enable formatter to always run on the generated code -->
Lines changed: 330 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,330 @@
1+
/*
2+
* Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved.
3+
*/
4+
5+
package com.sap.cloud.sdk.datamodel.openapi.petstore.api;
6+
7+
import java.util.HashMap;
8+
import java.util.List;
9+
import java.util.Locale;
10+
import java.util.Map;
11+
12+
import javax.annotation.Nonnull;
13+
import javax.annotation.Nullable;
14+
15+
import org.springframework.core.ParameterizedTypeReference;
16+
import org.springframework.http.HttpHeaders;
17+
import org.springframework.http.HttpMethod;
18+
import org.springframework.http.MediaType;
19+
import org.springframework.util.LinkedMultiValueMap;
20+
import org.springframework.util.MultiValueMap;
21+
import org.springframework.web.util.UriComponentsBuilder;
22+
23+
import com.google.common.annotations.Beta;
24+
import com.sap.cloud.sdk.cloudplatform.connectivity.Destination;
25+
import com.sap.cloud.sdk.datamodel.openapi.petstore.model.Pet;
26+
import com.sap.cloud.sdk.datamodel.openapi.petstore.model.PetInput;
27+
import com.sap.cloud.sdk.services.openapi.apiclient.ApiClient;
28+
import com.sap.cloud.sdk.services.openapi.core.AbstractOpenApiService;
29+
import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException;
30+
import com.sap.cloud.sdk.services.openapi.core.OpenApiResponse;
31+
32+
/**
33+
* Swagger Petstore in version 1.0.0.
34+
*
35+
* A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification
36+
*/
37+
public class DefaultApi extends AbstractOpenApiService
38+
{
39+
/**
40+
* Instantiates this API class to invoke operations on the Swagger Petstore.
41+
*
42+
* @param httpDestination
43+
* The destination that API should be used with
44+
*/
45+
public DefaultApi( @Nonnull final Destination httpDestination )
46+
{
47+
super(httpDestination);
48+
}
49+
50+
/**
51+
* Instantiates this API class to invoke operations on the Swagger Petstore based on a given {@link ApiClient}.
52+
*
53+
* @param apiClient
54+
* ApiClient to invoke the API on
55+
*/
56+
@Beta
57+
public DefaultApi( @Nonnull final ApiClient apiClient )
58+
{
59+
super(apiClient);
60+
}
61+
62+
/**
63+
* <p>
64+
* </p>
65+
* <p>
66+
* Creates a new pet in the store. Duplicates are allowed
67+
* </p>
68+
* <p>
69+
* <b>200</b> - pet response
70+
* <p>
71+
* <b>0</b> - unexpected error
72+
*
73+
* @param pet
74+
* Pet to add to the store
75+
* @return Pet
76+
* @throws OpenApiRequestException
77+
* if an error occurs while attempting to invoke the API
78+
*/
79+
@Nonnull
80+
public Pet addPet( @Nonnull final PetInput pet )
81+
throws OpenApiRequestException
82+
{
83+
final Object localVarPostBody = pet;
84+
85+
// verify the required parameter 'pet' is set
86+
if( pet == null ) {
87+
throw new OpenApiRequestException("Missing the required parameter 'pet' when calling addPet");
88+
}
89+
90+
final String localVarPath = UriComponentsBuilder.fromPath("/pets").build().toUriString();
91+
92+
final MultiValueMap<String, String> localVarQueryParams = new LinkedMultiValueMap<String, String>();
93+
final HttpHeaders localVarHeaderParams = new HttpHeaders();
94+
final MultiValueMap<String, Object> localVarFormParams = new LinkedMultiValueMap<String, Object>();
95+
96+
final String[] localVarAccepts = { "application/json" };
97+
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
98+
final String[] localVarContentTypes = { "application/json" };
99+
final MediaType localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
100+
101+
final String[] localVarAuthNames = new String[] {};
102+
103+
final ParameterizedTypeReference<Pet> localVarReturnType = new ParameterizedTypeReference<Pet>()
104+
{
105+
};
106+
return apiClient
107+
.invokeAPI(
108+
localVarPath,
109+
HttpMethod.POST,
110+
localVarQueryParams,
111+
localVarPostBody,
112+
localVarHeaderParams,
113+
localVarFormParams,
114+
localVarAccept,
115+
localVarContentType,
116+
localVarAuthNames,
117+
localVarReturnType);
118+
}
119+
120+
/**
121+
* <p>
122+
* </p>
123+
* <p>
124+
* deletes a single pet based on the ID supplied
125+
* </p>
126+
* <p>
127+
* <b>204</b> - pet deleted
128+
* <p>
129+
* <b>0</b> - unexpected error
130+
*
131+
* @param id
132+
* ID of pet to delete
133+
* @return An OpenApiResponse containing the status code of the HttpResponse.
134+
* @throws OpenApiRequestException
135+
* if an error occurs while attempting to invoke the API
136+
*/
137+
@Nonnull
138+
public OpenApiResponse deletePet( @Nonnull final Long id )
139+
throws OpenApiRequestException
140+
{
141+
final Object localVarPostBody = null;
142+
143+
// verify the required parameter 'id' is set
144+
if( id == null ) {
145+
throw new OpenApiRequestException("Missing the required parameter 'id' when calling deletePet");
146+
}
147+
148+
// create path and map variables
149+
final Map<String, Object> localVarPathParams = new HashMap<String, Object>();
150+
localVarPathParams.put("id", id);
151+
final String localVarPath =
152+
UriComponentsBuilder.fromPath("/pets/{id}").buildAndExpand(localVarPathParams).toUriString();
153+
154+
final MultiValueMap<String, String> localVarQueryParams = new LinkedMultiValueMap<String, String>();
155+
final HttpHeaders localVarHeaderParams = new HttpHeaders();
156+
final MultiValueMap<String, Object> localVarFormParams = new LinkedMultiValueMap<String, Object>();
157+
158+
final String[] localVarAccepts = { "application/json" };
159+
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
160+
final String[] localVarContentTypes = {};
161+
final MediaType localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
162+
163+
final String[] localVarAuthNames = new String[] {};
164+
165+
final ParameterizedTypeReference<Void> localVarReturnType = new ParameterizedTypeReference<Void>()
166+
{
167+
};
168+
apiClient
169+
.invokeAPI(
170+
localVarPath,
171+
HttpMethod.DELETE,
172+
localVarQueryParams,
173+
localVarPostBody,
174+
localVarHeaderParams,
175+
localVarFormParams,
176+
localVarAccept,
177+
localVarContentType,
178+
localVarAuthNames,
179+
localVarReturnType);
180+
return new OpenApiResponse(apiClient);
181+
}
182+
183+
/**
184+
* <p>
185+
* </p>
186+
* <p>
187+
* Returns a user based on a single ID, if the user does not have access to the pet
188+
* </p>
189+
* <p>
190+
* <b>200</b> - pet response
191+
* <p>
192+
* <b>0</b> - unexpected error
193+
*
194+
* @param id
195+
* ID of pet to fetch
196+
* @return Pet
197+
* @throws OpenApiRequestException
198+
* if an error occurs while attempting to invoke the API
199+
*/
200+
@Nonnull
201+
public Pet findPetById( @Nonnull final Long id )
202+
throws OpenApiRequestException
203+
{
204+
final Object localVarPostBody = null;
205+
206+
// verify the required parameter 'id' is set
207+
if( id == null ) {
208+
throw new OpenApiRequestException("Missing the required parameter 'id' when calling findPetById");
209+
}
210+
211+
// create path and map variables
212+
final Map<String, Object> localVarPathParams = new HashMap<String, Object>();
213+
localVarPathParams.put("id", id);
214+
final String localVarPath =
215+
UriComponentsBuilder.fromPath("/pets/{id}").buildAndExpand(localVarPathParams).toUriString();
216+
217+
final MultiValueMap<String, String> localVarQueryParams = new LinkedMultiValueMap<String, String>();
218+
final HttpHeaders localVarHeaderParams = new HttpHeaders();
219+
final MultiValueMap<String, Object> localVarFormParams = new LinkedMultiValueMap<String, Object>();
220+
221+
final String[] localVarAccepts = { "application/json", "application/xml", "text/xml", "text/html" };
222+
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
223+
final String[] localVarContentTypes = {};
224+
final MediaType localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
225+
226+
final String[] localVarAuthNames = new String[] {};
227+
228+
final ParameterizedTypeReference<Pet> localVarReturnType = new ParameterizedTypeReference<Pet>()
229+
{
230+
};
231+
return apiClient
232+
.invokeAPI(
233+
localVarPath,
234+
HttpMethod.GET,
235+
localVarQueryParams,
236+
localVarPostBody,
237+
localVarHeaderParams,
238+
localVarFormParams,
239+
localVarAccept,
240+
localVarContentType,
241+
localVarAuthNames,
242+
localVarReturnType);
243+
}
244+
245+
/**
246+
* <p>
247+
* </p>
248+
* <p>
249+
* Returns all pets from the system that the user has access to
250+
* </p>
251+
* <p>
252+
* <b>200</b> - pet response
253+
* <p>
254+
* <b>0</b> - unexpected error
255+
*
256+
* @param tags
257+
* (optional tags to filter by
258+
* @param limit
259+
* (optional) maximum number of results to return
260+
* @return List&lt;Pet&gt;
261+
* @throws OpenApiRequestException
262+
* if an error occurs while attempting to invoke the API
263+
*/
264+
@Nonnull
265+
public List<Pet> findPets( @Nullable final List<String> tags, @Nullable final Integer limit )
266+
throws OpenApiRequestException
267+
{
268+
final Object localVarPostBody = null;
269+
270+
final String localVarPath = UriComponentsBuilder.fromPath("/pets").build().toUriString();
271+
272+
final MultiValueMap<String, String> localVarQueryParams = new LinkedMultiValueMap<String, String>();
273+
final HttpHeaders localVarHeaderParams = new HttpHeaders();
274+
final MultiValueMap<String, Object> localVarFormParams = new LinkedMultiValueMap<String, Object>();
275+
276+
localVarQueryParams
277+
.putAll(
278+
apiClient
279+
.parameterToMultiValueMap(
280+
ApiClient.CollectionFormat.valueOf("csv".toUpperCase(Locale.ROOT)),
281+
"tags",
282+
tags));
283+
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "limit", limit));
284+
285+
final String[] localVarAccepts = { "application/json", "application/xml", "text/xml", "text/html" };
286+
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
287+
final String[] localVarContentTypes = {};
288+
final MediaType localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
289+
290+
final String[] localVarAuthNames = new String[] {};
291+
292+
final ParameterizedTypeReference<List<Pet>> localVarReturnType = new ParameterizedTypeReference<List<Pet>>()
293+
{
294+
};
295+
return apiClient
296+
.invokeAPI(
297+
localVarPath,
298+
HttpMethod.GET,
299+
localVarQueryParams,
300+
localVarPostBody,
301+
localVarHeaderParams,
302+
localVarFormParams,
303+
localVarAccept,
304+
localVarContentType,
305+
localVarAuthNames,
306+
localVarReturnType);
307+
}
308+
309+
/**
310+
* <p>
311+
* </p>
312+
* <p>
313+
* Returns all pets from the system that the user has access to
314+
* </p>
315+
* <p>
316+
* <b>200</b> - pet response
317+
* <p>
318+
* <b>0</b> - unexpected error
319+
*
320+
* @return List&lt;Pet&gt;
321+
* @throws OpenApiRequestException
322+
* if an error occurs while attempting to invoke the API
323+
*/
324+
@Nonnull
325+
public List<Pet> findPets()
326+
throws OpenApiRequestException
327+
{
328+
return findPets(null, null);
329+
}
330+
}

0 commit comments

Comments
 (0)