Skip to content

Commit 859a8f1

Browse files
authored
feat: [OpenAPI] Part 2: Testing Apache Client Support and some fixes. (#1062)
Moving to single larger PR (sorry), because its getting difficult to sync changes across. Both PRs have been thoroughly review at this point.
1 parent d8a945e commit 859a8f1

File tree

80 files changed

+10927
-479
lines changed

Some content is hidden

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

80 files changed

+10927
-479
lines changed

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

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,36 @@
4747
<groupId>com.fasterxml.jackson.core</groupId>
4848
<artifactId>jackson-annotations</artifactId>
4949
</dependency>
50+
<!-- test dependencies -->
51+
<dependency>
52+
<groupId>org.junit.jupiter</groupId>
53+
<artifactId>junit-jupiter-api</artifactId>
54+
<scope>test</scope>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.wiremock</groupId>
58+
<artifactId>wiremock</artifactId>
59+
<scope>test</scope>
60+
</dependency>
61+
<dependency>
62+
<groupId>org.assertj</groupId>
63+
<artifactId>assertj-core</artifactId>
64+
<scope>test</scope>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.junit.jupiter</groupId>
68+
<artifactId>junit-jupiter-params</artifactId>
69+
</dependency>
70+
<dependency>
71+
<groupId>com.fasterxml.jackson.core</groupId>
72+
<artifactId>jackson-databind</artifactId>
73+
<scope>test</scope>
74+
</dependency>
75+
<dependency>
76+
<groupId>com.fasterxml.jackson.datatype</groupId>
77+
<artifactId>jackson-datatype-jsr310</artifactId>
78+
<scope>test</scope>
79+
</dependency>
5080
</dependencies>
5181
<build>
5282
<plugins>
@@ -82,11 +112,11 @@
82112
<phase>generate-sources</phase>
83113
<configuration>
84114
<inputSpec>${project.basedir}/src/main/resources/sodastore.yaml</inputSpec>
85-
<apiPackage>com.sap.cloud.sdk.datamodel.openapi.apache.sample.api</apiPackage>
86-
<modelPackage>com.sap.cloud.sdk.datamodel.openapi.apache.sample.model</modelPackage>
115+
<apiPackage>com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.api</apiPackage>
116+
<modelPackage>com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model</modelPackage>
117+
<typeMappings>File=byte[]</typeMappings>
87118
<additionalProperties>
88119
<library>apache-httpclient</library>
89-
<supportUrlQuery>false</supportUrlQuery>
90120
<pojoBuilderMethodName>create</pojoBuilderMethodName>
91121
<pojoConstructorVisibility>protected</pojoConstructorVisibility>
92122
<useOneOfInterfaces>true</useOneOfInterfaces>

datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/petstore/api/DefaultApi.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ public Pet addPet( @Nonnull final PetInput pet )
9898

9999
final String[] localVarAccepts = { "application/json" };
100100
final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts);
101-
102101
final String[] localVarContentTypes = { "application/json" };
103102
final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes);
104103

105104
final TypeReference<Pet> localVarReturnType = new TypeReference<Pet>()
106105
{
107106
};
107+
108108
return apiClient
109109
.invokeAPI(
110110
localVarPath,
@@ -159,7 +159,6 @@ public OpenApiResponse deletePet( @Nonnull final Long id )
159159

160160
final String[] localVarAccepts = { "application/json" };
161161
final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts);
162-
163162
final String[] localVarContentTypes = {
164163

165164
};
@@ -168,6 +167,7 @@ public OpenApiResponse deletePet( @Nonnull final Long id )
168167
final TypeReference<OpenApiResponse> localVarReturnType = new TypeReference<OpenApiResponse>()
169168
{
170169
};
170+
171171
return apiClient
172172
.invokeAPI(
173173
localVarPath,
@@ -222,7 +222,6 @@ public Pet findPetById( @Nonnull final Long id )
222222

223223
final String[] localVarAccepts = { "application/json", "application/xml", "text/xml", "text/html" };
224224
final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts);
225-
226225
final String[] localVarContentTypes = {
227226

228227
};
@@ -231,6 +230,7 @@ public Pet findPetById( @Nonnull final Long id )
231230
final TypeReference<Pet> localVarReturnType = new TypeReference<Pet>()
232231
{
233232
};
233+
234234
return apiClient
235235
.invokeAPI(
236236
localVarPath,
@@ -283,7 +283,6 @@ public List<Pet> findPets( @Nullable final List<String> tags, @Nullable final In
283283

284284
final String[] localVarAccepts = { "application/json", "application/xml", "text/xml", "text/html" };
285285
final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts);
286-
287286
final String[] localVarContentTypes = {
288287

289288
};
@@ -292,6 +291,7 @@ public List<Pet> findPets( @Nullable final List<String> tags, @Nullable final In
292291
final TypeReference<List<Pet>> localVarReturnType = new TypeReference<List<Pet>>()
293292
{
294293
};
294+
295295
return apiClient
296296
.invokeAPI(
297297
localVarPath,

datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/petstore/model/ErrorModel.java

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@
1515

1616
package com.sap.cloud.sdk.datamodel.openapi.apache.petstore.model;
1717

18-
import java.io.UnsupportedEncodingException;
19-
import java.net.URLEncoder;
2018
import java.util.LinkedHashMap;
2119
import java.util.Map;
2220
import java.util.NoSuchElementException;
2321
import java.util.Objects;
2422
import java.util.Set;
25-
import java.util.StringJoiner;
2623

2724
import javax.annotation.Nonnull;
2825
import javax.annotation.Nullable;
@@ -232,78 +229,4 @@ private String toIndentedString( final java.lang.Object o )
232229
return o.toString().replace("\n", "\n ");
233230
}
234231

235-
/**
236-
* Convert the instance into URL query string.
237-
*
238-
* @return URL query string
239-
*/
240-
public String toUrlQueryString()
241-
{
242-
return toUrlQueryString(null);
243-
}
244-
245-
/**
246-
* Convert the instance into URL query string.
247-
*
248-
* @param prefix
249-
* prefix of the query string
250-
* @return URL query string
251-
*/
252-
public String toUrlQueryString( String prefix )
253-
{
254-
String suffix = "";
255-
String containerSuffix = "";
256-
String containerPrefix = "";
257-
if( prefix == null ) {
258-
// style=form, explode=true, e.g. /pet?name=cat&type=manx
259-
prefix = "";
260-
} else {
261-
// deepObject style e.g. /pet?id[name]=cat&id[type]=manx
262-
prefix = prefix + "[";
263-
suffix = "]";
264-
containerSuffix = "]";
265-
containerPrefix = "[";
266-
}
267-
268-
StringJoiner joiner = new StringJoiner("&");
269-
270-
// add `code` to the URL query string
271-
if( getCode() != null ) {
272-
try {
273-
joiner
274-
.add(
275-
String
276-
.format(
277-
"%scode%s=%s",
278-
prefix,
279-
suffix,
280-
URLEncoder.encode(String.valueOf(getCode()), "UTF-8").replaceAll("\\+", "%20")));
281-
}
282-
catch( UnsupportedEncodingException e ) {
283-
// Should never happen, UTF-8 is always supported
284-
throw new RuntimeException(e);
285-
}
286-
}
287-
288-
// add `message` to the URL query string
289-
if( getMessage() != null ) {
290-
try {
291-
joiner
292-
.add(
293-
String
294-
.format(
295-
"%smessage%s=%s",
296-
prefix,
297-
suffix,
298-
URLEncoder.encode(String.valueOf(getMessage()), "UTF-8").replaceAll("\\+", "%20")));
299-
}
300-
catch( UnsupportedEncodingException e ) {
301-
// Should never happen, UTF-8 is always supported
302-
throw new RuntimeException(e);
303-
}
304-
}
305-
306-
return joiner.toString();
307-
}
308-
309232
}

datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/petstore/model/Pet.java

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@
1515

1616
package com.sap.cloud.sdk.datamodel.openapi.apache.petstore.model;
1717

18-
import java.io.UnsupportedEncodingException;
19-
import java.net.URLEncoder;
2018
import java.util.LinkedHashMap;
2119
import java.util.Map;
2220
import java.util.NoSuchElementException;
2321
import java.util.Objects;
2422
import java.util.Set;
25-
import java.util.StringJoiner;
2623

2724
import javax.annotation.Nonnull;
2825
import javax.annotation.Nullable;
@@ -275,96 +272,4 @@ private String toIndentedString( final java.lang.Object o )
275272
return o.toString().replace("\n", "\n ");
276273
}
277274

278-
/**
279-
* Convert the instance into URL query string.
280-
*
281-
* @return URL query string
282-
*/
283-
public String toUrlQueryString()
284-
{
285-
return toUrlQueryString(null);
286-
}
287-
288-
/**
289-
* Convert the instance into URL query string.
290-
*
291-
* @param prefix
292-
* prefix of the query string
293-
* @return URL query string
294-
*/
295-
public String toUrlQueryString( String prefix )
296-
{
297-
String suffix = "";
298-
String containerSuffix = "";
299-
String containerPrefix = "";
300-
if( prefix == null ) {
301-
// style=form, explode=true, e.g. /pet?name=cat&type=manx
302-
prefix = "";
303-
} else {
304-
// deepObject style e.g. /pet?id[name]=cat&id[type]=manx
305-
prefix = prefix + "[";
306-
suffix = "]";
307-
containerSuffix = "]";
308-
containerPrefix = "[";
309-
}
310-
311-
StringJoiner joiner = new StringJoiner("&");
312-
313-
// add `id` to the URL query string
314-
if( getId() != null ) {
315-
try {
316-
joiner
317-
.add(
318-
String
319-
.format(
320-
"%sid%s=%s",
321-
prefix,
322-
suffix,
323-
URLEncoder.encode(String.valueOf(getId()), "UTF-8").replaceAll("\\+", "%20")));
324-
}
325-
catch( UnsupportedEncodingException e ) {
326-
// Should never happen, UTF-8 is always supported
327-
throw new RuntimeException(e);
328-
}
329-
}
330-
331-
// add `name` to the URL query string
332-
if( getName() != null ) {
333-
try {
334-
joiner
335-
.add(
336-
String
337-
.format(
338-
"%sname%s=%s",
339-
prefix,
340-
suffix,
341-
URLEncoder.encode(String.valueOf(getName()), "UTF-8").replaceAll("\\+", "%20")));
342-
}
343-
catch( UnsupportedEncodingException e ) {
344-
// Should never happen, UTF-8 is always supported
345-
throw new RuntimeException(e);
346-
}
347-
}
348-
349-
// add `tag` to the URL query string
350-
if( getTag() != null ) {
351-
try {
352-
joiner
353-
.add(
354-
String
355-
.format(
356-
"%stag%s=%s",
357-
prefix,
358-
suffix,
359-
URLEncoder.encode(String.valueOf(getTag()), "UTF-8").replaceAll("\\+", "%20")));
360-
}
361-
catch( UnsupportedEncodingException e ) {
362-
// Should never happen, UTF-8 is always supported
363-
throw new RuntimeException(e);
364-
}
365-
}
366-
367-
return joiner.toString();
368-
}
369-
370275
}

0 commit comments

Comments
 (0)